summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/PartialInlining.cpp
AgeCommit message (Collapse)Author
2025-10-09[Coroutines] Conditional elide coroutines based on hot/cold information ↵Adrian Vogelsgesang
(#162276) Unconditionally eliding all `[[clang::coro_await_elidable]]` coroutines is not good. For example, ``` Task bar(); Task foo(bool b) { if (b) [[unlikely]] { co_await bar(); } } ``` Assume Task is marked with `[[clang::coro_await_elidable]]`, now we will always elide the call to `bar()` into the frame of `foo()`. But this may be a regression instead of an optimization if `b` is always false. This patch tries to mitigate the problem by leveraging hot/cold information. This can be optimized further in the future but at least this patch makes things better. This patch was originally written by ChuanqiXu9 (#145831), but stalled during PR review because the diagnostics were not integrated with the existing optimization remarks. I rebased the original patch, integrated it with the optimization remarks, and did a couple of smaller cosmetic changes (e.g., made the test case expectations more targeted, etc.) Co-Authored-by: Chuanqi Xu <yedeng.yd@linux.alibaba.com>
2025-05-02[IR] Do not store Function inside BlockAddress (#137958)Nikita Popov
Currently BlockAddresses store both the Function and the BasicBlock they reference, and the BlockAddress is part of the use list of both the Function and BasicBlock. This is quite awkward, because this is not really a use of the function itself (and walks of function uses generally skip block addresses for that reason). This also has weird implications on function RAUW (as that will replace the function in block addresses in a way that generally doesn't make sense), and causes other peculiar issues, like the ability to have multiple block addresses for one block (with different functions). Instead, I believe it makes more sense to specify only the basic block and let the function be implied by the BB parent. This does mean that we may have block addresses without a function (if the BB is not inserted), but this should only happen during IR construction.
2025-04-23[CostModel] Remove optional from InstructionCost::getValue() (#135596)David Green
InstructionCost is already an optional value, containing an Invalid state that can be checked with isValid(). There is little point in returning another optional from getValue(). Most uses do not make use of it being a std::optional, dereferencing the value directly (either isValid has been checked previously or the Cost is assumed to be valid). The one case that does in AMDGPU used value_or which has been replaced by a isValid() check.
2025-03-23[Transforms] Use *Set::insert_range (NFC) (#132652)Kazu Hirata
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2025-02-20[IPO] Avoid repeated hash lookups (NFC) (#127957)Kazu Hirata
2025-02-14[PartialInlining] Use DenseSet instead of DenseMap (NFC) (#127170)Kazu Hirata
This patch changes the type of VisitedMap to DenseSet from DenseMap because the value side of the map is always "true". Technically: if (VisitedMap[*SI]) inserts "false" as a value, but the value is immediately overridden with: VisitedMap[*SI] = true; While we are at it, this patch removes the repeated hash lookups around the "if" statement.
2025-01-24[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites ↵Jeremy Morse
(#123737) As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to getFirstNonPHI use the iterator-returning version. This patch changes a bunch of call-sites calling getFirstNonPHI to use getFirstNonPHIIt, which returns an iterator. All these call sites are where it's obviously safe to fetch the iterator then dereference it. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, but not before adding concise documentation of what considerations are needed (very few). --------- Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
2024-08-03[Transforms] Construct SmallVector with ArrayRef (NFC) (#101851)Kazu Hirata
2024-08-01Revert "[Inliner] Fix bugs for partial inlining with vector"joshua-arch1
This reverts commit https://github.com/llvm/llvm-project/commit/0a5e5728fbb61d7c775aabc8048b7b629e9ca2d2, since I forgot to start a pull request.
2024-08-01[Inliner] Fix bugs for partial inlining with vectorjoshua-arch1
In the cost model of partial inlining, cost for intrinsics will be applied. However, some intrinsics for vector have invalid cost, which is not allowed for partial inlining. Instead of assertion, we directly do not do partial inlining in this circumstance to avoid compiling errors.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2023-10-31[AArch64][SME] Extend Inliner cost-model with custom penalty for calls. (#68416)Sander de Smalen
This is a stacked PR following on from #68415 This patch has two purposes: (1) It tries to make inlining more likely when it can avoid a streaming-mode change. (2) It avoids inlining when inlining causes more streaming-mode changes. An example of (1) is: ``` void streaming_compatible_bar(void); void foo(void) __arm_streaming { /* other code */ streaming_compatible_bar(); /* other code */ } void f(void) { foo(); // expensive streaming mode change } -> void f(void) { /* other code */ streaming_compatible_bar(); /* other code */ } ``` where it wouldn't have inlined the function when foo would be a non-streaming function. An example of (2) is: ``` void streaming_bar(void) __arm_streaming; void foo(void) __arm_streaming { streaming_bar(); streaming_bar(); } void f(void) { foo(); // expensive streaming mode change } -> (do not inline into) void f(void) { streaming_bar(); // these are now two expensive streaming mode changes streaming_bar(); }```
2023-09-11[NFC][RemoveDIs] Prefer iterator-insertion over instructionsJeremy Morse
Continuing the patch series to get rid of debug intrinsics [0], instruction insertion needs to be done with iterators rather than instruction pointers, so that we can communicate information in the iterator class. This patch adds an iterator-taking insertBefore method and converts various call sites to take iterators. These are all sites where such debug-info needs to be preserved so that a stage2 clang can be built identically; it's likely that many more will need to be changed in the future. At this stage, this is just changing the spelling of a few operations, which will eventually become signifiant once the debug-info bearing iterator is used. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939 Differential Revision: https://reviews.llvm.org/D152537
2023-09-01[llvm] Fix duplicate word typos. NFCFangrui Song
Those fixes were taken from https://reviews.llvm.org/D137338
2023-05-09[PartialInlining] Fix incorrect costing when IR has unreachable BBsVedant Paranjape
Partial Inlining identifies basic blocks that can be outlined into a function. It is possible that an unreachable basic block is marked for outlining. During costing of the outlined region, such unreachable basic blocks are included as well. However, the CodeExtractor eliminates such unreachable basic blocks and emits outlined function without them. Thus, during costing of the outlined function, it is possible that the cost of the outlined function comes out to be lesser than the cost of outlined region, which triggers an assert. Assertion `OutlinedFunctionCost >= Cloner.OutlinedRegionCost && "Outlined function cost should be no less than the outlined region"' failed. This patch adds code to eliminate unreachable blocks from the function body before passing it on to be inlined. It also adds a test that checks for behaviour of costing in case of unreachable basic blocks. Discussion: https://discourse.llvm.org/t/incorrect-costing-in-partialinliner-if-ir-has-unreachable-basic-blocks/70163 Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D149130
2023-04-17Remove several no longer needed includes. NFCIBjorn Pettersson
Mostly removing includes of InitializePasses.h and Pass.h in passes that no longer has support for the legacy PM.
2023-04-16[Transforms] Apply fixes from performance-for-range-copy (NFC)Kazu Hirata
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-02-06[IPO] Remove some legacy passesArthur Eubanks
These are part of the optimization pipeline, of which the legacy pass manager version is deprecated.
2023-01-19[llvm][ir] Purge MD_prof custom accessorsChristian Ulmann
This commit purges direct accesses to MD_prof metadata and replaces them with the accessors provided from the utility file wherever possible. This commit can be seen as the first step towards switching the branch weights to 64 bits. See post here: https://discourse.llvm.org/t/extend-md-prof-branch-weights-metadata-from-32-to-64-bits/67492 Reviewed By: davidxl, paulkirth Differential Revision: https://reviews.llvm.org/D141393
2022-12-05[PartialInlining] Enable recursive partial inlining.Mark Lacey
It seems unnecessarily limiting to disallow recursive partial inlining, and there are clearly cases where it can benefit code by avoiding a function call and potentially enabling other transformations like dead argument elimination in cases where an argument is only used prior to the early-out test at the top of the function. The pass already properly rewrites the recursive calls within the body of the freshly cloned function, so the only change here is removing the bail-out when recursion is detected. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D136383
2022-12-05Remove unused #include "llvm/ADT/Optional.h"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-08-27Use llvm::all_equal (NFC)Kazu Hirata
2022-08-26[TTI] NFC: Reduce InstructionCost::getValue() usage...Daniil Fukalov
in order to propagate `InstructionCost` value upper. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D103406
2022-08-07[Transforms] Fix comment typos (NFC)Kazu Hirata
2022-08-03[NFC][Inliner] Add cl::opt<int> to tune InstrCostVitaly Buka
The plan is tune this for sanitizers. Differential Revision: https://reviews.llvm.org/D131123
2022-08-03[llvm][NFC] Refactor code to use ProfDataUtilsPaul Kirth
In this patch we replace common code patterns with the use of utility functions for dealing with profiling metadata. There should be no change in functionality, as the existing checks should be preserved in all cases. Reviewed By: bogner, davidxl Differential Revision: https://reviews.llvm.org/D128860
2022-07-27Revert "[llvm][NFC] Refactor code to use ProfDataUtils"Paul Kirth
This reverts commit 300c9a78819b4608b96bb26f9320bea6b8a0c4d0. We will reland once these issues are ironed out.
2022-07-27[llvm][NFC] Refactor code to use ProfDataUtilsPaul Kirth
In this patch we replace common code patterns with the use of utility functions for dealing with profiling metadata. There should be no change in functionality, as the existing checks should be preserved in all cases. Reviewed By: bogner, davidxl Differential Revision: https://reviews.llvm.org/D128860
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata
2022-06-04Remove unneeded cl::ZeroOrMore for cl::opt optionsFangrui Song
Similar to 557efc9a8b68628c2c944678c6471dac30ed9e8e. This commit handles options where cl::ZeroOrMore is more than one line below cl::opt.
2022-06-03[llvm] Remove unneeded cl::ZeroOrMore for cl::opt options. NFCFangrui Song
Some cl::ZeroOrMore were added to avoid the `may only occur zero or one times!` error. More were added due to cargo cult. Since the error has been removed, cl::ZeroOrMore is unneeded. Also remove cl::init(false) while touching the lines.
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-20[Transform] Apply clang-tidy fixes for readability-redundant-smartptr-get (NFC)Kazu Hirata
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-06[llvm] Use = default (NFC)Kazu Hirata
2022-01-19[PartialInline] Bail out on asm-goto/callbrWenlei He
Fixing ICE when partial inline tries to deal with blockaddress uses of function which is typical for asm-goto/callbr. We ran into this with PGO multi-region partial inline. Differential Revision: https://reviews.llvm.org/D117509
2022-01-07[llvm] Remove redundant member initialization (NFC)Kazu Hirata
Identified with readability-redundant-member-init.
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-11-23[llvm][NFC] Inclusive language: Reword replace uses of sanity in ↵Zarko Todorovski
llvm/lib/Transform comments and asserts Reworded some comments and asserts to avoid usage of `sanity check/test` Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D114372
2021-11-14[NFC] Use Optional<ProfileCount> to model invalid countsMircea Trofin
ProfileCount could model invalid values, but a user had no indication that the getCount method could return bogus data. Optional<ProfileCount> addresses that, because the user must dereference the optional. In addition, the patch removes concept duplication. Differential Revision: https://reviews.llvm.org/D113839
2021-10-30[clang, llvm] Use Optional::getValueOr (NFC)Kazu Hirata
2021-03-30NFC: Migrate PartialInlining to work on InstructionCostSander de Smalen
This patch migrates cost values and arithmetic to work on InstructionCost. When the interfaces to TargetTransformInfo are changed, any InstructionCost state will propagate naturally. See this patch for the introduction of the type: https://reviews.llvm.org/D91174 See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D97382
2021-02-03[Transforms/IPO] Use range-based for loops (NFC)Kazu Hirata
2020-11-02[PartialInliner]: Handle code regions in a switch stmt casesEttore Tiotto
This patch enhances computeOutliningColdRegionsInfo() to allow it to consider regions containing a single basic block and a single predecessor as candidate for partial inlining. Reviewed By: fhann Differential Revision: https://reviews.llvm.org/D89911
2020-10-22[NFC][PartialInliner]: Clean up codeEttore Tiotto
Make member function const where possible, use LLVM_DEBUG to print debug traces rather than a custom option, pass by reference to avoid null checking, ... Reviewed By: fhann Differential Revision: https://reviews.llvm.org/D89895
2020-09-16[Partial Inliner] Compute intrinsic cost through TTIDangeti Tharun kumar
https://bugs.llvm.org/show_bug.cgi?id=45932 assert(OutlinedFunctionCost >= Cloner.OutlinedRegionCost && "Outlined function cost should be no less than the outlined region") getting triggered in computeBBInlineCost. Intrinsics like "assume" are considered regular function calls while computing costs. This patch enables computeBBInlineCost to queries TTI for intrinsic call cost. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D87132
2020-07-27Use llvm::is_contained where appropriate (NFC)Kazu Hirata
Summary: This patch replaces std::find with llvm::is_contained where appropriate. Reviewers: efriedma, nhaehnle Reviewed By: nhaehnle Subscribers: arsenm, jvesely, nhaehnle, hiraditya, rogfer01, kerbowa, llvm-commits, vkmr Tags: #llvm Differential Revision: https://reviews.llvm.org/D84489