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