[Mlir-commits] [mlir] [mlir] Speed up FuncToLLVM: CallOpLowering using a hashtable (PR #68082)

Mehdi Amini llvmlistbot at llvm.org
Tue Oct 3 14:43:41 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:

I see, that's fair.
I still have comments on the right datastructure here :)
It seems to me that a `SmallPtrSet` (using the `StringAttr` impl pointer) would be better: no need to own the string when everything is an attribute.



https://github.com/llvm/llvm-project/pull/68082


More information about the Mlir-commits mailing list