[Mlir-commits] [mlir] [mlir][inliner] Return early if the inliningThreshold is 0U or -1U. (PR #86287)

Fabian Tschopp llvmlistbot at llvm.org
Fri Mar 22 07:19:09 PDT 2024


https://github.com/naibaf7 created https://github.com/llvm/llvm-project/pull/86287

Computing the inlinling profitability can be costly due to walking the graph when counting the number of operations.

This PR addresses that by returning early if the threshold is set to never or always inline.

>From d61e0c4a920830329ff958d4fec92b0358f9bfc1 Mon Sep 17 00:00:00 2001
From: Fabian Tschopp <fabian.tschopp at modular.com>
Date: Fri, 22 Mar 2024 15:15:47 +0100
Subject: [PATCH] [mlir][inliner] Return early if the inliningThreshold is 0U
 or -1U.

Computing the inlinling profitability can be costly due to walking the
graph when counting the number of operations.

This PR addresses that by returning early if the threshold is set to
never or always inline.
---
 mlir/lib/Transforms/InlinerPass.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Transforms/InlinerPass.cpp b/mlir/lib/Transforms/InlinerPass.cpp
index 08d8dbf73a6a1d..8be7868b576721 100644
--- a/mlir/lib/Transforms/InlinerPass.cpp
+++ b/mlir/lib/Transforms/InlinerPass.cpp
@@ -93,12 +93,17 @@ InlinerPass::InlinerPass(std::function<void(OpPassManager &)> defaultPipeline,
 // Return true if the inlining ratio does not exceed the threshold.
 static bool isProfitableToInline(const Inliner::ResolvedCall &resolvedCall,
                                  unsigned inliningThreshold) {
+  if (inliningThreshold == 0U)
+    return false;
+  if (inliningThreshold == -1U)
+    return true;
+
   Region *callerRegion = resolvedCall.sourceNode->getCallableRegion();
   Region *calleeRegion = resolvedCall.targetNode->getCallableRegion();
 
   // We should not get external nodes here, but just return true
   // for now to preserve the original behavior of the inliner pass.
-  if (!calleeRegion || !calleeRegion)
+  if (!callerRegion || !calleeRegion)
     return true;
 
   auto countOps = [](Region *region) {



More information about the Mlir-commits mailing list