diff options
author | Fabian Tschopp <fabian.tschopp@modular.com> | 2024-03-23 00:09:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-23 00:09:11 +0100 |
commit | 5d187898f625cc54310f51b278b36ad6a97104ee (patch) | |
tree | d44cec39c81c25604840c0aa32d8427ee86e9d69 /mlir | |
parent | 00248754176d74aed2e0785d9982a5ea8e91a71a (diff) | |
download | llvm-5d187898f625cc54310f51b278b36ad6a97104ee.zip llvm-5d187898f625cc54310f51b278b36ad6a97104ee.tar.gz llvm-5d187898f625cc54310f51b278b36ad6a97104ee.tar.bz2 |
[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.
Diffstat (limited to 'mlir')
-rw-r--r-- | mlir/lib/Transforms/InlinerPass.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/mlir/lib/Transforms/InlinerPass.cpp b/mlir/lib/Transforms/InlinerPass.cpp index 08d8dbf..9a7d540 100644 --- a/mlir/lib/Transforms/InlinerPass.cpp +++ b/mlir/lib/Transforms/InlinerPass.cpp @@ -93,12 +93,19 @@ 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) { + // Return early, ratio <= 0U will always be false. + if (inliningThreshold == 0U) + return false; + // Return early, ratio <= -1U will always be true. + 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) { |