Skip to content

Commit ec7f4a7

Browse files
committed
[mlir:LLVM] Do not lookup symbol twice in the addressof verifier
`SymbolTable::lookupSymbolIn` is an expensive operation and we do not want to do it twice Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131145
1 parent d1d799b commit ec7f4a7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,29 +1729,31 @@ LogicalResult ResumeOp::verify() {
17291729
// Verifier for LLVM::AddressOfOp.
17301730
//===----------------------------------------------------------------------===//
17311731

1732-
template <typename OpTy>
1733-
static OpTy lookupSymbolInModule(Operation *parent, StringRef name) {
1732+
static Operation *lookupSymbolInModule(Operation *parent, StringRef name) {
17341733
Operation *module = parent;
17351734
while (module && !satisfiesLLVMModule(module))
17361735
module = module->getParentOp();
17371736
assert(module && "unexpected operation outside of a module");
1738-
return dyn_cast_or_null<OpTy>(
1739-
mlir::SymbolTable::lookupSymbolIn(module, name));
1737+
return mlir::SymbolTable::lookupSymbolIn(module, name);
17401738
}
17411739

17421740
GlobalOp AddressOfOp::getGlobal() {
1743-
return lookupSymbolInModule<LLVM::GlobalOp>((*this)->getParentOp(),
1744-
getGlobalName());
1741+
return dyn_cast_or_null<GlobalOp>(
1742+
lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
17451743
}
17461744

17471745
LLVMFuncOp AddressOfOp::getFunction() {
1748-
return lookupSymbolInModule<LLVM::LLVMFuncOp>((*this)->getParentOp(),
1749-
getGlobalName());
1746+
return dyn_cast_or_null<LLVMFuncOp>(
1747+
lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
17501748
}
17511749

17521750
LogicalResult AddressOfOp::verify() {
1753-
auto global = getGlobal();
1754-
auto function = getFunction();
1751+
Operation *symbol =
1752+
lookupSymbolInModule((*this)->getParentOp(), getGlobalName());
1753+
1754+
auto global = dyn_cast_or_null<GlobalOp>(symbol);
1755+
auto function = dyn_cast_or_null<LLVMFuncOp>(symbol);
1756+
17551757
if (!global && !function)
17561758
return emitOpError(
17571759
"must reference a global defined by 'llvm.mlir.global' or 'llvm.func'");

0 commit comments

Comments
 (0)