[Mlir-commits] [mlir] [mlir][emitc] Fix creating pointer from constant array (PR #162083)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 22 00:35:47 PST 2025


================
@@ -397,6 +397,51 @@ static bool shouldBeInlined(ExpressionOp expressionOp) {
   return false;
 }
 
+/// Helper function to check if a value traces back to a const global.
+/// Handles direct GetGlobalOp and GetGlobalOp through one or more SubscriptOps.
+/// Returns the GlobalOp if found and it has const_specifier, nullptr otherwise.
+static emitc::GlobalOp getConstGlobal(Value value, Operation *fromOp) {
+  while (auto subscriptOp = value.getDefiningOp<emitc::SubscriptOp>()) {
+    value = subscriptOp.getValue();
+  }
+
+  auto getGlobalOp = value.getDefiningOp<emitc::GetGlobalOp>();
+  if (!getGlobalOp)
+    return nullptr;
+
+  // Find the nearest symbol table to check whether the global is const.
+  Operation *symbolTableOp = fromOp;
+  while (symbolTableOp && !symbolTableOp->hasTrait<OpTrait::SymbolTable>()) {
+    symbolTableOp = symbolTableOp->getParentOp();
+  }
+
+  if (!symbolTableOp)
+    return nullptr;
+
+  SymbolTable symbolTable(symbolTableOp);
+  auto globalOp = symbolTable.lookup<emitc::GlobalOp>(getGlobalOp.getName());
----------------
Jimmy2027 wrote:

updated

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


More information about the Mlir-commits mailing list