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

Jaden Angella llvmlistbot at llvm.org
Mon Jul 14 10:12:56 PDT 2025


================
@@ -114,6 +122,10 @@ struct ConvertGlobal final : public OpConversionPattern<memref::GlobalOp> {
     bool externSpecifier = !staticSpecifier;
 
     Attribute initialValue = operands.getInitialValueAttr();
+    if (type.getRank() == 0) {
+      auto elementsAttr = llvm::cast<ElementsAttr>(*op.getInitialValue());
+      initialValue = elementsAttr.getSplatValue<Attribute>();
----------------
Jaddyen wrote:

Without using getSplatValue, we have the initial value as: `initial_value = dense<-1> : tensor<i32>`
After getting the splat value, we have ` emitc.global static const @__constant_xi32 : i32 = -1`

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


More information about the Mlir-commits mailing list