aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues
AgeCommit message (Collapse)AuthorFilesLines
2023-12-23[LiveDebugValues][nfc] Reduce memory usage of InstrRef (#76051)Felipe de Azevedo Piovezan2-31/+65
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 Piovezan1-9/+2
`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 Piovezan2-41/+36
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 ↵DianQK2-3/+3
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 Arsenault2-3/+3
This reverts commit bc7d88faf1a595ab59952a2054418cdd0d9eeee8. This is broken with 414ff812d6241b728754ce562081419e7fc091eb reverted.
2023-10-02CodeGen: Disable isCopyInstrImpl if there are implicit operandsMatt Arsenault2-3/+3
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-09-22[InstrRef][NFC] Improve diagram illustrating locations (#66944)Felipe de Azevedo Piovezan1-2/+2
The "register number" arrow should point to `LocationID`, not `LocIdx`.
2023-08-27[llvm] Use SmallDenseMap::contains (NFC)Kazu Hirata1-1/+1
2023-06-16[MC] Add MCRegisterInfo::regunits for iteration over register unitsSergei Barannikov1-2/+2
Reviewed By: foad Differential Revision: https://reviews.llvm.org/D152098
2023-06-10[llvm] Use DenseMapBase::lookup (NFC)Kazu Hirata1-4/+1
2023-06-01[CodeGen] Make use of MachineInstr::all_defs and all_uses. NFCI.Jay Foad1-2/+2
Differential Revision: https://reviews.llvm.org/D151424
2023-05-28use ref to avoid copy in range for-loopWang, Xin101-1/+1
Use big obj copy in range for-loop will call copy constructor every time, which can be avoided by use ref instead. Reviewed By: skan Differential Revision: https://reviews.llvm.org/D150024
2023-05-19[DebugInfo][InstrRef] Handle non-directly reachable DBG_PHIs in LiveDebugValuesStephen Tozer1-1/+6
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-05-18[LiveDebugValues] Initialized variable to avoid msan reportsVitaly Buka1-2/+2
Reproducible with =-1 and assert: https://reviews.llvm.org/P8309 Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D150420
2023-05-11[NFC][LiveDebugValues] Clang-format b135df08Vitaly Buka1-1/+1
2023-05-11[LiveDebugValues] Temporarily initialize MLocTracker::CurBBVitaly Buka1-1/+1
Looks like code assumes that it will be always set, but it's not true: https://reviews.llvm.org/D150420. This is temporarily suppression to enabled stricter msan on a bot.
2023-05-05[Coverity] Big parameter passed by value.Luo, Yuanke1-1/+1
2023-04-25[llvm] Replace None with std::nullopt in comments (NFC)Kazu Hirata1-1/+1
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
2023-04-18[MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIterator. NFC.Jay Foad1-10/+10
Differential Revision: https://reviews.llvm.org/D148613
2023-04-17Fix uninitialized pointer members in CodeGenAkshay Khadse1-1/+1
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr. Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D148303
2023-03-15[llvm] Use *{Map,Set}::contains (NFC)Kazu Hirata1-1/+1
2023-03-14[CodeGen] Use *{Set,Map}::contains (NFC)Kazu Hirata2-5/+5
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-31[LiveDebugValues] Allow EntryValue with OP_deref expressionsFelipe de Azevedo Piovezan2-2/+4
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 Topper2-6/+3
Use isPhysical/isVirtual methods. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D141715
2023-01-10[WebAssembly][LiveDebugValues] Handle target index defsHeejin Ahn1-11/+73
This adds the missing handling for defs for target index operands, as is already done for registers. There are two kinds of target indices: local indices and stack operands. - Locals are something similar to registers in Wasm-land. For local indices, we can check for local-defining instructions (`local.set` or `local.tee`). - Wasm is a stack machine, so we have values in certain Wasm value stack location, which change when Wasm instructions produce or consume values. So basically any value-producing instrucion, i.e., instruction with defs, can change values in the Wasm stack. But I think we don't need to worry about this here, because `WebAssemblyDebugFixup`, which runs right before this analysis, makes sure to insert terminating `DBG_VALUE $noreg` instructions whenever a stack value gets popped. After `WebAssemblyDebugFixup`, there shouldn't be any `DBG_VALUE`s for stack operands that don't have a terminating `DBG_VALUE $noreg` within the same BB. So this CL only works on `DBG_VALUE`s for locals. When we encounter a `local.set` or `local.tee` instructions, we delete `DBG_VALUE`s for those target index locations from the open range set, so they will not be availble in `OutLocs`. For example, ``` bb.0: successors: %bb.1 DBG_VALUE target-index(wasm-local) + 2, $noreg, "var", ... ... local.set 2 ... bb.1: ; predecessors: %bb.0 ; We shouldn't add `DBG_VALUE target (wasm-local) + 2 here because ; it was killed by 'local.set' in bb.0 ``` After disabling register coalescing at -O1, the average PC ranges covered for Emscripten core benchmarks is currently 20.6% in the LLVM tot. After applying D138943 and this CL, the coverage goes up to 57%. This also enables LiveDebugValues analysis in the Wasm pipeline by default. Reviewed By: dschuff, jmorse Differential Revision: https://reviews.llvm.org/D140373
2023-01-10[WebAssembly] Use LiveDebugValues analysisHeejin Ahn2-17/+68
This enables `LiveDebugValues` analysis for Wasm. `DBG_VALUE`s expire at the end of a BB, and this is the analysis extends their lifetime when possible, greatly increasing the coverage of variable debug info. Specifically, this removes the current constraint that this analysis is only used with physical registers, which was first introduced in D18421, because Wasm uses only virtual registers. I don't think there's anything inherent in this analysis that only applies to physical registers; it was just because all targets using this analysis ran this at the end of their compiliation pipeline, at which point all their vregs had been allocated, and Wasm's debug info infrastructure was not really set up yet, so it was not using it. This adds supports to Wasm-specific target-index operands, defined in https://github.com/llvm/llvm-project/blob/2166d9529a60d1cdedb733d2e4134c971f0969ec/llvm/lib/Target/WebAssembly/WebAssembly.h#L87-L100. Among these, `TI_LOCAL`, `TI_LOCAL_INDIRECT`, and `TI_OPERAND_STACK` are used by Wasm `DBG_VALUE` instructions. This does not yet handle mutable target indices, i.e., this does not terminate a `DBG_VALUE` for a local index when we encounter a new `local.set` or `local.tee`. It will be implemented as a follow-up. Reviewed By: dschuff, jmorse Differential Revision: https://reviews.llvm.org/D138943
2023-01-06[DebugInfo] Add support for variadic DBG_INSTR_REFs in LiveDebugValuesStephen Tozer2-66/+153
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 Tozer1-4/+4
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 Tozer2-5/+5
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-21[LiveDebugValues] Remove LexicalScope param from VarLoc (NFC)Heejin Ahn1-12/+10
It doesn't seem to be used anymore. Reviewed By: dschuff Differential Revision: https://reviews.llvm.org/D140258
2022-12-20[DebugInfo] Unify location selection logic for values in InstrRefBasedImplStephen Tozer1-45/+84
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 Tozer2-2/+7
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 Song3-48/+52
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata2-9/+9
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-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-2/+2
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-04DebugInfoMetadata: convert Optional to std::optionalKrzysztof Parzyszek2-3/+5
2022-12-02[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata3-21/+22
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 Hirata1-3/+4
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-08Reland "[llvm][NFC] Use c++17 style variable type traits"Nathan James1-2/+1
This reverts commit 632a389f96355cbe7ed8fa7b8d2ed6267c92457c. This relands commit 1834a310d060d55748ca38d4ae0482864c2047d8. Differential Revision: https://reviews.llvm.org/D137493
2022-11-08Revert "[llvm][NFC] Use c++17 style variable type traits"Nathan James1-1/+2
This reverts commit 1834a310d060d55748ca38d4ae0482864c2047d8.
2022-11-08[llvm][NFC] Use c++17 style variable type traitsNathan James1-2/+1
This was done as a test for D137302 and it makes sense to push these changes Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D137493
2022-09-03Use llvm::lower_bound (NFC)Kazu Hirata1-2/+1
2022-09-01Reapply "[DebugInfo] Extend the InstrRef LDV to support DbgValues with many Ops"Stephen Tozer2-17/+0
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 Tozer2-0/+14
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 Tozer2-14/+0
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 Tozer2-139/+340
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 Tozer2-97/+134
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 Tozer2-42/+107
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[LiveDebugValues] Fix a warningKazu Hirata1-4/+6
This patch fixes: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h:330:5: error: anonymous types declared in an anonymous union are an extension [-Werror,-Wnested-anon-types]