[Mlir-commits] [mlir] [mlir] Speed up FuncToLLVM: CallOpLowering using a hashtable (PR #68082)
Mehdi Amini
llvmlistbot at llvm.org
Tue Oct 3 11:52:46 PDT 2023
================
@@ -601,19 +602,37 @@ struct CallOpInterfaceLowering : public ConvertOpToLLVMPattern<CallOpType> {
}
};
-struct CallOpLowering : public CallOpInterfaceLowering<func::CallOp> {
- using Super::Super;
+class CallOpLowering : public CallOpInterfaceLowering<func::CallOp> {
+public:
+ CallOpLowering(const LLVMTypeConverter &typeConverter,
+ // Can be nullptr.
+ const StringSet<> *functionsHavingBarePtrAttribute,
+ PatternBenefit benefit = 1)
+ : CallOpInterfaceLowering<func::CallOp>(typeConverter, benefit),
+ barePtrCallConvForcedByOptions(
+ typeConverter.getOptions().useBarePtrCallConv),
+ functionsHavingBarePtrAttribute(functionsHavingBarePtrAttribute) {}
LogicalResult
matchAndRewrite(func::CallOp callOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
bool useBarePtrCallConv = false;
- if (Operation *callee = SymbolTable::lookupNearestSymbolFrom(
+ if (barePtrCallConvForcedByOptions) {
+ useBarePtrCallConv = true;
+ } else if (functionsHavingBarePtrAttribute != nullptr) {
+ useBarePtrCallConv = functionsHavingBarePtrAttribute->contains(
+ callOp.getCalleeAttr().getValue());
+ } else if ( // Warning: This is a linear lookup.
+ Operation *callee = SymbolTable::lookupNearestSymbolFrom(
callOp, callOp.getCalleeAttr())) {
----------------
joker-eph wrote:
Everything you're doing in this patch, I believe, is working around this bad `SymbolTable::lookupNearestSymbolFrom` API which isn't intended for repeated use.
The common pattern though is to build a SymbolTable once and pass this to the pattern instead of a custom StringSet.
Can you try that?
https://github.com/llvm/llvm-project/pull/68082
More information about the Mlir-commits
mailing list