Skip to content

[mlir][inliner] Return early if the inliningThreshold is 0U or -1U. #86287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

naibaf7
Copy link
Contributor

@naibaf7 naibaf7 commented Mar 22, 2024

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.

@naibaf7 naibaf7 requested a review from Mogball March 22, 2024 14:19
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Mar 22, 2024
@naibaf7 naibaf7 requested review from joker-eph and vzakhari March 22, 2024 14:19
@llvmbot
Copy link
Member

llvmbot commented Mar 22, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Fabian Tschopp (naibaf7)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/86287.diff

1 Files Affected:

  • (modified) mlir/lib/Transforms/InlinerPass.cpp (+6-1)
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) {

@naibaf7 naibaf7 requested a review from weiweichen March 22, 2024 14:19
Copy link
Contributor

@weiweichen weiweichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@dukebw dukebw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

github-actions bot commented Mar 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

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.
Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix!

@joker-eph
Copy link
Collaborator

And I thought I had checked for this on the original revision…. Apparently not, thanks for the fix!

@naibaf7 naibaf7 merged commit 5d18789 into llvm:main Mar 22, 2024
@naibaf7 naibaf7 deleted the inliner branch March 22, 2024 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants