summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
AgeCommit message (Collapse)Author
2025-06-27[InstrRef] Skip clobbered EntryValue register recovery (#142478)Shubham Sandeep Rastogi
This changes the final stage of InstrRef, i.e. the TransferTracker (which combines the values locations with the variable values), so that it treats a DEBUG_VALUE of an EntryValue just like a DEBUG_VALUE of a constant: a location that is never clobbered and can be propagated to subsequent BBs as long as no other DEBUG_VALUE intrinsics updated the variable. We add two tests here: 1. `entry_value_clobbered_stack_copy` that saves a register on the stack, uses this register as an entry value DBG_VALUE location, and then clobbers it. Prior to this patch, this test would crash because we would try to describe a new location for the variable in terms of what was saved on the stack, and use an invalid expression to do so. This is not needed as an EntryValue can never be clobbered. 2. `entry_value_gets_propagated`, that tests that an EntryValue DBG_VALUE is propagated in a diamond-shaped CFG. This patch is trying to reland https://github.com/llvm/llvm-project/pull/77938 but also fixes the bug with InstrRef based LiveDebugValues, where entry values were not being propagated in a diamond-shaped CFG.
2025-05-22[llvm] Use *Map::try_emplace (NFC) (#141190)Kazu Hirata
try_emplace can default-construct values, so we do not need to do so on our own. Plus, try_emplace(Key) is much simpler/shorter than insert({Key, LongValueType()}).
2025-05-16[CodeGen] Use llvm::lower_bound (NFC) (#140341)Kazu Hirata
2025-05-12[CodeGen] Use llvm::lower_bound (NFC) (#139655)Kazu Hirata
2025-05-05[CodeGen] Use range-based for loops (NFC) (#138488)Kazu Hirata
This is a reland of #138434 except that: - the bits for llvm/lib/CodeGen/RenameIndependentSubregs.cpp have been dropped because they caused a test failure under asan, and - the bits for llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp have been improved with structured bindings.
2025-05-04Revert "[CodeGen] Use range-based for loops (NFC) (#138434)"Nico Weber
This reverts commit a9699a334bc9666570418a3bed9520bcdc21518b. Breaks CodeGen/AMDGPU/collapse-endcf.ll in several configs (sanitizer builds; macOS; possibly more), see comments on https://github.com/llvm/llvm-project/pull/138434
2025-05-04[CodeGen] Use range-based for loops (NFC) (#138434)Kazu Hirata
2025-04-26[llvm] Use llvm::replace (NFC) (#137481)Kazu Hirata
2025-03-29[CodeGen] Use llvm::append_range (NFC) (#133603)Kazu Hirata
2025-03-23[CodeGen] Use *Set::insert_range (NFC) (#132651)Kazu Hirata
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range);
2025-03-20[llvm] Use *Set::insert_range (NFC) (#132325)Kazu Hirata
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-18[LiveDebugValues][NFC] Remove TargetPassConfig from LDVImpl (#131562)Akshat Oke
TPC is only used to access the option `ShouldEmitDebugEntryValues`.
2025-03-15[CodeGen] Avoid repeated hash lookups (NFC) (#131422)Kazu Hirata
2025-01-23[DebugInfo][InstrRef] Avoid producing broken DW_OP_deref_sizes (#123967)Jeremy Morse
We use variable locations such as DBG_VALUE $xmm0 as shorthand to refer to "the low lane of $xmm0", and this is reflected in how DWARF is interpreted too. However InstrRefBasedLDV tries to be smart and interprets such a DBG_VALUE as a 128-bit reference. We then issue a DW_OP_deref_size of 128 bits to the stack, which isn't permitted by DWARF (it's larger than a pointer). Solve this for now by not using DW_OP_deref_size if it would be illegal. Instead we'll use DW_OP_deref, and the consumer will load the variable type from the stack, which should be correct. There's still a risk of imprecision when LLVM decides to use smaller or larger value types than the source-variable type, which manifests as too-little or too-much memory being read from the stack. However we can't solve that without putting more type information in debug-info. fixes #64093
2025-01-19[CodeGen] Remove some implict conversions of MCRegister to unsigned by ↵Craig Topper
using(). NFC Many of these are indexing BitVectors or something where we can't using MCRegister and need the register number.
2024-12-13Reapply "[DomTreeUpdater] Move critical edge splitting code to updater" ↵paperchalice
(#119547) This relands commit #115111. Use traditional way to update post dominator tree, i.e. break critical edge splitting into insert, insert, delete sequence. When splitting critical edges, the post dominator tree may change its root node, and `setNewRoot` only works in normal dominator tree... See https://github.com/llvm/llvm-project/blob/6c7e5827eda26990e872eb7c3f0d7866ee3c3171/llvm/include/llvm/Support/GenericDomTree.h#L684-L687
2024-12-11Revert "[DomTreeUpdater] Move critical edge splitting code to updater" (#119512)paperchalice
Reverts llvm/llvm-project#115111 Causes #119511
2024-12-11[DomTreeUpdater] Move critical edge splitting code to updater (#115111)paperchalice
Support critical edge splitting in dominator tree updater. Continue the work in #100856. Compile time check: https://llvm-compile-time-tracker.com/compare.php?from=87c35d782795b54911b3e3a91a5b738d4d870e55&to=42b3e5623a9ab4c3648564dc0926b36f3b438a3a&stat=instructions%3Au
2024-11-21[DebugInfo][InstrRef][MIR][GlobalIsel][MachineLICM] NFC Use std::move to ↵abhishek-kaushik22
avoid copying (#116935)
2024-09-28[LiveDebugValues] Avoid repeated hash lookups (NFC) (#110379)Kazu Hirata
2024-09-13[LiveDebugValues] Avoid repeated hash lookups (NFC) (#108484)Kazu Hirata
2024-08-04[CodeGen] Construct SmallVector with ArrayRef (NFC) (#101841)Kazu Hirata
2024-07-28[llvm] Initialize SmallVector with ranges (NFC) (#100948)Kazu Hirata
2024-07-18suppresses unused variable warning (#99526)Christopher Di Bella
2024-07-18Reapply 078198f310d5 "Index DebugVariables and some DILocations"Jeremy Morse
Now revised to actually make the unit test compile, which I'd been ignoring. No actual functional change, it's a type difference. Original commit message follows. [DebugInfo][InstrRef] Index DebugVariables and some DILocations (#99318) A lot of time in LiveDebugValues is spent computing DenseMap keys for DebugVariables, and they're made up of three pointers, so are large. This patch installs an index for them: for the SSA and value-to-location mapping parts of InstrRefBasedLDV we don't need to access things like the variable declaration or the inlining site, so just use a uint32_t identifier for each variable fragment that's tracked. The compile-time performance improvements are substantial (almost 0.4% on the tracker). About 80% of this patch is just replacing DebugVariable references with DebugVariableIDs instead, however there are some larger consequences. We spend lots of time fetching DILocations when emitting DBG_VALUE instructions, so index those with the DebugVariables: this means all DILocations on all new DBG_VALUE instructions will normalise to the first-seen DILocation for the variable (which should be fine). We also used to keep an ordering of when each variable was seen first in a DBG_* instruction, in the AllVarsNumbering collection, so that we can emit new DBG_* instructions in a stable order. We can hang this off the DebugVariable index instead, so AllVarsNumbering is deleted. Finally, rather than ordering by AllVarsNumbering just before DBG_* instructions are linked into the output MIR, store instructions along with their DebugVariableID, so that they can be sorted by that instead.
2024-07-18Revert "[DebugInfo][InstrRef] Index DebugVariables and some DILocations ↵Jeremy Morse
(#99318)" This reverts commit 078198f310d55925ccd9e1aa5b6ff4af3b36bbc7. Buildbots unhappy, I must have fluffed it
2024-07-18[DebugInfo][InstrRef] Index DebugVariables and some DILocations (#99318)Jeremy Morse
A lot of time in LiveDebugValues is spent computing DenseMap keys for DebugVariables, and they're made up of three pointers, so are large. This patch installs an index for them: for the SSA and value-to-location mapping parts of InstrRefBasedLDV we don't need to access things like the variable declaration or the inlining site, so just use a uint32_t identifier for each variable fragment that's tracked. The compile-time performance improvements are substantial (almost 0.4% on the tracker). About 80% of this patch is just replacing DebugVariable references with DebugVariableIDs instead, however there are some larger consequences. We spend lots of time fetching DILocations when emitting DBG_VALUE instructions, so index those with the DebugVariables: this means all DILocations on all new DBG_VALUE instructions will normalise to the first-seen DILocation for the variable (which should be fine). We also used to keep an ordering of when each variable was seen first in a DBG_* instruction, in the AllVarsNumbering collection, so that we can emit new DBG_* instructions in a stable order. We can hang this off the DebugVariable index instead, so AllVarsNumbering is deleted. Finally, rather than ordering by AllVarsNumbering just before DBG_* instructions are linked into the output MIR, store instructions along with their DebugVariableID, so that they can be sorted by that instead.
2024-07-17[InstrRef][NFC] Avoid another DenseMap, use a sorted vector (#99051)Jeremy Morse
When resolving value-numbers to specific machine locations in the final stages of LiveDebugValues, we've been producing a DenseMap containing all the value-numbers we're interested in. However we never modify the map keys as they're all pre-known. Thus, this is a suitable collection to switch to a sorted vector that gets searched, rather than a DenseMap that gets probed. The overall operation of LiveDebugValues isn't affected at all.
2024-07-17[InstrRef][NFC] Avoid un-necessary DenseMap queries (#99048)Jeremy Morse
This patch adjusts how some data is stored to avoid a number of un-necessary DenseMap queries. There's no change to the compiler behaviour, and it's measurably faster on the compile time tracker. The BlockOrders vector in buildVLocValueMap collects the blocks over which a variables value have to be determined: however the Cmp ordering function makes two DenseMap queries to determine the RPO-order of blocks being compared. And given that sorting is O(N log(N)) comparisons this isn't fast. So instead, fetch the RPO-numbers of the block collection, order those, and then map back to the blocks themselves. The OrderToBB collection mapped an RPO-number to an MBB: it's completely un-necessary to have DenseMap here, we can just use the RPO number as an array index. Switch it to a SmallVector and deal with a few consequences when iterating. (And for good measure I've jammed in a couple of reserve calls).
2024-07-11Revert "[CodeGen] Remove `applySplitCriticalEdges` in `MachineDominatorTree` ↵Nikita Popov
(#97055)" This reverts commit c5e5088033fed170068d818c54af6862e449b545. Causes large compile-time regressions.
2024-07-11[CodeGen] Remove `applySplitCriticalEdges` in `MachineDominatorTree` (#97055)paperchalice
Summary: - Remove wrappers in `MachineDominatorTree`. - Remove `MachineDominatorTree` update code in `MachineBasicBlock::SplitCriticalEdge`. - Use `MachineDomTreeUpdater` in passes which call `MachineBasicBlock::SplitCriticalEdge` and preserve `MachineDominatorTreeWrapperPass` or CFG analyses. Commit abea99f65a97248974c02a5544eaf25fc4240056 introduced related methods in 2014. Now we have SemiNCA based dominator tree in 2017 and dominator tree updater, the solution adopted here seems a bit outdated.
2024-06-30SSAUpdater: use poison instead of undef in phi entries for unreachable ↵Nuno Lopes
predecessors
2024-03-17[CodeGen] Use LocationSize for MMO getSize (#84751)David Green
This is part of #70452 that changes the type used for the external interface of MMO to LocationSize as opposed to uint64_t. This means the constructors take LocationSize, and convert ~UINT64_C(0) to LocationSize::beforeOrAfter(). The getSize methods return a LocationSize. This allows us to be more precise with unknown sizes, not accidentally treating them as unsigned values, and in the future should allow us to add proper scalable vector support but none of that is included in this patch. It should mostly be an NFC. Global ISel is still expected to use the underlying LLT as it needs, and are not expected to see unknown sizes for generic operations. Most of the changes are hopefully fairly mechanical, adding a lot of getValue() calls and protecting them with hasValue() where needed.
2024-01-11[InstrRef] Add debug hint for not reachable blocks from entry (#77725)HaohaiWen
Those not reachable blocks was not analyzed by LiveDebugValues and may raise out of bound access to VarLocs as case in #77441.
2023-12-23[LiveDebugValues][nfc] Reduce memory usage of InstrRef (#76051)Felipe de Azevedo Piovezan
Commit 1b531d54f623 (#74203) removed the usage of unique_ptrs of arrays in favour of using vectors, but inadvertently increased peak memory usage by removing the ability to deallocate vector memory that was no longer needed mid-LDV. In that same review, it was pointed out that `FuncValueTable` typedef could be removed, since it was "just a vector". This commit addresses both issues by making `FuncValueTable` a real data structure, capable of mapping BBs to ValueTables and able to free ValueTables as needed. This reduces peak memory usage in the compiler by 10% in the benchmarks flagged by the original review. As a consequence, we had to remove a handful of instances of the "declare-then-initialize" antipattern in unittests, as the FuncValueTable class is no longer default-constructible.
2023-12-18[InstrRef][NFC] Delete unused variables (#75501)Felipe de Azevedo Piovezan
`V` was unused, and all the other deletions follow from that observation.
2023-12-14[InstrRef][nfc] Remove usage of unique_ptrs of arrays (#74203)Felipe de Azevedo Piovezan
These are usually difficult to reason about, and they were being used to pass raw pointers around with array semantic (i.e., we were using operator [] on raw pointers). To put it in InstrRef terminology: we were passing a pointer to a ValueTable but using it as if it were a FuncValueTable. These could have easily been SmallVectors, which now allow us to have reference semantics in some places, as well as simpler initialization. In the future, we can use even more pass-by-reference with some extra changes in the code.
2023-12-14 [AArch64] ORRWrs is copy instruction when there's no implicit def of the X ↵DianQK
register (#75184) Follows https://github.com/llvm/llvm-project/pull/74682#issuecomment-1850268782. Fixes #74680.
2023-10-02Revert "CodeGen: Disable isCopyInstrImpl if there are implicit operands"Matt Arsenault
This reverts commit bc7d88faf1a595ab59952a2054418cdd0d9eeee8. This is broken with 414ff812d6241b728754ce562081419e7fc091eb reverted.
2023-10-02CodeGen: Disable isCopyInstrImpl if there are implicit operandsMatt Arsenault
This is a conservative workaround for broken liveness tracking of SUBREG_TO_REG to speculatively fix all targets. The current reported failures are on X86 only, but this issue should appear for all targets that use SUBREG_TO_REG. The next minimally correct refinement would be to disallow only implicit defs. The coalescer now introduces implicit-defs of the super register to track the dependency on other subregisters. If we see such an implicit operand, we cannot simply treat the subregister def as the result operand in case downstream users depend on the implicitly defined parts. Really target implementations should be considering the implicit defs and trying to interpret them appropriately (maybe with some generic helpers). The full implicit def could possibly be reported as the move result, rather than the subregister def but that requires additional work. Hopefully fixes #64060 as well. This needs to be applied to the release branch. https://reviews.llvm.org/D156346
2023-08-27[llvm] Use SmallDenseMap::contains (NFC)Kazu Hirata
2023-06-16[MC] Add MCRegisterInfo::regunits for iteration over register unitsSergei Barannikov
Reviewed By: foad Differential Revision: https://reviews.llvm.org/D152098
2023-06-10[llvm] Use DenseMapBase::lookup (NFC)Kazu Hirata
2023-05-19[DebugInfo][InstrRef] Handle non-directly reachable DBG_PHIs in LiveDebugValuesStephen Tozer
Fixes: https://github.com/llvm/llvm-project/issues/62725 This patch fixes an error in which a DBG_INSTR_REF referring to a DBG_PHI in a block that is not directly reachable from the entry block results in a crash during LiveDebugValues. Note that this fix prevents a crash from occurring, but will give undef locations to users of these PHIs even if a valid location exists. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D150707
2023-04-18[MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIterator. NFC.Jay Foad
Differential Revision: https://reviews.llvm.org/D148613
2023-03-14[CodeGen] Use *{Set,Map}::contains (NFC)Kazu Hirata
2023-01-31[LiveDebugValues] Allow EntryValue with OP_deref expressionsFelipe de Azevedo Piovezan
With D68945, more DBG_VALUEs were created without the indirect operand, instead relying on OP_deref to accomplish the same effect. At the time, however, we were not able to handle arbitrary expressions in combination with OP_LLVM_entry_value, so D71416 prevented the use of such operation in the presence of expressions. As per the comment in DIExpression::isValid, "we support only entry values of a simple register location." As such, a simple deref operation should be supported. In fact, D80345 added support for indirect DBG_VALUEs. Taken the patches above into consideration, this commit relaxes the restrictions on which expressions are allowed for entry value candidates: the expression must be either empty or a single dereference operator. This patch is useful for D141381, which adds support for storing the address of ABI-indirect parameters on the stack. Depends on D142160 Differential Revision: https://reviews.llvm.org/D142654
2023-01-13[CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFCCraig Topper
Use isPhysical/isVirtual methods. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D141715
2023-01-06[DebugInfo] Add support for variadic DBG_INSTR_REFs in LiveDebugValuesStephen Tozer
Following support from the previous patches in this stack being added for variadic DBG_INSTR_REFs to exist, this patch modifies LiveDebugValues to handle those instructions. Support already exists for DBG_VALUE_LISTs, which covers most of the work needed to handle these instructions; this patch only modifies the transferDebugInstrRef function to correctly track them. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D133927
2023-01-06[DebugInfo] Allow non-stack_value variadic expressions and use in DBG_INSTR_REFStephen Tozer
Prior to this patch, variadic DIExpressions (i.e. ones that contain DW_OP_LLVM_arg) could only be created by salvaging debug values to create stack value expressions, resulting in a DBG_VALUE_LIST being created. As of the previous patch in this patch stack, DBG_INSTR_REF's syntax has been changed to match DBG_VALUE_LIST in preparation for supporting variadic expressions. This patch adds some minor changes needed to allow variadic expressions that aren't stack values to exist, and allows variadic expressions that are trivially reduceable to non-variadic expressions to be handled similarly to non-variadic expressions. Reviewed by: jmorse Differential Revision: https://reviews.llvm.org/D133926