summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
AgeCommit message (Collapse)Author
2023-01-06[DebugInfo][NFC] Add new MachineOperand type and change DBG_INSTR_REF syntaxStephen Tozer
This patch makes two notable changes to the MIR debug info representation, which result in different MIR output but identical final DWARF output (NFC w.r.t. the full compilation). The two changes are: * The introduction of a new MachineOperand type, MO_DbgInstrRef, which consists of two unsigned numbers that are used to index an instruction and an output operand within that instruction, having a meaning identical to first two operands of the current DBG_INSTR_REF instruction. This operand is only used in DBG_INSTR_REF (see below). * A change in syntax for the DBG_INSTR_REF instruction, shuffling the operands to make it resemble DBG_VALUE_LIST instead of DBG_VALUE, and replacing the first two operands with a single MO_DbgInstrRef-type operand. This patch is the first of a set that will allow DBG_INSTR_REF instructions to refer to multiple machine locations in the same manner as DBG_VALUE_LIST. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D129372
2022-12-20[DebugInfo] Unify location selection logic for values in InstrRefBasedImplStephen Tozer
Currently the instruction referencing live debug values has 3 separate places where we iterate over all known locations to find the best machine location for a set of values at a given point in the program. Each of these places has an implementation of this check, and one of them has slightly different logic to the others. This patch moves the check for the "quality" of a machine location into a separate function, which also avoids repeatedly calling expensive functions, giving a slight performance improvement. Differential Revision: https://reviews.llvm.org/D140412
2022-12-19[DebugInfo] Add function to test debug values for equivalenceStephen Tozer
This patch adds a new function that can be used to check all the properties, other than the machine values, of a pair of debug values for equivalence. This is done by folding the "directness" into the expression, converting the expression to variadic form if it is not already in that form, and then comparing directly. In a few places which check whether two debug values are identical to see if their ranges can be merged, this function will correctly identify cases where two debug values are expressed differently but have the same meaning, allowing those ranges to be correctly merged. Differential Revision: https://reviews.llvm.org/D136173
2022-12-13[CodeGen] llvm::Optional => std::optionalFangrui Song
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26[LiveDebugValues] Use std::optional in InstrRefBasedImpl.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-09-03Use llvm::lower_bound (NFC)Kazu Hirata
2022-09-01Reapply "[DebugInfo] Extend the InstrRef LDV to support DbgValues with many Ops"Stephen Tozer
Re-landing with an erroneous assert removed. This reverts commit 58d104b352a65bec3fb7a8fd23bf2d408b4c76f7.
2022-08-24Revert "[DebugInfo] Extend the InstrRef LDV to support DbgValues with many Ops"Stephen Tozer
Reverting due to reported errors when running Linux kernel builds with KMSAN -gdwarf-4. This reverts commit 2cb9e1ac422f46de0ab728c6c9d50ebafbfe372a.
2022-08-23[DebugInfo] Extend the InstrRef LDV to support DbgValues with many OpsStephen Tozer
This patch builds on prior support patches to enable support for variadic debug values in InstrRefLDV, allowing DBG_VALUE_LISTs to have their ranges extended. Differential Revision: https://reviews.llvm.org/D128212
2022-08-23[DebugInfo][InstrRef] Handle transfers of variadic debug values in LDVStephen Tozer
This patch adds the last of the changes required to enable DBG_VALUE_LIST handling in InstrRefLDV, handling variadic debug values during the transfer tracking step. Most of the changes are fairly straightforward, and based around tracking multiple locations per variable in TransferTracker::VLocTracker. Differential Revision: https://reviews.llvm.org/D128211
2022-08-23[DebugInfo][InstrRef][NFC] Emit variadic debug values from InstrRefLDVStephen Tozer
In preparation for supporting DBG_VALUE_LIST in InstrRefLDV, this patch adds the logic for emitting DBG_VALUE_LIST instructions from InstrRefLDV. The logical changes here are fairly simple, with the main change being that instead of directly prepending offsets to the DIExpr, we use appendOpsToArg to modify the expression for individual debug operands in the expression. The function emitLoc is also changed to take a list of debug ops, with an empty list meaning an undef value. Differential Revision: https://reviews.llvm.org/D128209
2022-08-22[DebugInfo] Let InstrRefBasedLDV handle joins for lists of debug opsStephen Tozer
In preparation for adding support for DBG_VALUE_LIST instructions in InstrRefLDV, this patch updates the logic for joining variables at block joins to support joining variables that use multiple debug operands. This is one of the more meaty "logical" changes, although the line count isn't too high - this changes pickVPHILoc to find a valid joined location for every operand, with part of the function being split off into pickValuePHILoc which finds a location for a single operand. Differential Revision: https://reviews.llvm.org/D128180
2022-08-22[DebugInfo][NFC] Represent DbgValues with multiple ops in IRefLDVStephen Tozer
In preparation for allowing InstrRefBasedLDV to handle DBG_VALUE_LIST, this patch updates the internal representation that it uses to represent debug values to store a list of values. This is one of the more significant changes in terms of line count, but is fairly simple and should not affect the output of this pass. Differential Revision: https://reviews.llvm.org/D128177
2022-08-22[DebugInfo][NFC] Update LDV to use generic DBG_VALUE* MI interfaceStephen Tozer
Currently, InstrRefLDV only handles DBG_VALUE instructions, not DBG_VALUE_LIST, and as a result of this it handles these instructions using functions that only work for that type of debug value, i.e. using getOperand(0) to get the debug operand. This patch changes this to use the generic debug value functions, such as getDebugOperand and isDebugOffsetImm, as well as adding an IsVariadic field to the DbgValueProperties class and a few other minor changes to acknowledge DBG_VALUE_LISTs. Note that this patch does not add support for DBG_VALUE_LIST here, but is a precursor to other patches that do add that support. Differential Revision: https://reviews.llvm.org/D128174
2022-08-22[DebugInfo] Handle joins PHI+Def values in InstrRef LiveDebugValuesStephen Tozer
In the InstrRefBasedImpl for LiveDebugValues, we attempt to propagate debug values through basic blocks in part by checking to see whether all a variable's incoming debug values to a BB "agree", i.e. whether their properties match and they refer to the same underlying value. Prior to this patch, the check for agreement between incoming values relied on exact equality, which meant that a VPHI and a Def DbgValue that referred to the same underlying value would be seen as disagreeing. This patch changes this behaviour to treat them as referring to the same value, allowing the shared value to propagate into the BB. Differential Revision: https://reviews.llvm.org/D125953
2022-08-20Remove redundant initialization of Optional (NFC)Kazu Hirata
2022-08-09LiveDebugValues: Fix another crash related to unreachable blocksAdrian Prantl
This is a follow-up patch to D130999. In the test, the MIR contains an unreachable MBB but the code attempts to look it up in MLocs. This patch fixes this issue by checking for the default-constructed value. rdar://97226240 Differential Revision: https://reviews.llvm.org/D131453
2022-08-07[llvm] Fix comment typos (NFC)Kazu Hirata
2022-08-03Fix LDV InstrRefBasedImpl to not crash when encountering unreachable MBBs.Adrian Prantl
The testcase was delta-reduced from an LTO build with sanitizer coverage and the MIR tail duplication pass caused a machine basic block to become unreachable in MIR. This caused the MBB to be invisible to the reverse post-order traversal used to initialize the MBB <-> RPONumber lookup tables. rdar://97226240 Differential Revision: https://reviews.llvm.org/D130999
2022-07-24Use llvm::less_first and llvm::less_second (NFC)Kazu Hirata
2022-07-24[CodeGen] Remove a redundant void (NFC)Kazu Hirata
Identified with modernize-redundant-void-arg.
2022-07-23Use llvm::sort instead of std::sort where possibleDmitri Gribenko
llvm::sort is beneficial even when we use the iterator-based overload, since it can optionally shuffle the elements (to detect non-determinism). However llvm::sort is not usable everywhere, for example, in compiler-rt. Reviewed By: nhaehnle Differential Revision: https://reviews.llvm.org/D130406
2022-07-17[CodeGen] Qualify auto variables in for loops (NFC)Kazu Hirata
2022-07-11[DebugInfo][InstrRef] Fix error in copy handling in InstrRefLDVStephen Tozer
Currently, an error exists when InstrRefBasedLDV observes transfers of variables across copies, which causes it to lose track of variables under certain circumstances, resulting in shorter lifetimes for those variables as LDV gives up searching for live locations for them. This patch fixes this issue by storing the currently tracked values in the destination first, then updating them manually later without clobbering or assigning them the wrong value. Differential Revision: https://reviews.llvm.org/D128101
2022-06-17[CodeGen] Init EmptyExpr before the first useVitaly Buka
2022-05-12[DebugInfo][InstrRef] Describe value sizes when spilt to stackJeremy Morse
This is a re-apply of D123599, which was reverted in 4fe2ab5279408, now with a more appropriate assertion. Original commit message follow: InstrRefBasedLDV can track and describe variable values that are spilt to the stack -- however it does not current describe the size of the value on the stack. This can cause uninitialized bytes to be read from the stack if a small register is spilt for a larger variable, or theoretically on big-endian machines if a large value on the stack is used for a small variable. Fix this by using DW_OP_deref_size to specify the amount of data to load from the stack, if there's any possibility for ambiguity. There are a few scenarios where this can be omitted (such as when using DW_OP_piece and a non-DW_OP_stack_value location), see deref-spills-with-size.mir for an explicit table of inputs flavours and output expressions. Differential Revision: https://reviews.llvm.org/D123599
2022-04-28Revert "[DebugInfo][InstrRef] Describe value sizes when spilt to stack"Zequan Wu
This reverts commit a15b66e76d1ecff625a4bbb4a46ff83a43138f49. This causes linker to crash at assertion: `Assertion failed: !Expr->isComplex(), file C:\b\s\w\ir\cache\builder\src\third_party\llvm\llvm\lib\CodeGen\LiveDebugValues\InstrRefBasedImpl.cpp, line 907`.
2022-04-27[DebugInfo][InstrRef] Describe value sizes when spilt to stackJeremy Morse
InstrRefBasedLDV can track and describe variable values that are spilt to the stack -- however it does not current describe the size of the value on the stack. This can cause uninitialized bytes to be read from the stack if a small register is spilt for a larger variable, or theoretically on big-endian machines if a large value on the stack is used for a small variable. Fix this by using DW_OP_deref_size to specify the amount of data to load from the stack, if there's any possibility for ambiguity. There are a few scenarios where this can be omitted (such as when using DW_OP_piece and a non-DW_OP_stack_value location), see deref-spills-with-size.mir for an explicit table of inputs flavours and output expressions. Differential Revision: https://reviews.llvm.org/D123599
2022-04-26Reapply D124184, [DebugInfo][InstrRef] Add a size operand to DBG_PHIJeremy Morse
This was reverted twice, in 987cd7c3ed75b and 13815e8cbf8d4. The latter stemed from not accounting for rare register classes in a pre-allocated array, and the former from an array not being completely initialized, leading to asan complaining.
2022-04-25Revert "Reapply D124184, [DebugInfo][InstrRef] Add a size operand to DBG_PHI"Jeremy Morse
This reverts commit 5db925023169f8a19419e68153682d1e518f8392. Further to the early revert, the sanitizers have found something wrong with this.
2022-04-25Reapply D124184, [DebugInfo][InstrRef] Add a size operand to DBG_PHIJeremy Morse
This was applied in fda4305e53784, reverted in 13815e8cbf8d49, the problem was that fp80 X86 registers that were spilt to the stack aren't expected by LiveDebugValues. It pre-allocates a position number for all register sizes that can be spilt, and 80 bits isn't exactly common. The solution is to scan the register classes to find any unrecognised register sizes, adn pre-allocate those position numbers, avoiding a later assertion.
2022-04-25Revert "[DebugInfo][InstrRef] Add a size operand to DBG_PHI"Jeremy Morse
This reverts commit fda4305e5378478051be225248bfe9c1d401d938. Green dragon has spotted a problem -- it's understood, but might be fiddly to fix, reverting in the meantime.
2022-04-25[DebugInfo][InstrRef] Add a size operand to DBG_PHIJeremy Morse
DBG_PHI instructions can refer to stack slots, to indicate that multiple values merge together on control flow joins in that slot. This is fine -- however the slot might be merged at a later date with a slot of a different size. In doing so, we lose information about the size the eliminated PHI. Later analysis passes have to guess. Improve this by attaching an optional "bit size" operand to DBG_PHI, which only gets added for stack slots, to let us know how large a size the value on the stack is. Differential Revision: https://reviews.llvm.org/D124184
2022-03-17[DebugInfo][InstrRef] Prefer stack locations for variablesJeremy Morse
This patch adjusts what location is picked for a known variable value -- preferring to leave locations on the stack, even when a value is re-loaded into a register. The benefit is reduced location list entropy, on a clang-3.4 build I found that .debug_loclists reduces in size by 6%, from 29Mb down to 27Mb. Testing: a few tests need the stack slot to be written to explicitly, to force LiveDebugValues into restoring the variable location to a register. I've added an explicit test for the desired behaviour in livedebugvalues_recover_clobbers.mir . Differential Revision: https://reviews.llvm.org/D120732
2022-03-16Cleanup codegen includesserge-sans-paille
This is a (fixed) recommit of https://reviews.llvm.org/D121169 after: 1061034926 before: 1063332844 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121681
2022-03-10Revert "Cleanup codegen includes"Nico Weber
This reverts commit 7f230feeeac8a67b335f52bd2e900a05c6098f20. Breaks CodeGenCUDA/link-device-bitcode.cu in check-clang, and many LLVM tests, see comments on https://reviews.llvm.org/D121169
2022-03-10Cleanup codegen includesserge-sans-paille
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2022-03-01[DebugInfo][InstrRef][NFC] Use unique_ptr instead of raw pointersJeremy Morse
InstrRefBasedLDV allocates some big tables of ValueIDNum, to store live-in and live-out block values in, that then get passed around as pointers everywhere. This patch wraps the allocation in a std::unique_ptr, names some types based on unique_ptr, and passes references to those around instead. There's no functional change, but it makes it clearer to the reader that references to these tables are borrowed rather than owned, and we get some extra validity assertions too. Differential Revision: https://reviews.llvm.org/D118774
2022-02-10[DebugInfo][InstrRef] Don't fire assertions if debug-info is faultyJeremy Morse
It's inevitable that optimisation passes will fail to update debug-info: when that happens, it's best if the compiler doesn't crash as a result. Therefore, downgrade a few assertions / failure modes that would crash when illegal debug-info was seen, to instead drop variable locations. In practice this means that an instruction reference to a nonexistant or illegal operand should be tolerated. Differential Revision: https://reviews.llvm.org/D118998
2022-02-06[CodeGen] Use = default (NFC)Kazu Hirata
Identified with modernize-use-equals-default
2022-02-02Follow up to 6e03a68b776dc, squelch another leakJeremy Morse
This patch is a sticking-paster until D118774 solves the situation with unique_ptrs. I'm certainly wishing I'd focused on that first X_X.
2022-02-02Follow up to 9fd9d56dc6b, avoid a memory leakJeremy Morse
Gaps in the basic block number range (from blocks being deleted or folded) get block-value-tables allocated but never ejected, leading to a memory leak, currently tripping up the asan buildbots. Fix this up by manually freeing that memory. As suggested elsewhere, if these things were owned by a unique_ptr then cleanup would happen automagically. D118774 should eliminate the need for this dance.
2022-02-02[DebugInfo][InstrRef] Fix a tombstone-in-DenseMap crash from D117877Jeremy Morse
This is a follow-up to D117877: variable assignments of DBG_VALUE $noreg, or DBG_INSTR_REFs where no value can be found, are represented by a DbgValue object with Kind "Undef", explicitly meaning "there is no value". In D117877 I added a special-case to some assignment accounting faster, without considering this scenario. It causes variables to be given the value ValueIDNum::EmptyValue, which then ends up being a DenseMap key. The DenseMap asserts, because EmptyValue is the tombstone key. Fix this by handling the assign-undef scenario in the special case, to match what happens in the general case: the variable has no value if it's only ever assigned $noreg / undef. Differential Revision: https://reviews.llvm.org/D118715
2022-02-02[DebugInfo][InstrRef][NFC] Use depth-first scope search for variable locsJeremy Morse
This patch aims to reduce max-rss from instruction referencing, by avoiding keeping variable value information in memory for too long. Instead of computing all the variable values then emitting them to DBG_VALUE instructions, this patch tries to stream the information out through a depth first search: * Make use of the fact LexicalScopes gives a depth-number to each lexical scope, * Produce a map that identifies the last lexical scope to make use of a block, * Enumerate each scope in LexicalScopes' DFS order, solving the variable value problem, * After each scope is processed, look for any blocks that won't be used by any other scope, and emit all the variable information to DBG_VALUE instructions. Differential Revision: https://reviews.llvm.org/D118460
2022-02-02[DebugInfo][InstrRef][NFC] Free resources at an earlier stageJeremy Morse
This patch releases some memory from InstrRefBasedLDV earlier that it would otherwise. The underlying problem is: * We store a big table of "live in values for each block", * We translate that into DBG_VALUE instructions in each block, And both exist in memory at the same time, which needlessly doubles that information. The most of what this patch does is: as we progressively translate live-in information into DBG_VALUEs, we free the variable-value / machine-value tracking information as we go, which significantly reduces peak memory. While I'm here, also add a clear method to wipe variable assignments that have been accumulated into VLocTracker objects, and turn a DenseMap into a SmallDenseMap to avoid an initial allocation. Differential Revision: https://reviews.llvm.org/D118453
2022-02-02[DebugInfo][InstrRef][NFC] Cache some PHI resolutionsJeremy Morse
Install a cache of DBG_INSTR_REF -> ValueIDNum resolutions, for scenarios where the value has to be reconstructed from several DBG_PHIs. Whenever this happens, it's because branch folding + tail duplication has messed with the SSA form of the program, and we have to solve a mini SSA problem to find the variable value. This is always called twice, so it makes sense to cache the value. This gives a ~0.5% geomean compile-time-performance improvement on CTMark. Differential Revision: https://reviews.llvm.org/D118455
2022-02-02Re-apply 3fab2d138e30, now with a triple addedJeremy Morse
Was reverted in 1c1b670a73a9 as it broke all non-x86 bots. Original commit message: [DebugInfo][InstrRef] Add a max-stack-slots-to-track cut-out In certain circumstances with things like autogenerated code and asan, you can end up with thousands of Values live at the same time, causing a large working set and a lot of information spilled to the stack. Unfortunately InstrRefBasedLDV doesn't cope well with this and consumes a lot of memory when there are many many stack slots. See the reproducer in D116821. It seems very unlikely that a developer would be able to reason about hundreds of live named local variables at the same time, so a huge working set and many stack slots is an indicator that we're likely analysing autogenerated or instrumented code. In those cases: gracefully degrade by setting an upper bound on the amount of stack slots to track. This limits peak memory consumption, at the cost of dropping some variable locations, but in a rare scenario where it's unlikely someone is actually going to use them. In terms of the patch, this adds a cl::opt for max number of stack slots to track, and has the stack-slot-numbering code optionally return None. That then filters through a number of code paths, which can then chose to not track a spill / restore if it touches an untracked spill slot. The added test checks that we drop variable locations that are on the stack, if we set the limit to zero. Differential Revision: https://reviews.llvm.org/D118601
2022-02-01Revert "[DebugInfo][InstrRef] Add a max-stack-slots-to-track cut-out"Kevin Athey
This reverts commit 3fab2d138e30c65249e1eaea6cc68b2b7f50955a. Breaking PPC sanitizer build: https://lab.llvm.org/buildbot/#/builders/105/builds/20857