[Mlir-commits] [mlir] [MLIR][LLVM] Support dso_local_equivalent constants (PR #132131)
Bruno Cardoso Lopes
llvmlistbot at llvm.org
Thu Mar 20 11:06:26 PDT 2025
================
@@ -2122,6 +2122,56 @@ OpFoldResult LLVM::AddressOfOp::fold(FoldAdaptor) {
return getGlobalNameAttr();
}
+//===----------------------------------------------------------------------===//
+// LLVM::DSOLocalEquivalentOp
+//===----------------------------------------------------------------------===//
+
+LLVMFuncOp
+DSOLocalEquivalentOp::getFunction(SymbolTableCollection &symbolTable) {
+ return dyn_cast_or_null<LLVMFuncOp>(symbolTable.lookupSymbolIn(
+ parentLLVMModule(*this), getFunctionNameAttr()));
+}
+
+AliasOp DSOLocalEquivalentOp::getAlias(SymbolTableCollection &symbolTable) {
+ return dyn_cast_or_null<AliasOp>(symbolTable.lookupSymbolIn(
+ parentLLVMModule(*this), getFunctionNameAttr()));
+}
+
+LogicalResult
+DSOLocalEquivalentOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+ Operation *symbol = symbolTable.lookupSymbolIn(parentLLVMModule(*this),
+ getFunctionNameAttr());
+ auto function = dyn_cast_or_null<LLVMFuncOp>(symbol);
+ auto alias = dyn_cast_or_null<AliasOp>(symbol);
+
+ if (!function && !alias)
+ return emitOpError(
+ "must reference a global defined by 'llvm.func' or 'llvm.mlir.alias'");
+
+ if (alias) {
+ if (alias.getInitializer()
+ .walk([&](AddressOfOp addrOp) {
+ if (addrOp.getGlobal(symbolTable))
+ return WalkResult::interrupt();
+ return WalkResult::advance();
+ })
+ .wasInterrupted())
+ return emitOpError("must reference an alias to a function");
+ }
+
+ if ((function && function.getLinkage() == LLVM::Linkage::ExternWeak) ||
+ (alias && alias.getLinkage() == LLVM::Linkage::ExternWeak))
+ return emitOpError(
+ "target function with 'extern_weak' linkage not allowed");
+
+ return success();
+}
+
+// DSOLocalEquivalentOp constant-folds to the global symbol name.
+OpFoldResult DSOLocalEquivalentOp::fold(FoldAdaptor) {
+ return getFunctionNameAttr();
----------------
bcardosolopes wrote:
Good point, that explains the comments for Undef as others in LLVMAttrs.td, I agree we need an attribute.
https://github.com/llvm/llvm-project/pull/132131
More information about the Mlir-commits
mailing list