MLIR 24.0.0git
LowerGpuOpsToROCDLOps.cpp
Go to the documentation of this file.
1//===- LowerGpuOpsToROCDLOps.cpp - MLIR GPU to ROCDL lowering passes ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements a pass to generate ROCDLIR operations for higher-level
10// GPU operations.
11//
12//===----------------------------------------------------------------------===//
13
24#include "mlir/Pass/Pass.h"
26
50#include "mlir/IR/Matchers.h"
53
56
57namespace mlir {
58#define GEN_PASS_DEF_CONVERTGPUOPSTOROCDLOPS
59#include "mlir/Conversion/Passes.h.inc"
60} // namespace mlir
61
62using namespace mlir;
63
64// Truncate or extend the result depending on the index bitwidth specified
65// by the LLVMTypeConverter options.
66static Value truncOrExtToLLVMType(ConversionPatternRewriter &rewriter,
67 Location loc, Value value,
68 const LLVMTypeConverter &converter) {
69 int64_t intWidth = cast<IntegerType>(value.getType()).getWidth();
70 int64_t indexBitwidth = converter.getIndexTypeBitwidth();
71 auto indexBitwidthType =
72 IntegerType::get(rewriter.getContext(), converter.getIndexTypeBitwidth());
73 // TODO: use <=> in C++20.
74 if (indexBitwidth > intWidth) {
75 return LLVM::SExtOp::create(rewriter, loc, indexBitwidthType, value);
76 }
77 if (indexBitwidth < intWidth) {
78 return LLVM::TruncOp::create(rewriter, loc, indexBitwidthType, value);
79 }
80 return value;
81}
82
83/// Returns true if the given `gpu.func` can be safely called using the bare
84/// pointer calling convention.
85static bool canBeCalledWithBarePointers(gpu::GPUFuncOp func) {
86 bool canBeBare = true;
87 for (Type type : func.getArgumentTypes())
88 if (auto memrefTy = dyn_cast<BaseMemRefType>(type))
89 canBeBare &= LLVMTypeConverter::canConvertToBarePtr(memrefTy);
90 return canBeBare;
91}
92
93static Value getLaneId(RewriterBase &rewriter, Location loc) {
94 auto int32Type = IntegerType::get(rewriter.getContext(), 32);
95 Value zero = arith::ConstantIntOp::create(rewriter, loc, 0, 32);
96 Value minus1 = arith::ConstantIntOp::create(rewriter, loc, -1, 32);
97 NamedAttribute noundef = rewriter.getNamedAttr(
98 LLVM::LLVMDialect::getNoUndefAttrName(), rewriter.getUnitAttr());
99 NamedAttribute lowRange = rewriter.getNamedAttr(
100 LLVM::LLVMDialect::getRangeAttrName(),
101 LLVM::ConstantRangeAttr::get(rewriter.getContext(), APInt::getZero(32),
102 APInt(32, 32)));
103 NamedAttribute highRange = rewriter.getNamedAttr(
104 LLVM::LLVMDialect::getRangeAttrName(),
105 LLVM::ConstantRangeAttr::get(rewriter.getContext(), APInt::getZero(32),
106 APInt(32, 64)));
107 Value mbcntLo = ROCDL::MbcntLoOp::create(
108 rewriter, loc, int32Type, minus1, zero, /*arg_attrs=*/{},
109 /*res_attrs=*/
110 rewriter.getArrayAttr(rewriter.getDictionaryAttr({noundef, lowRange})));
111 Value laneId = ROCDL::MbcntHiOp::create(
112 rewriter, loc, int32Type, minus1, mbcntLo, /*arg_attrs=*/{},
113 rewriter.getArrayAttr(rewriter.getDictionaryAttr({noundef, highRange})));
114 return laneId;
115}
116
117/// Maximum number of threads per block dimension on AMD GPUs.
118static constexpr int64_t kMaxThreadsPerBlockDim = 1024;
119
120/// Emits a call to an OCKL block/grid size function corresponding to
121/// `indexKind` with argument `dim`, except that if the context around
122/// `contextOp` gives an exact size for that dimension, return that as
123/// an `i64` constant instead.
126 gpu::Dimension dim, Operation *contextOp,
127 std::optional<uint32_t> opUpperBound) {
128 Location loc = contextOp->getLoc();
129 MLIRContext *context = contextOp->getContext();
130
131 auto i32Ty = IntegerType::get(context, 32);
132 auto i64Ty = IntegerType::get(context, 64);
133
134 if (std::optional<uint32_t> knownDim =
135 gpu::getKnownDimensionSizeAround(contextOp, indexKind, dim))
136 return LLVM::ConstantOp::create(rewriter, loc,
137 rewriter.getI64IntegerAttr(*knownDim));
138
139 int32_t dimParam = static_cast<int32_t>(dim);
140
141 StringRef functionName;
142 switch (indexKind) {
143 case gpu::index_lowering::IndexKind::Block:
144 functionName = "__ockl_get_local_size";
145 break;
146 case gpu::index_lowering::IndexKind::Grid:
147 functionName = "__ockl_get_num_groups";
148 break;
149 case gpu::index_lowering::IndexKind::Cluster:
150 case gpu::index_lowering::IndexKind::Other:
151 llvm_unreachable("Not valid index kinds for ockl lookup");
152 }
153
154 // Declare the ockl function: i64 @functionName(i32).
155 auto fnType = LLVM::LLVMFunctionType::get(i64Ty, {i32Ty});
156 Operation *moduleOp = contextOp->getParentWithTrait<OpTrait::SymbolTable>();
157 LLVM::LLVMFuncOp funcOp =
158 getOrDefineFunction(moduleOp, loc, rewriter, functionName, fnType);
159
160 // Create the call.
161 Value dimConst = LLVM::ConstantOp::create(rewriter, loc, i32Ty, dimParam);
162 auto callOp =
163 LLVM::CallOp::create(rewriter, loc, funcOp, ValueRange{dimConst});
164
165 LLVM::ConstantRangeAttr range;
166 if (opUpperBound) {
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) {
171 // Set the hardware limit for block ranges as the bounds on block dim calls.
172 range = LLVM::ConstantRangeAttr::get(context, APInt(64, 1),
173 APInt(64, kMaxThreadsPerBlockDim + 1));
174 }
175 if (range) {
176 callOp.setResAttrsAttr(rewriter.getArrayAttr(rewriter.getDictionaryAttr(
177 rewriter.getNamedAttr(LLVM::LLVMDialect::getRangeAttrName(), range))));
178 }
179 return callOp.getResult();
180}
181
182static constexpr StringLiteral amdgcnDataLayout =
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:"
185 "32-v32:"
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";
188
189namespace {
190
191/// Lowers gpu.block_dim / gpu.grid_dim to direct __ockl_get_local_size /
192/// __ockl_get_num_groups function calls.
193template <typename OpTy>
194struct GPUDimOpToOcklCall final : ConvertOpToLLVMPattern<OpTy> {
195 GPUDimOpToOcklCall(const LLVMTypeConverter &converter,
197 : ConvertOpToLLVMPattern<OpTy>(converter), indexKind(indexKind) {}
198
199 LogicalResult
200 matchAndRewrite(OpTy op, typename OpTy::Adaptor adaptor,
201 ConversionPatternRewriter &rewriter) const override {
202 Location loc = op.getLoc();
203
204 std::optional<uint32_t> opUpperBound;
205 if (auto bound = op.getUpperBound())
206 opUpperBound = static_cast<uint32_t>(bound->getZExtValue());
207
208 Value ocklCall = getKnownOrOcklDim(rewriter, indexKind, op.getDimension(),
209 op, opUpperBound);
210 Value result = truncOrExtToLLVMType(rewriter, loc, ocklCall,
211 *this->getTypeConverter());
212 rewriter.replaceOp(op, result);
213 return success();
214 }
215
216private:
217 const gpu::index_lowering::IndexKind indexKind;
218};
219
220struct GPULaneIdOpToROCDL : ConvertOpToLLVMPattern<gpu::LaneIdOp> {
222
223 LogicalResult
224 matchAndRewrite(gpu::LaneIdOp op, gpu::LaneIdOp::Adaptor adaptor,
225 ConversionPatternRewriter &rewriter) const override {
226 Location loc = op.getLoc();
227 MLIRContext *context = rewriter.getContext();
228 // convert to:
229 // %mlo = call noundef range(i32 0, 32)
230 // @llvm.amdgcn.mbcnt.lo(-1, 0)
231 // followed by:
232 // %lid = call noundef range(i32 0, 64)
233 // @llvm.amdgcn.mbcnt.hi(-1, %mlo)
234
235 Value laneId = getLaneId(rewriter, loc);
236 // Truncate or extend the result depending on the index bitwidth specified
237 // by the LLVMTypeConverter options.
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);
245 }
246 rewriter.replaceOp(op, {laneId});
247 return success();
248 }
249};
250
251struct GPUSubgroupSizeOpToROCDL : ConvertOpToLLVMPattern<gpu::SubgroupSizeOp> {
253
254 GPUSubgroupSizeOpToROCDL(const LLVMTypeConverter &converter,
257 }
258
259 LogicalResult
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 /*bitWidth=*/32, /*lower=*/isWave64 ? 64 : 32,
267 /*upper=*/op.getUpperBoundAttr().getInt() + 1);
268 }
269 Value wavefrontOp = ROCDL::WavefrontSizeOp::create(
270 rewriter, op.getLoc(), rewriter.getI32Type(), bounds);
271 wavefrontOp = truncOrExtToLLVMType(rewriter, op.getLoc(), wavefrontOp,
272 *getTypeConverter());
273 rewriter.replaceOp(op, {wavefrontOp});
274 return success();
275 }
276
278};
279
280struct GPUSubgroupIdOpToROCDL : ConvertOpToLLVMPattern<gpu::SubgroupIdOp> {
282
283 GPUSubgroupIdOpToROCDL(const LLVMTypeConverter &converter,
286
287 LogicalResult
288 matchAndRewrite(gpu::SubgroupIdOp op, gpu::SubgroupIdOp::Adaptor adaptor,
289 ConversionPatternRewriter &rewriter) const override {
290 Location loc = op.getLoc();
291 auto int32Type = rewriter.getI32Type();
292
293 Value subgroupId;
294 if (target.has(llvm::AMDGPU::FEAT_GFX12_INSTS)) {
295 // For gfx12+, use the hardware wave.id register directly.
296 LLVM::ConstantRangeAttr bounds;
297 if (auto upperBoundAttr = op.getUpperBoundAttr())
298 bounds = rewriter.getAttr<LLVM::ConstantRangeAttr>(
299 /*bitWidth=*/32, /*lower=*/0,
300 /*upper=*/upperBoundAttr.getInt());
301 subgroupId = ROCDL::WaveId::create(rewriter, loc, int32Type, bounds);
302 } else {
303 // For older architectures, compute:
304 // subgroup_id = linearized_thread_id / subgroup_size
305 // where linearized_thread_id = tid.x + dim.x * (tid.y + dim.y * tid.z)
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,
315 tidOp->setInherentAttr(rewriter.getStringAttr("range"), range);
316 };
317 setBoundFromContext(tidX, gpu::Dimension::x);
318 setBoundFromContext(tidY, gpu::Dimension::y);
319 setBoundFromContext(tidZ, gpu::Dimension::z);
320
321 auto flags =
322 LLVM::IntegerOverflowFlags::nsw | LLVM::IntegerOverflowFlags::nuw;
323
324 auto getBlockDim = [&](gpu::Dimension dim) {
325 Value dim64 =
326 getKnownOrOcklDim(rewriter, gpu::index_lowering::IndexKind::Block,
327 dim, op, std::nullopt);
328 Value dimTrunc =
329 LLVM::TruncOp::create(rewriter, loc, int32Type, dim64, flags);
330 return dimTrunc;
331 };
332 Value dimX = getBlockDim(gpu::Dimension::x);
333 Value dimY = getBlockDim(gpu::Dimension::y);
334
335 // linearized = tid.x + dim.x * (tid.y + dim.y * tid.z)
336 // Thread IDs and dimensions are non-negative and small, so use nuw+nsw.
337 Value dimYxTidZ =
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,
344 dimXxInner, flags);
345
346 Value subgroupSize =
347 ROCDL::WavefrontSizeOp::create(rewriter, loc, int32Type);
348 subgroupId = LLVM::UDivOp::create(rewriter, loc, int32Type, linearized,
349 subgroupSize);
350 }
351
352 subgroupId =
353 truncOrExtToLLVMType(rewriter, loc, subgroupId, *getTypeConverter());
354 rewriter.replaceOp(op, subgroupId);
355 return success();
356 }
357
359};
360
361static bool isSupportedReadLaneType(Type type) {
362 // https://llvm.org/docs/AMDGPUUsage.html#llvm-ir-intrinsics
363 if (isa<Float16Type, BFloat16Type, Float32Type, Float64Type,
364 LLVM::LLVMPointerType>(type))
365 return true;
366
367 if (auto intType = dyn_cast<IntegerType>(type))
368 return llvm::is_contained({16, 32, 64},
369 static_cast<int>(intType.getWidth()));
370
371 if (auto vecType = dyn_cast<VectorType>(type)) {
372 Type elementType = vecType.getElementType();
373 if (elementType.isInteger(32))
374 return true;
375
376 if (vecType.getNumElements() == 2 &&
377 (isa<Float16Type, BFloat16Type>(elementType) ||
378 elementType.isInteger(16)))
379 return true;
380 }
381
382 return false;
383}
384
385struct GPUSubgroupBroadcastOpToROCDL
386 : public ConvertOpToLLVMPattern<gpu::SubgroupBroadcastOp> {
388
389 LogicalResult
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);
396 return success();
397 }
398
399 Type i32 = rewriter.getI32Type();
400 Location loc = op.getLoc();
401 SmallVector<Value> decomposed;
402 if (failed(LLVM::decomposeValue(rewriter, loc, src, i32, decomposed,
403 /*permitVariablySizedScalars=*/true)))
404 return rewriter.notifyMatchFailure(op,
405 "Unexpected decomposition failure");
406
407 SmallVector<Value> results;
408 results.reserve(decomposed.size());
409 for (Value v : decomposed)
410 results.emplace_back(createReadlaneOp(op, adaptor, rewriter, v));
411
412 Value result = LLVM::composeValue(rewriter, loc, results, src.getType());
413 rewriter.replaceOp(op, result);
414 return success();
415 }
416
417private:
418 static Value createReadlaneOp(gpu::SubgroupBroadcastOp op, OpAdaptor adaptor,
419 ConversionPatternRewriter &rewriter,
420 Value src) {
421 if (adaptor.getBroadcastType() == gpu::BroadcastType::specific_lane) {
422 return ROCDL::ReadlaneOp::create(rewriter, op.getLoc(), src.getType(),
423 src, adaptor.getLane());
424 } else { // first_active_lane
425 return ROCDL::ReadfirstlaneOp::create(rewriter, op.getLoc(),
426 src.getType(), src);
427 }
428 }
429};
430
431struct GPUBallotOpToROCDL : public ConvertOpToLLVMPattern<gpu::BallotOp> {
433
434 LogicalResult
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();
439
440 // ROCDL ballot natively supports i32 and i64 for wavefront sizes of
441 // 32 and 64 lanes.
442 if (width != 32 && width != 64)
443 return rewriter.notifyMatchFailure(
444 op, "rocdl.ballot only supports i32 and i64 result types");
445
446 rewriter.replaceOpWithNewOp<ROCDL::BallotOp>(op, op.getType(),
447 adaptor.getPredicate());
448 return success();
449 }
450};
451
452struct GPUShuffleOpLowering : public ConvertOpToLLVMPattern<gpu::ShuffleOp> {
454
455 /// Lowers a shuffle to the corresponding ROCDL ops.
456 ///
457 /// Use the `width` argument to see if src lane is participating.
458 /// If not the dstLane would be itself.
459 ///
460 /// Shuffle with DS Bpermute:
461 /// let shflMode = [xor, up, down, idx]
462 /// let width = 32(usually warpsize), step = [1, 2, 4, 8, 16, ... , width].
463 /// 1. curLaneId = using mbcnt.lo + mbcnt.hi
464 /// 2. widthOrZeroIfOutside = (curLaneId + width) & -width
465 /// 3. dstLane = shflMode(curLaneId, step)
466 /// 4. isActiveSrcLane = dstLane < isActiveSrcLane
467 /// 5. dstLane = isActiveSrcLane ? dstLane : curLaneId
468 /// 6. dwordAlignedDstLane = dstLane * 4 or dstLane << 2.
469 /// 7. bpermute(dwordAlignedDstLane, shfl_value).
470 ///
471 LogicalResult
472 matchAndRewrite(gpu::ShuffleOp op, OpAdaptor adaptor,
473 ConversionPatternRewriter &rewriter) const override {
474 Location loc = op->getLoc();
475 Value initShflValue = adaptor.getValue();
476
477 Value srcLaneId = getLaneId(rewriter, loc);
478
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);
486 Value dstLane;
487
488 switch (op.getMode()) {
489 case gpu::ShuffleMode::UP:
490 dstLane = LLVM::SubOp::create(rewriter, loc, int32Type, srcLaneId,
491 adaptor.getOffset());
492 break;
493 case gpu::ShuffleMode::DOWN:
494 dstLane = LLVM::AddOp::create(rewriter, loc, int32Type, srcLaneId,
495 adaptor.getOffset());
496 break;
497 case gpu::ShuffleMode::XOR:
498 dstLane = LLVM::XOrOp::create(rewriter, loc, int32Type, srcLaneId,
499 adaptor.getOffset());
500 break;
501 case gpu::ShuffleMode::IDX:
502 dstLane = adaptor.getOffset();
503 break;
504 }
505 Value isActiveSrcLane = LLVM::ICmpOp::create(
506 rewriter, loc, LLVM::ICmpPredicate::slt, dstLane, widthOrZeroIfOutside);
507 Value selectDstLane = LLVM::SelectOp::create(rewriter, loc, isActiveSrcLane,
508 dstLane, srcLaneId);
509 Value two = LLVM::ConstantOp::create(rewriter, loc, int32Type, 2);
510 Value dwordAlignedDstLane =
511 LLVM::ShlOp::create(rewriter, loc, int32Type, selectDstLane, two);
512
513 SmallVector<Value> decomposed;
514 if (failed(LLVM::decomposeValue(rewriter, loc, initShflValue, int32Type,
515 decomposed)))
516 return rewriter.notifyMatchFailure(op,
517 "failed to decompose value to i32");
518 SmallVector<Value> swizzled;
519 for (Value v : decomposed) {
520 Value res = ROCDL::DsBpermuteOp::create(rewriter, loc, int32Type,
521 dwordAlignedDstLane, v);
522 swizzled.emplace_back(res);
523 }
524 Value shflValue =
525 LLVM::composeValue(rewriter, loc, swizzled, initShflValue.getType());
526 rewriter.replaceOp(op, {shflValue, isActiveSrcLane});
527 return success();
528 }
529};
530
531/// Emit an LLVM fence with MMRA metadata based on the given address spaces.
532/// If `addrSpaces` is nullopt, all memory is fenced (global + LDS).
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;
538
539 if (addrSpaces) {
540 for (auto spaceAttr : addrSpaces->getAsRange<gpu::AddressSpaceAttr>()) {
541 switch (spaceAttr.getValue()) {
542 case gpu::AddressSpace::Global:
543 fenceGlobal = true;
544 break;
545 case gpu::AddressSpace::Workgroup:
546 fenceLDS = true;
547 break;
548 case gpu::AddressSpace::Private:
549 case gpu::AddressSpace::Constant:
550 break;
551 }
552 }
553 } else {
554 fenceGlobal = true;
555 fenceLDS = true;
556 }
557
558 if (!fenceGlobal && !fenceLDS)
559 return;
560
561 Attribute mmra;
562 if (fenceLDS && !fenceGlobal)
563 mmra =
564 rewriter.getAttr<LLVM::MMRATagAttr>("amdgpu-synchronize-as", "local");
565 else if (fenceGlobal && !fenceLDS)
566 mmra =
567 rewriter.getAttr<LLVM::MMRATagAttr>("amdgpu-synchronize-as", "global");
568
569 auto ordering =
570 before ? LLVM::AtomicOrdering::release : LLVM::AtomicOrdering::acquire;
571 auto fence = LLVM::FenceOp::create(rewriter, loc, ordering, scope);
572 if (mmra)
573 fence->setDiscardableAttr(LLVM::LLVMDialect::getMmraAttrName(), mmra);
574}
575
576static constexpr int32_t kWholeClusterBarrierId = -3;
577static constexpr int32_t kWholeWorkgroupBarrierId = -1;
578struct GPUBarrierOpLowering final : ConvertOpToLLVMPattern<gpu::BarrierOp> {
579 GPUBarrierOpLowering(const LLVMTypeConverter &converter,
582
584
585 LogicalResult
586 matchAndRewrite(gpu::BarrierOp op, gpu::BarrierOp::Adaptor adaptor,
587 ConversionPatternRewriter &rewriter) const override {
588 Location loc = op.getLoc();
589 gpu::BarrierScope scope = op.getScope();
590
591 // Subgroup (wave) scope.
592 if (scope == gpu::BarrierScope::Subgroup) {
593 emitFences(op.getAddressSpaces(), rewriter, loc, "wavefront",
594 /*before=*/true);
595 ROCDL::WaveBarrierOp::create(rewriter, loc);
596 emitFences(op.getAddressSpaces(), rewriter, loc, "wavefront",
597 /*before=*/false);
598 rewriter.eraseOp(op);
599 return success();
600 }
601
602 // Cluster scope: gfx1250+ only, signal/wait with constant -3.
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",
607 /*before=*/true);
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",
612 /*before=*/false);
613 rewriter.eraseOp(op);
614 return success();
615 }
616
617 // Workgroup scope (default).
618 assert(scope == gpu::BarrierScope::Workgroup && "unsupported scope");
619
620 // Named barrier path.
621 if (Value namedBarrier = adaptor.getNamedBarrier()) {
622 if (!target.has(llvm::AMDGPU::FEAT_GFX12_INSTS))
623 return op.emitOpError("named barriers require gfx12+");
624
625 emitFences(op.getAddressSpaces(), rewriter, loc, "workgroup",
626 /*before=*/true);
627 // A wave must join the named barrier before it may signal it.
628 ROCDL::BarrierJoinOp::create(rewriter, loc, namedBarrier);
629 // Signal with memberCnt=0 retains the count from s.barrier.init.
630 ROCDL::BarrierSignalVarOp::create(rewriter, loc, namedBarrier,
631 /*memberCnt=*/0);
632 // id=1 selects the named-barrier wait class; the actual barrier waited
633 // on is the last one this wave joined.
634 ROCDL::BarrierWaitOp::create(rewriter, loc, static_cast<int16_t>(1));
635 emitFences(op.getAddressSpaces(), rewriter, loc, "workgroup",
636 /*before=*/false);
637 rewriter.eraseOp(op);
638 return success();
639 }
640
641 // Regular workgroup barrier.
642 emitFences(op.getAddressSpaces(), rewriter, loc, "workgroup",
643 /*before=*/true);
644 if (!target.has(llvm::AMDGPU::FEAT_GFX12_INSTS)) {
645 ROCDL::SBarrierOp::create(rewriter, loc);
646 } else {
647 ROCDL::BarrierSignalOp::create(rewriter, loc, kWholeWorkgroupBarrierId);
648 ROCDL::BarrierWaitOp::create(
649 rewriter, loc, static_cast<int16_t>(kWholeWorkgroupBarrierId));
650 }
651 emitFences(op.getAddressSpaces(), rewriter, loc, "workgroup",
652 /*before=*/false);
653 rewriter.eraseOp(op);
654 return success();
655 }
656};
657
658struct GPUInitializeNamedBarrierOpLowering final
659 : ConvertOpToLLVMPattern<gpu::InitializeNamedBarrierOp> {
660 GPUInitializeNamedBarrierOpLowering(const LLVMTypeConverter &converter,
663 target(target) {}
664
666
667 LogicalResult
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+");
673
674 Location loc = op.getLoc();
675
676 // The count must be a constant for rocdl.s.barrier.init.
677 IntegerAttr countAttr;
678 if (!matchPattern(op.getMemberCount(), m_Constant(&countAttr)))
679 return op.emitOpError(
680 "named barrier member count must be a constant for ROCDL lowering");
681 int32_t count = countAttr.getInt();
682
683 // Place the global in the symbol-table scope enclosing the function-like
684 // op that contains this barrier (typically a module).
685 auto funcOp = op->getParentOfType<FunctionOpInterface>();
686 if (!funcOp)
687 return op.emitOpError("must be inside a function-like op");
688 Operation *symbolTableOp =
690 if (!symbolTableOp)
691 return op.emitOpError(
692 "enclosing function-like op must have a symbol-table parent");
693
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);
698
699 // Build the global detached so SymbolTable::insert can both place it and
700 // rename it as needed without creating a transient name conflict in IR.
701 OpBuilder detachedBuilder(rewriter.getContext());
702 auto globalOp = LLVM::GlobalOp::create(
703 detachedBuilder, loc, targetTy, /*isConstant=*/false,
704 LLVM::Linkage::Internal, "__named_barrier", /*value=*/Attribute(),
705 /*alignment=*/0,
706 /*addrSpace=*/ROCDL::ROCDLDialect::kBarrierAddressSpace);
707 // Initialize with poison.
708 {
709 Region &region = globalOp.getInitializerRegion();
710 Block *block = detachedBuilder.createBlock(&region);
711 detachedBuilder.setInsertionPointToStart(block);
712 auto poison = LLVM::PoisonOp::create(detachedBuilder, loc, targetTy);
713 LLVM::ReturnOp::create(detachedBuilder, loc, poison);
714 }
715 // SymbolTable::insert places the op in the symbol-table body and renames
716 // the symbol to avoid collisions with any existing entries.
717 StringAttr globalName = SymbolTable(symbolTableOp).insert(globalOp);
718
719 // Get address of the global.
720 rewriter.setInsertionPoint(op);
721 auto addrOf = LLVM::AddressOfOp::create(rewriter, loc, ptrTy, globalName);
722
723 // Initialize the barrier.
724 ROCDL::BarrierInitOp::create(rewriter, loc, addrOf, count);
725
726 rewriter.replaceOp(op, addrOf.getResult());
727 return success();
728 }
729};
730
731/// Import the GPU Ops to ROCDL Patterns.
732#include "GPUToROCDL.cpp.inc"
733
734// A pass that replaces all occurrences of GPU device operations with their
735// corresponding ROCDL equivalent.
736//
737// This pass only handles device code and is not meant to be run on GPU host
738// code.
739struct LowerGpuOpsToROCDLOpsPass final
740 : public impl::ConvertGpuOpsToROCDLOpsBase<LowerGpuOpsToROCDLOpsPass> {
741 using Base::Base;
742
743 void getDependentDialects(DialectRegistry &registry) const override {
744 Base::getDependentDialects(registry);
746 }
747
748 void runOnOperation() override {
749 gpu::GPUModuleOp m = getOperation();
750 MLIRContext *ctx = m.getContext();
751
752 auto llvmDataLayout = m->getDiscardableAttrOfType<StringAttr>(
753 LLVM::LLVMDialect::getDataLayoutAttrName());
754 if (!llvmDataLayout) {
755 llvmDataLayout = StringAttr::get(ctx, amdgcnDataLayout);
756 m->setDiscardableAttr(LLVM::LLVMDialect::getDataLayoutAttrName(),
757 llvmDataLayout);
758 }
759 // Request C wrapper emission for externally visible functions only. A
760 // private function cannot be called from outside its module, so its C
761 // interface wrapper is unreachable and would only anchor the wrapped
762 // function against dead-code elimination.
763 for (auto func : m.getOps<func::FuncOp>()) {
764 if (func.isPrivate())
765 continue;
766 func->setDiscardableAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName(),
767 UnitAttr::get(ctx));
768 }
769
770 FailureOr<ROCDL::TargetInfo> targetInfo = ROCDL::TargetInfo::get(
771 ROCDL::resolveArchOption(arch, chipset), waveSize,
772 [&] { return emitError(UnknownLoc::get(ctx)); });
773 if (failed(targetInfo))
774 return signalPassFailure();
775
776 /// Customize the bitwidth used for the device side index computations.
778 ctx, DataLayout(cast<DataLayoutOpInterface>(m.getOperation())));
779 options.dataLayout = llvm::DataLayout(llvmDataLayout.getValue());
780 if (indexBitwidth != kDeriveIndexBitwidthFromDataLayout)
781 options.overrideIndexBitwidth(indexBitwidth);
782
783 if (useBarePtrCallConv) {
784 options.useBarePtrCallConv = true;
785 WalkResult canUseBarePointers =
786 m.walk([](gpu::GPUFuncOp func) -> WalkResult {
788 return WalkResult::advance();
789 return WalkResult::interrupt();
790 });
791 if (canUseBarePointers.wasInterrupted()) {
792 emitError(UnknownLoc::get(ctx),
793 "bare pointer calling convention requires all memrefs to "
794 "have static shape and use the identity map");
795 return signalPassFailure();
796 }
797 }
798
799 // Apply in-dialect lowering. In-dialect lowering will replace
800 // ops which need to be lowered further, which is not supported by a
801 // single conversion pass.
802 {
803 RewritePatternSet patterns(ctx);
805 populateGpuPromoteShuffleToAMDGPUPatterns(patterns, *targetInfo);
806 (void)applyPatternsGreedily(m, std::move(patterns));
807 }
808
809 LLVMTypeConverter converter(ctx, options);
811
812 RewritePatternSet llvmPatterns(ctx);
814
815 llvm::SmallDenseSet<StringRef> allowedDialectsSet(allowedDialects.begin(),
816 allowedDialects.end());
817 for (Dialect *dialect : ctx->getLoadedDialects()) {
818 bool allowed = allowedDialectsSet.contains(dialect->getNamespace());
819 // Empty `allowedDialectsSet` means all dialects are allowed.
820 if (!allowedDialectsSet.empty() && !allowed)
821 continue;
822
823 auto *iface = dyn_cast<ConvertToLLVMPatternInterface>(dialect);
824 if (!iface) {
825 // Error out if dialect was explicily specified but doesn't implement
826 // conversion interface.
827 if (allowed) {
828 m.emitError()
829 << "dialect does not implement ConvertToLLVMPatternInterface: "
830 << dialect->getNamespace();
831 return signalPassFailure();
832 }
833 continue;
834 }
835
836 iface->populateConvertToLLVMConversionPatterns(target, converter,
837 llvmPatterns);
838 }
839
840 populateAMDGPUToROCDLConversionPatterns(converter, llvmPatterns,
841 *targetInfo);
842 populateGpuToROCDLConversionPatterns(converter, llvmPatterns, runtime,
843 *targetInfo);
845 if (failed(applyPartialConversion(m, target, std::move(llvmPatterns))))
846 signalPassFailure();
847 auto *rocdlDialect = getContext().getLoadedDialect<ROCDL::ROCDLDialect>();
848 auto reqdWorkGroupSizeAttrHelper =
849 rocdlDialect->getReqdWorkGroupSizeAttrHelper();
850 auto flatWorkGroupSizeAttrHelper =
851 rocdlDialect->getFlatWorkGroupSizeAttrHelper();
852 // Manually rewrite known block size attributes so the LLVMIR translation
853 // infrastructure can pick them up.
854 m.walk([&](LLVM::LLVMFuncOp op) {
855 if (reqdWorkGroupSizeAttrHelper.isAttrPresent(op)) {
856 auto blockSizes = reqdWorkGroupSizeAttrHelper.getAttr(op);
857 // Also set up the rocdl.flat_work_group_size attribute to prevent
858 // conflicting metadata.
859 uint32_t flatSize = 1;
860 for (uint32_t size : blockSizes.asArrayRef()) {
861 flatSize *= size;
862 }
863 StringAttr flatSizeAttr =
864 StringAttr::get(ctx, Twine(flatSize) + "," + Twine(flatSize));
865 flatWorkGroupSizeAttrHelper.setAttr(op, flatSizeAttr);
866 }
867 });
868 }
869};
870
871} // namespace
872
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>();
881 // These ops are legal for f32 type.
882 target.addDynamicallyLegalOp<LLVM::ExpOp, LLVM::LogOp>([](Operation *op) {
883 return any_of(op->getOperandTypes(), llvm::IsaPred<Float32Type>);
884 });
885 // TODO: Remove once we support replacing non-root ops.
886 target.addLegalOp<gpu::YieldOp, gpu::GPUModuleOp>();
887}
888
890 const LLVMTypeConverter &converter, RewritePatternSet &patterns,
895 auto *rocdlDialect =
896 converter.getContext().getLoadedDialect<ROCDL::ROCDLDialect>();
897 populateWithGenerated(patterns);
898 patterns.add<
899 gpu::index_lowering::OpLowering<gpu::ThreadIdOp, ROCDL::ThreadIdXOp,
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,
906 IndexKind::Block);
907 patterns.add<GPUDimOpToOcklCall<gpu::GridDimOp>>(converter, IndexKind::Grid);
908 patterns.add<GPUReturnOpLowering>(converter);
909 patterns.add<GPUFuncOpLowering>(
910 converter,
912 /*allocaAddrSpace=*/ROCDL::ROCDLDialect::kPrivateMemoryAddressSpace,
913 /*workgroupAddrSpace=*/ROCDL::ROCDLDialect::kSharedMemoryAddressSpace,
914 rocdlDialect->getKernelAttrHelper().getName(),
915 rocdlDialect->getReqdWorkGroupSizeAttrHelper().getName(),
916 /*kernelClusterSizeAttributeName=*/{}});
917 if (Runtime::HIP == runtime) {
918 patterns.add<GPUPrintfOpToHIPLowering>(converter);
919 } else if (Runtime::OpenCL == runtime) {
920 // Use address space = 4 to match the OpenCL definition of printf()
921 patterns.add<GPUPrintfOpToLLVMCallLowering>(converter, /*addressSpace=*/4);
922 }
923 // TODO: Add alignment for workgroup memory
924 patterns.add<GPUDynamicSharedMemoryOpLowering>(converter);
925
926 patterns.add<GPUShuffleOpLowering, GPULaneIdOpToROCDL,
927 GPUSubgroupBroadcastOpToROCDL, GPUBallotOpToROCDL>(converter);
928 patterns.add<GPUSubgroupIdOpToROCDL, GPUSubgroupSizeOpToROCDL,
929 GPUBarrierOpLowering, GPUInitializeNamedBarrierOpLowering>(
930 converter, target);
931
932 populateMathToROCDLConversionPatterns(converter, patterns, target);
933}
return success()
b getContext())
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
#define add(a, b)
Attributes are known-constant values of operations.
Definition Attributes.h:25
Block represents an ordered list of Operations.
Definition Block.h:34
UnitAttr getUnitAttr()
Definition Builders.cpp:106
IntegerAttr getI64IntegerAttr(int64_t value)
Definition Builders.cpp:120
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition Builders.cpp:275
MLIRContext * getContext() const
Definition Builders.h:56
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
Definition Builders.cpp:112
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Definition Builders.cpp:102
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Definition Pattern.h:233
ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition Pattern.h:239
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...
Definition Dialect.h:38
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...
Definition Location.h:76
Options to control the LLVM lowering.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
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.
Definition Attributes.h:166
This class helps build Operations.
Definition Builders.h:210
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.
Definition Builders.cpp:439
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Definition Builders.h:434
A trait used to provide symbol table functionalities to a region operation.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
void setInherentAttr(StringAttr name, Attribute value)
Set an inherent attribute by name.
Operation * getParentWithTrait()
Returns the closest surrounding parent operation with trait Trait.
Definition Operation.h:273
Location getLoc()
The source location the operation was defined or derived from.
Definition Operation.h:240
MLIRContext * getContext()
Return the context this operation is associated with.
Definition Operation.h:233
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.
Definition Region.h:26
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...
Definition SymbolTable.h:25
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...
Definition Types.h:74
bool isInteger() const
Return true if this is an integer type (with the specified width).
Definition Types.cpp:58
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:392
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Type getType() const
Return the type of this value.
Definition Value.h:105
A utility result that is used to signal how to proceed with an ongoing walk:
Definition WalkResult.h:29
static WalkResult advance()
Definition WalkResult.h:47
bool wasInterrupted() const
Returns true if the walk was interrupted.
Definition WalkResult.h:51
static WalkResult interrupt()
Definition WalkResult.h:46
static ConstantIntOp create(OpBuilder &builder, Location location, int64_t value, unsigned width)
Definition ArithOps.cpp:352
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...
Definition Pattern.cpp:520
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...
Definition Pattern.cpp:619
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.
Definition Runtimes.h:15
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.
Definition Matchers.h:490
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 &region, 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.
Definition Passes.h:75
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 &registry)
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.
Definition Matchers.h:369
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.