summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/Inliner.cpp
AgeCommit message (Collapse)Author
2025-05-28[MemProf] Emit remarks when hinting allocations not needing cloning (#141859)Teresa Johnson
The context disambiguation code already emits remarks when hinting allocations (by adding hotness attributes) during cloning. However, we did not yet emit hints when applying the hotness attributes during building of the metadata (during matching and again after inlining). Add remarks when we apply the hint attributes for these non-context-sensitive allocations.
2025-03-22Revert "[Analysis][EphemeralValuesAnalysis][NFCI] Remove ↵Vasileios Porpodas
EphemeralValuesCache class (#132454)" This reverts commit 4adefcfb856aa304b7b0a9de1eec1814f3820e83.
2025-03-21[Analysis][EphemeralValuesAnalysis][NFCI] Remove EphemeralValuesCache class ↵vporpo
(#132454) This is a follow-up to https://github.com/llvm/llvm-project/pull/130210. The EphemeralValuesAnalysis pass used to return an EphemeralValuesCache object which used to hold the ephemeral values and used to provide a lazy collection of the ephemeral values, and an invalidation using the `clear()` function. This patch removes the EphemeralValuesCache class completely and instead returns the SmallVector containing the ephemeral values.
2025-03-19[Analysis][EphemeralValuesCache][InlineCost] Ephemeral values caching for ↵vporpo
the CallAnalyzer (#130210) This patch does two things: 1. It implements an ephemeral values cache analysis pass that collects the ephemeral values of a function and caches them for fast lookups. The collection of the ephemeral values is done lazily when the user calls `EphemeralValuesCache::ephValues()`. 2. It adds caching of ephemeral values using the `EphemeralValuesCache` to speed up `CallAnalyzer::analyze()`. Without caching this can take a long time to run in cases where the function contains a large number of `@llvm.assume()` calls and a large number of callsites. The time is spent in `collectEphemeralvalues()`.
2024-11-03[IPO] Remove unused includes (NFC) (#114716)Kazu Hirata
Identified with misc-include-cleaner.
2024-06-28[Inliner] Pass updated SCC to InlineAdvisor::onPassExit() (#96553)Arthur Eubanks
InitialC may be logically invalid, although iterating through it doesn't crash. Always use the updated SCC.
2024-06-11[CGSCC] Fix compile time blowup with large RefSCCs (#94815)Arthur Eubanks
In some modules, e.g. Kotlin-generated IR, we end up with a huge RefSCC and the call graph updates done as a result of the inliner take a long time. This is due to RefSCC::removeInternalRefEdges() getting called many times, each time removing one function from the RefSCC, but each call to removeInternalRefEdges() is proportional to the size of the RefSCC. There are two places that call removeInternalRefEdges(), in updateCGAndAnalysisManagerForPass() and LazyCallGraph::removeDeadFunction(). 1) Since LazyCallGraph can deal with spurious (edges that exist in the graph but not in the IR) ref edges, we can simply not call removeInternalRefEdges() in updateCGAndAnalysisManagerForPass(). 2) LazyCallGraph::removeDeadFunction() still ends up taking the brunt of compile time with the above change for the original reason. So instead we batch all the dead function removals so we can call removeInternalRefEdges() just once. This requires some changes to callers of removeDeadFunction() to not actually erase the function from the module, but defer it to when we batch delete dead functions at the end of the CGSCC run, leaving the function body as "unreachable" in the meantime. We still need to ensure that call edges are accurate. I had also tried deleting dead functions after visiting a RefSCC, but deleting them all at once at the end was simpler. Many test changes are due to not performing unnecessary revisits of an SCC (the CGSCC infrastructure deems ref edge refinements as unimportant when it comes to revisiting SCCs, although that seems to not be consistently true given these changes) because we don't remove some ref edges. Specifically for devirt-invalidated.ll this seems to expose an inlining order issue with the inliner. Probably unimportant for this type of intentionally weird call graph. Compile time: https://llvm-compile-time-tracker.com/compare.php?from=6f2c61071c274a1b5e212e6ad4114641ec7c7fc3&to=b08c90d05e290dd065755ea776ceaf1420680224&stat=instructions:u
2023-12-03[llvm] Stop including vector (NFC)Kazu Hirata
Identified with clangd.
2023-11-11[llvm] Stop including llvm/ADT/DenseMap.h (NFC)Kazu Hirata
Ientified with clangd.
2023-05-25[Inliner] Mark inlinings stopped with inlining history as noinlineArthur Eubanks
The inline history makes sure that we don't keep inlining due to mutual devirtualization. But this gets forgotten between inliner invocations. So mark the inlined calls as noinline so we respect previous inline history decisions. This overlaps with D121084, but they're not redundant since we may not inline completely through a child SCC, but we still want a cost multiplier when that happens. See discussions in D145516. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D150989
2023-03-21[AlwaysInliner] Make legacy pass like the new passArthur Eubanks
The legacy pass is only used in AMDGPU codegen, which doesn't care about running it in call graph order (it actually has to work around that fact). Make the legacy pass a module pass and share code with the new pass. This allows us to remove the legacy inliner infrastructure. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D146446
2023-03-16[Inliner] clang-format InlineCost.cpp and Inliner.cpp (NFC)Kazu Hirata
2023-03-16[Inliner] Remove alloca mergingArthur Eubanks
See https://discourse.llvm.org/t/rfc-we-should-stop-merging-allocas-in-the-inliner/41975 for the RFC from 2016 around this. Backend stack coloring takes care of what this initially set out to help with. This only affects the legacy inliner, which for the most part doesn't matter anymore. The new PM inliner never looked at this flag. There are some backends running the legacy always-inline pass, but that's unlikely to matter. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D146091
2023-03-07[Inliner][NFC] Remove redundant nullptr checkAlex MacLean
Remove the null pointer check on Callee since it is guaranteed to pass by the check at the top of the loop which continues if Callee is null. While this change is somewhat trivial, for what it's worth this check triggers Coverity warnings because it implies that Callee might be null at this point even though it is dereferenced in the preceding code. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D145463
2023-02-22[NFC] Use single quotes for single char output during `printPipline`Liren Peng
Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D144365
2022-12-05Remove unused #include "llvm/ADT/Optional.h"Fangrui Song
2022-11-24[Inliner] Move cl::opt inside llvm::Fangrui Song
2022-09-20[IPO] Reorder parameters of InlineFunction (NFC)Kazu Hirata
With the recent addition of new parameter MergeAttributes (D134117), callers need to specify several default parameters before getting to specify the new parameter. This patch reorders the parameters so that callers do not have to specify as many default parameters. Differential Revision: https://reviews.llvm.org/D134125
2022-09-17[Transforms] Merge function attributes within InlineFunction (NFC)Kazu Hirata
In the past, we've had a bug resulting in a compiler crash after forgetting to merge function attributes (D105729). This patch teaches InlineFunction to merge function attributes. This way, we minimize the "time" when the IR is valid, but the function attributes are not. Differential Revision: https://reviews.llvm.org/D134117
2022-09-16[Inliner] Retire DefaultInlineOrder (NFC)Kazu Hirata
DefaultInlineOrder was largely an exercise in generalizing the traversal order of call sites within the inliner. Now that the module inliner is starting to form its shape, there is no point in sharing DefaultInlineOrder between the module inliner and the CGSCC inliner. DefaultInlineOrder and all the other inline orders are mutually exclusive in the following sense: - The use of DefaultInlineOrder doesn't make sense in the module inliner because there is no priority inherent in the order in which call sites are added to the list of call sites -- SmallVector. - The use of any other inline order doesn't make sense in the CGSCC inliner because little prioritization can be done within one CGSCC. This patch essentially reverts the addition of DefaultInlineOrder so that the loop structure of Inliner.cpp looks like the state just before we started working on the module inliner (circa June 2021). At the same time, ww remove the choice of DefaultInlineOrder from UseInlinePriority. Differential Revision: https://reviews.llvm.org/D134080
2022-06-24[Inline] Annotate inline pass name with link phase information for analysis.Mingming Liu
The annotation is flag gated; flag is turned off by default. Differential Revision: https://reviews.llvm.org/D125495
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata
2022-06-15[mlgo] Fix accounting for SCC splitsJin Xin Ng
Previously if the inliner split an SCC such that an empty one remained, the MLInlineAdvisor could potentially lose track of the EdgeCount if a subsequent CGSCC pass modified the calls of a function that was initially in the SCC pre-split. Saving the seen nodes in onPassEntry resolves this. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D127693
2022-06-14[inliner] Add per-SCC-pass InlineAdvisor printing optionJin Xin Ng
Adds option to print the contents of the Inline Advisor after each SCC Inliner pass Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D127689
2022-04-26[llvm][Inline] Remove PriorityInlineOrder in SCC inlinerLiqiang Tao
Since the size of most of SCC's is 1, the PriorityInlineOrder would not change the inline order in SCC inliner. Reviewed By: kazu Differential Revision: https://reviews.llvm.org/D123608
2022-03-22Cleanup includes: Transforms/IPOserge-sans-paille
Preprocessor output diff: -238205 lines Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D122183
2022-03-07[NewPM][Inliner] Make inlined calls to functions in same SCC as callee ↵Arthur Eubanks
exponentially expensive Introduce a new attribute "function-inline-cost-multiplier" which multiplies the inline cost of a call site (or all calls to a callee) by the multiplier. When processing the list of calls created by inlining, check each call to see if the new call's callee is in the same SCC as the original callee. If so, set the "function-inline-cost-multiplier" attribute of the new call site to double the original call site's attribute value. This does not happen when the original call site is intra-SCC. This is an alternative to D120584, which marks the call sites as noinline. Hopefully fixes PR45253. Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D121084
2022-03-01Cleanup includes: LLVMAnalysisserge-sans-paille
Number of lines output by preprocessor: before: 1065940348 after: 1065307662 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120659
2022-01-18[mlgo][inline] Improve global state trackingMircea Trofin
The global state refers to the number of the nodes currently in the module, and the number of direct calls between nodes, across the module. Node counts are not a problem; edge counts are because we want strictly the kind of edges that affect inlining (direct calls), and that is not easily obtainable without iteration over the whole module. This patch avoids relying on analysis invalidation because it turned out to be too aggressive in some cases. It leverages the fact that Node objects are stable - they do not get deleted while cgscc passes are run over the module; and cgscc pass manager invariants. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D115847
2022-01-13[Inline] Attempt to delete any discardable if unused functionsArthur Eubanks
Previously we limited ourselves to only internal/private functions. We can also delete linkonce_odr functions. Minor compile time wins: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=instructions Major memory wins on tramp3d: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=max-rss Relanding with fix for compile times D117236. Reviewed By: nikic, mtrofin Differential Revision: https://reviews.llvm.org/D115545
2022-01-13[Inliner] Don't removeDeadConstantUsers() when checking if a function is deadArthur Eubanks
If a function has many uses, this can take a good chunk of compile times. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D117236
2022-01-13Revert "[Inline] Attempt to delete any discardable if unused functions"James Y Knight
Somehow this ends up causing an infinite loop in the inliner. This reverts commit d5be48c66d3e5e8be21805c3a33dc67a20e258be.
2022-01-12[Inline] Attempt to delete any discardable if unused functionsArthur Eubanks
Previously we limited ourselves to only internal/private functions. We can also delete linkonce_odr functions. Minor compile time wins: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=instructions Major memory wins on tramp3d: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=max-rss Reviewed By: nikic, mtrofin Differential Revision: https://reviews.llvm.org/D115545
2022-01-11[NFC][MLGO] Use LazyCallGraph::Node to track functions.Mircea Trofin
This avoids the InlineAdvisor carrying the responsibility of deleting Function objects. We use LazyCallGraph::Node objects instead, which are stable in memory for the duration of the Module-wide performance of CGSCC passes started under the same ModuleToPostOrderCGSCCPassAdaptor (which is the case here) Differential Revision: https://reviews.llvm.org/D116964
2022-01-07[llvm] Remove redundant member initialization (NFC)Kazu Hirata
Identified with readability-redundant-member-init.
2022-01-07Revert "[Inline] Attempt to delete any discardable if unused functions"Arthur Eubanks
This reverts commit 335a3163aab4ab3a52c7c15d03bcf1ce9ba79fbb. Causes crashes when building llvm-test-suite's kc under ReleaseLTO-g.
2022-01-07[Inline] Attempt to delete any discardable if unused functionsArthur Eubanks
Previously we limited ourselves to only internal/private functions. We can also delete linkonce_odr functions. Minor compile time wins: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=instructions Major memory wins on tramp3d: https://llvm-compile-time-tracker.com/compare.php?from=d51e3474e060cb0e90dc2e2487f778b0d3e6a8de&to=bccffe3f8d5dd4dda884c9ac1f93e51772519cad&stat=max-rss Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D115545
2022-01-07[ModuleUtils] Remove dead arg from filterDeadComdatFunctions() (NFC)Nikita Popov
The module argument is no longer used.
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata
Identified with readability-redundant-member-init.
2021-12-09[Inliner] Add debug message for history skip (NFC)Nikita Popov
2021-11-17[NewPM] Add option to prevent rerunning function pipeline on functions in ↵Arthur Eubanks
CGSCC adaptor In a CGSCC pass manager, we may visit the same function multiple times due to SCC mutations. In the inliner pipeline, this results in running the function simplification pipeline on a function multiple times even if it hasn't been changed since the last function simplification pipeline run. We use a newly introduced analysis to keep track of whether or not a function has changed since the last time the function simplification pipeline has run on it. If we see this analysis available for a function in a CGSCCToFunctionPassAdaptor, we skip running the function passes on the function. The analysis is queried at the end of the function passes so that it's available after the first time the function simplification pipeline runs on a function. This is a per-adaptor option so it doesn't apply to every adaptor. The goal of this is to improve compile times. However, currently we can't turn this on by default at least for the higher optimization levels since the function simplification pipeline is not robust enough to be idempotent in many cases, resulting in performance regressions if we stop running the function simplification pipeline on a function multiple times. We may be able to turn this on for -O1 in the near future, but turning this on for higher optimization levels would require more investment in the function simplification pipeline. Heavily inspired by D98103. Example compile time improvements with flag turned on: https://llvm-compile-time-tracker.com/compare.php?from=998dc4a5d3491d2ae8cbe742d2e13bc1b0cacc5f&to=5c27c913687d3d5559ef3ab42b5a3d513531d61c&stat=instructions Reviewed By: asbirlea, nikic Differential Revision: https://reviews.llvm.org/D113947
2021-11-15[NewPM] Only invalidate modified functions' analyses in CGSCC passes + turn ↵Arthur Eubanks
on eagerly invalidate analyses Previously, any change in any function in an SCC would cause all analyses for all functions in the SCC to be invalidated. With this change, we now manually invalidate analyses for functions we modify, then let the pass manager know that all function analyses should be preserved since we've already handled function analysis invalidation. So far this only touches the inliner, argpromotion, function-attrs, and updateCGAndAnalysisManager(), since they are the most used. This is part of an effort to investigate running the function simplification pipeline less on functions we visit multiple times in the inliner pipeline. However, this causes major memory regressions especially on larger IR. To counteract this, turn on the option to eagerly invalidate function analyses. This invalidates analyses on functions immediately after they're processed in a module or scc to function adaptor for specific parts of the pipeline. Within an SCC, if a pass only modifies one function, other functions in the SCC do not have their analyses invalidated, so in later function passes in the SCC pass manager the analyses may still be cached. It is only after the function passes that the eager invalidation takes effect. For the default pipelines this makes sense because the inliner pipeline runs the function simplification pipeline after all other SCC passes (except CoroSplit which doesn't request any analyses). Overall this has mostly positive effects on compile time and positive effects on memory usage. https://llvm-compile-time-tracker.com/compare.php?from=7f627596977624730f9298a1b69883af1555765e&to=39e824e0d3ca8a517502f13032dfa67304841c90&stat=instructions https://llvm-compile-time-tracker.com/compare.php?from=7f627596977624730f9298a1b69883af1555765e&to=39e824e0d3ca8a517502f13032dfa67304841c90&stat=max-rss D113196 shows that we slightly regressed compile times in exchange for some memory improvements when turning on eager invalidation. D100917 shows that we slightly improved compile times in exchange for major memory regressions in some cases when invalidating less in SCC passes. Turning these on at the same time keeps the memory improvements while keeping compile times neutral/slightly positive. Reviewed By: asbirlea, nikic Differential Revision: https://reviews.llvm.org/D113304
2021-10-29[InlineAdvisor] Add fallback/format switches and negative remark processing ↵modimo
to Replay Inliner Adds the following switches: 1. --sample-profile-inline-replay-fallback/--cgscc-inline-replay-fallback: controls what the replay advisor does for inline sites that are not present in the replay. Options are: 1. Original: defers to original advisor 2. AlwaysInline: inline all sites not in replay 3. NeverInline: inline no sites not in replay 2. --sample-profile-inline-replay-format/--cgscc-inline-replay-format: controls what format should be generated to match against the replay remarks. Options are: 1. Line 2. LineColumn 3. LineDiscriminator 4. LineColumnDiscriminator Adds support for negative inlining decisions. These are denoted by "will not be inlined into" as compared to the positive "inlined into" in the remarks. All of these together with the previous `--sample-profile-inline-replay-scope/--cgscc-inline-replay-scope` allow tweaking in how to apply replay. In my testing, I'm using: 1. --sample-profile-inline-replay-scope/--cgscc-inline-replay-scope = Function to only replay on a function 2. --sample-profile-inline-replay-fallback/--cgscc-inline-replay-fallback = NeverInline since I'm feeding in only positive remarks to the replay system 3. --sample-profile-inline-replay-format/--cgscc-inline-replay-format = Line since I'm generating the remarks from DWARF information from GCC which can conflict quite heavily in column number compared to Clang An alternative configuration could be to do Function, AlwaysInline, Line fallback with negative remarks which closer matches the final call-sites. Note that this can lead to unbounded inlining if a negative remark doesn't match/exist for one reason or another. Updated various tests to cover the new switches and negative remarks Testing: ninja check-all Reviewed By: wenlei, mtrofin Differential Revision: https://reviews.llvm.org/D112040
2021-10-18[InlineAdvisor] Add -inline-replay-scope=<Function|Module> to control replay ↵modimo
scope The goal is to allow grafting an inline tree from Clang or GCC into a new compilation without affecting other functions. For GCC, we're doing this by extracting the inline tree from dwarf information and generating the equivalent remarks. This allows easier side-by-side asm analysis and a trial way to see if a particular inlining setup provides benefits by itself. Testing: ninja check-all Reviewed By: wenlei, mtrofin Differential Revision: https://reviews.llvm.org/D110658
2021-10-12[Inline] Make sure the InlineAdvisor is correctly cleared.Mircea Trofin
If another inlining session came after a ModuleInlinerWrapperPass, the advisor alanysis would still be cached, but its Result would be cleared. We need to clear both. This addresses PR52118 Differential Revision: https://reviews.llvm.org/D111586
2021-10-05[inliner] Mandatory inlining decisions produce remarksMircea Trofin
This also removes the need to disable the mandatory inlining phase in tests. In a departure from the previous remark, we don't output a 'cost' in this case, because there's no such thing. We just report that inlining happened because of the attribute. Differential Revision: https://reviews.llvm.org/D110891
2021-09-23[ModuleInlinerWrapperPass] Do some naive printing of wrapped pipeline with ↵Bjorn Pettersson
-print-pipeline-passes Bisecting and reducing opt pipelines that includes the ModuleInlinerWrapperPass has turned out to be a bit problematic. This is far from perfect (it still lacks information about inline advisor params etc.), but it should give some kind of hint to what the wrapped pipeline looks like when using -print-pipeline-passes. Reviewed By: aeubanks, mtrofin Differential Revision: https://reviews.llvm.org/D109878
2021-09-20[NewPM] Make InlinerPass (aka 'inline') a parameterized passBjorn Pettersson
In default pipelines the ModuleInlinerWrapperPass is adding the InlinerPass to the pipeline twice, once due to MandatoryFirst (passing true in the ctor) and then a second time with false as argument. To make it possible to bisect and reduce opt test cases for this part of the pipeline we need to be able to choose between the two different variants of the InlinerPass when running opt. This patch is changing 'inline' to a CGSCC_PASS_WITH_PARAMS in the PassRegistry, making it possible run opt with both -passes=cgscc(inline) and -passes=cgscc(inline<only-mandatory>). Reviewed By: aeubanks, mtrofin Differential Revision: https://reviews.llvm.org/D109877
2021-08-12[llvm][Inline] Refactor out InlineOrderLiqiang Tao
Move InlineOrder to separated file. Reviewed By: kazu Differential Revision: https://reviews.llvm.org/D107831