summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
AgeCommit message (Collapse)Author
2025-02-18[Analysis] Remove skipSCC (#127412)Kazu Hirata
The last use was removed in: commit fa6ea7a419f37befbed04368bcb8af4c718facbb Author: Arthur Eubanks <aeubanks@google.com> Date: Mon Mar 20 11:18:35 2023 -0700
2024-12-12[AlwaysInline] Fix analysis invalidation (#119566)Nikita Popov
This is a followup to #117750. Currently, AlwaysInline only invalidates analyses at the end, by returning that no analyses are preserved. However, this means that analyses fetched during inlining may be outdated. The aforementioned PR exposed this issue. Instead, bring the logic closer to what the normal inliner does, by directly invalidating the caller in FAM. This should make sure that we don't receive any outdated analyses even if they are fetched during inlining. Also drop the BFI updating entirely -- there's no point in doing it if we're going to invalidate everything anyway.
2024-11-27[AlwaysInline] Avoid unnecessary BFI fetches (#117750)Nikita Popov
AlwaysInliner doesn't use BFI itself, it only updates it. If BFI is not already computed, it will spend time to first compute it, and then update it. This is not necessary: If BFI is not available in the first place, there is no need to update it. This is mainly relevant in debug builds for IR that has a lot of alwaysinline functions.
2024-07-02[NFC][AlwaysInliner] Reduce AlwaysInliner memory consumption. (#96958)Daniil Fukalov
Refactored AlwaysInliner to remove some of inlined functions earlier. Before the change AlwaysInliner walked through all functions in the module and inlined them into calls where it is appropriate. Removing of the dead inlined functions was performed only after all of inlining. For the test case from the issue [59126](https://github.com/llvm/llvm-project/issues/59126) compiler consumes all of the memory on 64GB machine, so is killed. The change checks if just inlined function can be removed from the module and removes it.
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
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-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-17[AlwaysInliner] Emit inline remark only when successfulEllis Hoag
Failures in `InlineFunction()` are caught after D121722, but `emitInlinedIntoBasedOnCost()` should only be called when inlining is successful. This also removes an unnecessary call to `shouldInline()` which always returned `InlineCost::getAlways()`. Reviewed By: kyulee, nikic Differential Revision: https://reviews.llvm.org/D121946
2022-03-17[AlwaysInliner] Check inliner errors even without asssertsEllis Hoag
When we build clang without asserts we should still check the result of `InlineFunction()` to be sure there wasn't an error. Otherwise we could incorrectly merge attributes in the next line. This also removes a redundent call to `getCaller()`. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D121722
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-02-14[AlwaysInliner] Check for callsite noinline attribute simplifiedDávid Bolvanský
2022-02-11[AlwaysInliner] Respect noinline call site attributeDávid Bolvanský
``` always_inline foo() { } bar () { noinline foo(); } ``` We should prefer call site attribute over attribute on decl. This is fix for AlwaysInliner, similar fix is needed for normal Inliner (follow up). Related to https://reviews.llvm.org/D119061 Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D119553
2022-01-26Reland "[AlwaysInliner] Enable call site inlining to make flatten attribute ↵Dávid Bolvanský
working again (#53360)"
2022-01-25Revert "[AlwaysInliner] Enable call site inlining to make flatten attribute ↵Dávid Bolvanský
working again (#53360)" This reverts commit ceec4383681c42bfd3d06a6913ce7554bea160b0. Clang tests fail.
2022-01-25[AlwaysInliner] Enable call site inlining to make flatten attribute working ↵Dávid Bolvanský
again (#53360) Problem: Migration to new PM broke flatten attribute. This is one use case why LLVM should support inlining call-site with alwaysinline. The flatten attribute is nowdays broken, so we should either land patch like this one or remove everything related to flatten attribute from Clang. Second use case is something like "per call site inlining intrinsics" to control inlining even more; mentioned in https://lists.llvm.org/pipermail/cfe-dev/2018-September/059232.html Fixes https://github.com/llvm/llvm-project/issues/53360 Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D117965
2022-01-07[ModuleUtils] Remove dead arg from filterDeadComdatFunctions() (NFC)Nikita Popov
The module argument is no longer used.
2021-10-25[AlwaysInliner] Invalidate analyses when we delete functionsArthur Eubanks
Fixes PR52292. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D112473
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
2020-12-08[coroutine] should disable inline before calling coro splitXun Li
This is a rework of D85812, which didn't land. When callee coroutine function is inlined into caller coroutine function before coro-split pass, llvm will emits "coroutine should have exactly one defining @llvm.coro.begin". It seems that coro-early pass can not handle this quiet well. So we believe that unsplited coroutine function should not be inlined. This patch fix such issue by not inlining function if it has attribute "coroutine.presplit" (it means the function has not been splited) to fix this issue test plan: check-llvm, check-clang In D85812, there was suggestions on moving the macros to Attributes.td to avoid circular header dependency issue. I believe it's not worth doing just to be able to use one constant string in one place. Today, there are already 3 possible attribute values for "coroutine.presplit": https://github.com/llvm/llvm-project/blob/c6543cc6b8f107b58e7205d8fc64865a508bacba/llvm/lib/Transforms/Coroutines/CoroInternal.h#L40-L42 If we move them into Attributes.td, we would be adding 3 new attributes to EnumAttr, just to support this, which I think is an overkill. Instead, I think the best way to do this is to add an API in Function class that checks whether this function is a coroutine, by checking the attribute by name directly. Differential Revision: https://reviews.llvm.org/D92706
2020-11-13[AlwaysInliner] Call mergeAttributesForInlining after inliningGuozhi Wei
Like inlineCallIfPossible and InlinerPass, after inlining mergeAttributesForInlining should be called to merge callee's attributes to caller. But it is not called in AlwaysInliner, causes caller's attributes inconsistent with inlined code. Attached test case demonstrates that attribute "min-legal-vector-width"="512" is not merged into caller without this patch, and it causes failure in SelectionDAG when lowering the inlined AVX512 intrinsic. Differential Revision: https://reviews.llvm.org/D91446
2020-10-26Reland [AlwaysInliner] Pass callee AAResults to InlineFunction()Arthur Eubanks
Test copied from noalias-calls.ll with small changes. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D89609
2020-10-26Revert "[AlwaysInliner] Pass callee AAResults to InlineFunction()"Arthur Eubanks
This reverts commit 504fbec7a61cdfbb5f6e1b25cf14afe5195ccaf6. Test failure.
2020-10-26[AlwaysInliner] Pass callee AAResults to InlineFunction()Arthur Eubanks
Test copied from noalias-calls.ll with small changes. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D89609
2020-10-02Reland [AlwaysInliner] Update BFI when inliningArthur Eubanks
Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D88324
2020-10-02Revert "[AlwaysInliner] Update BFI when inlining"Arthur Eubanks
This reverts commit b1bf24667fc3ec5dc4b541148d0d722ffa28a6df.
2020-10-02[AlwaysInliner] Update BFI when inliningArthur Eubanks
Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D88324
2020-09-21[AlwaysInliner] Emit optimization remarksArthur Eubanks
To match the normal inliner in preparation for https://reviews.llvm.org/D86988. Also change a FIXME to an assert. Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D88067
2020-08-24Revert D85812 "[coroutine] should disable inline before calling coro split"Fangrui Song
This reverts commit 2e43acfed89b1903de473f682c65878bdebc395a. LLVMCoroutines (the library which contains Coroutines.h) depends on LLVMipo (the library which contains SampleProfile.cpp). It is inappropriate for SampleProfile.cpp to depent on Coroutines.h (circular dependency). The test inverted dependencies as well: llvm/test/Transforms/Coroutines/coro-inline.ll uses -sample-profile.
2020-08-24[coroutine] should disable inline before calling coro splitdongAxis
summary: When callee coroutine function is inlined into caller coroutine function before coro-split pass, llvm will emits "coroutine should have exactly one defining @llvm.coro.begin". It seems that coro-early pass can not handle this quiet well. So we believe that unsplited coroutine function should not be inlined. This patch fix such issue by not inlining function if it has attribute "coroutine.presplit" (it means the function has not been splited) to fix this issue TestPlan: check-llvm Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D85812
2020-05-15Revert "Revert "[llvm][NFC] Cleanup uses of std::function in ↵Mircea Trofin
Inlining-related APIs"" This reverts commit 454de99a6fec705e76ed7743bf538f7a77296f59. The problem was that one of the ctor arguments of CallAnalyzer was left to be const std::function<>&. A function_ref was passed for it, and then the ctor stored the value in a function_ref field. So a std::function<> would be created as a temporary, and not survive past the ctor invocation, while the field would. Tested locally by following https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild Original Differential Revision: https://reviews.llvm.org/D79917
2020-05-14Revert "[llvm][NFC] Cleanup uses of std::function in Inlining-related APIs"Mircea Trofin
This reverts commit 767db5be67cab5aa04d81227725765cad9620611.
2020-05-14[llvm][NFC] Cleanup uses of std::function in Inlining-related APIsMircea Trofin
Summary: Replacing uses of std::function pointers or refs, or Optional, to function_ref, since the usage pattern allows that. If the function is optional, using a default parameter value (nullptr). This led to a few parameter reshufles, to push all optionals to the end of the parameter list. Reviewers: davidxl, dblaikie Subscribers: arsenm, jvesely, nhaehnle, eraman, hiraditya, haicheng, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79917
2020-04-13[llvm][NFC] CallSite removal from inliner-related filesMircea Trofin
Summary: This removes CallSite from inliner files. Some dependencies where thus affected. Reviewers: dblaikie, davidxl, craig.topper Subscribers: arsenm, jvesely, nhaehnle, eraman, hiraditya, aheejin, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77991
2020-01-15[NFC] Refactor InlineResult for readabilityMircea Trofin
Summary: InlineResult is used both in APIs assessing whether a call site is inlinable (e.g. llvm::isInlineViable) as well as in the function inlining utility (llvm::InlineFunction). It means slightly different things (can/should inlining happen, vs did it happen), and the implicit casting may introduce ambiguity (casting from 'false' in InlineFunction will default a message about hight costs, which is incorrect here). The change renames the type to a more generic name, and disables implicit constructors. Reviewers: eraman, davidxl Reviewed By: davidxl Subscribers: kerbowa, arsenm, jvesely, nhaehnle, eraman, hiraditya, haicheng, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72744
2019-11-13Sink all InitializePasses.h includesReid Kleckner
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-06-13[clang][NewPM] Fix broken -O0 test from missing assumptionsLeonard Chan
Add an AssumptionCache callback to the InlineFuntionInfo used for the AlwaysInlinerPass to match codegen of the AlwaysInlinerLegacyPass to generate llvm.assume. This fixes CodeGen/builtin-movdir.c when new PM is enabled by default. Differential Revision: https://reviews.llvm.org/D63170 llvm-svn: 363287
2019-02-01Provide reason messages for unviable inliningYevgeny Rouban
InlineCost's isInlineViable() is changed to return InlineResult instead of bool. This provides messages for failure reasons and allows to get more specific messages for cases where callsites are not viable for inlining. Reviewed By: xbolva00, anemet Differential Revision: https://reviews.llvm.org/D57089 llvm-svn: 352849
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-08-05Enrich inline messagesDavid Bolvansky
Summary: This patch improves Inliner to provide causes/reasons for negative inline decisions. 1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message. 2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision. 3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost. 4. Adjusted tests for changed printing. Patch by: yrouban (Yevgeny Rouban) Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00 Reviewed By: tejohnson, xbolva00 Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith Differential Revision: https://reviews.llvm.org/D49412 llvm-svn: 338969
2018-08-01Revert "Enrich inline messages", tests failDavid Bolvansky
llvm-svn: 338496
2018-08-01Enrich inline messagesDavid Bolvansky
Summary: This patch improves Inliner to provide causes/reasons for negative inline decisions. 1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message. 2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision. 3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost. 4. Adjusted tests for changed printing. Patch by: yrouban (Yevgeny Rouban) Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00 Reviewed By: tejohnson, xbolva00 Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith Differential Revision: https://reviews.llvm.org/D49412 llvm-svn: 338494
2018-07-31Revert Enrich inline messagesDavid Bolvansky
llvm-svn: 338389
2018-07-31Enrich inline messagesDavid Bolvansky
Summary: This patch improves Inliner to provide causes/reasons for negative inline decisions. 1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message. 2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision. 3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost. 4. Adjusted tests for changed printing. Patch by: yrouban (Yevgeny Rouban) Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00 Reviewed By: tejohnson, xbolva00 Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith Differential Revision: https://reviews.llvm.org/D49412 llvm-svn: 338387
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-01-08AlwaysInliner: Alow setting InsertLifetime in the new-style passJustin Bogner
llvm-svn: 322033
2017-12-13Remove redundant includes from lib/Transforms.Michael Zolotukhin
llvm-svn: 320628
2016-12-26[PM] Teach the always inliner in the new pass manager to supportChandler Carruth
removing fully-dead comdats without removing dead entries in comdats with live members. This factors the core logic out of the current inliner's internals to a reusable utility and leverages that in both places. The factored out code should also be (minorly) more efficient in cases where we have very few dead functions or dead comdats to consider. I've added a test case to cover this behavior of the always inliner. This is the last significant bug in the new PM's always inliner I've found (so far). llvm-svn: 290557
2016-12-23[PM] Teach the always inlining test case to be much more strict aboutChandler Carruth
whether functions are removed, and fix the new PM's always inliner to actually pass this test. Without this, the new PM's always inliner leaves all the functions kicking around which won't work out very well given the semantics of always inline. Doing this really highlights how frustrating the current alwaysinline semantic contract is though -- why can we put it on *external* functions, etc? Also I've added a number of tricky and interesting test cases for removing functions with the always inliner. There is one remaining case not handled -- fully removing comdats -- and I've left a FIXME about this. llvm-svn: 290457
2016-12-20[PM] Provide an initial, minimal port of the inliner to the new pass manager.Chandler Carruth
This doesn't implement *every* feature of the existing inliner, but tries to implement the most important ones for building a functional optimization pipeline and beginning to sort out bugs, regressions, and other problems. Notable, but intentional omissions: - No alloca merging support. Why? Because it isn't clear we want to do this at all. Active discussion and investigation is going on to remove it, so for simplicity I omitted it. - No support for trying to iterate on "internally" devirtualized calls. Why? Because it adds what I suspect is inappropriate coupling for little or no benefit. We will have an outer iteration system that tracks devirtualization including that from function passes and iterates already. We should improve that rather than approximate it here. - Optimization remarks. Why? Purely to make the patch smaller, no other reason at all. The last one I'll probably work on almost immediately. But I wanted to skip it in the initial patch to try to focus the change as much as possible as there is already a lot of code moving around and both of these *could* be skipped without really disrupting the core logic. A summary of the different things happening here: 1) Adding the usual new PM class and rigging. 2) Fixing minor underlying assumptions in the inline cost analysis or inline logic that don't generally hold in the new PM world. 3) Adding the core pass logic which is in essence a loop over the calls in the nodes in the call graph. This is a bit duplicated from the old inliner, but only a handful of lines could realistically be shared. (I tried at first, and it really didn't help anything.) All told, this is only about 100 lines of code, and most of that is the mechanics of wiring up analyses from the new PM world. 4) Updating the LazyCallGraph (in the new PM) based on the *newly inlined* calls and references. This is very minimal because we cannot form cycles. 5) When inlining removes the last use of a function, eagerly nuking the body of the function so that any "one use remaining" inline cost heuristics are immediately refined, and queuing these functions to be completely deleted once inlining is complete and the call graph updated to reflect that they have become dead. 6) After all the inlining for a particular function, updating the LazyCallGraph and the CGSCC pass manager to reflect the function-local simplifications that are done immediately and internally by the inline utilties. These are the exact same fundamental set of CG updates done by arbitrary function passes. 7) Adding a bunch of test cases to specifically target CGSCC and other subtle aspects in the new PM world. Many thanks to the careful review from Easwaran and Sanjoy and others! Differential Revision: https://reviews.llvm.org/D24226 llvm-svn: 290161