aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenRegisters.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-2519/+0
Refactor of the llvm-tblgen source into: - a "Basic" library, which contains the bare minimum utilities to build `llvm-min-tablegen` - a "Common" library which contains all of the helpers for TableGen backends. Such helpers can be shared by more than one backend, and even unit tested (e.g. CodeExpander is, maybe we can add more over time) Fixes #80647
2024-03-22[TableGen] Minor cleanup in CodeGenRegBank::getConcatSubRegIndex. NFCCraig Topper1-4/+4
Mark a variable const. Capitalize a variable name. I'm going to add HwMode support to this code and wanted to clean it up a bit beforehand.
2024-02-15[TableGen] New RegUnitSet(Name) constructor. NFC.Jay Foad1-8/+7
2024-02-14[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)Jay Foad1-17/+17
These are unnecessary since C++17.
2024-02-13[TableGen] Trivial simplification in computeRegUnitSets. NFC.Jay Foad1-4/+2
2024-02-13[TableGen] Remove trivial helper function hasRegUnit. NFC.Jay Foad1-8/+2
2024-02-13[TableGen] Do not speculatively grow RegUnitSets. NFC.Jay Foad1-17/+8
This seems to be a trick to avoid copying a RegUnitSet, but it can be done more simply using std::move.
2024-02-13[TableGen] Use emplace_back instead of resize to size() + 1. NFC.Jay Foad1-13/+11
2024-02-13[TableGen] Use std::move instead of swap. NFC. (#81606)Jay Foad1-3/+3
Historically TableGen has used `A.swap(B)` to move containers without the expense of copying them. Perhaps this predated rvalue references. In any case `A = std::move(B)` seems like a more direct way to implement this when only A is required after the operation.
2024-02-13[TableGen] Use vectors instead of sets for testing intersection. NFC. (#81602)Jay Foad1-6/+5
In a few places we test whether sets (i.e. sorted ranges) intersect by computing the set_intersection and then testing whether it is empty. For this purpose it should be more efficient to use a std:vector instead of a std::set to hold the result of the set_intersection, since insertion is simpler.
2024-02-12[TableGen] Make use of find_if. NFC.Jay Foad1-7/+2
2024-02-09[NFC] clang-format utils/TableGen (#80973)Pierre van Houtryve1-138/+148
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2023-11-02[NFC][X86] Reorder the registers to reduce unnecessary iterations (#70222)Shengchen Kan1-16/+36
* Introduce field `PositionOrder` for class `Register` and `RegisterTuples` * If register A's `PositionOrder` < register B's `PositionOrder`, then A is placed before B in the enum in X86GenRegisterInfo.inc * The new order of registers in the enum for X86 will be 1. Registers before AVX512, 2. AVX512 registers (X/YMM16-31, ZMM0-31, K registers) 3. AMX registers (TMM) 4. APX registers (R16-R31) * Add a new target hook `getNumSupportedRegs()` to return the number of registers for the function (may overestimate). * Replace `getNumRegs()` with `getNumSupportedRegs()` in LiveVariables to eliminate iterations on unsupported registers This patch can reduce 0.3% instruction count regression for sqlite3 during compile-stage (O3) by not iterating on APX registers for #67702
2023-09-25[TableGen][NFCI] Speed up generating *GenRegisterInfo.inc files on builds ↵Ivan Kosarev1-8/+12
with expensive checks. (#67340) This is mostly AMDGPU-specific. When the expensive checks are enabled, generating of AMDGPUGenRegisterInfo.inc currently takes about 20 minutes on my machine for release+asserts builds, which effectively prevents such testing from regular use. This patch fixes this by reducing the time to about 2 minutes. Generation times for AMDGPUGenRegisterInfo.inc without expensive checks and other *GenRegisterInfo.inc files with and without the expensive checks remain approximately the same. The patch doesn't cause any changes in the contents of the generated files. The root cause of the current poor performance is that where glibcxx is used, enabling the expensive checks defines _GLIBCXX_DEBUG, which enables various consistency checks in the library. One such check is in std::binary_search() to make sure the range is ordered. As CodeGenRegisterClass::contains() relies on std::binary_search() and it is called very a large number of times from within CodeGenRegBank::inferMatchingSuperRegClass(), the libcxx checks heavily affect the runtimes.
2023-09-24[TableGen] Fix ordering of register classes. (#67245)Ivan Kosarev1-8/+8
This commit: TableGen: Try to fix expensive checks failures d2a9b87fee84766b28bd39b46c913da00e1450f4 fixed one of the sort() calls, but there's another. Caught on expensive-checks buildbots that started to fail sporadically after submitting [AMDGPU] Add True16 register classes. 469b3bfad20550968ac428738eb1f8bb8ce3e96d
2023-08-14[CodeGen] Set regunitmasks for leaf regs to all instead of noneJay Foad1-3/+3
This simplifies every use of MCRegUnitMaskIterator. Differential Revision: https://reviews.llvm.org/D157864
2023-08-03[TableGen][NFC] Refine obtaining qualified register class ids.Ivan Kosarev1-4/+13
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D156110
2023-03-27[RISCV] Replace RISCV -> RISC-V in comments. NFCCraig Topper1-1/+1
To be consistent with RISC-V branding guidelines https://riscv.org/about/risc-v-branding-guidelines/ Think we should be using RISC-V where possible. More patches will follow. Reviewed By: asb Differential Revision: https://reviews.llvm.org/D146449
2023-01-25[TableGen] Speed up computeUberSets. NFC.Jay Foad1-6/+5
Differential Revision: https://reviews.llvm.org/D142472
2022-12-06[TableGen] llvm::Optional => std::optionalFangrui Song1-1/+1
2022-12-02[utils] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
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-20[TableGen] Fix SubRegIndex size computation for concatenated subregs of ↵Bjorn Pettersson1-2/+6
unknown size When calculating the size of concatenated subregisters, and at least one of the subregisters involved has an unknown size (-1), then the concatenated size should be set to -1 as well. This bug was found for an out-of-tree target. Looking at lib/Target the only in-tree target that has a subregister with unknown size is X86: X86RegisterInfo.td: def sub_mask_0 : SubRegIndex<-1>; But it looks like sub_mask_0 don't result in any concatenated subreg index with faulty size if looking at X86SubRegIdxRanges[]. Differential Revision: https://reviews.llvm.org/D138341
2022-09-15RegAllocGreedy: Avoid overflowing priority bitfieldsMatt Arsenault1-3/+7
The class priority is expected to be at most 5 bits before it starts clobbering bits used for other fields. Also clamp the instruction distance in case we have millions of instructions. AMDGPU was accidentally overflowing into the global priority bit in some cases. I think in principal we would have wanted this, but in the cases I've looked at, it had the counter intuitive effect and de-prioritized the large register tuple. Avoid using weird bit hack PPC uses for global priority. The AllocationPriority field is really 5 bits, and PPC was relying on overflowing this to 6-bits to forcibly set the global priority bit. Split this out as a separate flag to avoid having magic behavior for values above 31.
2022-08-24[RegisterInfoEmitter] Generate isConstantPhysReg(). NFCIAlex Richardson1-2/+2
This commit moves the information on whether a register is constant into the Tablegen files to allow generating the implementaiton of isConstantPhysReg(). I've marked isConstantPhysReg() as final in this generated file to ensure that changes are made to tablegen instead of overriding this function, but if that turns out to be too restrictive, we can remove the qualifier. This should be pretty much NFC, but I did notice that e.g. the AMDGPU generated file also includes the LO16/HI16 registers now. The new isConstant flag will also be used by D131958 to ensure that constant registers are marked as call-preserved. Differential Revision: https://reviews.llvm.org/D131962
2022-07-07[TableGen] Fix CodeGenRegisterClass::hasType for simple-type argumentsKrzysztof Parzyszek1-0/+20
The `hasType` function may be given a type that has been modified from its original form (in particular made "simple", due to a predicate). Make sure that such a type is still recognized as associated with a register class, if the class contains it under any hw-mode. This is somewhat optimistic though, since there is no information as to where that simple type originated from.
2022-05-11[TableGen] Remove the use of global Record stateRiver Riddle1-3/+4
This commits removes TableGens reliance on managed static global record state by moving the RecordContext into the RecordKeeper. The RecordKeeper is now treated similarly to a (LLVM|MLIR|etc)Context object and is passed to static construction functions. This is an important step forward in removing TableGens reliance on global state, and in a followup will allow for users that parse tablegen to parse multiple tablegen files without worrying about Record lifetime. Differential Revision: https://reviews.llvm.org/D125276
2022-04-06Fix warnings about variables that are set but only used in debug modeMartin Storsjö1-0/+1
Add void casts to mark the variables used, next to the places where they are used in assert or `LLVM_DEBUG()` expressions. Differential Revision: https://reviews.llvm.org/D123117
2022-03-11Cleanup include: TableGenserge-sans-paille1-4/+1
This also includes a few cleanup from Support. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121331
2022-02-11[TableGen][AMDGPU] Allow empty register classesJay Foad1-1/+7
Remove ARTIFICIAL_VGPR which only existed to make VReg_1 not empty. Differential Revision: https://reviews.llvm.org/D119552
2022-02-08[X86] Implement -fzero-call-used-regs optionBill Wendling1-0/+17
The "-fzero-call-used-regs" option tells the compiler to zero out certain registers before the function returns. It's also available as a function attribute: zero_call_used_regs. The two upper categories are: - "used": Zero out used registers. - "all": Zero out all registers, whether used or not. The individual options are: - "skip": Don't zero out any registers. This is the default. - "used": Zero out all used registers. - "used-arg": Zero out used registers that are used for arguments. - "used-gpr": Zero out used registers that are GPRs. - "used-gpr-arg": Zero out used GPRs that are used as arguments. - "all": Zero out all registers. - "all-arg": Zero out all registers used for arguments. - "all-gpr": Zero out all GPRs. - "all-gpr-arg": Zero out all GPRs used for arguments. This is used to help mitigate Return-Oriented Programming exploits. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D110869
2021-09-23[TableGen] Allow targets to entirely ignore Psets for registersChristudasan Devadasan1-1/+5
Tablegen currently expects targets to have at least one pressure set for every broader register category. AMDGPU's VGPR or AGPR, for instance, seemed to work correctly without any pset, though we have forced one for each type to avoid the assertion in computeRegUnitSets. However, psets can not be entirely empty. At least one set is mandatory for every target. This patch bypasses the assertion for the classes when GeneratePressureSet is zero while ensuring the RegUnitSets are not empty. Reviewed By: arsenm, rampitec Differential Revision: https://reviews.llvm.org/D110305
2021-09-16[llvm] Use drop_begin (NFC)Kazu Hirata1-3/+3
2021-08-31[TableGen] Allow target specific flags for RegisterClassChristudasan Devadasan1-2/+9
Analogous to the TSFlags for machine instructions, this patch introduces a bit vector for register classes to have target specific flags that become a tablegened value in TargetRegisterClass. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D108767
2021-07-16[TableGen] Allow isAllocatable inheritence from any superclassCarl Ritson1-1/+4
When setting Allocatable on a generated register class check all superclasses and set Allocatable true if any superclass is allocatable. Without this change generated register classes based on an allocatable class may end up unallocatable due to the topological inheritance order. This change primarily effects AMDGPU backend; however, there are a few changes in MIPs GlobalISel register constraints as a result. Reviewed By: kparzysz Differential Revision: https://reviews.llvm.org/D105967
2021-05-07[TableGen] Use range-based for loops (NFC)Coelacanthus1-52/+42
Use range-based for loops in TableGen. Reviewed By: Paul-C-Anagnostopoulos Differential Revision: https://reviews.llvm.org/D101994
2021-02-11[TableGen] Make the map in InfoByHwMode protected. NFCICraig Topper1-1/+1
Switch some for loops to just use the begin()/end() implementations in the InfoByHwMode struct. Add a method to insert into the map for the one case that was modifying the map directly.
2021-01-29Support a list of CostPerUse valuesChristudasan Devadasan1-12/+11
This patch allows targets to define multiple cost values for each register so that the cost model can be more flexible and better used during the register allocation as per the target requirements. For AMDGPU the VGPR allocation will be more efficient if the register cost can be associated dynamically based on the calling convention. Reviewed By: qcolombet Differential Revision: https://reviews.llvm.org/D86836
2021-01-25[TableGen] Use llvm::append_range (NFC)Kazu Hirata1-4/+3
2021-01-17[TableGen] Drop redundant const from return types (NFC)Kazu Hirata1-1/+1
Identified with readability-const-return-type.
2021-01-01[llvm] Use *Map::lookup (NFC)Kazu Hirata1-2/+1
2020-11-06[TableGen] Indentation and whitespace fixes in generated code. NFC.Jay Foad1-1/+1
Some of these were found by running clang-format over the generated code, although that complains about far more issues than I have fixed here. Differential Revision: https://reviews.llvm.org/D90937
2020-09-15[TableGen] Fix invalid comparison function `SizeOrder` in ↵Ta-Wei Tu1-0/+2
`getMatchingSubClassWithSubRegs` Building LLVM with -DEXPENSIVE_CHECKS fails with the following error message with libstdc++ in debug mode: Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)). The patch fixes the comparison function SizeOrder by returning false when comparing two equal items.
2020-07-17[TableGen] Report an error instead of assertingJay Foad1-1/+2
This gives a nice error if you accidentally try to use an empty list for the RegTypes of a RegisterClass. Differential Revision: https://reviews.llvm.org/D78285
2020-03-18[TableGen][GlobalISel] Rework RegisterBankEmitter for easier const correctness.lewis-revill1-2/+2
This patch rewrites the RegisterBankEmitter class to derive RegisterClassHierarchy from CodeGenTarget::getRegBank() rather than constructing our own copy. All are now accessed through a const reference. Differential Revision: https://reviews.llvm.org/D76006
2020-02-18[TBLGEN] Emit register pressure set enumStanislav Mekhanoshin1-1/+1
Differential Revision: https://reviews.llvm.org/D74649
2020-02-17[TBLGEN] Inhibit generation of unneeded psetsStanislav Mekhanoshin1-1/+4
Differential Revision: https://reviews.llvm.org/D74744
2020-02-14[TBLGEN] Allow to override RC weightStanislav Mekhanoshin1-0/+10
Differential Revision: https://reviews.llvm.org/D74509
2020-02-12[TBLGEN] Fix subreg value overflow in DAGISelMatcherStanislav Mekhanoshin1-0/+6
Tablegen's DAGISelMatcher emits integers in a VBR format, so if an integer is below 128 it can fit into a single byte, otherwise high bit is set, next byte is used etc. MatcherTable is essentially an unsigned char table. When SelectionDAGISel parses the table it does a reverse translation. In a situation when numeric value of an integer to emit is unknown it can be emitted not as OPC_EmitInteger but as OPC_EmitStringInteger using a symbolic name of the value. In this situation the value should not exceed 127. One of the situations when OPC_EmitStringInteger is used is if we need to emit a subreg into a matcher table. However, number of subregs can exceed 127. Currently last defined subreg for AMDGPU is 192. That results in a silent bug in the ISel with matcher reading from an invalid offset. Fixed this bug to emit actual VBR encoded value for a subregs which value exceeds 127. Differential Revision: https://reviews.llvm.org/D74368
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-19/+10
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-27TableGen: Try to fix expensive checks failuresMatt Arsenault1-1/+1