8 #ifndef MLIR_CONVERSION_GPUCOMMON_INDEXINTRINSICSOPLOWERING_H_
9 #define MLIR_CONVERSION_GPUCOMMON_INDEXINTRINSICSOPLOWERING_H_
18 namespace index_lowering {
31 template <
typename Op,
typename XOp,
typename YOp,
typename ZOp>
34 unsigned indexBitwidth;
50 indexKind(indexKind), intrType(intrType) {}
59 switch (op.getDimension()) {
60 case gpu::Dimension::x:
63 case gpu::Dimension::y:
66 case gpu::Dimension::z:
78 if (
auto funcOp = op->template getParentOfType<FunctionOpInterface>()) {
82 gpu::GPUDialect::KnownBlockSizeAttrHelper(op.
getContext());
83 if (blockHelper.isAttrPresent(funcOp))
84 funcBounds = blockHelper.getAttr(funcOp);
89 gpu::GPUDialect::KnownGridSizeAttrHelper(op.
getContext());
90 if (gridHelper.isAttrPresent(funcOp))
91 funcBounds = gridHelper.getAttr(funcOp);
98 if (
auto gpuFunc = op->template getParentOfType<gpu::GPUFuncOp>()) {
101 funcBounds = gpuFunc.getKnownBlockSizeAttr();
104 funcBounds = gpuFunc.getKnownGridSizeAttr();
110 std::optional<int32_t> upperBound;
113 funcBounds.
asArrayRef()[
static_cast<uint32_t
>(op.getDimension())];
114 if (
auto opBound = op.getUpperBound())
115 upperBound = opBound->getZExtValue();
123 if (indexBitwidth > 32) {
124 newOp = rewriter.
create<LLVM::SExtOp>(
126 }
else if (indexBitwidth < 32) {
127 newOp = rewriter.
create<LLVM::TruncOp>(
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
Block represents an ordered list of Operations.
MLIRContext * getContext() const
This class implements a pattern rewriter for use with ConversionPatterns.
void replaceOp(Operation *op, ValueRange newValues) override
Replace the given operation with the new values.
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.
MLIRContext * getContext()
Return the context this operation belongs to.
Location getLoc()
The source location the operation was defined or derived from.
This provides public APIs that all operations should have.
Operation is the basic unit of execution within MLIR.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
result_range getResults()
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
ArrayRef< T > asArrayRef() const
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
OpLowering(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
LogicalResult matchAndRewrite(Op op, typename Op::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override
OpLowering(const LLVMTypeConverter &typeConverter, IndexKind indexKind, IntrType intrType, PatternBenefit benefit=1)