aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2023-03-16[Assignment Tracking] Do not convert variadic locations to kill locations [3/x]OCHyams1-17/+2
Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D145914
2023-03-16[Assignment Tracking][NFC] Use RawLocationWrapper in VarLocInfo [2/x]OCHyams1-24/+36
Use RawLocationWrapper rather than a Value to represent the location operand(s) so that it's possible to represent multiple location operands. AssignmentTrackingAnalysis still converts variadic debug intrinsics to kill locations so this patch is NFC. Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D145911
2023-03-02[DebugInfo] Remove `dbg.addr` from CodeGenJ. Ryan Stinnett1-1/+0
As part of this work, removing `SDDbgValue::clearIsEmitted` originally added for `dbg.addr` in 045c67769d7fe577fc38cccb6fb40fd814437447 was attempted, but it appears some tests for `DBG_INSTR_REF` now depend on that behaviour as well, so it was kept and comments were updated instead. Part of `dbg.addr` removal Discussed in https://discourse.llvm.org/t/what-is-the-status-of-dbg-addr/62898 Differential Revision: https://reviews.llvm.org/D144800
2023-02-23[Assignment Tracking][NFC] Avoid doing some work when maps have same keysOCHyams1-0/+8
Where the new checks have been added, `SymmetricDifference` - still being built - contains entries for variables present in `A` and not in `B`. If `SymmetricDifference` is empty at this point it means the variables (map keys) in `A` are a subset of those in `B`, so if `A` and `B` are the same size then we know they're identical. This reduces the number of instructions retired building some of the CTMark projects in a ReleaseLTO-g configuration (geomean change -0.05% with the best improvement being -0.24% for tramp3d-v4) Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D144621
2023-02-23[Assignment Tracking] Initialise maps with minimum required number of entriesOCHyams1-2/+2
The size lower bound is known - the `Join` map in both cases gets an entry for each variable from both input maps (union). This reduces the number of times the map grows, improving ReleaseLTO-g compile time for CTMark projects by an average of around 0.2%. Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D144486
2023-02-10[Assignment Tracking] Fix fragment index error in getDerefOffsetInBytesOCHyams1-8/+10
Without this patch `getDerefOffsetInBytes` incorrectly always returns `std::nullopt` for expressions with fragments due to an off-by-one error with fragment element indices. Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D143567
2023-01-20[Assignment Tracking] Fix invalidated iterator usageOCHyams1-3/+8
The iterator `FirstOverlap` is invalidated after the call to `insert` - avoid dereferencing the iterator after the call to `insert`. Reviewed By: CarlosAlbertoEnciso Differential Revision: https://reviews.llvm.org/D141854
2023-01-20[Assignment Tracking][NFC] Replace LLVM command line option with a module flagOCHyams1-0/+3
Remove LLVM flag -experimental-assignment-tracking. Assignment tracking is still enabled from Clang with the command line -Xclang -fexperimental-assignment-tracking which tells Clang to ask LLVM to run the pass declare-to-assign. That pass converts conventional debug intrinsics to assignment tracking metadata. With this patch it now also sets a module flag debug-info-assignment-tracking with the value `i1 true` (using the flag conflict rule `Max` since enabling assignment tracking on IR that contains only conventional debug intrinsics should cause no issues). Update the docs and tests too. Reviewed By: CarlosAlbertoEnciso Differential Revision: https://reviews.llvm.org/D142027
2023-01-12[DebugInfo] Replace UndefValue with PoisonValue in AssignmentTrackingAnalysisOCHyams1-13/+6
This helps towards the effort to remove UndefValue from LLVM. Related to https://discourse.llvm.org/t/auto-undef-debug-uses-of-a-deleted-value Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D140906
2023-01-12[NFC][Assignment Tracking] Add is/setKillAddressOCHyams1-8/+8
Unlike D140903 this patch folds in treating an empty metadata address component of a dbg.assign the same as undef because it was already being treated that way in the AssignmentTrackingAnalysis pass. Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D141125
2023-01-08[CodeGen] Fix a warningKazu Hirata1-0/+2
This patch fixes: llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp:1220:13: error: unused function 'locStr' [-Werror,-Wunused-function]
2023-01-08[NFC] Hide implementation details in anonymous namespacesBenjamin Kramer1-0/+2