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

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Tue Oct 3 14:34:54 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())) {
----------------
ftynse wrote:

The initial patch was doing more or less that, but the invariant of symbol uniqueness is broken during pattern rewrite as the old function is not deleted immediately and the new converted function with the same name is added. This has led to the table-based approach.

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


More information about the Mlir-commits mailing list