[Mlir-commits] [mlir] ec7f4a7 - [mlir:LLVM] Do not lookup symbol twice in the addressof verifier
Eugene Zhulenev
llvmlistbot at llvm.org
Thu Aug 4 08:42:41 PDT 2022
Author: Eugene Zhulenev
Date: 2022-08-04T08:42:38-07:00
New Revision: ec7f4a7c5d9794c9fdf4f894873e7edbbfddf3e2
URL: https://github.com/llvm/llvm-project/commit/ec7f4a7c5d9794c9fdf4f894873e7edbbfddf3e2
DIFF: https://github.com/llvm/llvm-project/commit/ec7f4a7c5d9794c9fdf4f894873e7edbbfddf3e2.diff
LOG: [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
Added:
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 8ff803f0fd7d5..76cb05a162550 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1729,29 +1729,31 @@ LogicalResult ResumeOp::verify() {
// Verifier for LLVM::AddressOfOp.
//===----------------------------------------------------------------------===//
-template <typename OpTy>
-static OpTy lookupSymbolInModule(Operation *parent, StringRef name) {
+static Operation *lookupSymbolInModule(Operation *parent, StringRef name) {
Operation *module = parent;
while (module && !satisfiesLLVMModule(module))
module = module->getParentOp();
assert(module && "unexpected operation outside of a module");
- return dyn_cast_or_null<OpTy>(
- mlir::SymbolTable::lookupSymbolIn(module, name));
+ return mlir::SymbolTable::lookupSymbolIn(module, name);
}
GlobalOp AddressOfOp::getGlobal() {
- return lookupSymbolInModule<LLVM::GlobalOp>((*this)->getParentOp(),
- getGlobalName());
+ return dyn_cast_or_null<GlobalOp>(
+ lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
}
LLVMFuncOp AddressOfOp::getFunction() {
- return lookupSymbolInModule<LLVM::LLVMFuncOp>((*this)->getParentOp(),
- getGlobalName());
+ return dyn_cast_or_null<LLVMFuncOp>(
+ lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
}
LogicalResult AddressOfOp::verify() {
- auto global = getGlobal();
- auto function = getFunction();
+ Operation *symbol =
+ lookupSymbolInModule((*this)->getParentOp(), getGlobalName());
+
+ auto global = dyn_cast_or_null<GlobalOp>(symbol);
+ auto function = dyn_cast_or_null<LLVMFuncOp>(symbol);
+
if (!global && !function)
return emitOpError(
"must reference a global defined by 'llvm.mlir.global' or 'llvm.func'");
More information about the Mlir-commits
mailing list