-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MLIR][LLVM] Support dso_local_equivalent constants #132131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
652a83d
f797c34
9abbf31
e9e87d4
f3da569
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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(); | ||||
|
||||
| Operation *LLVMDialect::materializeConstant(OpBuilder &builder, Attribute value, |
However, I wonder how we can decide there if something is an AddressOf or a DSOLocalEquivalentOp? I guess we would needs some other attribute type to achieve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, that explains the comments for Undef as others in LLVMAttrs.td, I agree we need an attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was searching for ways to test materializeConstant, but when I comment out most of this function and run ninja check-mlir, it all passes, which makes this either non-tested or not being used anymore?
Operation *LLVMDialect::materializeConstant(OpBuilder &builder, Attribute value,
Type type, Location loc) {
// If this was folded from an operation other than llvm.mlir.constant, it
// should be materialized as such. Note that an llvm.mlir.zero may fold into
// a builtin zero attribute and thus will materialize as a llvm.mlir.constant.
// if (auto symbol = dyn_cast<FlatSymbolRefAttr>(value))
// if (isa<LLVM::LLVMPointerType>(type))
// return builder.create<LLVM::AddressOfOp>(loc, type, symbol);
// if (isa<LLVM::UndefAttr>(value))
// return builder.create<LLVM::UndefOp>(loc, type);
// if (isa<LLVM::PoisonAttr>(value))
// return builder.create<LLVM::PoisonOp>(loc, type);
// if (isa<LLVM::ZeroAttr>(value))
// return builder.create<LLVM::ZeroOp>(loc, type);
// Otherwise try materializing it as a regular llvm.mlir.constant op.
return LLVM::ConstantOp::materialize(builder, value, type, loc);
}
Any ideas on how to test any modifications of this function?
Uh oh!
There was an error while loading. Please reload this page.