Skip to content

Commit 5d18789

Browse files
authored
[mlir][inliner] Return early if the inliningThreshold is 0U or -1U. (#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.
1 parent 0024875 commit 5d18789

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mlir/lib/Transforms/InlinerPass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,19 @@ InlinerPass::InlinerPass(std::function<void(OpPassManager &)> defaultPipeline,
9393
// Return true if the inlining ratio does not exceed the threshold.
9494
static bool isProfitableToInline(const Inliner::ResolvedCall &resolvedCall,
9595
unsigned inliningThreshold) {
96+
// Return early, ratio <= 0U will always be false.
97+
if (inliningThreshold == 0U)
98+
return false;
99+
// Return early, ratio <= -1U will always be true.
100+
if (inliningThreshold == -1U)
101+
return true;
102+
96103
Region *callerRegion = resolvedCall.sourceNode->getCallableRegion();
97104
Region *calleeRegion = resolvedCall.targetNode->getCallableRegion();
98105

99106
// We should not get external nodes here, but just return true
100107
// for now to preserve the original behavior of the inliner pass.
101-
if (!calleeRegion || !calleeRegion)
108+
if (!callerRegion || !calleeRegion)
102109
return true;
103110

104111
auto countOps = [](Region *region) {

0 commit comments

Comments
 (0)