summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
AgeCommit message (Collapse)Author
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
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