[Mlir-commits] [mlir] [MLIR][GPU-LLVM] Convert `gpu.func` to `llvm.func` (PR #101664)

Mehdi Amini llvmlistbot at llvm.org
Mon Aug 5 05:31:02 PDT 2024


================
@@ -19,35 +20,101 @@
 
 using namespace mlir;
 
+namespace {
+constexpr int64_t sizeQueryFailure = 0;
+
+static int64_t getAttributionSize(BlockArgument attribution,
+                                  const LLVMTypeConverter &converter,
+                                  const DataLayout &layout) {
+  auto attributionType = cast<MemRefType>(attribution.getType());
+  int64_t numElements = attributionType.getNumElements();
+  Type elementType = converter.convertType(attributionType.getElementType());
+  if (!elementType)
+    return sizeQueryFailure;
+  int64_t elementTypeSize = layout.getTypeSize(elementType);
+  return numElements * elementTypeSize;
+}
+} // namespace
+
 LogicalResult
 GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor,
                                    ConversionPatternRewriter &rewriter) const {
   Location loc = gpuFuncOp.getLoc();
 
   SmallVector<LLVM::GlobalOp, 3> workgroupBuffers;
-  workgroupBuffers.reserve(gpuFuncOp.getNumWorkgroupAttributions());
-  for (const auto [idx, attribution] :
-       llvm::enumerate(gpuFuncOp.getWorkgroupAttributions())) {
-    auto type = dyn_cast<MemRefType>(attribution.getType());
-    assert(type && type.hasStaticShape() && "unexpected type in attribution");
-
-    uint64_t numElements = type.getNumElements();
-
-    auto elementType =
-        cast<Type>(typeConverter->convertType(type.getElementType()));
-    auto arrayType = LLVM::LLVMArrayType::get(elementType, numElements);
-    std::string name =
-        std::string(llvm::formatv("__wg_{0}_{1}", gpuFuncOp.getName(), idx));
-    uint64_t alignment = 0;
-    if (auto alignAttr =
-            dyn_cast_or_null<IntegerAttr>(gpuFuncOp.getWorkgroupAttributionAttr(
-                idx, LLVM::LLVMDialect::getAlignAttrName())))
-      alignment = alignAttr.getInt();
-    auto globalOp = rewriter.create<LLVM::GlobalOp>(
-        gpuFuncOp.getLoc(), arrayType, /*isConstant=*/false,
-        LLVM::Linkage::Internal, name, /*value=*/Attribute(), alignment,
-        workgroupAddrSpace);
-    workgroupBuffers.push_back(globalOp);
+  if (encodeWorkgroupAttributionsAsArguments) {
----------------
joker-eph wrote:

This likely deserves some description of what this branch will do.

https://github.com/llvm/llvm-project/pull/101664


More information about the Mlir-commits mailing list