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