aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/MergeFunctions.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-18[DebugInfo] Suppress lots of users of DbgValueInst (#149476)Jeremy Morse1-11/+8
This is another prune of dead code -- we never generate debug intrinsics nowadays, therefore there's no need for these codepaths to run. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2025-06-12[DebugInfo][RemoveDIs] Delete debug-info-format flag (#143746)Jeremy Morse1-2/+0
This flag was used to let us incrementally introduce debug records into LLVM, however everything is now using records. It serves no purpose now, so delete it.
2025-05-24[Transforms] Remove unused includes (NFC) (#141357)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-04-04[MergeFunc] Fix crash caused by bitcasting ArrayType (#133259)Tobias Stadler1-29/+2
createCast in MergeFunctions did not consider ArrayTypes, which results in the creation of a bitcast between ArrayTypes in the thunk function, leading to an assertion failure in the provided test case. The version of createCast in GlobalMergeFunctions does handle ArrayTypes, so this common code has been factored out into the IRBuilder.
2025-03-19[Transforms] Use *Set::insert_range (NFC) (#132056)Kazu Hirata1-1/+1
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-03-10[MergeFunc] Keep comdat on new function, not thunk. (#130583)Florian Hahn1-0/+2
MergeFunc uses the original function F as Thunk and creates a new function NewF for the original function F. Preserve F's comdat info on NewF instead of the thunk. This fixes a crash when trying to lower comdat on the thunk during codegen.
2025-02-27[MergeFunc] Remove discardables function before writing alias or thunk. ↵Florian Hahn1-14/+21
(#128865) Update writeThunkOrAlias to only create an alias or thunk if it is actually needed. Drop discardable linkone_odr functions if they are not used before. PR: https://github.com/llvm/llvm-project/pull/128865
2025-02-25[MergeFuncs] Don't introduce calls to (linkonce,weak)_odr functions. (#125050)Florian Hahn1-2/+27
Avoid creating new calls to linkonce_odr/weak_odr functions when merging 2 functions, as this may introduce an infinite call cycle. Consider 2 functions below, both present in 2 modules. Module X -- define linkonce_odr void @"A"() { call void @"foo"() } define linkonce_odr void @"B"() { call void @"foo"() } --- Module Y --- global @"g" = @"B" define linkonce_odr void @"A"() { %l = load @"g" call void %l() } define linkonce_odr void @"B"() { call void @"foo"() } --- @"A" and @"B" in both modules are semantically equivalent Module X after function merging: --- define linkonce_odr void @"A"() { call void @"foo"() } define linkonce_odr void @"B"() { call void @"A"() } --- Module Y is unchanged. Then the linker picks @"A" from module Y and @"B" from module X. Now there's an infinite call cycle PR: https://github.com/llvm/llvm-project/pull/125050
2024-11-28[MergeFunctions] Add support to run the pass over a set of function pointers ↵Rafael Eckstein1-16/+45
(#111045) This modification will enable the usage of `MergeFunctions` as a standalone library. Currently, `MergeFunctions` can only be applied to an entire module. By adopting this change, developers will gain the flexibility to reuse the `MergeFunctions` code within their own projects, choosing which functions to merge; hence, promoting code reusability. Notice that this modification will not break backward compatibility, because `MergeFunctions` will still work as a pass after the modification.
2024-11-03[IPO] Remove unused includes (NFC) (#114716)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-26Reland (2nd attempt) [StructuralHash] Refactor (#112621)Kyungwoo Lee1-3/+3
This is largely NFC, and it prepares for #112638. - Use stable_hash instead of uint64_t - Rename update* to hash* functions. They compute stable_hash locally and return it. This is a patch for https://discourse.llvm.org/t/rfc-global-function-merging/82608.
2024-10-26Revert "Reland [StructuralHash] Refactor (#112621)"Kyungwoo Lee1-3/+3
This reverts commit 98ca9a635bd2fb98cee473a9558687a5b522e219.
2024-10-26Reland [StructuralHash] Refactor (#112621)Kyungwoo Lee1-3/+3
This is largely NFC, and it prepares for #112638. - Use stable_hash instead of uint64_t - Rename update* to hash* functions. They compute stable_hash locally and return it. This is a patch for https://discourse.llvm.org/t/rfc-global-function-merging/82608.
2024-10-26Revert "[StructuralHash] Refactor (#112621)"Kyungwoo Lee1-3/+3
This reverts commit b667d161f0a9ff6b29cda0ccdb0081610c1e8b8c.
2024-10-26[StructuralHash] Refactor (#112621)Kyungwoo Lee1-3/+3
This is largely NFC, and it prepares for #112638. - Use stable_hash instead of uint64_t - Rename update* to hash* functions. They compute stable_hash locally and return it. This is a patch for https://discourse.llvm.org/t/rfc-global-function-merging/82608.
2024-04-10[MergeFuncs/CFI] Ensure all type metadata is propogated for CFI (#88218)Oskar Wirga1-5/+7
I noticed that we weren't propagating ALL type metadata that was attached to CFI functions: # BEFORE ``` ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !dbg !62311 !type !34028 !type !34029 !type !34030 ... fn merging ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !type !34028 ``` # AFTER ``` ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !dbg !62311 !type !34028 !type !34029 !type !34030 ... fn merging ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !type !type !34028 !type !34029 !type !34030 ``` This patch makes sure that the entire vector of metadata is copied over.
2024-03-19[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)Stephen Tozer1-30/+32
This is the major rename patch that prior patches have built towards. The DPValue class is being renamed to DbgVariableRecord, which reflects the updated terminology for the "final" implementation of the RemoveDI feature. This is a pure string substitution + clang-format patch. The only manual component of this patch was determining where to perform these string substitutions: `DPValue` and `DPV` are almost exclusively used for DbgRecords, *except* for: - llvm/lib/target, where 'DP' is used to mean double-precision, and so appears as part of .td files and in variable names. NB: There is a single existing use of `DPValue` here that refers to debug info, which I've manually updated. - llvm/tools/gold, where 'LDPV' is used as a prefix for symbol visibility enums. Outside of these places, I've applied several basic string substitutions, with the intent that they only affect DbgRecord-related identifiers; I've checked them as I went through to verify this, with reasonable confidence that there are no unintended changes that slipped through the cracks. The substitutions applied are all case-sensitive, and are applied in the order shown: ``` DPValue -> DbgVariableRecord DPVal -> DbgVarRec DPV -> DVR ``` Following the previous rename patches, it should be the case that there are no instances of any of these strings that are meant to refer to the general case of DbgRecords, or anything other than the DPValue class. The idea behind this patch is therefore that pure string substitution is correct in all cases as long as these assumptions hold.
2024-03-14[RemoveDIs][NFC] Move DPValue::filter -> filterDbgVars (#85208)Stephen Tozer1-2/+2
This patch changes DPValue::filter to be a non-member method filterDbgVars. There are two reasons for this: firstly, the name of DPValue is about to change to DbgVariableRecord, which will result in every `for` loop that uses DPValue::filter to require a line break. This is a small thing, but it makes the rename patch more difficult to review, and is just generally more awkward for what is a fairly common loop. Secondly, the intent is to later break up the DPValue class into subclasses, at which point it would be better to have a non-member function that allows template arguments for the cases we want to filter with greater specificity.
2024-03-12[RemoveDIs][NFC] Rename common interface functions for DPValues->DbgRecords ↵Stephen Tozer1-2/+2
(#84793) As part of the effort to rename the DbgRecord classes, this patch renames the widely-used functions that operate on DbgRecords but refer to DbgValues or DPValues in their names to refer to DbgRecords instead; all such functions are defined in one of `BasicBlock.h`, `Instruction.h`, and `DebugProgramInstruction.h`. This patch explicitly does not change the names of any comments or variables, except for where they use the exact name of one of the renamed functions. The reason for this is reviewability; this patch can be trivially examined to determine that the only changes are direct string substitutions and any results from clang-format responding to the changed line lengths. Future patches will cover renaming variables and comments, and then renaming the classes themselves.
2024-02-20[MergeFunctions] Fix thunks for non-instruction debug info (#82080)Shoaib Meenai1-0/+2
When MergeFunctions creates new thunk functions, it needs to copy over the debug info format kind from the original function, otherwise we'll mix debug info formats and run into assertions. This was exposed by a downstream change that runs MergeFunctions before inlining, which caused assertions when inlining attempted to inline thunks created by merging, and the added test covers both scenarios where merging creates thunks.
2024-02-20[RemoveDIs][NFC] Introduce DbgRecord base class [1/3] (#78252)Orlando Cazalet-Hyams1-2/+2
Patch 1 of 3 to add llvm.dbg.label support to the RemoveDIs project. The patch stack adds a new base class -> 1. Add DbgRecord base class for DPValue and the not-yet-added DPLabel class. 2. Add the DPLabel class. 3. Enable dbg.label conversion and add support to passes. Patches 1 and 2 are NFC. In the near future we also will rename DPValue to DbgVariableRecord and DPLabel to DbgLabelRecord, at which point we'll overhaul the function names too. The name DPLabel keeps things consistent for now.
2024-02-07[DebugInfo][RemoveDIs] Instrument MergeFunctions for DPValues (#80974)Jeremy Morse1-69/+118
The MergeFunctions pass has a "preserve some debug-info" mode that tries to preserve parameter values. This patch generalises its decision-making so that it applies to both debug-info stored in intrinsics, and debug-info stored in DPValue objects. For the most part this involves using a generic lambda and applying it to each type of object. (Normally we avoid debug-info affecting the code generated, but this is hidden behind a command line switch, so won't usually be encountered by users). Note that this diff is messy, but that's because I'm hoisting some code into lambdas. The actual decision making processes here are identical.
2023-10-18[CFI/MergeFunctions] Modify MergeFunctions to propagate type information ↵Oskar Wirga1-0/+13
(#68628) When MergeFuncs creates a thunk, it does not modify the function in place, but creates a new one altogether. If type metadata is not properly forwarded to this new function, LowerTypeTests will be unable to put this thunk into the dispatch table. The fix here is to just forward the type metadata to the newly created functions.
2023-10-11[MergeFuncs] Use sizeWithoutDebug to decide if we create a thunk (#68627)Oskar Wirga1-1/+1
I noticed that when we determine the size of the function to figure out if its profitable, we include debug instructions which can end up making larger functions than necessary.
2023-09-23Fix: Distinguish CFI Metadata Checks in MergeFunctions Pass (#65963)Oskar Wirga1-1/+24
This diff fixes an issue in the MergeFunctions pass where two different Control Flow Integrity (CFI) metadata checks were incorrectly considered identical. These merges would lead to runtime violations down the line as two separate objects contained a single destructor which itself contained checks for only one of the objects. Here I update the comparison logic to take into account the metadata at llvm.type.test checks. Now, only truly identical checks will be considered for merging, thus preserving the integrity of each check. Previous discussion: https://reviews.llvm.org/D154119
2023-08-23[MergeFunctions] Remove unnecessary bitcasts (NFC)Nikita Popov1-6/+3
2023-08-19Reland "[NFCi][MergeFunctions] Consolidate Hashing Functions"Aiden Grossman1-7/+6
This is a reland of 28134a29fdedd8972acdfb39223571ddcc15dc59 which was reverted due to behavioral differences between 32 and 64 bit builds that have since been fixed. Differential Revision: https://reviews.llvm.org/D158217
2023-08-19Revert "[NFCi][MergeFunctions] Consolidate Hashing Functions"Aiden Grossman1-6/+7
This reverts commit 28134a29fdedd8972acdfb39223571ddcc15dc59. This patch was causing build failures on multiple buildbots on 32-bit architectures. Reverting now so I can deboug out-of-trunk and resubmit later.
2023-08-18[NFCi][MergeFunctions] Consolidate Hashing FunctionsAiden Grossman1-7/+6
A couple years ago, StructuralHash was created, copying the exact hashing implementation from FunctionComparator (minus a couple small details/refactorings). Since then, the hashing implementation has not diverged, but several other areas, like unit testing, have diverged significantly, with StructuralHash getting more attention in these areas. This patch aims to consolidate the two hashing functions into StructuralHash given they do the exact same thing and having less divergence in areas like unit testing would be beneficial. The original aim at creating a separate StructuralHash was to make the implementation divergent and capture additional details like instruction operands (which neither hashing implementation does currently). The MergeFunctions pass doesn't need these detaisl, but verification of pass return values would benefit from this additional data. Setting an option to calculate these values would allow for divergent behavior where appropriate while reducing code duplication with little runtime overhead. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D158217
2023-04-17Remove several no longer needed includes. NFCIBjorn Pettersson1-2/+0
Mostly removing includes of InitializePasses.h and Pass.h in passes that no longer has support for the legacy PM.
2023-02-06[MergeFunctions] Remove legacy passArthur Eubanks1-26/+0
It's part of the optimization pipeline, which the legacy pass manager version is deprecated.
2023-01-15[ADT] Make StringRef::compare like std::string_view::compareBenjamin Kramer1-1/+1
string_view has a slightly weaker contract, which only specifies whether the value is bigger or smaller than 0. Adapt users accordingly and just forward to the standard function (that also compiles down to memcmp)
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-5/+4
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-13[rereland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-3/+14
GlobalObject::getAlignment from llvm Differential Revision: https://reviews.llvm.org/D139836
2022-12-12Revert "[reland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-12/+4
GlobalObject::getAlignment from llvm" This reverts commit 3bbfaee23d41c099547c652f87b252ab6e1f6c46.
2022-12-12[reland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-4/+12
GlobalObject::getAlignment from llvm Differential Revision: https://reviews.llvm.org/D139836
2022-12-12Revert D139836 "[Alignment][NFC] Remove deprecated GlobalObject::getAlignment"Guillaume Chatelet1-12/+4
This breaks lldb. This reverts commit f3f15ca27fbb433ad5a65b1a1e0a071d2e9af505.
2022-12-12[Alignment][NFC] Remove deprecated GlobalObject::getAlignmentGuillaume Chatelet1-4/+12
Differential Revision: https://reviews.llvm.org/D139836
2022-07-03[NFC] Switch a few uses of undef to poison as placeholders for unreachble codeNuno Lopes1-1/+1
2022-06-16[MergeFunctions] Preserve symbols used llvm.used/llvm.compiler.usedAmanieu d'Antras1-1/+14
llvm.used and llvm.compiler.used are often used with inline assembly that refers to a specific symbol so that the symbol is kept through to the linker even though there are no references to it from LLVM IR. This fixes the MergeFunctions pass to preserve references to these symbols in llvm.used/llvm.compiler.used so they are not deleted from the IR. This doesn't prevent these functions from being merged, but guarantees that an alias or thunk with the expected symbol name is kept in the IR. Differential Revision: https://reviews.llvm.org/D127751
2022-04-18[llvm][IPO] Inclusive language: Rename mergefunc-sanity to mergefunc-verify ↵Zarko Todorovski1-13/+13
and remove other instances of sanity in MergeFunctions.cpp This patch renames the mergefunc-sanity to mergefunc-verify and renames the related functions to use more inclusive language Reviewed By: cebowleratibm Differential Revision: https://reviews.llvm.org/D114374
2022-03-22Cleanup includes: Transforms/IPOserge-sans-paille1-4/+1
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
2021-11-02[Transforms] Use make_early_inc_range (NFC)Kazu Hirata1-6/+4
2021-07-13[OpaquePtr] Use GlobalValue::getValueType() moreArthur Eubanks1-3/+2
2021-07-09[Clang] Introduce Swift async calling convention.Varun Gandhi1-1/+4
This change is intended as initial setup. The plan is to add more semantic checks later. I plan to update the documentation as more semantic checks are added (instead of documenting the details up front). Most of the code closely mirrors that for the Swift calling convention. Three places are marked as [FIXME: swiftasynccc]; those will be addressed once the corresponding convention is introduced in LLVM. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D95561
2021-02-03[Transforms/IPO] Use range-based for loops (NFC)Kazu Hirata1-12/+8
2021-01-29[llvm] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2020-12-11Migrate deprecated DebugLoc::get to DILocation::getFangrui Song1-2/+4
This migrates all LLVM (except Kaleidoscope and CodeGen/StackProtector.cpp) DebugLoc::get to DILocation::get. The CodeGen/StackProtector.cpp usage may have a nullptr Scope and can trigger an assertion failure, so I don't migrate it. Reviewed By: #debug-info, dblaikie Differential Revision: https://reviews.llvm.org/D93087
2020-04-22[llvm][NFC][CallSite] Remove CallSite from a few trivial locationsMircea Trofin1-4/+3
Summary: Implementation details and internal (to module) APIs. Reviewers: craig.topper, dblaikie Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78610
2020-01-14[NewPM] Port MergeFunctions passNikita Popov1-14/+33
This ports the MergeFunctions pass to the NewPM. This was rather straightforward, as no analyses are used. Additionally MergeFunctions needs to be conditionally enabled in the PassBuilder, but I left that part out of this patch. Differential Revision: https://reviews.llvm.org/D72537