[Mlir-commits] [mlir] [MLIR][LLVM] Support dso_local_equivalent constants (PR #132131)

Tobias Gysi llvmlistbot at llvm.org
Thu Mar 20 00:01:51 PDT 2025


================
@@ -526,6 +526,32 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
     return success();
   }
 
+  // Emit dso_local_equivalent. We need to look up the global value referenced
+  // by the operation and store it in the MLIR-to-LLVM value mapping.
+  if (auto dsoLocalEquivalentOp =
+          dyn_cast<LLVM::DSOLocalEquivalentOp>(opInst)) {
+    LLVM::LLVMFuncOp function =
+        dsoLocalEquivalentOp.getFunction(moduleTranslation.symbolTable());
+    LLVM::AliasOp alias =
+        dsoLocalEquivalentOp.getAlias(moduleTranslation.symbolTable());
+
+    // The verifier should not have allowed this.
+    assert((function || alias) &&
+           "referencing an undefined function, or alias");
+
+    llvm::Value *llvmValue = nullptr;
+    if (alias)
+      llvmValue = moduleTranslation.lookupAlias(alias);
+    else
+      llvmValue = moduleTranslation.lookupFunction(function.getName());
+
+    auto gv = dyn_cast_or_null<llvm::GlobalValue>(llvmValue);
+    assert(gv && "expected LLVM IR global value");
+    moduleTranslation.mapValue(dsoLocalEquivalentOp.getResult(),
+                               llvm::DSOLocalEquivalent::get(gv));
----------------
gysit wrote:

```suggestion
    moduleTranslation.mapValue(dsoLocalEquivalentOp.getResult(),
                               llvm::DSOLocalEquivalent::get(cast<llvm::GlobalValue>(llvmValue)));
```
nit: a cast already asserts internally so except the message attached to the assert is relevant I would simplify this.

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


More information about the Mlir-commits mailing list