58#define GEN_PASS_DEF_CONVERTGPUOPSTOROCDLOPS
59#include "mlir/Conversion/Passes.h.inc"
71 auto indexBitwidthType =
74 if (indexBitwidth > intWidth) {
75 return LLVM::SExtOp::create(rewriter, loc, indexBitwidthType, value);
77 if (indexBitwidth < intWidth) {
78 return LLVM::TruncOp::create(rewriter, loc, indexBitwidthType, value);
86 bool canBeBare =
true;
87 for (
Type type :
func.getArgumentTypes())
88 if (
auto memrefTy = dyn_cast<BaseMemRefType>(type))
94 auto int32Type = IntegerType::get(rewriter.
getContext(), 32);
98 LLVM::LLVMDialect::getNoUndefAttrName(), rewriter.
getUnitAttr());
100 LLVM::LLVMDialect::getRangeAttrName(),
101 LLVM::ConstantRangeAttr::get(rewriter.
getContext(), APInt::getZero(32),
104 LLVM::LLVMDialect::getRangeAttrName(),
105 LLVM::ConstantRangeAttr::get(rewriter.
getContext(), APInt::getZero(32),
107 Value mbcntLo = ROCDL::MbcntLoOp::create(
108 rewriter, loc, int32Type, minus1, zero, {},
111 Value laneId = ROCDL::MbcntHiOp::create(
112 rewriter, loc, int32Type, minus1, mbcntLo, {},
126 gpu::Dimension dim,
Operation *contextOp,
127 std::optional<uint32_t> opUpperBound) {
131 auto i32Ty = IntegerType::get(context, 32);
132 auto i64Ty = IntegerType::get(context, 64);
134 if (std::optional<uint32_t> knownDim =
136 return LLVM::ConstantOp::create(rewriter, loc,
139 int32_t dimParam =
static_cast<int32_t
>(dim);
141 StringRef functionName;
143 case gpu::index_lowering::IndexKind::Block:
144 functionName =
"__ockl_get_local_size";
146 case gpu::index_lowering::IndexKind::Grid:
147 functionName =
"__ockl_get_num_groups";
149 case gpu::index_lowering::IndexKind::Cluster:
150 case gpu::index_lowering::IndexKind::Other:
151 llvm_unreachable(
"Not valid index kinds for ockl lookup");
155 auto fnType = LLVM::LLVMFunctionType::get(i64Ty, {i32Ty});
157 LLVM::LLVMFuncOp funcOp =
161 Value dimConst = LLVM::ConstantOp::create(rewriter, loc, i32Ty, dimParam);
163 LLVM::CallOp::create(rewriter, loc, funcOp,
ValueRange{dimConst});
165 LLVM::ConstantRangeAttr range;
167 range = LLVM::ConstantRangeAttr::get(
168 context, APInt(64, 1),
169 APInt(64,
static_cast<uint64_t
>(*opUpperBound) + 1));
170 }
else if (indexKind == gpu::index_lowering::IndexKind::Block) {
172 range = LLVM::ConstantRangeAttr::get(context, APInt(64, 1),
177 rewriter.
getNamedAttr(LLVM::LLVMDialect::getRangeAttrName(), range))));
179 return callOp.getResult();
183 "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32"
184 "-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:"
186 "32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:"
187 "64-S32-A5-G1-ni:7:8:9";
193template <
typename OpTy>
200 matchAndRewrite(OpTy op,
typename OpTy::Adaptor adaptor,
201 ConversionPatternRewriter &rewriter)
const override {
204 std::optional<uint32_t> opUpperBound;
205 if (
auto bound = op.getUpperBound())
206 opUpperBound =
static_cast<uint32_t
>(bound->getZExtValue());
211 *this->getTypeConverter());
212 rewriter.replaceOp(op,
result);
224 matchAndRewrite(gpu::LaneIdOp op, gpu::LaneIdOp::Adaptor adaptor,
225 ConversionPatternRewriter &rewriter)
const override {
238 const unsigned indexBitwidth = getTypeConverter()->getIndexTypeBitwidth();
239 if (indexBitwidth > 32) {
240 laneId = LLVM::SExtOp::create(
241 rewriter, loc, IntegerType::get(context, indexBitwidth), laneId);
242 }
else if (indexBitwidth < 32) {
243 laneId = LLVM::TruncOp::create(
244 rewriter, loc, IntegerType::get(context, indexBitwidth), laneId);
246 rewriter.replaceOp(op, {laneId});
260 matchAndRewrite(gpu::SubgroupSizeOp op, gpu::SubgroupSizeOp::Adaptor adaptor,
261 ConversionPatternRewriter &rewriter)
const override {
262 LLVM::ConstantRangeAttr bounds =
nullptr;
263 bool isWave64 =
target.getWavefrontSize() == 64;
264 if (
auto upperBoundAttr = op.getUpperBoundAttr()) {
265 bounds = rewriter.getAttr<LLVM::ConstantRangeAttr>(
266 32, isWave64 ? 64 : 32,
267 op.getUpperBoundAttr().getInt() + 1);
269 Value wavefrontOp = ROCDL::WavefrontSizeOp::create(
270 rewriter, op.getLoc(), rewriter.getI32Type(), bounds);
272 *getTypeConverter());
273 rewriter.replaceOp(op, {wavefrontOp});
288 matchAndRewrite(gpu::SubgroupIdOp op, gpu::SubgroupIdOp::Adaptor adaptor,
289 ConversionPatternRewriter &rewriter)
const override {
291 auto int32Type = rewriter.getI32Type();
294 if (
target.has(llvm::AMDGPU::FEAT_GFX12_INSTS)) {
296 LLVM::ConstantRangeAttr bounds;
297 if (
auto upperBoundAttr = op.getUpperBoundAttr())
298 bounds = rewriter.getAttr<LLVM::ConstantRangeAttr>(
300 upperBoundAttr.getInt());
301 subgroupId = ROCDL::WaveId::create(rewriter, loc, int32Type, bounds);
306 auto tidX = ROCDL::ThreadIdXOp::create(rewriter, loc, int32Type);
307 auto tidY = ROCDL::ThreadIdYOp::create(rewriter, loc, int32Type);
308 auto tidZ = ROCDL::ThreadIdZOp::create(rewriter, loc, int32Type);
309 auto setBoundFromContext = [&](
Operation *tidOp, gpu::Dimension dim) {
310 if (LLVM::ConstantRangeAttr range =
312 op, dim, std::nullopt,
313 gpu::index_lowering::IndexKind::Block,
317 setBoundFromContext(tidX, gpu::Dimension::x);
318 setBoundFromContext(tidY, gpu::Dimension::y);
319 setBoundFromContext(tidZ, gpu::Dimension::z);
322 LLVM::IntegerOverflowFlags::nsw | LLVM::IntegerOverflowFlags::nuw;
324 auto getBlockDim = [&](gpu::Dimension dim) {
327 dim, op, std::nullopt);
329 LLVM::TruncOp::create(rewriter, loc, int32Type, dim64, flags);
332 Value dimX = getBlockDim(gpu::Dimension::x);
333 Value dimY = getBlockDim(gpu::Dimension::y);
338 LLVM::MulOp::create(rewriter, loc, int32Type, dimY, tidZ, flags);
339 Value tidYPlusDimYxTidZ =
340 LLVM::AddOp::create(rewriter, loc, int32Type, tidY, dimYxTidZ, flags);
341 Value dimXxInner = LLVM::MulOp::create(rewriter, loc, int32Type, dimX,
342 tidYPlusDimYxTidZ, flags);
343 Value linearized = LLVM::AddOp::create(rewriter, loc, int32Type, tidX,
347 ROCDL::WavefrontSizeOp::create(rewriter, loc, int32Type);
348 subgroupId = LLVM::UDivOp::create(rewriter, loc, int32Type, linearized,
354 rewriter.replaceOp(op, subgroupId);
361static bool isSupportedReadLaneType(
Type type) {
363 if (isa<Float16Type, BFloat16Type, Float32Type, Float64Type,
364 LLVM::LLVMPointerType>(type))
367 if (
auto intType = dyn_cast<IntegerType>(type))
368 return llvm::is_contained({16, 32, 64},
369 static_cast<int>(intType.getWidth()));
371 if (
auto vecType = dyn_cast<VectorType>(type)) {
372 Type elementType = vecType.getElementType();
376 if (vecType.getNumElements() == 2 &&
377 (isa<Float16Type, BFloat16Type>(elementType) ||
385struct GPUSubgroupBroadcastOpToROCDL
390 matchAndRewrite(gpu::SubgroupBroadcastOp op, OpAdaptor adaptor,
391 ConversionPatternRewriter &rewriter)
const override {
392 Value src = adaptor.getSrc();
393 if (isSupportedReadLaneType(src.
getType())) {
394 Value result = createReadlaneOp(op, adaptor, rewriter, src);
395 rewriter.replaceOp(op,
result);
399 Type i32 = rewriter.getI32Type();
404 return rewriter.notifyMatchFailure(op,
405 "Unexpected decomposition failure");
408 results.reserve(decomposed.size());
409 for (
Value v : decomposed)
410 results.emplace_back(createReadlaneOp(op, adaptor, rewriter, v));
413 rewriter.replaceOp(op,
result);
418 static Value createReadlaneOp(gpu::SubgroupBroadcastOp op, OpAdaptor adaptor,
419 ConversionPatternRewriter &rewriter,
421 if (adaptor.getBroadcastType() == gpu::BroadcastType::specific_lane) {
422 return ROCDL::ReadlaneOp::create(rewriter, op.getLoc(), src.
getType(),
423 src, adaptor.getLane());
425 return ROCDL::ReadfirstlaneOp::create(rewriter, op.getLoc(),
435 matchAndRewrite(gpu::BallotOp op, gpu::BallotOp::Adaptor adaptor,
436 ConversionPatternRewriter &rewriter)
const override {
437 auto intType = cast<IntegerType>(op.getType());
438 unsigned width = intType.getWidth();
442 if (width != 32 && width != 64)
443 return rewriter.notifyMatchFailure(
444 op,
"rocdl.ballot only supports i32 and i64 result types");
446 rewriter.replaceOpWithNewOp<ROCDL::BallotOp>(op, op.getType(),
447 adaptor.getPredicate());
472 matchAndRewrite(gpu::ShuffleOp op, OpAdaptor adaptor,
473 ConversionPatternRewriter &rewriter)
const override {
475 Value initShflValue = adaptor.getValue();
479 auto int32Type = IntegerType::get(rewriter.getContext(), 32);
480 Value width = adaptor.getWidth();
481 Value zero = LLVM::ConstantOp::create(rewriter, loc, int32Type, 0);
482 Value negwidth = LLVM::SubOp::create(rewriter, loc, int32Type, zero, width);
483 Value add = LLVM::AddOp::create(rewriter, loc, int32Type, srcLaneId, width);
484 Value widthOrZeroIfOutside =
485 LLVM::AndOp::create(rewriter, loc, int32Type,
add, negwidth);
488 switch (op.getMode()) {
489 case gpu::ShuffleMode::UP:
490 dstLane = LLVM::SubOp::create(rewriter, loc, int32Type, srcLaneId,
491 adaptor.getOffset());
493 case gpu::ShuffleMode::DOWN:
494 dstLane = LLVM::AddOp::create(rewriter, loc, int32Type, srcLaneId,
495 adaptor.getOffset());
497 case gpu::ShuffleMode::XOR:
498 dstLane = LLVM::XOrOp::create(rewriter, loc, int32Type, srcLaneId,
499 adaptor.getOffset());
501 case gpu::ShuffleMode::IDX:
502 dstLane = adaptor.getOffset();
505 Value isActiveSrcLane = LLVM::ICmpOp::create(
506 rewriter, loc, LLVM::ICmpPredicate::slt, dstLane, widthOrZeroIfOutside);
507 Value selectDstLane = LLVM::SelectOp::create(rewriter, loc, isActiveSrcLane,
509 Value two = LLVM::ConstantOp::create(rewriter, loc, int32Type, 2);
510 Value dwordAlignedDstLane =
511 LLVM::ShlOp::create(rewriter, loc, int32Type, selectDstLane, two);
516 return rewriter.notifyMatchFailure(op,
517 "failed to decompose value to i32");
519 for (
Value v : decomposed) {
520 Value res = ROCDL::DsBpermuteOp::create(rewriter, loc, int32Type,
521 dwordAlignedDstLane, v);
522 swizzled.emplace_back(res);
526 rewriter.replaceOp(op, {shflValue, isActiveSrcLane});
533static void emitFences(std::optional<ArrayAttr> addrSpaces,
534 ConversionPatternRewriter &rewriter,
Location loc,
535 StringRef scope,
bool before) {
536 bool fenceGlobal =
false;
537 bool fenceLDS =
false;
540 for (
auto spaceAttr : addrSpaces->getAsRange<gpu::AddressSpaceAttr>()) {
541 switch (spaceAttr.getValue()) {
542 case gpu::AddressSpace::Global:
545 case gpu::AddressSpace::Workgroup:
548 case gpu::AddressSpace::Private:
549 case gpu::AddressSpace::Constant:
558 if (!fenceGlobal && !fenceLDS)
562 if (fenceLDS && !fenceGlobal)
564 rewriter.getAttr<LLVM::MMRATagAttr>(
"amdgpu-synchronize-as",
"local");
565 else if (fenceGlobal && !fenceLDS)
567 rewriter.getAttr<LLVM::MMRATagAttr>(
"amdgpu-synchronize-as",
"global");
570 before ? LLVM::AtomicOrdering::release : LLVM::AtomicOrdering::acquire;
571 auto fence = LLVM::FenceOp::create(rewriter, loc, ordering, scope);
573 fence->setDiscardableAttr(LLVM::LLVMDialect::getMmraAttrName(), mmra);
576static constexpr int32_t kWholeClusterBarrierId = -3;
577static constexpr int32_t kWholeWorkgroupBarrierId = -1;
586 matchAndRewrite(gpu::BarrierOp op, gpu::BarrierOp::Adaptor adaptor,
587 ConversionPatternRewriter &rewriter)
const override {
589 gpu::BarrierScope scope = op.getScope();
592 if (scope == gpu::BarrierScope::Subgroup) {
593 emitFences(op.getAddressSpaces(), rewriter, loc,
"wavefront",
595 ROCDL::WaveBarrierOp::create(rewriter, loc);
596 emitFences(op.getAddressSpaces(), rewriter, loc,
"wavefront",
598 rewriter.eraseOp(op);
603 if (scope == gpu::BarrierScope::Cluster) {
604 if (!
target.has(llvm::AMDGPU::FEAT_GFX1250_INSTS))
605 return op.emitOpError(
"cluster scope barriers require gfx1250+");
606 emitFences(op.getAddressSpaces(), rewriter, loc,
"cluster",
608 ROCDL::BarrierSignalOp::create(rewriter, loc, kWholeClusterBarrierId);
609 ROCDL::BarrierWaitOp::create(
610 rewriter, loc,
static_cast<int16_t
>(kWholeClusterBarrierId));
611 emitFences(op.getAddressSpaces(), rewriter, loc,
"cluster",
613 rewriter.eraseOp(op);
618 assert(scope == gpu::BarrierScope::Workgroup &&
"unsupported scope");
621 if (
Value namedBarrier = adaptor.getNamedBarrier()) {
622 if (!
target.has(llvm::AMDGPU::FEAT_GFX12_INSTS))
623 return op.emitOpError(
"named barriers require gfx12+");
625 emitFences(op.getAddressSpaces(), rewriter, loc,
"workgroup",
628 ROCDL::BarrierJoinOp::create(rewriter, loc, namedBarrier);
630 ROCDL::BarrierSignalVarOp::create(rewriter, loc, namedBarrier,
634 ROCDL::BarrierWaitOp::create(rewriter, loc,
static_cast<int16_t
>(1));
635 emitFences(op.getAddressSpaces(), rewriter, loc,
"workgroup",
637 rewriter.eraseOp(op);
642 emitFences(op.getAddressSpaces(), rewriter, loc,
"workgroup",
644 if (!
target.has(llvm::AMDGPU::FEAT_GFX12_INSTS)) {
645 ROCDL::SBarrierOp::create(rewriter, loc);
647 ROCDL::BarrierSignalOp::create(rewriter, loc, kWholeWorkgroupBarrierId);
648 ROCDL::BarrierWaitOp::create(
649 rewriter, loc,
static_cast<int16_t
>(kWholeWorkgroupBarrierId));
651 emitFences(op.getAddressSpaces(), rewriter, loc,
"workgroup",
653 rewriter.eraseOp(op);
658struct GPUInitializeNamedBarrierOpLowering final
668 matchAndRewrite(gpu::InitializeNamedBarrierOp op,
669 gpu::InitializeNamedBarrierOp::Adaptor adaptor,
670 ConversionPatternRewriter &rewriter)
const override {
671 if (!
target.has(llvm::AMDGPU::FEAT_GFX12_INSTS))
672 return op.emitOpError(
"named barriers require gfx12+");
677 IntegerAttr countAttr;
679 return op.emitOpError(
680 "named barrier member count must be a constant for ROCDL lowering");
681 int32_t count = countAttr.getInt();
685 auto funcOp = op->getParentOfType<FunctionOpInterface>();
687 return op.emitOpError(
"must be inside a function-like op");
691 return op.emitOpError(
692 "enclosing function-like op must have a symbol-table parent");
694 auto targetTy = LLVM::LLVMTargetExtType::get(
695 rewriter.getContext(),
"amdgcn.named.barrier", {}, {0});
696 auto ptrTy = LLVM::LLVMPointerType::get(
697 rewriter.getContext(), ROCDL::ROCDLDialect::kBarrierAddressSpace);
701 OpBuilder detachedBuilder(rewriter.getContext());
702 auto globalOp = LLVM::GlobalOp::create(
703 detachedBuilder, loc, targetTy,
false,
704 LLVM::Linkage::Internal,
"__named_barrier",
Attribute(),
706 ROCDL::ROCDLDialect::kBarrierAddressSpace);
709 Region ®ion = globalOp.getInitializerRegion();
712 auto poison = LLVM::PoisonOp::create(detachedBuilder, loc, targetTy);
713 LLVM::ReturnOp::create(detachedBuilder, loc, poison);
720 rewriter.setInsertionPoint(op);
721 auto addrOf = LLVM::AddressOfOp::create(rewriter, loc, ptrTy, globalName);
724 ROCDL::BarrierInitOp::create(rewriter, loc, addrOf, count);
726 rewriter.replaceOp(op, addrOf.getResult());
732#include "GPUToROCDL.cpp.inc"
739struct LowerGpuOpsToROCDLOpsPass final
744 Base::getDependentDialects(registry);
748 void runOnOperation()
override {
749 gpu::GPUModuleOp m = getOperation();
752 auto llvmDataLayout = m->getDiscardableAttrOfType<StringAttr>(
753 LLVM::LLVMDialect::getDataLayoutAttrName());
754 if (!llvmDataLayout) {
756 m->setDiscardableAttr(LLVM::LLVMDialect::getDataLayoutAttrName(),
763 for (
auto func : m.getOps<func::FuncOp>()) {
764 if (
func.isPrivate())
766 func->setDiscardableAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName(),
772 [&] {
return emitError(UnknownLoc::get(ctx)); });
773 if (failed(targetInfo))
774 return signalPassFailure();
778 ctx,
DataLayout(cast<DataLayoutOpInterface>(m.getOperation())));
779 options.dataLayout = llvm::DataLayout(llvmDataLayout.getValue());
781 options.overrideIndexBitwidth(indexBitwidth);
783 if (useBarePtrCallConv) {
784 options.useBarePtrCallConv =
true;
793 "bare pointer calling convention requires all memrefs to "
794 "have static shape and use the identity map");
795 return signalPassFailure();
815 llvm::SmallDenseSet<StringRef> allowedDialectsSet(allowedDialects.begin(),
816 allowedDialects.end());
818 bool allowed = allowedDialectsSet.contains(dialect->getNamespace());
820 if (!allowedDialectsSet.empty() && !allowed)
823 auto *iface = dyn_cast<ConvertToLLVMPatternInterface>(dialect);
829 <<
"dialect does not implement ConvertToLLVMPatternInterface: "
830 << dialect->getNamespace();
831 return signalPassFailure();
836 iface->populateConvertToLLVMConversionPatterns(
target, converter,
845 if (failed(applyPartialConversion(m,
target, std::move(llvmPatterns))))
847 auto *rocdlDialect =
getContext().getLoadedDialect<ROCDL::ROCDLDialect>();
848 auto reqdWorkGroupSizeAttrHelper =
849 rocdlDialect->getReqdWorkGroupSizeAttrHelper();
850 auto flatWorkGroupSizeAttrHelper =
851 rocdlDialect->getFlatWorkGroupSizeAttrHelper();
854 m.walk([&](LLVM::LLVMFuncOp op) {
855 if (reqdWorkGroupSizeAttrHelper.isAttrPresent(op)) {
856 auto blockSizes = reqdWorkGroupSizeAttrHelper.getAttr(op);
859 uint32_t flatSize = 1;
860 for (uint32_t size : blockSizes.asArrayRef()) {
863 StringAttr flatSizeAttr =
864 StringAttr::get(ctx, Twine(flatSize) +
"," + Twine(flatSize));
865 flatWorkGroupSizeAttrHelper.setAttr(op, flatSizeAttr);
874 target.addIllegalOp<func::FuncOp>();
875 target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
876 target.addLegalDialect<ROCDL::ROCDLDialect>();
877 target.addIllegalDialect<gpu::GPUDialect>();
878 target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::Exp2Op, LLVM::FCeilOp,
879 LLVM::FFloorOp, LLVM::FRemOp, LLVM::LogOp, LLVM::Log10Op,
880 LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp>();
882 target.addDynamicallyLegalOp<LLVM::ExpOp, LLVM::LogOp>([](
Operation *op) {
883 return any_of(op->getOperandTypes(), llvm::IsaPred<Float32Type>);
886 target.addLegalOp<gpu::YieldOp, gpu::GPUModuleOp>();
897 populateWithGenerated(patterns);
900 ROCDL::ThreadIdYOp, ROCDL::ThreadIdZOp>>(
901 converter, IndexKind::Block, IntrType::Id);
903 gpu::BlockIdOp, ROCDL::BlockIdXOp, ROCDL::BlockIdYOp, ROCDL::BlockIdZOp>>(
904 converter, IndexKind::Grid, IntrType::Id);
905 patterns.
add<GPUDimOpToOcklCall<gpu::BlockDimOp>>(converter,
907 patterns.
add<GPUDimOpToOcklCall<gpu::GridDimOp>>(converter, IndexKind::Grid);
912 ROCDL::ROCDLDialect::kPrivateMemoryAddressSpace,
913 ROCDL::ROCDLDialect::kSharedMemoryAddressSpace,
914 rocdlDialect->getKernelAttrHelper().getName(),
915 rocdlDialect->getReqdWorkGroupSizeAttrHelper().getName(),
919 }
else if (Runtime::OpenCL ==
runtime) {
926 patterns.
add<GPUShuffleOpLowering, GPULaneIdOpToROCDL,
927 GPUSubgroupBroadcastOpToROCDL, GPUBallotOpToROCDL>(converter);
928 patterns.
add<GPUSubgroupIdOpToROCDL, GPUSubgroupSizeOpToROCDL,
929 GPUBarrierOpLowering, GPUInitializeNamedBarrierOpLowering>(
static Value getLaneId(RewriterBase &rewriter, Location loc)
static constexpr int64_t kMaxThreadsPerBlockDim
Maximum number of threads per block dimension on AMD GPUs.
static bool canBeCalledWithBarePointers(gpu::GPUFuncOp func)
Returns true if the given gpu.func can be safely called using the bare pointer calling convention.
static constexpr StringLiteral amdgcnDataLayout
static Value getKnownOrOcklDim(RewriterBase &rewriter, gpu::index_lowering::IndexKind indexKind, gpu::Dimension dim, Operation *contextOp, std::optional< uint32_t > opUpperBound)
Emits a call to an OCKL block/grid size function corresponding to indexKind with argument dim,...
static Value truncOrExtToLLVMType(ConversionPatternRewriter &rewriter, Location loc, Value value, const LLVMTypeConverter &converter)
static llvm::ManagedStatic< PassManagerOptions > options
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
IntegerAttr getI64IntegerAttr(int64_t value)
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
MLIRContext * getContext() const
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
The main mechanism for performing data layout queries.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
static bool canConvertToBarePtr(BaseMemRefType type)
Check if a memref type can be converted to a bare pointer.
MLIRContext & getContext() const
Returns the MLIR context.
unsigned getIndexTypeBitwidth() const
Gets the bitwidth of the index type when converted to LLVM.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Options to control the LLVM lowering.
MLIRContext is the top-level object for a collection of MLIR operations.
Dialect * getLoadedDialect(StringRef name)
Get a registered IR dialect with the given namespace.
std::vector< Dialect * > getLoadedDialects()
Return information about all IR dialects loaded in the context.
NamedAttribute represents a combination of a name and an Attribute value.
This class helps build Operations.
Block * createBlock(Region *parent, Region::iterator insertPt={}, TypeRange argTypes={}, ArrayRef< Location > locs={})
Add new block with 'argTypes' arguments and set the insertion point to the end of it.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
A trait used to provide symbol table functionalities to a region operation.
Operation is the basic unit of execution within MLIR.
void setInherentAttr(StringAttr name, Attribute value)
Set an inherent attribute by name.
Operation * getParentWithTrait()
Returns the closest surrounding parent operation with trait Trait.
Location getLoc()
The source location the operation was defined or derived from.
MLIRContext * getContext()
Return the context this operation is associated with.
Describes the AMDGPU target a lowering is producing code for: the triple's subarch (which identifies ...
static FailureOr< TargetInfo > get(StringRef arch, unsigned waveSize=0, function_ref< InFlightDiagnostic()> emitError=nullptr)
Resolves a target description.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isInteger() const
Return true if this is an integer type (with the specified width).
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
bool wasInterrupted() const
Returns true if the walk was interrupted.
static WalkResult interrupt()
static ConstantIntOp create(OpBuilder &builder, Location location, int64_t value, unsigned width)
LogicalResult decomposeValue(OpBuilder &builder, Location loc, Value src, Type dstType, SmallVectorImpl< Value > &result, bool permitVariablySizedScalars=false)
Decomposes a src value into a set of values of type dstType through series of bitcasts and vector ops...
Value composeValue(OpBuilder &builder, Location loc, ValueRange src, Type dstType)
Composes a set of src values into a single value of type dstType through series of bitcasts and vecto...
StringRef resolveArchOption(StringRef arch, StringRef deprecatedAlias)
Returns the target architecture that a pass should parse, given its arch option and the value of the ...
void populateCommonGPUTypeAndAttributeConversions(TypeConverter &typeConverter)
Remap common GPU memory spaces (Workgroup, Private, etc) to LLVM address spaces.
Runtime
Potential runtimes for AMD GPU kernels.
gpu::DimensionKind IndexKind
LLVM::ConstantRangeAttr getIndexOpRange(Operation *op, gpu::Dimension dim, std::optional< uint32_t > opUpperBound, IndexKind indexKind, IntrType intrType, unsigned bitWidth)
Returns a ConstantRangeAttr for a GPU index op, or nullptr if no bounds are found.
std::optional< uint32_t > getKnownDimensionSizeAround(Operation *op, DimensionKind kind, Dimension dim)
Retrieve the constant bounds for a given dimension and dimension kind from the context surrounding op...
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
void populateGpuPromoteShuffleToAMDGPUPatterns(RewritePatternSet &patterns, std::optional< ROCDL::TargetInfo > target)
Tries to promote gpu.shuffles to specialized AMDGPU intrinsics.
static constexpr unsigned kDeriveIndexBitwidthFromDataLayout
Value to pass as bitwidth for the index type when the converter is expected to derive the bitwidth fr...
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
void populateGpuRewritePatterns(RewritePatternSet &patterns)
Collect all patterns to rewrite ops within the GPU dialect.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
void configureGpuToROCDLConversionLegality(ConversionTarget &target)
Configure target to convert from the GPU dialect to ROCDL.
void populateGpuToROCDLConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, gpu::amd::Runtime runtime, const ROCDL::TargetInfo &target)
Collect a set of patterns to convert from the GPU dialect to ROCDL.
LLVM::LLVMFuncOp getOrDefineFunction(Operation *moduleOp, Location loc, OpBuilder &b, StringRef name, LLVM::LLVMFunctionType type)
Note that these functions don't take a SymbolTable because GPU module lowerings can have name collisi...
void populateAMDGPUToROCDLConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, const ROCDL::TargetInfo &target)
Note: This function will also add conversions for the AMDGPU-specific address spaces and types,...
void registerConvertToLLVMDependentDialectLoading(DialectRegistry ®istry)
Register the extension that will load dependent dialects for LLVM conversion.
void populateMathToROCDLConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, std::optional< ROCDL::TargetInfo > target)
Populate the given list with patterns that convert from Math to ROCDL calls.
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.
Lowering for gpu.dynamic.shared.memory to LLVM dialect.
The lowering of gpu.printf to a call to HIP hostcalls.
The lowering of gpu.printf to a call to an external printf() function.