LLVM 20.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/iterator.h"
21#include "llvm/MC/LaneBitmask.h"
22#include "llvm/MC/MCRegister.h"
23#include <cassert>
24#include <cstdint>
25#include <iterator>
26#include <utility>
27
28namespace llvm {
29
30class MCRegUnitIterator;
31class MCSubRegIterator;
32class MCSuperRegIterator;
33
34/// MCRegisterClass - Base class of TargetRegisterClass.
36public:
37 using iterator = const MCPhysReg*;
38 using const_iterator = const MCPhysReg*;
39
41 const uint8_t *const RegSet;
45 const uint16_t ID;
47 const int8_t CopyCost;
48 const bool Allocatable;
49 const bool BaseClass;
50
51 /// getID() - Return the register class ID number.
52 ///
53 unsigned getID() const { return ID; }
54
55 /// begin/end - Return all of the registers in this class.
56 ///
57 iterator begin() const { return RegsBegin; }
58 iterator end() const { return RegsBegin + RegsSize; }
59
60 /// getNumRegs - Return the number of registers in this class.
61 ///
62 unsigned getNumRegs() const { return RegsSize; }
63
64 /// getRegister - Return the specified register in the class.
65 ///
66 unsigned getRegister(unsigned i) const {
67 assert(i < getNumRegs() && "Register number out of range!");
68 return RegsBegin[i];
69 }
70
71 /// contains - Return true if the specified register is included in this
72 /// register class. This does not include virtual registers.
73 bool contains(MCRegister Reg) const {
74 unsigned RegNo = Reg.id();
75 unsigned InByte = RegNo % 8;
76 unsigned Byte = RegNo / 8;
77 if (Byte >= RegSetSize)
78 return false;
79 return (RegSet[Byte] & (1 << InByte)) != 0;
80 }
81
82 /// contains - Return true if both registers are in this class.
83 bool contains(MCRegister Reg1, MCRegister Reg2) const {
84 return contains(Reg1) && contains(Reg2);
85 }
86
87 /// Return the size of the physical register in bits if we are able to
88 /// determine it. This always returns zero for registers of targets that use
89 /// HW modes, as we need more information to determine the size of registers
90 /// in such cases. Use TargetRegisterInfo to cover them.
91 unsigned getSizeInBits() const { return RegSizeInBits; }
92
93 /// getCopyCost - Return the cost of copying a value between two registers in
94 /// this class. A negative number means the register class is very expensive
95 /// to copy e.g. status flag register classes.
96 int getCopyCost() const { return CopyCost; }
97
98 /// isAllocatable - Return true if this register class may be used to create
99 /// virtual registers.
100 bool isAllocatable() const { return Allocatable; }
101
102 /// Return true if this register class has a defined BaseClassOrder.
103 bool isBaseClass() const { return BaseClass; }
104};
105
106/// MCRegisterDesc - This record contains information about a particular
107/// register. The SubRegs field is a zero terminated array of registers that
108/// are sub-registers of the specific register, e.g. AL, AH are sub-registers
109/// of AX. The SuperRegs field is a zero terminated array of registers that are
110/// super-registers of the specific register, e.g. RAX, EAX, are
111/// super-registers of AX.
112///
114 uint32_t Name; // Printable name for the reg (for debugging)
115 uint32_t SubRegs; // Sub-register set, described above
116 uint32_t SuperRegs; // Super-register set, described above
117
118 // Offset into MCRI::SubRegIndices of a list of sub-register indices for each
119 // sub-register in SubRegs.
121
122 // Points to the list of register units. The low bits hold the first regunit
123 // number, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
125
126 /// Index into list with lane mask sequences. The sequence contains a lanemask
127 /// for every register unit.
129
130 // Is true for constant registers.
132
133 // Is true for artificial registers.
135};
136
137/// MCRegisterInfo base class - We assume that the target defines a static
138/// array of MCRegisterDesc objects that represent all of the machine
139/// registers that the target has. As such, we simply have to track a pointer
140/// to this array so that we can turn register number into a register
141/// descriptor.
142///
143/// Note this class is designed to be a base class of TargetRegisterInfo, which
144/// is the interface used by codegen. However, specific targets *should never*
145/// specialize this class. MCRegisterInfo should only contain getters to access
146/// TableGen generated physical register data. It must not be extended with
147/// virtual methods.
148///
150public:
152
153 /// DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be
154 /// performed with a binary search.
156 unsigned FromReg;
157 unsigned ToReg;
158
159 bool operator<(DwarfLLVMRegPair RHS) const { return FromReg < RHS.FromReg; }
160 };
161
162private:
163 const MCRegisterDesc *Desc; // Pointer to the descriptor array
164 unsigned NumRegs; // Number of entries in the array
165 MCRegister RAReg; // Return address register
166 MCRegister PCReg; // Program counter register
167 const MCRegisterClass *Classes; // Pointer to the regclass array
168 unsigned NumClasses; // Number of entries in the array
169 unsigned NumRegUnits; // Number of regunits.
170 const MCPhysReg (*RegUnitRoots)[2]; // Pointer to regunit root table.
171 const int16_t *DiffLists; // Pointer to the difflists array
172 const LaneBitmask *RegUnitMaskSequences; // Pointer to lane mask sequences
173 // for register units.
174 const char *RegStrings; // Pointer to the string table.
175 const char *RegClassStrings; // Pointer to the class strings.
176 const uint16_t *SubRegIndices; // Pointer to the subreg lookup
177 // array.
178 unsigned NumSubRegIndices; // Number of subreg indices.
179 const uint16_t *RegEncodingTable; // Pointer to array of register
180 // encodings.
181
182 unsigned L2DwarfRegsSize;
183 unsigned EHL2DwarfRegsSize;
184 unsigned Dwarf2LRegsSize;
185 unsigned EHDwarf2LRegsSize;
186 const DwarfLLVMRegPair *L2DwarfRegs; // LLVM to Dwarf regs mapping
187 const DwarfLLVMRegPair *EHL2DwarfRegs; // LLVM to Dwarf regs mapping EH
188 const DwarfLLVMRegPair *Dwarf2LRegs; // Dwarf to LLVM regs mapping
189 const DwarfLLVMRegPair *EHDwarf2LRegs; // Dwarf to LLVM regs mapping EH
190 DenseMap<MCRegister, int> L2SEHRegs; // LLVM to SEH regs mapping
191 DenseMap<MCRegister, int> L2CVRegs; // LLVM to CV regs mapping
192
193 mutable std::vector<std::vector<MCPhysReg>> RegAliasesCache;
194 ArrayRef<MCPhysReg> getCachedAliasesOf(MCRegister R) const;
195
196 /// Iterator class that can traverse the differentially encoded values in
197 /// DiffLists. Don't use this class directly, use one of the adaptors below.
198 class DiffListIterator
199 : public iterator_facade_base<DiffListIterator, std::forward_iterator_tag,
200 unsigned> {
201 unsigned Val = 0;
202 const int16_t *List = nullptr;
203
204 public:
205 /// Constructs an invalid iterator, which is also the end iterator.
206 /// Call init() to point to something useful.
207 DiffListIterator() = default;
208
209 /// Point the iterator to InitVal, decoding subsequent values from DiffList.
210 void init(unsigned InitVal, const int16_t *DiffList) {
211 Val = InitVal;
212 List = DiffList;
213 }
214
215 /// Returns true if this iterator is not yet at the end.
216 bool isValid() const { return List; }
217
218 /// Dereference the iterator to get the value at the current position.
219 const unsigned &operator*() const { return Val; }
220
221 using DiffListIterator::iterator_facade_base::operator++;
222 /// Pre-increment to move to the next position.
223 DiffListIterator &operator++() {
224 assert(isValid() && "Cannot move off the end of the list.");
225 int16_t D = *List++;
226 Val += D;
227 // The end of the list is encoded as a 0 differential.
228 if (!D)
229 List = nullptr;
230 return *this;
231 }
232
233 bool operator==(const DiffListIterator &Other) const {
234 return List == Other.List;
235 }
236 };
237
238public:
239 /// Return an iterator range over all sub-registers of \p Reg, excluding \p
240 /// Reg.
241 iterator_range<MCSubRegIterator> subregs(MCRegister Reg) const;
242
243 /// Return an iterator range over all sub-registers of \p Reg, including \p
244 /// Reg.
245 iterator_range<MCSubRegIterator> subregs_inclusive(MCRegister Reg) const;
246
247 /// Return an iterator range over all super-registers of \p Reg, excluding \p
248 /// Reg.
249 iterator_range<MCSuperRegIterator> superregs(MCRegister Reg) const;
250
251 /// Return an iterator range over all super-registers of \p Reg, including \p
252 /// Reg.
253 iterator_range<MCSuperRegIterator> superregs_inclusive(MCRegister Reg) const;
254
255 /// Return an iterator range over all sub- and super-registers of \p Reg,
256 /// including \p Reg.
257 detail::concat_range<const MCPhysReg, iterator_range<MCSubRegIterator>,
258 iterator_range<MCSuperRegIterator>>
259 sub_and_superregs_inclusive(MCRegister Reg) const;
260
261 /// Returns an iterator range over all regunits for \p Reg.
262 iterator_range<MCRegUnitIterator> regunits(MCRegister Reg) const;
263
264 // These iterators are allowed to sub-class DiffListIterator and access
265 // internal list pointers.
266 friend class MCSubRegIterator;
268 friend class MCSuperRegIterator;
269 friend class MCRegUnitIterator;
272 friend class MCRegAliasIterator;
273
274 virtual ~MCRegisterInfo() {}
275
276 /// Initialize MCRegisterInfo, called by TableGen
277 /// auto-generated routines. *DO NOT USE*.
278 void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA,
279 unsigned PC, const MCRegisterClass *C, unsigned NC,
280 const MCPhysReg (*RURoots)[2], unsigned NRU,
281 const int16_t *DL, const LaneBitmask *RUMS,
282 const char *Strings, const char *ClassStrings,
283 const uint16_t *SubIndices, unsigned NumIndices,
284 const uint16_t *RET) {
285 Desc = D;
286 NumRegs = NR;
287 RAReg = RA;
288 PCReg = PC;
289 Classes = C;
290 DiffLists = DL;
291 RegUnitMaskSequences = RUMS;
292 RegStrings = Strings;
293 RegClassStrings = ClassStrings;
294 NumClasses = NC;
295 RegUnitRoots = RURoots;
296 NumRegUnits = NRU;
297 SubRegIndices = SubIndices;
298 NumSubRegIndices = NumIndices;
299 RegEncodingTable = RET;
300
301 // Initialize DWARF register mapping variables
302 EHL2DwarfRegs = nullptr;
303 EHL2DwarfRegsSize = 0;
304 L2DwarfRegs = nullptr;
305 L2DwarfRegsSize = 0;
306 EHDwarf2LRegs = nullptr;
307 EHDwarf2LRegsSize = 0;
308 Dwarf2LRegs = nullptr;
309 Dwarf2LRegsSize = 0;
310
311 RegAliasesCache.resize(NumRegs);
312 }
313
314 /// Used to initialize LLVM register to Dwarf
315 /// register number mapping. Called by TableGen auto-generated routines.
316 /// *DO NOT USE*.
318 bool isEH) {
319 if (isEH) {
320 EHL2DwarfRegs = Map;
321 EHL2DwarfRegsSize = Size;
322 } else {
323 L2DwarfRegs = Map;
324 L2DwarfRegsSize = Size;
325 }
326 }
327
328 /// Used to initialize Dwarf register to LLVM
329 /// register number mapping. Called by TableGen auto-generated routines.
330 /// *DO NOT USE*.
332 bool isEH) {
333 if (isEH) {
334 EHDwarf2LRegs = Map;
335 EHDwarf2LRegsSize = Size;
336 } else {
337 Dwarf2LRegs = Map;
338 Dwarf2LRegsSize = Size;
339 }
340 }
341
342 /// mapLLVMRegToSEHReg - Used to initialize LLVM register to SEH register
343 /// number mapping. By default the SEH register number is just the same
344 /// as the LLVM register number.
345 /// FIXME: TableGen these numbers. Currently this requires target specific
346 /// initialization code.
347 void mapLLVMRegToSEHReg(MCRegister LLVMReg, int SEHReg) {
348 L2SEHRegs[LLVMReg] = SEHReg;
349 }
350
351 void mapLLVMRegToCVReg(MCRegister LLVMReg, int CVReg) {
352 L2CVRegs[LLVMReg] = CVReg;
353 }
354
355 /// This method should return the register where the return
356 /// address can be found.
358 return RAReg;
359 }
360
361 /// Return the register which is the program counter.
363 return PCReg;
364 }
365
367 assert(Reg.id() < NumRegs &&
368 "Attempting to access record for invalid register number!");
369 return Desc[Reg.id()];
370 }
371
372 /// Provide a get method, equivalent to [], but more useful with a
373 /// pointer to this object.
375 return operator[](Reg);
376 }
377
378 /// Returns the physical register number of sub-register "Index"
379 /// for physical register RegNo. Return zero if the sub-register does not
380 /// exist.
381 MCRegister getSubReg(MCRegister Reg, unsigned Idx) const;
382
383 /// Return a super-register of the specified register
384 /// Reg so its sub-register of index SubIdx is Reg.
386 const MCRegisterClass *RC) const;
387
388 /// For a given register pair, return the sub-register index
389 /// if the second register is a sub-register of the first. Return zero
390 /// otherwise.
391 unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const;
392
393 /// Return the human-readable symbolic target-specific name for the
394 /// specified physical register.
395 const char *getName(MCRegister RegNo) const {
396 return RegStrings + get(RegNo).Name;
397 }
398
399 /// Returns true if the given register is constant.
400 bool isConstant(MCRegister RegNo) const { return get(RegNo).IsConstant; }
401
402 /// Returns true if the given register is artificial, which means it
403 /// represents a regunit that is not separately addressable but still needs to
404 /// be modelled, such as the top 16-bits of a 32-bit GPR.
405 bool isArtificial(MCRegister RegNo) const { return get(RegNo).IsArtificial; }
406
407 /// Returns true when the given register unit is considered artificial.
408 /// Register units are considered artificial when at least one of the
409 /// root registers is artificial.
410 bool isArtificialRegUnit(MCRegUnit Unit) const;
411
412 /// Return the number of registers this target has (useful for
413 /// sizing arrays holding per register information)
414 unsigned getNumRegs() const {
415 return NumRegs;
416 }
417
418 /// Return the number of sub-register indices
419 /// understood by the target. Index 0 is reserved for the no-op sub-register,
420 /// while 1 to getNumSubRegIndices() - 1 represent real sub-registers.
421 unsigned getNumSubRegIndices() const {
422 return NumSubRegIndices;
423 }
424
425 /// Return the number of (native) register units in the
426 /// target. Register units are numbered from 0 to getNumRegUnits() - 1. They
427 /// can be accessed through MCRegUnitIterator defined below.
428 unsigned getNumRegUnits() const {
429 return NumRegUnits;
430 }
431
432 /// Map a target register to an equivalent dwarf register
433 /// number. Returns -1 if there is no equivalent value. The second
434 /// parameter allows targets to use different numberings for EH info and
435 /// debugging info.
436 virtual int64_t getDwarfRegNum(MCRegister RegNum, bool isEH) const;
437
438 /// Map a dwarf register back to a target register. Returns std::nullopt if
439 /// there is no mapping.
440 std::optional<MCRegister> getLLVMRegNum(uint64_t RegNum, bool isEH) const;
441
442 /// Map a target EH register number to an equivalent DWARF register
443 /// number.
444 int64_t getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const;
445
446 /// Map a target register to an equivalent SEH register
447 /// number. Returns LLVM register number if there is no equivalent value.
448 int getSEHRegNum(MCRegister RegNum) const;
449
450 /// Map a target register to an equivalent CodeView register
451 /// number.
452 int getCodeViewRegNum(MCRegister RegNum) const;
453
454 regclass_iterator regclass_begin() const { return Classes; }
455 regclass_iterator regclass_end() const { return Classes+NumClasses; }
458 }
459
460 unsigned getNumRegClasses() const {
461 return (unsigned)(regclass_end()-regclass_begin());
462 }
463
464 /// Returns the register class associated with the enumeration
465 /// value. See class MCOperandInfo.
466 const MCRegisterClass& getRegClass(unsigned i) const {
467 assert(i < getNumRegClasses() && "Register Class ID out of range");
468 return Classes[i];
469 }
470
471 const char *getRegClassName(const MCRegisterClass *Class) const {
472 return RegClassStrings + Class->NameIdx;
473 }
474
475 /// Returns the encoding for Reg
477 assert(Reg.id() < NumRegs &&
478 "Attempting to get encoding for invalid register number!");
479 return RegEncodingTable[Reg.id()];
480 }
481
482 /// Returns true if RegB is a sub-register of RegA.
483 bool isSubRegister(MCRegister RegA, MCRegister RegB) const {
484 return isSuperRegister(RegB, RegA);
485 }
486
487 /// Returns true if RegB is a super-register of RegA.
488 bool isSuperRegister(MCRegister RegA, MCRegister RegB) const;
489
490 /// Returns true if RegB is a sub-register of RegA or if RegB == RegA.
491 bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const {
492 return isSuperRegisterEq(RegB, RegA);
493 }
494
495 /// Returns true if RegB is a super-register of RegA or if
496 /// RegB == RegA.
497 bool isSuperRegisterEq(MCRegister RegA, MCRegister RegB) const {
498 return RegA == RegB || isSuperRegister(RegA, RegB);
499 }
500
501 /// Returns true if RegB is a super-register or sub-register of RegA
502 /// or if RegB == RegA.
504 return isSubRegisterEq(RegA, RegB) || isSuperRegister(RegA, RegB);
505 }
506
507 /// Returns true if the two registers are equal or alias each other.
508 bool regsOverlap(MCRegister RegA, MCRegister RegB) const;
509};
510
511//===----------------------------------------------------------------------===//
512// Register List Iterators
513//===----------------------------------------------------------------------===//
514
515// MCRegisterInfo provides lists of super-registers, sub-registers, and
516// aliasing registers. Use these iterator classes to traverse the lists.
517
518/// MCSubRegIterator enumerates all sub-registers of Reg.
519/// If IncludeSelf is set, Reg itself is included in the list.
521 : public iterator_adaptor_base<MCSubRegIterator,
522 MCRegisterInfo::DiffListIterator,
523 std::forward_iterator_tag, const MCPhysReg> {
524 // Cache the current value, so that we can return a reference to it.
525 MCPhysReg Val;
526
527public:
528 /// Constructs an end iterator.
529 MCSubRegIterator() = default;
530
532 bool IncludeSelf = false) {
534 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SubRegs);
535 // Initially, the iterator points to Reg itself.
536 Val = MCPhysReg(*I);
537 if (!IncludeSelf)
538 ++*this;
539 }
540
541 const MCPhysReg &operator*() const { return Val; }
542
543 using iterator_adaptor_base::operator++;
545 Val = MCPhysReg(*++I);
546 return *this;
547 }
548
549 /// Returns true if this iterator is not yet at the end.
550 bool isValid() const { return I.isValid(); }
551};
552
553/// Iterator that enumerates the sub-registers of a Reg and the associated
554/// sub-register indices.
556 MCSubRegIterator SRIter;
557 const uint16_t *SRIndex;
558
559public:
560 /// Constructs an iterator that traverses subregisters and their
561 /// associated subregister indices.
563 : SRIter(Reg, MCRI) {
564 SRIndex = MCRI->SubRegIndices + MCRI->get(Reg).SubRegIndices;
565 }
566
567 /// Returns current sub-register.
569 return *SRIter;
570 }
571
572 /// Returns sub-register index of the current sub-register.
573 unsigned getSubRegIndex() const {
574 return *SRIndex;
575 }
576
577 /// Returns true if this iterator is not yet at the end.
578 bool isValid() const { return SRIter.isValid(); }
579
580 /// Moves to the next position.
582 ++SRIter;
583 ++SRIndex;
584 return *this;
585 }
586};
587
588/// MCSuperRegIterator enumerates all super-registers of Reg.
589/// If IncludeSelf is set, Reg itself is included in the list.
591 : public iterator_adaptor_base<MCSuperRegIterator,
592 MCRegisterInfo::DiffListIterator,
593 std::forward_iterator_tag, const MCPhysReg> {
594 // Cache the current value, so that we can return a reference to it.
595 MCPhysReg Val;
596
597public:
598 /// Constructs an end iterator.
600
602 bool IncludeSelf = false) {
604 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SuperRegs);
605 // Initially, the iterator points to Reg itself.
606 Val = MCPhysReg(*I);
607 if (!IncludeSelf)
608 ++*this;
609 }
610
611 const MCPhysReg &operator*() const { return Val; }
612
613 using iterator_adaptor_base::operator++;
615 Val = MCPhysReg(*++I);
616 return *this;
617 }
618
619 /// Returns true if this iterator is not yet at the end.
620 bool isValid() const { return I.isValid(); }
621};
622
623// Definition for isSuperRegister. Put it down here since it needs the
624// iterator defined above in addition to the MCRegisterInfo class itself.
626 return is_contained(superregs(RegA), RegB);
627}
628
629//===----------------------------------------------------------------------===//
630// Register Units
631//===----------------------------------------------------------------------===//
632
633// MCRegUnitIterator enumerates a list of register units for Reg. The list is
634// in ascending numerical order.
636 : public iterator_adaptor_base<MCRegUnitIterator,
637 MCRegisterInfo::DiffListIterator,
638 std::forward_iterator_tag, const MCRegUnit> {
639 // The value must be kept in sync with RegisterInfoEmitter.cpp.
640 static constexpr unsigned RegUnitBits = 12;
641 // Cache the current value, so that we can return a reference to it.
642 MCRegUnit Val;
643
644public:
645 /// Constructs an end iterator.
646 MCRegUnitIterator() = default;
647
649 assert(Reg && "Null register has no regunits");
651 // Decode the RegUnits MCRegisterDesc field.
652 unsigned RU = MCRI->get(Reg).RegUnits;
653 unsigned FirstRU = RU & ((1u << RegUnitBits) - 1);
654 unsigned Offset = RU >> RegUnitBits;
655 I.init(FirstRU, MCRI->DiffLists + Offset);
656 Val = MCRegUnit(*I);
657 }
658
659 const MCRegUnit &operator*() const { return Val; }
660
661 using iterator_adaptor_base::operator++;
663 Val = MCRegUnit(*++I);
664 return *this;
665 }
666
667 /// Returns true if this iterator is not yet at the end.
668 bool isValid() const { return I.isValid(); }
669};
670
671/// MCRegUnitMaskIterator enumerates a list of register units and their
672/// associated lane masks for Reg. The register units are in ascending
673/// numerical order.
675 MCRegUnitIterator RUIter;
676 const LaneBitmask *MaskListIter;
677
678public:
680
681 /// Constructs an iterator that traverses the register units and their
682 /// associated LaneMasks in Reg.
684 : RUIter(Reg, MCRI) {
686 MaskListIter = &MCRI->RegUnitMaskSequences[Idx];
687 }
688
689 /// Returns a (RegUnit, LaneMask) pair.
690 std::pair<unsigned,LaneBitmask> operator*() const {
691 return std::make_pair(*RUIter, *MaskListIter);
692 }
693
694 /// Returns true if this iterator is not yet at the end.
695 bool isValid() const { return RUIter.isValid(); }
696
697 /// Moves to the next position.
699 ++MaskListIter;
700 ++RUIter;
701 return *this;
702 }
703};
704
705// Each register unit has one or two root registers. The complete set of
706// registers containing a register unit is the union of the roots and their
707// super-registers. All registers aliasing Unit can be visited like this:
708//
709// for (MCRegUnitRootIterator RI(Unit, MCRI); RI.isValid(); ++RI) {
710// for (MCSuperRegIterator SI(*RI, MCRI, true); SI.isValid(); ++SI)
711// visit(*SI);
712// }
713
714/// MCRegUnitRootIterator enumerates the root registers of a register unit.
716 uint16_t Reg0 = 0;
717 uint16_t Reg1 = 0;
718
719public:
721
722 MCRegUnitRootIterator(unsigned RegUnit, const MCRegisterInfo *MCRI) {
723 assert(RegUnit < MCRI->getNumRegUnits() && "Invalid register unit");
724 Reg0 = MCRI->RegUnitRoots[RegUnit][0];
725 Reg1 = MCRI->RegUnitRoots[RegUnit][1];
726 }
727
728 /// Dereference to get the current root register.
729 unsigned operator*() const {
730 return Reg0;
731 }
732
733 /// Check if the iterator is at the end of the list.
734 bool isValid() const {
735 return Reg0;
736 }
737
738 /// Preincrement to move to the next root register.
740 assert(isValid() && "Cannot move off the end of the list.");
741 Reg0 = Reg1;
742 Reg1 = 0;
743 return *this;
744 }
745};
746
747/// MCRegAliasIterator enumerates all registers aliasing Reg.
749private:
750 const MCPhysReg *It = nullptr;
751 const MCPhysReg *End = nullptr;
752
753public:
755 bool IncludeSelf) {
756 ArrayRef<MCPhysReg> Cache = MCRI->getCachedAliasesOf(Reg);
757 assert(Cache.back() == Reg);
758 It = Cache.begin();
759 End = Cache.end();
760 if (!IncludeSelf)
761 --End;
762 }
763
764 bool isValid() const { return It != End; }
765
766 MCRegister operator*() const { return *It; }
767
769 assert(isValid() && "Cannot move off the end of the list.");
770 ++It;
771 return *this;
772 }
773};
774
775inline iterator_range<MCSubRegIterator>
777 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSubRegIterator());
778}
779
782 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSubRegIterator());
783}
784
787 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSuperRegIterator());
788}
789
792 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSuperRegIterator());
793}
794
798 return concat<const MCPhysReg>(subregs_inclusive(Reg), superregs(Reg));
799}
800
803 return make_range({Reg, this}, MCRegUnitIterator());
804}
805
806} // end namespace llvm
807
808#endif // LLVM_MC_MCREGISTERINFO_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
A common definition of LaneBitmask for use in TableGen and CodeGen.
unsigned Reg
const NodeList & List
Definition: RDFGraph.cpp:200
static constexpr Register RAReg
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI optimize exec mask operations pre RA
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:177
iterator end() const
Definition: ArrayRef.h:157
iterator begin() const
Definition: ArrayRef.h:156
MCRegAliasIterator enumerates all registers aliasing Reg.
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 enumerates a list of register units and their associated lane masks for Reg.
MCRegUnitMaskIterator(MCRegister Reg, const MCRegisterInfo *MCRI)
Constructs an iterator that traverses the register units and their associated LaneMasks in Reg.
MCRegUnitMaskIterator & operator++()
Moves to the next position.
bool isValid() const
Returns true if this iterator is not yet at the end.
std::pair< unsigned, LaneBitmask > operator*() const
Returns a (RegUnit, LaneMask) pair.
MCRegUnitRootIterator enumerates the root registers of a register unit.
MCRegUnitRootIterator & operator++()
Preincrement to move to the next root register.
unsigned operator*() const
Dereference to get the current root register.
MCRegUnitRootIterator(unsigned RegUnit, const MCRegisterInfo *MCRI)
bool isValid() const
Check if the iterator is at the end of the list.
MCRegisterClass - Base class of TargetRegisterClass.
const uint32_t NameIdx
unsigned getID() const
getID() - Return the register class ID number.
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
const uint16_t RegSizeInBits
unsigned getSizeInBits() const
Return the size of the physical register in bits if we are able to determine it.
const uint16_t RegSetSize
bool contains(MCRegister Reg1, MCRegister Reg2) const
contains - Return true if both registers are in this class.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
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 uint8_t *const RegSet
bool isBaseClass() const
Return true if this register class has a defined BaseClassOrder.
const iterator RegsBegin
int getCopyCost() const
getCopyCost - Return the cost of copying a value between two registers in this class.
iterator end() const
const uint16_t RegsSize
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
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.
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.
const MCRegisterDesc & get(MCRegister Reg) const
Provide a get method, equivalent to [], but more useful with a pointer to this object.
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg.
int getCodeViewRegNum(MCRegister RegNum) const
Map a target register to an equivalent CodeView register number.
iterator_range< regclass_iterator > regclasses() const
int64_t getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const
Map a target EH register number to an equivalent DWARF register number.
regclass_iterator regclass_begin() const
int getSEHRegNum(MCRegister RegNum) const
Map a target register to an equivalent SEH register number.
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.
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)
Initialize MCRegisterInfo, called by TableGen auto-generated routines.
const char * getRegClassName(const MCRegisterClass *Class) const
friend class MCSubRegIterator
virtual int64_t getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
bool isArtificialRegUnit(MCRegUnit Unit) const
Returns true when the given register unit is considered artificial.
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.
unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const
For a given register pair, return the sub-register index if the second register is a sub-register of ...
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.
iterator_range< MCRegUnitIterator > regunits(MCRegister Reg) const
Returns an iterator range over all regunits for Reg.
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.
std::optional< MCRegister > getLLVMRegNum(uint64_t RegNum, bool isEH) const
Map a dwarf register back to a target register.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: MCRegister.h:67
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices.
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:1140
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
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.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2204
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition: MCRegister.h:21
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
@ Other
Any other memory.
unsigned MCRegUnit
Register units are used to compute register aliasing.
Definition: MCRegister.h:30
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
#define NC
Definition: regutils.h:42
Description of the encoding of one expression Op.
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