8 #ifndef MLIR_CONVERSION_GPUCOMMON_INDEXINTRINSICSOPLOWERING_H_
9 #define MLIR_CONVERSION_GPUCOMMON_INDEXINTRINSICSOPLOWERING_H_
23 template <
typename Op,
typename XOp,
typename YOp,
typename ZOp>
26 unsigned indexBitwidth;
27 StringRef boundsAttrName;
36 StringRef boundsAttrName)
39 boundsAttrName(boundsAttrName) {}
45 auto loc = op->getLoc();
48 switch (op.getDimension()) {
49 case gpu::Dimension::x:
52 case gpu::Dimension::y:
55 case gpu::Dimension::z:
61 if (
auto gpuFunc = op->template getParentOfType<gpu::GPUFuncOp>())
63 if (
auto llvmFunc = op->template getParentOfType<LLVM::LLVMFuncOp>())
65 if (!boundsAttrName.empty() &&
function) {
66 if (
auto attr = function->template getAttrOfType<DenseI32ArrayAttr>(
68 int32_t maximum = attr[
static_cast<uint32_t
>(op.getDimension())];
73 if (indexBitwidth > 32) {
74 newOp = rewriter.create<LLVM::SExtOp>(
76 }
else if (indexBitwidth < 32) {
77 newOp = rewriter.create<LLVM::TruncOp>(
81 rewriter.replaceOp(op, newOp->getResults());
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
MLIRContext * getContext() const
This class implements a pattern rewriter for use with ConversionPatterns.
const TypeConverter * typeConverter
An optional type converter for use by this pattern.
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Conversion from types to the LLVM IR dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This provides public APIs that all operations should have.
Operation is the basic unit of execution within MLIR.
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
Include the generated interface declarations.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
GPUIndexIntrinsicOpLowering(LLVMTypeConverter &typeConverter)
LogicalResult matchAndRewrite(Op op, typename Op::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override
GPUIndexIntrinsicOpLowering(LLVMTypeConverter &typeConverter, StringRef boundsAttrName)
This class represents an efficient way to signal success or failure.