aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetRegisterInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
13 days[CodeGen] Adjust global-split remat heuristic to match LICM (#160709)Philip Reames1-1/+2
This heuristic was originally added in 40c4aa with the stated purpose of avoiding global split on live long ranges created by MachineLICM hoisting trivially rematerializable instructions. In the meantime, various backends have introduced non-trivial rematerialization cases, MachineLICM gained an explicitly triviality check, and we've reworked our APIs to match naming wise. Let's move this heuristic back to truely trivial remat only. This is a functional change, though somewhat hard to hit. This change will cause non-trivially rematerializable instructions to be globally split more often. This is likely a good thing since non-trivial remat may not be legal at all possible points in the live interval, but may cost slightly more compile time. I don't have a motivating example; I found it when reviewing the callers of isRemMaterializable(MI).
2025-09-24[TII] Split isTrivialReMaterializable into two versions [nfc] (#160377)Philip Reames1-2/+1
This change builds on https://github.com/llvm/llvm-project/pull/160319 which tries to clarify which *callers* (not backends) assume that the result is actually trivial. This change itself should be NFC. Essentially, I'm just renaming the existing isTrivialRematerializable to the non-trivial version and then adding a new trivial version (with the same name as the prior function) and simplifying a few callers which want that semantic. This change does *not* enable non-trivial remat any more broadly than was already done for our targets which were lying through the old APIs; that will come separately. The goal here is simply to make the code easier to follow in terms of what assumptions are being made where. --------- Co-authored-by: Luke Lau <luke_lau@icloud.com>
2025-09-16CodeGen: Surface shouldRewriteCopySrc utility function (#158524)Matt Arsenault1-20/+8
Change shouldRewriteCopySrc to return the common register class and expose it as a utility function. I've found myself reproducing essentially the same logic in multiple places. The purpose of this function is to jsut work through the API constraints of which combination of register class and subreg indexes you have. i.e. you need to use a different function if you have 0, 1, or 2 subregister indexes involved in a pair of copy-like operations.
2025-03-13[RegAlloc] Scale the spill weight by target factor (#113675)Pengcheng Wang1-0/+5
Currently, the spill weight is only determined by isDef/isUse and block frequency. However, for registers with different register classes, the costs of spilling them are different. For example, for `LMUL>1` registers (in which, several physical registers compound a bigger logical register), the costs are larger than `LMUL=1` case (in which, there is only one physical register). To solve this problem, a new target hook `getSpillWeightScaleFactor` is added. Targets can override the default factor (which is `1.0`) according to the register class. For RISC-V, the factors are set to the `RegClassWeight` which is used to track register pressure. The values of `RegClassWeight` happen to be the number of register units. I believe all of the targets with compounded registers can benefit from this change, but only RISC-V is customized in this patch since it has widely been agreed to do so. The other targets need more performance data to go further. Partially fixes #113489.
2025-03-06[CodeGen] Use Register::id(). NFCCraig Topper1-1/+1
2025-02-20Revert "[CodeGen] Remove static member function Register::isVirtualRegister. ↵Christopher Di Bella1-1/+1
NFC (#127968)" This reverts commit ff99af7ea03b3be46bec7203bd2b74048d29a52a.
2025-02-20[CodeGen] Remove static member function Register::isVirtualRegister. NFC ↵Craig Topper1-1/+1
(#127968) Use nonstatic member instead. This requires explicit conversions, but many will go away as we continue converting unsigned to Register. In a few places where it was simple, I changed unsigned to Register.
2025-02-19[CodeGen] Remove static member function Register::virtReg2Index. NFC (#127962)Craig Topper1-1/+1
Use the nonstatic member instead. I'm pretty sure the code in SPRIV is a layering violation. MC layer files are using a CodeGen header.
2025-02-05X86: Remove hack in shouldRewriteCopySrc for subregister handling (#125224)Matt Arsenault1-1/+4
In the problematic situation fixed in 61e556d2bdf3fa0a10dbaadd2dd03d01c341bd27, shouldRewriteCopySrc is called with identical register class arguments, but one has a subregister index. This was very surprising to me, and it probably shouldn't be valid for it to occur. It happens in cases with uncoalescable copies where the register class changes, and further up the chain there is a subregister operand. We could possibly just skip over uncoalsecable instructions in the chain rather than letting this query deal with it (or pre-filter the obvious subreg with same class case). The generic implementation is supposed to account for checking for valid subregisters by checking getMatchingSuperRegClass already, but that was bypassed by the early exit for exact class match. Also adds a reduced mir test demonstrating the exact problematic case.
2025-01-29[CodeGen] Add Register::stackSlotIndex(). Replace uses of ↵Craig Topper1-3/+3
Register::stackSlot2Index. NFC (#125028)
2025-01-18[CodeGen] Use Register/MCRegister::isPhysical. NFCCraig Topper1-8/+5
2025-01-14[CodeGen] Remove unused argument from getCoveringSubRegIndexes. NFC. (#122884)Jay Foad1-2/+2
2024-12-23[TRI][RISCV] Add methods to get common register class of two registers (#118435)Pengcheng Wang1-18/+59
Here we add two methods `getCommonMinimalPhysRegClass` and a LLT version `getCommonMinimalPhysRegClassLLT`, which return the most sub register class of the right type that contains these two input registers. We don't overload the `getMinimalPhysRegClass` as there will be ambiguities. We use it to simplify some code in RISC-V target.
2024-11-12[CodeGen] Remove unused includes (NFC) (#115996)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-09-02[CodeGen] Update a few places that were passing Register to ↵Craig Topper1-1/+1
raw_ostream::operator<< (#106877) These would implicitly cast the register to `unsigned`. Switch most of them to use printReg will give a more readable output. Change some others to use Register::id() so we can eventually remove the implicit cast to `unsigned`.
2024-08-07[CodeGen] Allocate RegAllocHints map lazily (#102186)Alexis Engelke1-3/+6
This hint map is not required whenever a new register is added, in fact, at -O0, it is not used at all. Growing this map is quite expensive, as SmallVectors are not trivially copyable. Grow this map only when hints are actually added to avoid multiple grows and grows when no hints are added at all.
2024-05-29[CodeGen] Don't check attrs for stack realign (#92564)aengelke1-7/+2
shouldRealignStack/canRealignStack are repeatedly called in PEI (through hasStackRealignment). Checking function attributes is expensive, so cache this data in the MachineFrameInfo, which had most data already. This slightly changes the semantics of `MachineFrameInfo::ForcedRealign` to be also true when the `stackrealign` attribute is set.
2024-03-27[Target][RISCV] Add HwMode support to subregister index size/offset. (#86368)Craig Topper1-2/+2
This is needed to provide proper size and offset for the GPRPair subreg indices on RISC-V. The size of a GPR already uses HwMode. Previously we said the subreg indices have unknown size and offset, but this stops DwarfExpression::addMachineReg from being able to find the registers that make up the pair. I believe this fixes https://github.com/llvm/llvm-project/issues/85864 but need to verify.
2024-03-22[Target] Move SubRegIdxRanges from MCSubtargetInfo to TargetInfo. (#86245)Craig Topper1-14/+22
I'm planning to add HwMode support to SubRegIdxRanges for RISC-V GPR pairs. The MC layer is currently unaware of the HwMode for registers and I'd like to keep it that way. This information is not used by the MC layer so I think it is safe to move it.
2024-01-25[llvm] Move CodeGenTypes library to its own directory (#79444)Nico Weber1-1/+1
Finally addresses https://reviews.llvm.org/D148769#4311232 :) No behavior change.
2023-11-07[CodeGen][MachineVerifier] Use TypeSize instead of unsigned for getRe… ↵Michael Maitland1-10/+9
(#70881) …gSizeInBits This patch changes getRegSizeInBits to return a TypeSize instead of an unsigned in the case that a virtual register has a scalable LLT. In the case that register is physical, a Fixed TypeSize is returned. The MachineVerifier pass is updated to allow copies between fixed and scalable operands as long as the Src size will fit into the Dest size. This is a precommit which will be stacked on by a change to GISel to generate COPYs with a scalable destination but a fixed size source. This patch is stacked on https://github.com/llvm/llvm-project/pull/70893 for the ability to use scalable vector types in MIR tests.
2023-08-21Move VTList pointer out of RegClassInfosBenjamin Kramer1-1/+2
Store it in TargetRegisterInfo instead. Worth 54k on llc size.
2023-05-03Restore CodeGen/MachineValueType.h from `Support`NAKAMURA Takumi1-1/+1
This is rework of; - rG13e77db2df94 (r328395; MVT) Since `LowLevelType.h` has been restored to `CodeGen`, `MachinveValueType.h` can be restored as well. Depends on D148767 Differential Revision: https://reviews.llvm.org/D149024
2023-04-18[MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIterator. NFC.Jay Foad1-6/+6
Differential Revision: https://reviews.llvm.org/D148613
2023-03-22[CodeGen] Fix type of MachineRegisterInfo::RegAllocHints. NFC.Jay Foad1-2/+2
The first member of the pair should be unsigned instead of Register because it is the hint type, 0 for simple (target independent) hints and other values for target dependent hints. Differential Revision: https://reviews.llvm.org/D146646
2023-01-28Use llvm::count{lr}_{zero,one} (NFC)Kazu Hirata1-1/+1
2023-01-18[CodeGen] Prevent overlapping subregs in getCoveringSubRegIndexesPierre van Houtryve1-4/+8
If `getCoveringSubRegIndexes` returns a set of subregister indexes where some subregisters overlap others, it can create unsatisfiable copy bundles that eventually cause VirtRegRewriter to error out due to "cycles in copy bundle". We can simply prevent this by making the algorithm skip over subregisters indexes that would cause an overlap with already-covered lanes. Note that in the case of AMDGPU, this problem is caused by the lack of subregisters indexes for 13/14/15-register tuples. We have everything up until 12, then we have 16 and 32 but nothing between 12 and 16. This means that the best candidate to do the least amount of copies when splitting a 29-register tuple was to copy (e.g.) 0-15 and 14-29, causing an overlap. With this change, getCoveringSubRegIndexes will now prefer using something like 0-15, 16-28 and 1 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D141576
2023-01-13[CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFCCraig Topper1-1/+1
Use isPhysical/isVirtual methods. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D141715
2022-02-04Reduce dependencies on llvm/BinaryFormat/Dwarf.hserge-sans-paille1-1/+2
This header is very large (3M Lines once expended) and was included in location where dwarf-specific information were not needed. More specifically, this commit suppresses the dependencies on llvm/BinaryFormat/Dwarf.h in two headers: llvm/IR/IRBuilder.h and llvm/IR/DebugInfoMetadata.h. As these headers (esp. the former) are widely used, this has a decent impact on number of preprocessed lines generated during compilation of LLVM, as showcased below. This is achieved by moving some definitions back to the .cpp file, no performance impact implied[0]. As a consequence of that patch, downstream user may need to manually some extra files: llvm/IR/IRBuilder.h no longer includes llvm/BinaryFormat/Dwarf.h llvm/IR/DebugInfoMetadata.h no longer includes llvm/BinaryFormat/Dwarf.h In some situations, codes maybe relying on the fact that llvm/BinaryFormat/Dwarf.h was including llvm/ADT/Triple.h, this hidden dependency now needs to be explicit. $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Transforms/Scalar/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l after: 10978519 before: 11245451 Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup [0] https://llvm-compile-time-tracker.com/compare.php?from=fa7145dfbf94cb93b1c3e610582c495cb806569b&to=995d3e326ee1d9489145e20762c65465a9caeab4&stat=instructions Differential Revision: https://reviews.llvm.org/D118781
2022-01-07[llvm] Use true/false instead of 1/0 (NFC)Kazu Hirata1-2/+2
Identified with modernize-use-bool-literals.
2021-12-07[llvm] Use range-based for loops (NFC)Kazu Hirata1-2/+2
2021-05-12[TargetRegisterInfo] Speed up getAllocatableSet. NFCI.Jay Foad1-2/+3
MachineRegisterInfo caches the reserved register set that is computed by by TargetRegisterInfo::getReservedRegs, so call into MRI to get the reserved regs to avoid recomputing them. In particular this speeds up AMDGPU's SIFormMemoryClauses pass because AMDGPU has a particularly complicated reserved set that is expensive to compute. Differential Revision: https://reviews.llvm.org/D102318
2021-04-28GlobalISel: Relax verification of physical register copy typesMatt Arsenault1-0/+17
This was picking a concrete size for a physical register, and enforcing exact match on the virtual register's type size. Some targets add multiple types to a register class, and some are smaller than the full bit width. For example x86 adds f32 to 128-bit xmm registers, and AMDGPU adds i16/f16 to 32-bit registers. It might be better to represent these cases as a copy of the full register and an extraction of the subpart, but a lot of code assumes you can directly copy. This will help fix the current usage of the DAG calling convention infrastructure which is incompatible with how GlobalISel is now using it. The API is somewhat cumbersome here, but I just mirrored the existing functions, except now with LLTs (and allow returning null on failure, unlike the MVT version). I think the concept of selecting register classes based on type is flawed to begin with, but I'm trying to keep this compatible with the existing handling.
2021-03-30[NFC][CodeGen] Tidy up TargetRegisterInfo stack realignment functionsTomas Matheson1-12/+4
Currently needsStackRealignment returns false if canRealignStack returns false. This means that the behavior of needsStackRealignment does not correspond to it's name and description; a function might need stack realignment, but if it is not possible then this function returns false. Furthermore, needsStackRealignment is not virtual and therefore some backends have made use of canRealignStack to indicate whether a function needs stack realignment. This patch attempts to clarify the situation by separating them and introducing new names: - shouldRealignStack - true if there is any reason the stack should be realigned - canRealignStack - true if we are still able to realign the stack (e.g. we can still reserve/have reserved a frame pointer) - hasStackRealignment = shouldRealignStack && canRealignStack (not target customisable) Targets can now override shouldRealignStack to indicate that stack realignment is required. This change will make it easier in a future change to handle the case where we need to realign the stack but can't do so (for example when the register allocator creates an aligned spill after the frame pointer has been eliminated). Differential Revision: https://reviews.llvm.org/D98716 Change-Id: Ib9a4d21728bf9d08a545b4365418d3ffe1af4d87
2021-02-15CodeGen: Move function to get subregister indexes to cover a LaneMaskMatt Arsenault1-0/+71
Return the best covering index, and additional needed to complete the mask. This logically belongs in TargetRegisterInfo, although I ended up not needing it for why I originally split this out.
2021-01-21[NFC] [TargetRegisterInfo] add another API to get srcreg through copy.Chen Zheng1-0/+25
Reviewed By: nemanjai, jsji Differential Revision: https://reviews.llvm.org/D92069
2021-01-18Revert "[NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike."Chen Zheng1-14/+5
This reverts commit 3bdf4507b66348ad78df4655a8e4f36c3fc10f3c. Post commit comments need to be addressed first.
2021-01-17[NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike.Chen Zheng1-5/+14
add one use check to lookThruCopyLike. The root node is safe to be deleted if we are sure that every definition in the copy chain only has one use. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D92069
2021-01-06[AArch64][SVE] Emit DWARF location expression for SVE stack objects.Sander de Smalen1-0/+26
Extend PEI to emit a DWARF expression for StackOffsets that have a fixed and scalable component. This means the expression that needs to be added is either: <base> + offset or: <base> + offset + scalable_offset * scalereg where for SVE, the scale reg is the Vector Granule Dwarf register, which encodes the number of 64bit 'granules' in an SVE vector and which the debugger can evaluate at runtime. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D90020
2020-09-16[NFC][Regalloc] accessors for 'reg' and 'weight'Mircea Trofin1-1/+1
Also renamed the fields to follow style guidelines. Accessors help with readability - weight mutation, in particular, is easier to follow this way. Differential Revision: https://reviews.llvm.org/D87725
2020-04-07CodeGen: More conversions to use RegisterMatt Arsenault1-15/+13
2020-04-07CodeGen: Use Register in more placesMatt Arsenault1-10/+10
2020-03-18[Alignment][NFC] Deprecate getMaxAlignmentGuillaume Chatelet1-2/+2
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, arsenm, dschuff, jyknight, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76348
2020-02-03[TargetRegisterInfo] Make the heuristic to skip region split overridable by ↵Quentin Colombet1-1/+21
the target RegAllocGreedy uses a fairly compile time intensive splitting heuristic called region splitting. This heuristic was disabled via another heuristic when it is likely that it won't be worth the compile time. The only way to control this other heuristic was via a command line option (huge-size-for-split). This commit gives more control on this heuristic by making it overridable by the target using a target hook in TargetRegisterInfo called shouldRegionSplitForVirtReg. The default implementation of this hook keeps the heuristic as it was before this patch.
2019-09-13[TargetRegisterInfo] Remove SVT argument from getCommonSubClass.Craig Topper1-13/+5
This was added to support fp128 on x86-64, but appears to be unneeded now. This may be because the FR128 register class added back then was merged with the VR128 register class later. llvm-svn: 371815
2019-08-13Eliminate implicit Register->unsigned conversions in VirtRegMap. NFCDaniel Sanders1-1/+1
Summary: This was mostly an experiment to assess the feasibility of completely eliminating a problematic implicit conversion case in D61321 in advance of landing that* but it also happens to align with the goal of propagating the use of Register/MCRegister instead of unsigned so I believe it makes sense to commit it. The overall process for eliminating the implicit conversions from Register/MCRegister -> unsigned was to: 1. Add an explicit conversion to support genuinely required conversions to unsigned. For example, using them as an index for IndexedMap. Sadly it's not possible to have an explicit and implicit conversion to the same type and only deprecate the implicit one so I called the explicit conversion get(). 2. Temporarily annotate the implicit conversion to unsigned with LLVM_ATTRIBUTE_DEPRECATED to make them visible 3. Eliminate implicit conversions by propagating Register/MCRegister/ explicit-conversions appropriately 4. Remove the deprecation added in 2. * My conclusion is that it isn't feasible as there's too much code to update in one go. Depends on D65678 Reviewers: arsenm Subscribers: MatzeB, wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65685 llvm-svn: 368643
2019-08-01Finish moving TargetRegisterInfo::isVirtualRegister() and friends to ↵Daniel Sanders1-14/+15
llvm::Register as started by r367614. NFC llvm-svn: 367633
2019-07-31Reland "[DwarfDebug] Dump call site debug info"Djordje Todorovic1-0/+13
The build failure found after the rL365467 has been resolved. Differential Revision: https://reviews.llvm.org/D60716 llvm-svn: 367446
2019-07-12Revert "[DwarfDebug] Dump call site debug info"Djordje Todorovic1-14/+0
A build failure was found on the SystemZ platform. This reverts commit 9e7e73578e54cd22b3c7af4b54274d743b6607cc. llvm-svn: 365886
2019-07-09[DwarfDebug] Dump call site debug infoDjordje Todorovic1-0/+14
Dump the DWARF information about call sites and call site parameters into debug info sections. The patch also provides an interface for the interpretation of instructions that could load values of a call site parameters in order to generate DWARF about the call site parameters. ([13/13] Introduce the debug entry values.) Co-authored-by: Ananth Sowda <asowda@cisco.com> Co-authored-by: Nikola Prica <nikola.prica@rt-rk.com> Co-authored-by: Ivan Baev <ibaev@cisco.com> Differential Revision: https://reviews.llvm.org/D60716 llvm-svn: 365467