[Mlir-commits] [mlir] [mlir] Speed up FuncToLLVM: CallOpLowering using a hashtable (PR #68082)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 3 10:52:24 PDT 2023
================
@@ -601,19 +602,38 @@ 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 std::unordered_map<std::string, bool> *hasBarePtrAttribute,
+ PatternBenefit benefit = 1)
+ : CallOpInterfaceLowering<func::CallOp>(typeConverter, benefit),
+ barePtrCallConvForcedByOptions(
+ typeConverter.getOptions().useBarePtrCallConv),
+ hasBarePtrAttribute(hasBarePtrAttribute) {}
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 (hasBarePtrAttribute != nullptr) {
+ useBarePtrCallConv =
+ hasBarePtrAttribute->at(callOp.getCalleeAttr().getValue().str());
+ } else if ( // Warning: This is a linear lookup.
+ Operation *callee = SymbolTable::lookupNearestSymbolFrom(
callOp, callOp.getCalleeAttr())) {
- useBarePtrCallConv = shouldUseBarePtrCallConv(callee, getTypeConverter());
+ useBarePtrCallConv = callee->hasAttr(barePtrAttrName);
}
return matchAndRewriteImpl(callOp, adaptor, rewriter, useBarePtrCallConv);
}
+
+private:
+ bool barePtrCallConvForcedByOptions = false;
+ const std::unordered_map<std::string, bool> *hasBarePtrAttribute = nullptr;
----------------
tdanyluk wrote:
Thanks for the friendly explanation. I guess llvm::StringSet is the safest/easiest for now. It is also great in performance.
https://github.com/llvm/llvm-project/pull/68082
More information about the Mlir-commits
mailing list