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;
48 indexKind(indexKind), intrType(intrType) {}
57 switch (op.getDimension()) {
58 case gpu::Dimension::x:
61 case gpu::Dimension::y:
64 case gpu::Dimension::z:
76 if (
auto funcOp = op->template getParentOfType<FunctionOpInterface>()) {
80 gpu::GPUDialect::KnownBlockSizeAttrHelper(op.
getContext());
81 if (blockHelper.isAttrPresent(funcOp))
82 funcBounds = blockHelper.getAttr(funcOp);
87 gpu::GPUDialect::KnownGridSizeAttrHelper(op.
getContext());
88 if (gridHelper.isAttrPresent(funcOp))
89 funcBounds = gridHelper.getAttr(funcOp);
96 if (
auto gpuFunc = op->template getParentOfType<gpu::GPUFuncOp>()) {
99 funcBounds = gpuFunc.getKnownBlockSizeAttr();
102 funcBounds = gpuFunc.getKnownGridSizeAttr();
108 std::optional<int32_t> upperBound;
111 funcBounds.
asArrayRef()[
static_cast<uint32_t
>(op.getDimension())];
112 if (
auto opBound = op.getUpperBound())
113 upperBound = opBound->getZExtValue();
121 if (indexBitwidth > 32) {
122 newOp = rewriter.
create<LLVM::SExtOp>(
124 }
else if (indexBitwidth < 32) {
125 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()
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)
LogicalResult matchAndRewrite(Op op, typename Op::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override
OpLowering(const LLVMTypeConverter &typeConverter, IndexKind indexKind, IntrType intrType)