[Mlir-commits] [mlir] Expand the MemRefToEmitC pass - Adding scalars (PR #148055)

Jaden Angella llvmlistbot at llvm.org
Thu Jul 17 12:40:28 PDT 2025


================
@@ -132,7 +144,17 @@ struct ConvertGetGlobal final
   matchAndRewrite(memref::GetGlobalOp op, OpAdaptor operands,
                   ConversionPatternRewriter &rewriter) const override {
 
-    auto resultTy = getTypeConverter()->convertType(op.getType());
+    MemRefType type = op.getType();
+    Type resultTy;
+    if (type.getRank() == 0)
+      resultTy = emitc::LValueType::get(
----------------
Jaddyen wrote:

What I've tried and been able to implement is the conversion:
From:
```
memref.global "private" constant @__constant_xi32 : memref<i32> = dense<-1>
func.func @globals() {
    memref.get_global @__constant_xi32 : memref<i32>
}
```
To:
```
emitc.global static const @__constant_xi32 : i32 = -1
    emitc.func @globals() {
      %0 = get_global @__constant_xi32 : !emitc.lvalue<i32>
      %1 = apply "&"(%0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
      return
    }
```

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


More information about the Mlir-commits mailing list