LLVM 24.0.0git
MCRegisterInfo.h
Go to the documentation of this file.
1//===- MC/MCRegisterInfo.h - Target Register Description --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes an abstract interface used to get information about a
10// target machines register file. This information is used for a variety of
11// purposed, especially register allocation.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MC_MCREGISTERINFO_H
16#define LLVM_MC_MCREGISTERINFO_H
17
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/Sequence.h"
20#include "llvm/ADT/iterator.h"
22#include "llvm/MC/LaneBitmask.h"
23#include "llvm/MC/MCRegister.h"
25#include <cassert>
26#include <cstdint>
27#include <iterator>
28#include <utility>
29
30namespace llvm {
31
35
36/// MCRegisterClass - Base class of TargetRegisterClass.
38public:
39 using iterator = const MCPhysReg*;
40 using const_iterator = const MCPhysReg*;
41
42 // TODO: reorder fields to reduce memory usage.
43 const uint32_t RegsOff; ///< Relative offset to MCPhysReg array.
44 const uint32_t RegSetOff; ///< Relative offset to uint8_t array.
48 /// Register denoted by first bit in RegSet.
51 const uint16_t ID;
53 const bool Allocatable;
54 const bool BaseClass;
55
56 const uint32_t SubClassMaskOff; ///< Relative offset to uint32_t array.
57 /// Relative offset to a uint32_t array holding, for each entry of
58 /// getSuperRegIndices(), the relative offset of that entry's bit mask.
60 const uint32_t SuperRegIndicesOff; ///< Relative offset to MCPhysReg array.
62 /// Classes with a higher priority value are assigned first by register
63 /// allocators using a greedy heuristic. The value is in the range [0,31].
65
66 // Change allocation priority heuristic used by greedy.
67 const bool GlobalPriority;
68
69 /// Configurable target specific flags.
72 /// Whether the class supports two (or more) disjunct subregister indices.
74 /// Whether a combination of subregisters can cover every register in the
75 /// class. See also the CoveredBySubRegs description in Target.td.
76 const bool CoveredBySubRegs;
77 const uint32_t SuperClassesOff; ///< Relative offset to unsigned array.
79
80 /// getID() - Return the register class ID number.
81 ///
82 unsigned getID() const { return ID; }
83
84 /// begin/end - Return all of the registers in this class.
85 ///
86 iterator begin() const {
87 return reinterpret_cast<iterator>(reinterpret_cast<const char *>(this) +
88 RegsOff);
89 }
90 iterator end() const { return begin() + RegsSize; }
91
92 /// getNumRegs - Return the number of registers in this class.
93 ///
94 unsigned getNumRegs() const { return RegsSize; }
95
96 /// getRegister - Return the specified register in the class.
97 ///
98 MCRegister getRegister(unsigned i) const {
99 assert(i < getNumRegs() && "Register number out of range!");
100 return begin()[i];
101 }
102
104 return ArrayRef(begin(), RegsSize);
105 }
106
107 /// contains - Return true if the specified register is included in this
108 /// register class. This does not include virtual registers.
109 bool contains(MCRegister Reg) const {
110 unsigned RegSetIdx = Reg.id() - RegSetBegin;
111 if (RegSetIdx >= RegSetSize)
112 return false;
113 unsigned InByte = RegSetIdx % 8;
114 unsigned Byte = RegSetIdx / 8;
115 const uint8_t *RegSet = reinterpret_cast<const uint8_t *>(this) + RegSetOff;
116 return (RegSet[Byte] & (1 << InByte)) != 0;
117 }
118
119 /// contains - Return true if both registers are in this class.
120 bool contains(MCRegister Reg1, MCRegister Reg2) const {
121 return contains(Reg1) && contains(Reg2);
122 }
123
124 /// Return the size of the physical register in bits if we are able to
125 /// determine it. This always returns zero for registers of targets that use
126 /// HW modes, as we need more information to determine the size of registers
127 /// in such cases. Use TargetRegisterInfo to cover them.
128 unsigned getSizeInBits() const { return RegSizeInBits; }
129
130 /// getCopyCost - Return the cost of copying a value between two registers in
131 /// this class. A negative number means the register class is very expensive
132 /// to copy e.g. status flag register classes.
133 uint8_t getCopyCost() const { return CopyCost; }
134
135 /// \return true if register class is very expensive to copy e.g. status flag
136 /// register classes.
138 return CopyCost == std::numeric_limits<uint8_t>::max();
139 }
140
141 /// isAllocatable - Return true if this register class may be used to create
142 /// virtual registers.
143 bool isAllocatable() const { return Allocatable; }
144
145 /// Return true if this register class has a defined BaseClassOrder.
146 bool isBaseClass() const { return BaseClass; }
147
148 /// Return true if the specified TargetRegisterClass
149 /// is a proper sub-class of this TargetRegisterClass.
150 bool hasSubClass(const MCRegisterClass *RC) const {
151 return RC != this && hasSubClassEq(RC);
152 }
153
154 /// Returns true if RC is a sub-class of or equal to this class.
155 bool hasSubClassEq(const MCRegisterClass *RC) const {
156 unsigned ID = RC->getID();
157 return (getSubClassMask()[ID / 32] >> (ID % 32)) & 1;
158 }
159
160 /// Return true if the specified MCRegisterClass is a
161 /// proper super-class of this MCRegisterClass.
162 bool hasSuperClass(const MCRegisterClass *RC) const {
163 return RC->hasSubClass(this);
164 }
165
166 /// Returns true if RC is a super-class of or equal to this class.
167 bool hasSuperClassEq(const MCRegisterClass *RC) const {
168 return RC->hasSubClassEq(this);
169 }
170
171 /// Returns a bit vector of subclasses, including this one.
172 /// The vector is indexed by class IDs.
173 ///
174 /// To use it, consider the returned array as a chunk of memory that
175 /// contains an array of bits of size NumRegClasses. Each 32-bit chunk
176 /// contains a bitset of the ID of the subclasses in big-endian style.
177
178 /// I.e., the representation of the memory from left to right at the
179 /// bit level looks like:
180 /// [31 30 ... 1 0] [ 63 62 ... 33 32] ...
181 /// [ XXX NumRegClasses NumRegClasses - 1 ... ]
182 /// Where the number represents the class ID and XXX bits that
183 /// should be ignored.
184 ///
185 /// See the implementation of hasSubClassEq for an example of how it
186 /// can be used.
187 const uint32_t *getSubClassMask() const {
188 return reinterpret_cast<const uint32_t *>(
189 reinterpret_cast<const char *>(this) + SubClassMaskOff);
190 }
191
192 /// Returns the relative offsets of this class's super-register class bit
193 /// masks, one per entry of getSuperRegIndices(). Identical masks are stored
194 /// once and shared, so the masks of one class are not contiguous and cannot
195 /// be reached by striding. Resolve an entry with getSuperRegClassMaskAt().
197 return reinterpret_cast<const uint32_t *>(
198 reinterpret_cast<const char *>(this) + SuperRegMaskOffsetsOff);
199 }
200
201 /// Returns the bit mask of register classes that the sub-register index
202 /// belonging to Offset projects into this class, where Offset is an entry of
203 /// getSuperRegClassMaskOffsets().
205 return reinterpret_cast<const uint32_t *>(
206 reinterpret_cast<const char *>(this) + Offset);
207 }
208
209 /// Returns a 0-terminated list of sub-register indices that project some
210 /// super-register class into this register class. The list has an entry for
211 /// each Idx such that:
212 ///
213 /// There exists SuperRC where:
214 /// For all Reg in SuperRC:
215 /// this->contains(Reg:Idx)
217 return reinterpret_cast<const uint16_t *>(
218 reinterpret_cast<const char *>(this) + SuperRegIndicesOff);
219 }
220
221 /// Returns a list of super-classes. The
222 /// classes are ordered by ID which is also a topological ordering from large
223 /// to small classes. The list does NOT include the current class.
225 const unsigned *SuperClasses = reinterpret_cast<const unsigned *>(
226 reinterpret_cast<const char *>(this) + SuperClassesOff);
227 return ArrayRef(SuperClasses, SuperClassesSize);
228 }
229
230 /// Returns the combination of all lane masks of register in this class.
231 /// The lane masks of the registers are the combination of all lane masks
232 /// of their subregisters. Returns 1 if there are no subregisters.
233 LaneBitmask getLaneMask() const { return LaneMask; }
234};
235
236template <unsigned RegClassCount, unsigned RegCount, unsigned BitSetSize,
237 unsigned SubClassMaskSize, unsigned SuperRegMaskOffsetSize,
238 unsigned SuperRegIdxSeqSize, unsigned SuperClassSize>
240 MCRegisterClass Classes[RegClassCount];
241 MCPhysReg Regs[RegCount];
242 uint8_t BitSets[BitSetSize];
243 uint32_t SubClassMasks[SubClassMaskSize];
244 // Avoid zero-sized arrays.
245 uint32_t SuperRegMaskOffsets[SuperRegMaskOffsetSize > 0
246 ? SuperRegMaskOffsetSize
247 : 1];
248 uint16_t SuperRegIdxSeqs[SuperRegIdxSeqSize];
249 // Avoid zero-sized arrays.
250 unsigned SuperClasses[SuperClassSize > 0 ? SuperClassSize : 1];
251};
252
253/// MCRegisterDesc - This record contains information about a particular
254/// register. The SubRegs field is a zero terminated array of registers that
255/// are sub-registers of the specific register, e.g. AL, AH are sub-registers
256/// of AX. The SuperRegs field is a zero terminated array of registers that are
257/// super-registers of the specific register, e.g. RAX, EAX, are
258/// super-registers of AX.
259///
261 uint32_t Name; // Printable name for the reg (for debugging)
262 uint32_t SubRegs; // Sub-register set, described above
263 uint32_t SuperRegs; // Super-register set, described above
264
265 // Offset into MCRI::SubRegIndices of a list of sub-register indices for each
266 // sub-register in SubRegs.
268
269 // Points to the list of register units. The low bits hold the first regunit
270 // number, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
272
273 /// Index into list with lane mask sequences. The sequence contains a lanemask
274 /// for every register unit.
276
277 // Is true for constant registers.
279
280 // Is true for artificial registers.
282};
283
284/// MCRegisterInfo base class - We assume that the target defines a static
285/// array of MCRegisterDesc objects that represent all of the machine
286/// registers that the target has. As such, we simply have to track a pointer
287/// to this array so that we can turn register number into a register
288/// descriptor.
289///
290/// Note this class is designed to be a base class of TargetRegisterInfo, which
291/// is the interface used by codegen. However, specific targets *should never*
292/// specialize this class. MCRegisterInfo should only contain getters to access
293/// TableGen generated physical register data. It must not be extended with
294/// virtual methods.
295///
297public:
299
300 /// DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be
301 /// performed with a binary search.
303 unsigned FromReg;
304 unsigned ToReg;
305
306 bool operator<(DwarfLLVMRegPair RHS) const { return FromReg < RHS.FromReg; }
307 };
308
309private:
310 const MCRegisterDesc *Desc; // Pointer to the descriptor array
311 unsigned NumRegs; // Number of entries in the array
312 MCRegister RAReg; // Return address register
313 MCRegister PCReg; // Program counter register
314 const MCRegisterClass *Classes; // Pointer to the regclass array
315 unsigned NumClasses; // Number of entries in the array
316 unsigned NumRegUnits; // Number of regunits.
317 const MCPhysReg (*RegUnitRoots)[2]; // Pointer to regunit root table.
318 const int16_t *DiffLists; // Pointer to the difflists array
319 const LaneBitmask *RegUnitMaskSequences; // Pointer to lane mask sequences
320 // for register units.
321 const char *RegStrings; // Pointer to the string table.
322 const char *RegClassStrings; // Pointer to the class strings.
323 const uint16_t *SubRegIndices; // Pointer to the subreg lookup
324 // array.
325 unsigned NumSubRegIndices; // Number of subreg indices.
326 const uint16_t *RegEncodingTable; // Pointer to array of register
327 // encodings.
328 const unsigned (*RegUnitIntervals)[2]; // Pointer to regunit interval table.
329
330 unsigned L2DwarfRegsSize;
331 unsigned EHL2DwarfRegsSize;
332 unsigned Dwarf2LRegsSize;
333 unsigned EHDwarf2LRegsSize;
334 const DwarfLLVMRegPair *L2DwarfRegs; // LLVM to Dwarf regs mapping
335 const DwarfLLVMRegPair *EHL2DwarfRegs; // LLVM to Dwarf regs mapping EH
336 const DwarfLLVMRegPair *Dwarf2LRegs; // Dwarf to LLVM regs mapping
337 const DwarfLLVMRegPair *EHDwarf2LRegs; // Dwarf to LLVM regs mapping EH
338 DenseMap<MCRegister, int> L2SEHRegs; // LLVM to SEH regs mapping
339 DenseMap<MCRegister, int> L2CVRegs; // LLVM to CV regs mapping
340
341 mutable std::vector<std::vector<MCPhysReg>> RegAliasesCache;
342 ArrayRef<MCPhysReg> getCachedAliasesOf(MCRegister R) const;
343
344 /// Iterator class that can traverse the differentially encoded values in
345 /// DiffLists. Don't use this class directly, use one of the adaptors below.
346 class DiffListIterator
347 : public iterator_facade_base<DiffListIterator, std::forward_iterator_tag,
348 unsigned> {
349 unsigned Val = 0;
350 const int16_t *List = nullptr;
351
352 public:
353 /// Constructs an invalid iterator, which is also the end iterator.
354 /// Call init() to point to something useful.
355 DiffListIterator() = default;
356
357 /// Point the iterator to InitVal, decoding subsequent values from DiffList.
358 void init(unsigned InitVal, const int16_t *DiffList) {
359 Val = InitVal;
360 List = DiffList;
361 }
362
363 /// Returns true if this iterator is not yet at the end.
364 bool isValid() const { return List; }
365
366 /// Dereference the iterator to get the value at the current position.
367 const unsigned &operator*() const { return Val; }
368
369 using DiffListIterator::iterator_facade_base::operator++;
370 /// Pre-increment to move to the next position.
371 DiffListIterator &operator++() {
372 assert(isValid() && "Cannot move off the end of the list.");
373 int16_t D = *List++;
374 Val += D;
375 // The end of the list is encoded as a 0 differential.
376 if (!D)
377 List = nullptr;
378 return *this;
379 }
380
381 bool operator==(const DiffListIterator &Other) const {
382 return List == Other.List;
383 }
384 };
385
386public:
387 /// Return an iterator range over all sub-registers of \p Reg, excluding \p
388 /// Reg.
389 iterator_range<MCSubRegIterator> subregs(MCRegister Reg) const;
390
391 /// Return an iterator range over all sub-registers of \p Reg, including \p
392 /// Reg.
393 iterator_range<MCSubRegIterator> subregs_inclusive(MCRegister Reg) const;
394
395 /// Return an iterator range over all super-registers of \p Reg, excluding \p
396 /// Reg.
397 iterator_range<MCSuperRegIterator> superregs(MCRegister Reg) const;
398
399 /// Return an iterator range over all super-registers of \p Reg, including \p
400 /// Reg.
401 iterator_range<MCSuperRegIterator> superregs_inclusive(MCRegister Reg) const;
402
403 /// Return an iterator range over all sub- and super-registers of \p Reg,
404 /// including \p Reg.
405 detail::concat_range<const MCPhysReg, iterator_range<MCSubRegIterator>,
406 iterator_range<MCSuperRegIterator>>
407 sub_and_superregs_inclusive(MCRegister Reg) const;
408
409 /// Returns an iterator range over all regunits.
410 iota_range<MCRegUnit> regunits() const;
411
412 /// Returns an iterator range over all regunits for \p Reg.
413 iterator_range<MCRegUnitIterator> regunits(MCRegister Reg) const;
414
415 // These iterators are allowed to sub-class DiffListIterator and access
416 // internal list pointers.
417 friend class MCSubRegIterator;
419 friend class MCSuperRegIterator;
420 friend class MCRegUnitIterator;
423 friend class MCRegAliasIterator;
424
425 virtual ~MCRegisterInfo() = default;
426
427 /// Initialize MCRegisterInfo, called by TableGen
428 /// auto-generated routines. *DO NOT USE*.
429 void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA,
430 unsigned PC, const MCRegisterClass *C, unsigned NC,
431 const MCPhysReg (*RURoots)[2], unsigned NRU,
432 const int16_t *DL, const LaneBitmask *RUMS,
433 const char *Strings, const char *ClassStrings,
434 const uint16_t *SubIndices, unsigned NumIndices,
435 const uint16_t *RET,
436 const unsigned (*RUI)[2] = nullptr) {
437 Desc = D;
438 NumRegs = NR;
439 RAReg = RA;
440 PCReg = PC;
441 Classes = C;
442 DiffLists = DL;
443 RegUnitMaskSequences = RUMS;
444 RegStrings = Strings;
445 RegClassStrings = ClassStrings;
446 NumClasses = NC;
447 RegUnitRoots = RURoots;
448 NumRegUnits = NRU;
449 SubRegIndices = SubIndices;
450 NumSubRegIndices = NumIndices;
451 RegEncodingTable = RET;
452 RegUnitIntervals = RUI;
453
454 // Initialize DWARF register mapping variables
455 EHL2DwarfRegs = nullptr;
456 EHL2DwarfRegsSize = 0;
457 L2DwarfRegs = nullptr;
458 L2DwarfRegsSize = 0;
459 EHDwarf2LRegs = nullptr;
460 EHDwarf2LRegsSize = 0;
461 Dwarf2LRegs = nullptr;
462 Dwarf2LRegsSize = 0;
463
464 RegAliasesCache.resize(NumRegs);
465 }
466
467 /// Used to initialize LLVM register to Dwarf
468 /// register number mapping. Called by TableGen auto-generated routines.
469 /// *DO NOT USE*.
471 bool isEH) {
472 if (isEH) {
473 EHL2DwarfRegs = Map;
474 EHL2DwarfRegsSize = Size;
475 } else {
476 L2DwarfRegs = Map;
477 L2DwarfRegsSize = Size;
478 }
479 }
480
481 /// Used to initialize Dwarf register to LLVM
482 /// register number mapping. Called by TableGen auto-generated routines.
483 /// *DO NOT USE*.
485 bool isEH) {
486 if (isEH) {
487 EHDwarf2LRegs = Map;
488 EHDwarf2LRegsSize = Size;
489 } else {
490 Dwarf2LRegs = Map;
491 Dwarf2LRegsSize = Size;
492 }
493 }
494
495 /// mapLLVMRegToSEHReg - Used to initialize LLVM register to SEH register
496 /// number mapping. By default the SEH register number is just the same
497 /// as the LLVM register number.
498 /// FIXME: TableGen these numbers. Currently this requires target specific
499 /// initialization code.
500 void mapLLVMRegToSEHReg(MCRegister LLVMReg, int SEHReg) {
501 L2SEHRegs[LLVMReg] = SEHReg;
502 }
503
504 void mapLLVMRegToCVReg(MCRegister LLVMReg, int CVReg) {
505 L2CVRegs[LLVMReg] = CVReg;
506 }
507
508 /// This method should return the register where the return
509 /// address can be found.
511 return RAReg;
512 }
513
514 /// Return the register which is the program counter.
516 return PCReg;
517 }
518
520 assert(Reg.id() < NumRegs &&
521 "Attempting to access record for invalid register number!");
522 return Desc[Reg.id()];
523 }
524
525 /// Provide a get method, equivalent to [], but more useful with a
526 /// pointer to this object.
528 return operator[](Reg);
529 }
530
531 /// Returns the physical register number of sub-register "Index"
532 /// for physical register RegNo. Return zero if the sub-register does not
533 /// exist.
534 MCRegister getSubReg(MCRegister Reg, unsigned Idx) const;
535
536 /// Return a super-register of the specified register
537 /// Reg so its sub-register of index SubIdx is Reg.
538 MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx,
539 const MCRegisterClass *RC) const;
540
541 /// For a given register pair, return the sub-register index
542 /// if the second register is a sub-register of the first. Return zero
543 /// otherwise.
544 unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const;
545
546 /// Return the human-readable symbolic target-specific name for the
547 /// specified physical register.
548 const char *getName(MCRegister RegNo) const {
549 return RegStrings + get(RegNo).Name;
550 }
551
552 /// Returns true if the given register is constant.
553 bool isConstant(MCRegister RegNo) const { return get(RegNo).IsConstant; }
554
555 /// Returns true if the given register is artificial, which means it
556 /// represents a regunit that is not separately addressable but still needs to
557 /// be modelled, such as the top 16-bits of a 32-bit GPR.
558 bool isArtificial(MCRegister RegNo) const { return get(RegNo).IsArtificial; }
559
560 /// Returns true when the given register unit is considered artificial.
561 /// Register units are considered artificial when at least one of the
562 /// root registers is artificial.
563 bool isArtificialRegUnit(MCRegUnit Unit) const;
564
565 /// Return the number of registers this target has (useful for
566 /// sizing arrays holding per register information)
567 unsigned getNumRegs() const {
568 return NumRegs;
569 }
570
571 /// Return the number of sub-register indices
572 /// understood by the target. Index 0 is reserved for the no-op sub-register,
573 /// while 1 to getNumSubRegIndices() - 1 represent real sub-registers.
574 unsigned getNumSubRegIndices() const {
575 return NumSubRegIndices;
576 }
577
578 /// Return the number of (native) register units in the
579 /// target. Register units are numbered from 0 to getNumRegUnits() - 1. They
580 /// can be accessed through MCRegUnitIterator defined below.
581 unsigned getNumRegUnits() const {
582 return NumRegUnits;
583 }
584
585 /// Map a target register to an equivalent dwarf register
586 /// number. Returns -1 if there is no equivalent value. The second
587 /// parameter allows targets to use different numberings for EH info and
588 /// debugging info.
589 virtual int64_t getDwarfRegNum(MCRegister Reg, bool isEH) const;
590
591 /// Map a dwarf register back to a target register. Returns std::nullopt if
592 /// there is no mapping.
593 std::optional<MCRegister> getLLVMRegNum(uint64_t RegNum, bool isEH) const;
594
595 /// Map a target EH register number to an equivalent DWARF register
596 /// number.
597 int64_t getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const;
598
599 /// Map a target register to an equivalent SEH register
600 /// number. Returns LLVM register number if there is no equivalent value.
601 int getSEHRegNum(MCRegister Reg) const;
602
603 /// Map a target register to an equivalent CodeView register
604 /// number.
605 int getCodeViewRegNum(MCRegister Reg) const;
606
607 regclass_iterator regclass_begin() const { return Classes; }
608 regclass_iterator regclass_end() const { return Classes+NumClasses; }
612
613 unsigned getNumRegClasses() const {
614 return (unsigned)(regclass_end()-regclass_begin());
615 }
616
617 /// Returns the register class associated with the enumeration
618 /// value. See class MCOperandInfo.
619 const MCRegisterClass& getRegClass(unsigned i) const {
620 assert(i < getNumRegClasses() && "Register Class ID out of range");
621 return Classes[i];
622 }
623
624 const char *getRegClassName(const MCRegisterClass *Class) const {
625 return RegClassStrings + Class->NameIdx;
626 }
627
628 /// Returns the encoding for Reg
630 assert(Reg.id() < NumRegs &&
631 "Attempting to get encoding for invalid register number!");
632 return RegEncodingTable[Reg.id()];
633 }
634
635 /// Returns true if RegB is a sub-register of RegA.
636 bool isSubRegister(MCRegister RegA, MCRegister RegB) const {
637 return isSuperRegister(RegB, RegA);
638 }
639
640 /// Returns true if RegB is a super-register of RegA.
641 bool isSuperRegister(MCRegister RegA, MCRegister RegB) const;
642
643 /// Returns true if RegB is a sub-register of RegA or if RegB == RegA.
644 bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const {
645 return isSuperRegisterEq(RegB, RegA);
646 }
647
648 /// Returns true if RegB is a super-register of RegA or if
649 /// RegB == RegA.
650 bool isSuperRegisterEq(MCRegister RegA, MCRegister RegB) const {
651 return RegA == RegB || isSuperRegister(RegA, RegB);
652 }
653
654 /// Returns true if RegB is a super-register or sub-register of RegA
655 /// or if RegB == RegA.
657 return isSubRegisterEq(RegA, RegB) || isSuperRegister(RegA, RegB);
658 }
659
660 /// Returns true if the two registers are equal or alias each other.
661 bool regsOverlap(MCRegister RegA, MCRegister RegB) const;
662
663 /// Returns true if this target uses regunit intervals.
664 bool hasRegUnitIntervals() const { return RegUnitIntervals != nullptr; }
665
666 /// Returns an iterator range over all native regunits in the RegUnitInterval
667 /// table for \p Reg.
670 "Target does not support regunit intervals");
671 assert(Reg.id() < NumRegs && "Invalid register number");
672 return seq<unsigned>(RegUnitIntervals[Reg.id()][0],
673 RegUnitIntervals[Reg.id()][1]);
674 }
675};
676
677//===----------------------------------------------------------------------===//
678// Register List Iterators
679//===----------------------------------------------------------------------===//
680
681// MCRegisterInfo provides lists of super-registers, sub-registers, and
682// aliasing registers. Use these iterator classes to traverse the lists.
683
684/// MCSubRegIterator enumerates all sub-registers of Reg.
685/// If IncludeSelf is set, Reg itself is included in the list.
687 : public iterator_adaptor_base<MCSubRegIterator,
688 MCRegisterInfo::DiffListIterator,
689 std::forward_iterator_tag, const MCPhysReg> {
690 // Cache the current value, so that we can return a reference to it.
691 MCPhysReg Val;
692
693public:
694 /// Constructs an end iterator.
695 MCSubRegIterator() = default;
696
698 bool IncludeSelf = false) {
699 assert(Reg.isPhysical());
700 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SubRegs);
701 // Initially, the iterator points to Reg itself.
702 Val = MCPhysReg(*I);
703 if (!IncludeSelf)
704 ++*this;
705 }
706
707 const MCPhysReg &operator*() const { return Val; }
708
709 using iterator_adaptor_base::operator++;
711 Val = MCPhysReg(*++I);
712 return *this;
713 }
714
715 /// Returns true if this iterator is not yet at the end.
716 bool isValid() const { return I.isValid(); }
717};
718
719/// Iterator that enumerates the sub-registers of a Reg and the associated
720/// sub-register indices.
722 MCSubRegIterator SRIter;
723 const uint16_t *SRIndex;
724
725public:
726 /// Constructs an iterator that traverses subregisters and their
727 /// associated subregister indices.
729 : SRIter(Reg, MCRI) {
730 SRIndex = MCRI->SubRegIndices + MCRI->get(Reg).SubRegIndices;
731 }
732
733 /// Returns current sub-register.
735 return *SRIter;
736 }
737
738 /// Returns sub-register index of the current sub-register.
739 unsigned getSubRegIndex() const {
740 return *SRIndex;
741 }
742
743 /// Returns true if this iterator is not yet at the end.
744 bool isValid() const { return SRIter.isValid(); }
745
746 /// Moves to the next position.
748 ++SRIter;
749 ++SRIndex;
750 return *this;
751 }
752};
753
754/// MCSuperRegIterator enumerates all super-registers of Reg.
755/// If IncludeSelf is set, Reg itself is included in the list.
757 : public iterator_adaptor_base<MCSuperRegIterator,
758 MCRegisterInfo::DiffListIterator,
759 std::forward_iterator_tag, const MCPhysReg> {
760 // Cache the current value, so that we can return a reference to it.
761 MCPhysReg Val;
762
763public:
764 /// Constructs an end iterator.
766
768 bool IncludeSelf = false) {
769 assert(Reg.isPhysical());
770 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SuperRegs);
771 // Initially, the iterator points to Reg itself.
772 Val = MCPhysReg(*I);
773 if (!IncludeSelf)
774 ++*this;
775 }
776
777 const MCPhysReg &operator*() const { return Val; }
778
779 using iterator_adaptor_base::operator++;
781 Val = MCPhysReg(*++I);
782 return *this;
783 }
784
785 /// Returns true if this iterator is not yet at the end.
786 bool isValid() const { return I.isValid(); }
787};
788
789// Definition for isSuperRegister. Put it down here since it needs the
790// iterator defined above in addition to the MCRegisterInfo class itself.
792 return is_contained(superregs(RegA), RegB);
793}
794
795//===----------------------------------------------------------------------===//
796// Register Units
797//===----------------------------------------------------------------------===//
798
799// MCRegUnitIterator enumerates a list of register units for Reg. The list is
800// in ascending numerical order.
802 : public iterator_adaptor_base<MCRegUnitIterator,
803 MCRegisterInfo::DiffListIterator,
804 std::forward_iterator_tag, const MCRegUnit> {
805 // The value must be kept in sync with RegisterInfoEmitter.cpp.
806 static constexpr unsigned RegUnitBits = 12;
807 // Cache the current value, so that we can return a reference to it.
808 MCRegUnit Val;
809
810public:
811 /// Constructs an end iterator.
812 MCRegUnitIterator() = default;
813
815 assert(Reg.isPhysical());
816 // Decode the RegUnits MCRegisterDesc field.
817 unsigned RU = MCRI->get(Reg).RegUnits;
818 unsigned FirstRU = RU & ((1u << RegUnitBits) - 1);
819 unsigned Offset = RU >> RegUnitBits;
820 I.init(FirstRU, MCRI->DiffLists + Offset);
821 Val = MCRegUnit(*I);
822 }
823
824 const MCRegUnit &operator*() const { return Val; }
825
826 using iterator_adaptor_base::operator++;
828 Val = MCRegUnit(*++I);
829 return *this;
830 }
831
832 /// Returns true if this iterator is not yet at the end.
833 bool isValid() const { return I.isValid(); }
834};
835
836/// MCRegUnitMaskIterator enumerates a list of register units and their
837/// associated lane masks for Reg. The register units are in ascending
838/// numerical order.
840 MCRegUnitIterator RUIter;
841 const LaneBitmask *MaskListIter;
842
843public:
845
846 /// Constructs an iterator that traverses the register units and their
847 /// associated LaneMasks in Reg.
849 : RUIter(Reg, MCRI) {
850 uint16_t Idx = MCRI->get(Reg).RegUnitLaneMasks;
851 MaskListIter = &MCRI->RegUnitMaskSequences[Idx];
852 }
853
854 /// Returns a (RegUnit, LaneMask) pair.
855 std::pair<MCRegUnit, LaneBitmask> operator*() const {
856 return std::make_pair(*RUIter, *MaskListIter);
857 }
858
859 /// Returns true if this iterator is not yet at the end.
860 bool isValid() const { return RUIter.isValid(); }
861
862 /// Moves to the next position.
864 ++MaskListIter;
865 ++RUIter;
866 return *this;
867 }
868};
869
870// Each register unit has one or two root registers. The complete set of
871// registers containing a register unit is the union of the roots and their
872// super-registers. All registers aliasing Unit can be visited like this:
873//
874// for (MCRegUnitRootIterator RI(Unit, MCRI); RI.isValid(); ++RI) {
875// for (MCSuperRegIterator SI(*RI, MCRI, true); SI.isValid(); ++SI)
876// visit(*SI);
877// }
878
879/// MCRegUnitRootIterator enumerates the root registers of a register unit.
881 uint16_t Reg0 = 0;
882 uint16_t Reg1 = 0;
883
884public:
886
887 MCRegUnitRootIterator(MCRegUnit RegUnit, const MCRegisterInfo *MCRI) {
888 assert(static_cast<unsigned>(RegUnit) < MCRI->getNumRegUnits() &&
889 "Invalid register unit");
890 Reg0 = MCRI->RegUnitRoots[static_cast<unsigned>(RegUnit)][0];
891 Reg1 = MCRI->RegUnitRoots[static_cast<unsigned>(RegUnit)][1];
892 }
893
894 /// Dereference to get the current root register.
895 unsigned operator*() const {
896 return Reg0;
897 }
898
899 /// Check if the iterator is at the end of the list.
900 bool isValid() const {
901 return Reg0;
902 }
903
904 /// Preincrement to move to the next root register.
906 assert(isValid() && "Cannot move off the end of the list.");
907 Reg0 = Reg1;
908 Reg1 = 0;
909 return *this;
910 }
911};
912
913/// MCRegAliasIterator enumerates all registers aliasing Reg.
915private:
916 const MCPhysReg *It = nullptr;
917 const MCPhysReg *End = nullptr;
918
919public:
921 bool IncludeSelf) {
922 ArrayRef<MCPhysReg> Cache = MCRI->getCachedAliasesOf(Reg);
923 assert(Cache.back() == Reg);
924 It = Cache.begin();
925 End = Cache.end();
926 if (!IncludeSelf)
927 --End;
928 }
929
930 bool isValid() const { return It != End; }
931
932 MCRegister operator*() const { return *It; }
933
935 assert(isValid() && "Cannot move off the end of the list.");
936 ++It;
937 return *this;
938 }
939};
940
943 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSubRegIterator());
944}
945
948 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSubRegIterator());
949}
950
953 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSuperRegIterator());
954}
955
958 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSuperRegIterator());
959}
960
966
968 return enum_seq(static_cast<MCRegUnit>(0),
969 static_cast<MCRegUnit>(getNumRegUnits()),
971}
972
977
978} // end namespace llvm
979
980#endif // LLVM_MC_MCREGISTERINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register Reg
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
static constexpr MCPhysReg RAReg
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
SI optimize exec mask operations pre RA
Provides some synthesis utilities to produce sequences of values.
static unsigned getDwarfRegNum(MCRegister Reg, const TargetRegisterInfo *TRI)
Go up the super-register chain until we hit a valid dwarf register number.
Value * RHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
MCRegAliasIterator(MCRegister Reg, const MCRegisterInfo *MCRI, bool IncludeSelf)
MCRegister operator*() const
MCRegAliasIterator & operator++()
const MCRegUnit & operator*() const
MCRegUnitIterator()=default
Constructs an end iterator.
bool isValid() const
Returns true if this iterator is not yet at the end.
MCRegUnitIterator & operator++()
MCRegUnitIterator(MCRegister Reg, const MCRegisterInfo *MCRI)
MCRegUnitMaskIterator(MCRegister Reg, const MCRegisterInfo *MCRI)
Constructs an iterator that traverses the register units and their associated LaneMasks in Reg.
std::pair< MCRegUnit, LaneBitmask > operator*() const
Returns a (RegUnit, LaneMask) pair.
MCRegUnitMaskIterator & operator++()
Moves to the next position.
bool isValid() const
Returns true if this iterator is not yet at the end.
MCRegUnitRootIterator & operator++()
Preincrement to move to the next root register.
unsigned operator*() const
Dereference to get the current root register.
MCRegUnitRootIterator(MCRegUnit RegUnit, const MCRegisterInfo *MCRI)
bool isValid() const
Check if the iterator is at the end of the list.
MCRegisterClass - Base class of TargetRegisterClass.
const uint8_t SpillStackID
ArrayRef< unsigned > superclasses() const
Returns a list of super-classes.
const MCPhysReg RegSetBegin
Register denoted by first bit in RegSet.
bool hasSuperClass(const MCRegisterClass *RC) const
Return true if the specified MCRegisterClass is a proper super-class of this MCRegisterClass.
const bool CoveredBySubRegs
Whether a combination of subregisters can cover every register in the class.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
const uint32_t NameIdx
bool hasSuperClassEq(const MCRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
unsigned getID() const
getID() - Return the register class ID number.
ArrayRef< MCPhysReg > getRegisters() const
const uint32_t RegSizeInBits
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
const uint32_t * getSuperRegClassMaskOffsets() const
Returns the relative offsets of this class's super-register class bit masks, one per entry of getSupe...
const uint8_t AllocationPriority
Classes with a higher priority value are assigned first by register allocators using a greedy heurist...
const uint32_t SuperRegMaskOffsetsOff
Relative offset to a uint32_t array holding, for each entry of getSuperRegIndices(),...
const MCPhysReg * iterator
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
const uint8_t TSFlags
Configurable target specific flags.
const uint32_t SuperClassesOff
Relative offset to unsigned array.
const LaneBitmask LaneMask
unsigned getSizeInBits() const
Return the size of the physical register in bits if we are able to determine it.
const uint32_t RegSetOff
Relative offset to uint8_t array.
const uint16_t RegSetSize
bool contains(MCRegister Reg1, MCRegister Reg2) const
contains - Return true if both registers are in this class.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
const uint32_t SuperRegIndicesOff
Relative offset to MCPhysReg array.
const uint16_t * getSuperRegIndices() const
Returns a 0-terminated list of sub-register indices that project some super-register class into this ...
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
const uint32_t SubClassMaskOff
Relative offset to uint32_t array.
iterator begin() const
begin/end - Return all of the registers in this class.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
const uint32_t RegsOff
Relative offset to MCPhysReg array.
bool isBaseClass() const
Return true if this register class has a defined BaseClassOrder.
bool expensiveOrImpossibleToCopy() const
uint8_t getCopyCost() const
getCopyCost - Return the cost of copying a value between two registers in this class.
iterator end() const
const uint32_t * getSuperRegClassMaskAt(uint32_t Offset) const
Returns the bit mask of register classes that the sub-register index belonging to Offset projects int...
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
bool hasSubClass(const MCRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
const uint16_t SuperClassesSize
const MCPhysReg * const_iterator
const uint16_t RegsSize
bool hasSubClassEq(const MCRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
iota_range< unsigned > regunits_interval(MCRegister Reg) const
Returns an iterator range over all native regunits in the RegUnitInterval table for Reg.
void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA, unsigned PC, const MCRegisterClass *C, unsigned NC, const MCPhysReg(*RURoots)[2], unsigned NRU, const int16_t *DL, const LaneBitmask *RUMS, const char *Strings, const char *ClassStrings, const uint16_t *SubIndices, unsigned NumIndices, const uint16_t *RET, const unsigned(*RUI)[2]=nullptr)
Initialize MCRegisterInfo, called by TableGen auto-generated routines.
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
const MCRegisterDesc & operator[](MCRegister Reg) const
bool isSuperRegisterEq(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a super-register of RegA or if RegB == RegA.
unsigned getNumRegClasses() const
MCRegister getRARegister() const
This method should return the register where the return address can be found.
virtual ~MCRegisterInfo()=default
MCRegister getProgramCounter() const
Return the register which is the program counter.
regclass_iterator regclass_end() const
void mapDwarfRegsToLLVMRegs(const DwarfLLVMRegPair *Map, unsigned Size, bool isEH)
Used to initialize Dwarf register to LLVM register number mapping.
unsigned getNumRegUnits() const
Return the number of (native) register units in the target.
friend class MCRegAliasIterator
const MCRegisterDesc & get(MCRegister Reg) const
Provide a get method, equivalent to [], but more useful with a pointer to this object.
const MCRegisterClass * regclass_iterator
iterator_range< regclass_iterator > regclasses() const
regclass_iterator regclass_begin() const
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
void mapLLVMRegToCVReg(MCRegister LLVMReg, int CVReg)
iterator_range< MCSuperRegIterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
bool hasRegUnitIntervals() const
Returns true if this target uses regunit intervals.
const char * getRegClassName(const MCRegisterClass *Class) const
friend class MCSubRegIterator
friend class MCRegUnitRootIterator
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
iterator_range< MCSubRegIterator > subregs_inclusive(MCRegister Reg) const
Return an iterator range over all sub-registers of Reg, including Reg.
bool isSuperOrSubRegisterEq(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a super-register or sub-register of RegA or if RegB == RegA.
bool isSubRegister(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a sub-register of RegA.
friend class MCSuperRegIterator
iterator_range< MCSubRegIterator > subregs(MCRegister Reg) const
Return an iterator range over all sub-registers of Reg, excluding Reg.
bool isConstant(MCRegister RegNo) const
Returns true if the given register is constant.
friend class MCRegUnitMaskIterator
void mapLLVMRegsToDwarfRegs(const DwarfLLVMRegPair *Map, unsigned Size, bool isEH)
Used to initialize LLVM register to Dwarf register number mapping.
bool isSuperRegister(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a super-register of RegA.
bool isArtificial(MCRegister RegNo) const
Returns true if the given register is artificial, which means it represents a regunit that is not sep...
bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a sub-register of RegA or if RegB == RegA.
friend class MCRegUnitIterator
void mapLLVMRegToSEHReg(MCRegister LLVMReg, int SEHReg)
mapLLVMRegToSEHReg - Used to initialize LLVM register to SEH register number mapping.
iterator_range< MCSuperRegIterator > superregs_inclusive(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, including Reg.
detail::concat_range< const MCPhysReg, iterator_range< MCSubRegIterator >, iterator_range< MCSuperRegIterator > > sub_and_superregs_inclusive(MCRegister Reg) const
Return an iterator range over all sub- and super-registers of Reg, including Reg.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
friend class MCSubRegIndexIterator
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MCSubRegIndexIterator(MCRegister Reg, const MCRegisterInfo *MCRI)
Constructs an iterator that traverses subregisters and their associated subregister indices.
MCSubRegIndexIterator & operator++()
Moves to the next position.
bool isValid() const
Returns true if this iterator is not yet at the end.
unsigned getSubRegIndex() const
Returns sub-register index of the current sub-register.
MCRegister getSubReg() const
Returns current sub-register.
MCSubRegIterator enumerates all sub-registers of Reg.
const MCPhysReg & operator*() const
MCSubRegIterator & operator++()
bool isValid() const
Returns true if this iterator is not yet at the end.
MCSubRegIterator()=default
Constructs an end iterator.
MCSubRegIterator(MCRegister Reg, const MCRegisterInfo *MCRI, bool IncludeSelf=false)
MCSuperRegIterator enumerates all super-registers of Reg.
MCSuperRegIterator(MCRegister Reg, const MCRegisterInfo *MCRI, bool IncludeSelf=false)
MCSuperRegIterator & operator++()
const MCPhysReg & operator*() const
MCSuperRegIterator()=default
Constructs an end iterator.
bool isValid() const
Returns true if this iterator is not yet at the end.
Helper to store a sequence of ranges being concatenated and access them.
Definition STLExtras.h:1116
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterator.h:80
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2261
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum
Definition Sequence.h:110
Op::Description Desc
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1167
constexpr auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition Sequence.h:373
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
#define NC
Definition regutils.h:42
uint8_t BitSets[BitSetSize]
uint32_t SuperRegMaskOffsets[SuperRegMaskOffsetSize > 0 ? SuperRegMaskOffsetSize :1]
MCRegisterClass Classes[RegClassCount]
uint32_t SubClassMasks[SubClassMaskSize]
uint16_t SuperRegIdxSeqs[SuperRegIdxSeqSize]
unsigned SuperClasses[SuperClassSize > 0 ? SuperClassSize :1]
MCRegisterDesc - This record contains information about a particular register.
uint16_t RegUnitLaneMasks
Index into list with lane mask sequences.
DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be performed with a binary se...
bool operator<(DwarfLLVMRegPair RHS) const