aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-03[NFC] Fix `assignment` typo. (#151864)Connector Switch1-2/+2
2025-06-24[RemoveDIs][NFC] Remove dbg intrinsic handling code from ↵Orlando Cazalet-Hyams1-226/+94
AssignmentTrackingAnalysis (#144674) See PR for breakdown into individual commits.
2025-06-21[CodeGen] Remove extraneous casts to VariableID (NFC) (#145144)Kazu Hirata1-3/+3
We do not need these casts because values being cast here are already of type VariableID.
2025-05-20Revert "[llvm][NFC] Use `llvm::sort()`" (#140668)Iris Shi1-4/+5
2025-05-17[llvm][NFC] Use `llvm::sort()` (#140335)Iris Shi1-5/+4
2025-05-04[CodeGen] Remove unused local variables (NFC) (#138441)Kazu Hirata1-1/+0
2025-04-22[DebugInfo] Handle additional types of stores in assignment tracking (#129070)Stephen Tozer1-4/+106
Fixes #126417. Currently, assignment tracking recognizes allocas, stores, and mem intrinsics as valid instructions to tag with DIAssignID, with allocas representing the allocation for a variable and the others representing instructions that may assign to the variable. There are other intrinsics that can perform these assignments however, and if we transform a store instruction into one of these intrinsics and correctly transfer the DIAssignID over, this results in a verifier error. The AssignmentTrackingAnalysis pass also does not know how to handle these intrinsics if they are untagged, as it does not know how to extract assignment information (base address, offset, size) from them. This patch adds _some_ support for some intrinsics that may perform assignments: masked store/scatter, and vp store/strided store/scatter. This patch does not add support for extracting assignment information from these, as they may store with either non-constant size or to non-contiguous blocks of memory; instead it adds support for recognizing untagged stores with "unknown" assignment info, for which we assume that the memory location of the associated variable should not be used, as we can't determine which fragments of it should or should not be used. In principle, it should be possible to handle the more complex cases mentioned above, but it would require more substantial changes to AssignmentTrackingAnalysis, and it is mostly only needed as a fallback if the DIAssignID is not preserved on these alternative stores.
2025-04-03[ADT] Make DenseMap::init() private (NFC) (#134229)Nikita Popov1-4/+4
I believe this method was not supposed to be public, as it has additional preconditions (it will misbehave when called on a non-empty DenseMap). The public API for this is reserve().
2025-03-16[CodeGen] Avoid repeated hash lookups (NFC) (#131551)Kazu Hirata1-3/+3
2025-03-06[IR] Store Triple in Module (NFC) (#129868)Nikita Popov1-2/+1
The module currently stores the target triple as a string. This means that any code that wants to actually use the triple first has to instantiate a Triple, which is somewhat expensive. The change in #121652 caused a moderate compile-time regression due to this. While it would be easy enough to work around, I think that architecturally, it makes more sense to store the parsed Triple in the module, so that it can always be directly queried. For this change, I've opted not to add any magic conversions between std::string and Triple for backwards-compatibilty purses, and instead write out needed Triple()s or str()s explicitly. This is because I think a decent number of them should be changed to work on Triple as well, to avoid unnecessary conversions back and forth. The only interesting part in this patch is that the default triple is Triple("") instead of Triple() to preserve existing behavior. The former defaults to using the ELF object format instead of unknown object format. We should fix that as well.
2025-03-02[CodeGen] Avoid repeated hash lookups (NFC) (#129418)Kazu Hirata1-7/+7
2025-02-27[CodeGen] Avoid repeated hash lookups (NFC) (#129190)Kazu Hirata1-3/+3
2025-01-17[CodeGen] Avoid repeated hash lookups (NFC) (#123287)Kazu Hirata1-2/+3
2024-11-10[llvm] Migrate away from PointerUnion::{is,get,dyn_cast} (NFC) (#115626)Kazu Hirata1-3/+3
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-09-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad1-4/+4
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-08-13[DataLayout] Remove constructor accepting a pointer to Module (#102841)Sergei Barannikov1-2/+1
The constructor initializes `*this` with `M->getDataLayout()`, which is effectively the same as calling the copy constructor. There does not seem to be a case where a copy would be necessary. Pull Request: https://github.com/llvm/llvm-project/pull/102841
2024-07-02[CodeGen] Use range-based for loops (NFC) (#97500)Kazu Hirata1-10/+9
2024-06-28[IR] Don't include Module.h in Analysis.h (NFC) (#97023)Nikita Popov1-0/+1
Replace it with a forward declaration instead. Analysis.h is pulled in by all passes, but not all passes need to access the module.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-2/+2
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-06-27[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)Nikita Popov1-1/+1
This is a helper to avoid writing `getModule()->getDataLayout()`. I regularly try to use this method only to remember it doesn't exist... `getModule()->getDataLayout()` is also a common (the most common?) reason why code has to include the Module.h header.
2024-06-26[CodeGen] Use range-based for loops (NFC) (#96777)Kazu Hirata1-6/+6
2024-06-25Revert "[llvm] Use llvm::sort (NFC) (#96434)"Kazu Hirata1-4/+5
This reverts commit 05d167fc201b4f2e96108be0d682f6800a70c23d. Reverting the patch fixes the following under EXPENSIVE_CHECKS: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir LLVM :: CodeGen/AMDGPU/sched-group-barrier-pre-RA.mir LLVM :: CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll LLVM :: CodeGen/PowerPC/merge-string-used-by-metadata.mir LLVM :: CodeGen/PowerPC/mergeable-string-pool-large.ll LLVM :: CodeGen/PowerPC/mergeable-string-pool-pass-only.mir LLVM :: CodeGen/PowerPC/mergeable-string-pool.ll
2024-06-23[llvm] Use llvm::sort (NFC) (#96434)Kazu Hirata1-5/+4
2024-06-13[llvm-project] Fix typo "seperate" (#95373)Jay Foad1-3/+3
2024-04-09Remove the unused IntervalPartition analysis pass (#88133)Björn Pettersson1-1/+0
This removes the old legacy PM "intervals" analysis pass (aka IntervalPartition). It also removes the associated Interval and IntervalIterator help classes. Reasons for removal: 1) The pass is not used by llvm-project (not even being tested by any regression tests). 2) Pass has not been ported to new pass manager, which at least indicates that it isn't used by the middle-end. 3) ASan reports heap-use-after-free on ++I; // After the first one... even if false is passed to intervals_begin. Not sure if that is a false positive, but it makes the code a bit less trustworthy.
2024-03-19[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)Stephen Tozer1-75/+79
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-8/+8
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-13[RemoveDI][NFC] Rename DPValue->DbgRecord in comments and varnames (#84939)Stephen Tozer1-17/+18
This patch continues the ongoing rename work, replacing DPValue with DbgRecord in comments and the names of variables, both members and fn-local. This is the most labour-intensive part of the rename, as it is where the most decisions have to be made about whether a given comment or variable is referring to DPValues (equivalent to debug variable intrinsics) or DbgRecords (a catch-all for all debug intrinsics); these decisions are not individually difficult, but comprise a fairly large amount of text to review. This patch still largely performs basic string substitutions followed by clang-format; there are almost* no places where, for example, a comment has been expanded or modified to reflect the semantic difference between DPValues and DbgRecords. I don't believe such a change is generally necessary in LLVM, but it may be useful in the docs, and so I'll be submitting docs changes as a separate patch. *In a few places, `dbg.values` was replaced with `debug intrinsics`.
2024-03-12[RemoveDIs][NFC] Rename common interface functions for DPValues->DbgRecords ↵Stephen Tozer1-13/+13
(#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-23[RemoveDIs] Add DPLabels support [3a/3] (#82633)Orlando Cazalet-Hyams1-5/+4
Patch 2 of 3 to add llvm.dbg.label support to the RemoveDIs project. The patch stack adds the DPLabel class, which is the RemoveDIs llvm.dbg.label equivalent. 1. Add DbgRecord base class for DPValue and the not-yet-added DPLabel class. 2. Add the DPLabel class. -> 3. Add support to passes. The next patch, #82639, will enable conversion between dbg.labels and DPLabels. AssignemntTrackingAnalysis support could have gone two ways: 1. Have the analysis store a DPLabel representation in its results - SelectionDAGBuilder reads the analysis results and ignores all DbgRecord kinds. 2. Ignore DPLabels in the analysis - SelectionDAGBuilder reads the analysis results but still needs to iterate over DPLabels from the IR. I went with option 2 because it's less work and is no less correct than 1. It's worth noting that causes labels to sink to the bottom of packs of debug records. e.g., [value, label, value] becomes [value, value, label]. This shouldn't be a problem because labels and variable locations don't have an ordering requirement. The ordering between variable locations is maintained and the label movement is deterministic
2024-02-20[RemoveDIs][NFC] Introduce DbgRecord base class [1/3] (#78252)Orlando Cazalet-Hyams1-12/+16
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-01-23[RemoveDIs][DebugInfo] Handle DPVAssigns in Assignment Tracking excluding ↵Stephen Tozer1-127/+153
lowering (#78982) This patch adds support for DPVAssigns across all of AssignmentTrackingAnalysis except for AssignmentTrackingLowering, which is implemented in a separate patch. This patch includes handling DPValues in MemLocFragFill, the removal of redundant DPValues as part of AssignmentTrackingAnalysis (which is different to the version in `BasicBlockUtils.cpp`), and preventing the DPVAssigns from being directly emitted in SelectionDAG (just as we don't emit llvm.dbg.assigns directly, but receive a set of locations from AssignmentTrackingAnalysis' output).
2024-01-23[RemoveDIs][DebugInfo] Handle DPVAssigns in AssignmentTrackingLowering (#78980)Stephen Tozer1-138/+290
Following on from the previous patch 6aeb7a7, this patch adds the necessary code to process the DPV equivalents of llvm.dbg.assign intrinsics. Most of the content of this patch is simply duplicating existing functionality, using generic code for simple functions and PointerUnions where storage is required. The most complex changes are in the places that iterate over instructions, as iterating over DPValues between instructions is different to iterating over instructions that may or may not be debug intrinsics; this is most complex in `AssignmentTrackingLowering::process`, where I've added some comments to explain the state of the program at each key point depending on whether we are operating on intrinsics or DPValues.
2024-01-22[RemoveDIs][DebugInfo] Add interface changes for AT analysis (#78460)Stephen Tozer1-21/+70
This patch adds the preliminary changes for handling DPValues in AssignmentTrackingAnalysis - very few functional changes are included, but internal data structures have been changed to operate with DPValues as well as Instructions, allowing future patches to process DPValues correctly.
2024-01-19[CodeGen] Use a range-based for loop with llvm::predecessors (NFC)Kazu Hirata1-2/+1
2024-01-10[CodeGen][NewPM] Port AssignmentTrackingAnalysis to new pass manager (#77550)paperchalice1-0/+34
2023-12-11[AssignmentTracking] Skip large types in redundant debug info pruning (#74329)Orlando Cazalet-Hyams1-10/+17
Fix https://github.com/llvm/llvm-project/issues/74189 (crash report). The pruning code uses a BitVector to track which parts of a variable have been defined in order to find redundant debug records. BitVector uses a u32 to track size; variable of types with a bit-size greater than max(u32) ish* can't be represented using a BitVector. Fix the assertion by introducing a limit on type size. Improve performance by bringing the limit down to a sensible number and tracking byte-sizes instead of bit-sizes. Skipping variables in this pruning code doesn't cause debug info correctness issues; it just means there may be some extra redundant debug records. (*) `max(u32) - 63` due to BitVector::NumBitWords implementation.
2023-11-22[IR] Don't include GenericDomTreeConstruction.h in header (NFC)Nikita Popov1-0/+1
The whole point of the GenericDomTree.h vs GenericDomTreeConstruction.h distinction is that the latter only needs to be included in the source file and not the header.
2023-11-11[llvm] Stop including llvm/ADT/SmallSet.h (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-09-15[Assignment Tracking] Trim assignments for untagged out of bounds stores ↵Orlando Cazalet-Hyams1-14/+17
(#66095) Fixes #65004 by trimming assignments from out of bounds stores (out of bounds of either the base variable or the backing alloca). If there's no overlap at all or the out of bounds access starts at a negative offset from the alloca, the assignment is simply skipped.
2023-04-26[Assignment Tracking] Remove overly defensive AllocaInst assertionOCHyams1-2/+1
Remove assert from AssignmentTrackingAnalysis that fires if a local variable has non-alloca storage. The analysis can emit these locations but the assignment tracking code in SelectionDAG isn't ready to handle non-alloca storage for locals yet. The AssignmentTrackingPass (pass that adds assignment tracking metadata) ignores non-alloca dbg.declares, so the only variables affected are those who's backing storage is changed from an alloca during optimisation, and the result is the variables are dropped. Fixes: https://ci.chromium.org/ui/p/pigweed/builders/toolchain/ toolchain-ci-pigweed-linux/b8783274592206481489/overview Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D149135
2023-04-26[Assignment Tracking] Fix faulty assertion inside std::sort predicateOCHyams1-8/+9
The vectors being sorted here shouldn't contain duplicate entries. Prior to this patch this was checked with an assert within the `std::sort` predicate. However, `std::sort` may compare an element against itself which causes the assert to fire (false positive). Move the assert outside of the sort predicate to avoid such issues. Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D149045
2023-04-05[Assignment Tracking] Ignore zero-sized fragmentsOCHyams1-4/+19
Such dbg.assigns will occur if you write zero-sized memcpys (see https://reviews.llvm.org/D146987#4240016). Handle this in AssignmentTrackingAnalysis (back end) rather than AssignmentTrackingPass (declare-to-assign) in case it is possible to reproduce this as a result of optimisations. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D147435
2023-03-31[NFC]add & to avoid copyWang, Xin101-1/+1
The elements in FragmentMap are big objects, use reference can get better performance, as someone do in line 1912. Differential Revision: https://reviews.llvm.org/D147126
2023-03-29[Assignment Tracking] Coalesce dbg loc definitions with contiguous fragmentsOCHyams1-5/+66
MemLocFragmentFill uses an IntervalMap to track which bits of each variable are stack-homed. Intervals with the same value (same stack location base address) are automatically coalesced by the map. This patch changes the analysis to take advantage of that and insert a new dbg loc after each def if any coalescing took place. This results in some additional redundant defs (we insert a def, then another that by definition shadows the previous one if any coalescing took place) but they're all cleaned up thanks to the previous patch in this stack. This reduces the total number of fragments created by AssignmentTrackingAnalysis which reduces compile time because LiveDebugValues computes SSA for every fragment it encounters. There's a geomean reduction in instructions retired in a CTMark LTO-O3-g build of 0.3% with these two patches. One small caveat is that this technique can produce partially overlapping fragments (e.g. slice [0, 32) and slice [16, 64)), which we know LiveDebugVariables doesn't really handle correctly. Used in combination with instruction-referencing this isn't a problem, since LiveDebugVariables is effectively side-stepped in instruction-referencing mode. Given this, the coalescing is only enabled when instruction-referencing is enabled (but the behaviour can be overriden using -debug-ata-coalesce-frags=<bool>). Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D146980
2023-03-29[Assignment Tracking] Improve removeRedundantDbgLocsUsingBackwardScanOCHyams1-15/+37
`removeRedundantDbgLocsUsingBackwardScan` removes redundant dbg loc definitions by scanning backwards through contiguous sets of them (a "wedge"), removing earlier (in IR order terms) defs for fragments of variables that are defined later in the wedge. In this patch we use a `Bitvector` for each variable to track which bits have definitions to more accurately determine whether a loc def is redundant. This patch increases compile time by itself, but reduces it when combined with the follow-up patch. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D146978
2023-03-29[Assignment Tracking] Elide a map copy in some casesOCHyams1-31/+55
Restructure AssignmentTrackingLowering::join to avoid a map copy in the case where BB has more than one pred. We only need to perform a copy of a pred LiveOut if there's exactly one already-visited pred (Result = PredLiveOut). With more than one pred the result is built by calling Result = join(std::move(Result), PredLiveOut) for each subsequent pred, where join parameters are const &. i.e. with more than 1 pred we can avoid copying by referencing the first two pred LiveOuts in the first join and then using a move + reference for the rest. This reduces compile time for CTMark LTO-O3-g builds. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D144732
2023-03-29[Assignment Tracking][NFC] Reduce work done in fragment overlap calculationOCHyams1-1/+7
Only calculate fragment overlaps for partially stack homed variables. This filter is already applied to the rest of the analysis - this change simply prevents some unnecessary work. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D145515
2023-03-24[NFC] Fix auto usage to avoid copiesAkshay Khadse1-3/+3
Fixes some usages of the "auto" keyword to avoid creation of copies. Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D146694
2023-03-21[Assignment Tracking][NFC] Use BitVectors as masks for SmallVectorsOCHyams1-196/+212
...rather than using DenseMaps to track per-variable information. Rather than tracking 3 maps of {VariableID: SomeInfo} per block, use a BitVector indexed by VariableID to mask 3 vectors of SomeInfo. BlockInfos now need to be initialised with a call to init which sets the BitVector width to the number of partially promoted variables in the function and fills the vectors with Top values. Prior to this patch, in joinBlockInfo, it was necessary to insert Top values into the Join result for variables in A XOR B after joining the variables in A AND B. Now, because the vectors are pre-filled with Top values we need only join the variables A AND B and set the BitVector of tracked variables to A OR B. The patch achieves an average of 0.25% reduction in instructions retired and a 1.1% max-rss for the CTMark suite in LTO-O3-g builds. Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D145558