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
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 const unsigned (*RegUnitIntervals)[2]; // Pointer to regunit interval table.
184
185 unsigned L2DwarfRegsSize;
186 unsigned EHL2DwarfRegsSize;
187 unsigned Dwarf2LRegsSize;
188 unsigned EHDwarf2LRegsSize;
189 const DwarfLLVMRegPair *L2DwarfRegs; // LLVM to Dwarf regs mapping
190 const DwarfLLVMRegPair *EHL2DwarfRegs; // LLVM to Dwarf regs mapping EH
191 const DwarfLLVMRegPair *Dwarf2LRegs; // Dwarf to LLVM regs mapping
192 const DwarfLLVMRegPair *EHDwarf2LRegs; // Dwarf to LLVM regs mapping EH
193 DenseMap<MCRegister, int> L2SEHRegs; // LLVM to SEH regs mapping
194 DenseMap<MCRegister, int> L2CVRegs; // LLVM to CV regs mapping
195
196 mutable std::vector<std::vector<MCPhysReg>> RegAliasesCache;
197 ArrayRef<MCPhysReg> getCachedAliasesOf(MCRegister R) const;
198
199 /// Iterator class that can traverse the differentially encoded values in
200 /// DiffLists. Don't use this class directly, use one of the adaptors below.
201 class DiffListIterator
202 : public iterator_facade_base<DiffListIterator, std::forward_iterator_tag,
203 unsigned> {
204 unsigned Val = 0;
205 const int16_t *List = nullptr;
206
207 public:
208 /// Constructs an invalid iterator, which is also the end iterator.
209 /// Call init() to point to something useful.
210 DiffListIterator() = default;
211
212 /// Point the iterator to InitVal, decoding subsequent values from DiffList.
213 void init(unsigned InitVal, const int16_t *DiffList) {
214 Val = InitVal;
215 List = DiffList;
216 }
217
218 /// Returns true if this iterator is not yet at the end.
219 bool isValid() const { return List; }
220
221 /// Dereference the iterator to get the value at the current position.
222 const unsigned &operator*() const { return Val; }
223
224 using DiffListIterator::iterator_facade_base::operator++;
225 /// Pre-increment to move to the next position.
226 DiffListIterator &operator++() {
227 assert(isValid() && "Cannot move off the end of the list.");
228 int16_t D = *List++;
229 Val += D;
230 // The end of the list is encoded as a 0 differential.
231 if (!D)
232 List = nullptr;
233 return *this;
234 }
235
236 bool operator==(const DiffListIterator &Other) const {
237 return List == Other.List;
238 }
239 };
240
241public:
242 /// Return an iterator range over all sub-registers of \p Reg, excluding \p
243 /// Reg.
244 iterator_range<MCSubRegIterator> subregs(MCRegister Reg) const;
245
246 /// Return an iterator range over all sub-registers of \p Reg, including \p
247 /// Reg.
248 iterator_range<MCSubRegIterator> subregs_inclusive(MCRegister Reg) const;
249
250 /// Return an iterator range over all super-registers of \p Reg, excluding \p
251 /// Reg.
252 iterator_range<MCSuperRegIterator> superregs(MCRegister Reg) const;
253
254 /// Return an iterator range over all super-registers of \p Reg, including \p
255 /// Reg.
256 iterator_range<MCSuperRegIterator> superregs_inclusive(MCRegister Reg) const;
257
258 /// Return an iterator range over all sub- and super-registers of \p Reg,
259 /// including \p Reg.
260 detail::concat_range<const MCPhysReg, iterator_range<MCSubRegIterator>,
261 iterator_range<MCSuperRegIterator>>
262 sub_and_superregs_inclusive(MCRegister Reg) const;
263
264 /// Returns an iterator range over all regunits.
265 iota_range<MCRegUnit> regunits() const;
266
267 /// Returns an iterator range over all regunits for \p Reg.
268 iterator_range<MCRegUnitIterator> regunits(MCRegister Reg) const;
269
270 // These iterators are allowed to sub-class DiffListIterator and access
271 // internal list pointers.
272 friend class MCSubRegIterator;
274 friend class MCSuperRegIterator;
275 friend class MCRegUnitIterator;
278 friend class MCRegAliasIterator;
279
280 virtual ~MCRegisterInfo() = default;
281
282 /// Initialize MCRegisterInfo, called by TableGen
283 /// auto-generated routines. *DO NOT USE*.
284 void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA,
285 unsigned PC, const MCRegisterClass *C, unsigned NC,
286 const MCPhysReg (*RURoots)[2], unsigned NRU,
287 const int16_t *DL, const LaneBitmask *RUMS,
288 const char *Strings, const char *ClassStrings,
289 const uint16_t *SubIndices, unsigned NumIndices,
290 const uint16_t *RET,
291 const unsigned (*RUI)[2] = nullptr) {
292 Desc = D;
293 NumRegs = NR;
294 RAReg = RA;
295 PCReg = PC;
296 Classes = C;
297 DiffLists = DL;
298 RegUnitMaskSequences = RUMS;
299 RegStrings = Strings;
300 RegClassStrings = ClassStrings;
301 NumClasses = NC;
302 RegUnitRoots = RURoots;
303 NumRegUnits = NRU;
304 SubRegIndices = SubIndices;
305 NumSubRegIndices = NumIndices;
306 RegEncodingTable = RET;
307 RegUnitIntervals = RUI;
308
309 // Initialize DWARF register mapping variables
310 EHL2DwarfRegs = nullptr;
311 EHL2DwarfRegsSize = 0;
312 L2DwarfRegs = nullptr;
313 L2DwarfRegsSize = 0;
314 EHDwarf2LRegs = nullptr;
315 EHDwarf2LRegsSize = 0;
316 Dwarf2LRegs = nullptr;
317 Dwarf2LRegsSize = 0;
318
319 RegAliasesCache.resize(NumRegs);
320 }
321
322 /// Used to initialize LLVM register to Dwarf
323 /// register number mapping. Called by TableGen auto-generated routines.
324 /// *DO NOT USE*.
326 bool isEH) {
327 if (isEH) {
328 EHL2DwarfRegs = Map;
329 EHL2DwarfRegsSize = Size;
330 } else {
331 L2DwarfRegs = Map;
332 L2DwarfRegsSize = Size;
333 }
334 }
335
336 /// Used to initialize Dwarf register to LLVM
337 /// register number mapping. Called by TableGen auto-generated routines.
338 /// *DO NOT USE*.
340 bool isEH) {
341 if (isEH) {
342 EHDwarf2LRegs = Map;
343 EHDwarf2LRegsSize = Size;
344 } else {
345 Dwarf2LRegs = Map;
346 Dwarf2LRegsSize = Size;
347 }
348 }
349
350 /// mapLLVMRegToSEHReg - Used to initialize LLVM register to SEH register
351 /// number mapping. By default the SEH register number is just the same
352 /// as the LLVM register number.
353 /// FIXME: TableGen these numbers. Currently this requires target specific
354 /// initialization code.
355 void mapLLVMRegToSEHReg(MCRegister LLVMReg, int SEHReg) {
356 L2SEHRegs[LLVMReg] = SEHReg;
357 }
358
359 void mapLLVMRegToCVReg(MCRegister LLVMReg, int CVReg) {
360 L2CVRegs[LLVMReg] = CVReg;
361 }
362
363 /// This method should return the register where the return
364 /// address can be found.
366 return RAReg;
367 }
368
369 /// Return the register which is the program counter.
371 return PCReg;
372 }
373
375 assert(Reg.id() < NumRegs &&
376 "Attempting to access record for invalid register number!");
377 return Desc[Reg.id()];
378 }
379
380 /// Provide a get method, equivalent to [], but more useful with a
381 /// pointer to this object.
383 return operator[](Reg);
384 }
385
386 /// Returns the physical register number of sub-register "Index"
387 /// for physical register RegNo. Return zero if the sub-register does not
388 /// exist.
389 MCRegister getSubReg(MCRegister Reg, unsigned Idx) const;
390
391 /// Return a super-register of the specified register
392 /// Reg so its sub-register of index SubIdx is Reg.
393 MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx,
394 const MCRegisterClass *RC) const;
395
396 /// For a given register pair, return the sub-register index
397 /// if the second register is a sub-register of the first. Return zero
398 /// otherwise.
399 unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const;
400
401 /// Return the human-readable symbolic target-specific name for the
402 /// specified physical register.
403 const char *getName(MCRegister RegNo) const {
404 return RegStrings + get(RegNo).Name;
405 }
406
407 /// Returns true if the given register is constant.
408 bool isConstant(MCRegister RegNo) const { return get(RegNo).IsConstant; }
409
410 /// Returns true if the given register is artificial, which means it
411 /// represents a regunit that is not separately addressable but still needs to
412 /// be modelled, such as the top 16-bits of a 32-bit GPR.
413 bool isArtificial(MCRegister RegNo) const { return get(RegNo).IsArtificial; }
414
415 /// Returns true when the given register unit is considered artificial.
416 /// Register units are considered artificial when at least one of the
417 /// root registers is artificial.
418 bool isArtificialRegUnit(MCRegUnit Unit) const;
419
420 /// Return the number of registers this target has (useful for
421 /// sizing arrays holding per register information)
422 unsigned getNumRegs() const {
423 return NumRegs;
424 }
425
426 /// Return the number of sub-register indices
427 /// understood by the target. Index 0 is reserved for the no-op sub-register,
428 /// while 1 to getNumSubRegIndices() - 1 represent real sub-registers.
429 unsigned getNumSubRegIndices() const {
430 return NumSubRegIndices;
431 }
432
433 /// Return the number of (native) register units in the
434 /// target. Register units are numbered from 0 to getNumRegUnits() - 1. They
435 /// can be accessed through MCRegUnitIterator defined below.
436 unsigned getNumRegUnits() const {
437 return NumRegUnits;
438 }
439
440 /// Map a target register to an equivalent dwarf register
441 /// number. Returns -1 if there is no equivalent value. The second
442 /// parameter allows targets to use different numberings for EH info and
443 /// debugging info.
444 virtual int64_t getDwarfRegNum(MCRegister Reg, bool isEH) const;
445
446 /// Map a dwarf register back to a target register. Returns std::nullopt if
447 /// there is no mapping.
448 std::optional<MCRegister> getLLVMRegNum(uint64_t RegNum, bool isEH) const;
449
450 /// Map a target EH register number to an equivalent DWARF register
451 /// number.
452 int64_t getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const;
453
454 /// Map a target register to an equivalent SEH register
455 /// number. Returns LLVM register number if there is no equivalent value.
456 int getSEHRegNum(MCRegister Reg) const;
457
458 /// Map a target register to an equivalent CodeView register
459 /// number.
460 int getCodeViewRegNum(MCRegister Reg) const;
461
462 regclass_iterator regclass_begin() const { return Classes; }
463 regclass_iterator regclass_end() const { return Classes+NumClasses; }
467
468 unsigned getNumRegClasses() const {
469 return (unsigned)(regclass_end()-regclass_begin());
470 }
471
472 /// Returns the register class associated with the enumeration
473 /// value. See class MCOperandInfo.
474 const MCRegisterClass& getRegClass(unsigned i) const {
475 assert(i < getNumRegClasses() && "Register Class ID out of range");
476 return Classes[i];
477 }
478
479 const char *getRegClassName(const MCRegisterClass *Class) const {
480 return RegClassStrings + Class->NameIdx;
481 }
482
483 /// Returns the encoding for Reg
485 assert(Reg.id() < NumRegs &&
486 "Attempting to get encoding for invalid register number!");
487 return RegEncodingTable[Reg.id()];
488 }
489
490 /// Returns true if RegB is a sub-register of RegA.
491 bool isSubRegister(MCRegister RegA, MCRegister RegB) const {
492 return isSuperRegister(RegB, RegA);
493 }
494
495 /// Returns true if RegB is a super-register of RegA.
496 bool isSuperRegister(MCRegister RegA, MCRegister RegB) const;
497
498 /// Returns true if RegB is a sub-register of RegA or if RegB == RegA.
499 bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const {
500 return isSuperRegisterEq(RegB, RegA);
501 }
502
503 /// Returns true if RegB is a super-register of RegA or if
504 /// RegB == RegA.
505 bool isSuperRegisterEq(MCRegister RegA, MCRegister RegB) const {
506 return RegA == RegB || isSuperRegister(RegA, RegB);
507 }
508
509 /// Returns true if RegB is a super-register or sub-register of RegA
510 /// or if RegB == RegA.
512 return isSubRegisterEq(RegA, RegB) || isSuperRegister(RegA, RegB);
513 }
514
515 /// Returns true if the two registers are equal or alias each other.
516 bool regsOverlap(MCRegister RegA, MCRegister RegB) const;
517
518 /// Returns true if this target uses regunit intervals.
519 bool hasRegUnitIntervals() const { return RegUnitIntervals != nullptr; }
520
521 /// Returns an iterator range over all native regunits in the RegUnitInterval
522 /// table for \p Reg.
525 "Target does not support regunit intervals");
526 assert(Reg.id() < NumRegs && "Invalid register number");
527 return seq<unsigned>(RegUnitIntervals[Reg.id()][0],
528 RegUnitIntervals[Reg.id()][1]);
529 }
530};
531
532//===----------------------------------------------------------------------===//
533// Register List Iterators
534//===----------------------------------------------------------------------===//
535
536// MCRegisterInfo provides lists of super-registers, sub-registers, and
537// aliasing registers. Use these iterator classes to traverse the lists.
538
539/// MCSubRegIterator enumerates all sub-registers of Reg.
540/// If IncludeSelf is set, Reg itself is included in the list.
542 : public iterator_adaptor_base<MCSubRegIterator,
543 MCRegisterInfo::DiffListIterator,
544 std::forward_iterator_tag, const MCPhysReg> {
545 // Cache the current value, so that we can return a reference to it.
546 MCPhysReg Val;
547
548public:
549 /// Constructs an end iterator.
550 MCSubRegIterator() = default;
551
553 bool IncludeSelf = false) {
554 assert(Reg.isPhysical());
555 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SubRegs);
556 // Initially, the iterator points to Reg itself.
557 Val = MCPhysReg(*I);
558 if (!IncludeSelf)
559 ++*this;
560 }
561
562 const MCPhysReg &operator*() const { return Val; }
563
564 using iterator_adaptor_base::operator++;
566 Val = MCPhysReg(*++I);
567 return *this;
568 }
569
570 /// Returns true if this iterator is not yet at the end.
571 bool isValid() const { return I.isValid(); }
572};
573
574/// Iterator that enumerates the sub-registers of a Reg and the associated
575/// sub-register indices.
577 MCSubRegIterator SRIter;
578 const uint16_t *SRIndex;
579
580public:
581 /// Constructs an iterator that traverses subregisters and their
582 /// associated subregister indices.
584 : SRIter(Reg, MCRI) {
585 SRIndex = MCRI->SubRegIndices + MCRI->get(Reg).SubRegIndices;
586 }
587
588 /// Returns current sub-register.
590 return *SRIter;
591 }
592
593 /// Returns sub-register index of the current sub-register.
594 unsigned getSubRegIndex() const {
595 return *SRIndex;
596 }
597
598 /// Returns true if this iterator is not yet at the end.
599 bool isValid() const { return SRIter.isValid(); }
600
601 /// Moves to the next position.
603 ++SRIter;
604 ++SRIndex;
605 return *this;
606 }
607};
608
609/// MCSuperRegIterator enumerates all super-registers of Reg.
610/// If IncludeSelf is set, Reg itself is included in the list.
612 : public iterator_adaptor_base<MCSuperRegIterator,
613 MCRegisterInfo::DiffListIterator,
614 std::forward_iterator_tag, const MCPhysReg> {
615 // Cache the current value, so that we can return a reference to it.
616 MCPhysReg Val;
617
618public:
619 /// Constructs an end iterator.
621
623 bool IncludeSelf = false) {
624 assert(Reg.isPhysical());
625 I.init(Reg.id(), MCRI->DiffLists + MCRI->get(Reg).SuperRegs);
626 // Initially, the iterator points to Reg itself.
627 Val = MCPhysReg(*I);
628 if (!IncludeSelf)
629 ++*this;
630 }
631
632 const MCPhysReg &operator*() const { return Val; }
633
634 using iterator_adaptor_base::operator++;
636 Val = MCPhysReg(*++I);
637 return *this;
638 }
639
640 /// Returns true if this iterator is not yet at the end.
641 bool isValid() const { return I.isValid(); }
642};
643
644// Definition for isSuperRegister. Put it down here since it needs the
645// iterator defined above in addition to the MCRegisterInfo class itself.
647 return is_contained(superregs(RegA), RegB);
648}
649
650//===----------------------------------------------------------------------===//
651// Register Units
652//===----------------------------------------------------------------------===//
653
654// MCRegUnitIterator enumerates a list of register units for Reg. The list is
655// in ascending numerical order.
657 : public iterator_adaptor_base<MCRegUnitIterator,
658 MCRegisterInfo::DiffListIterator,
659 std::forward_iterator_tag, const MCRegUnit> {
660 // The value must be kept in sync with RegisterInfoEmitter.cpp.
661 static constexpr unsigned RegUnitBits = 12;
662 // Cache the current value, so that we can return a reference to it.
663 MCRegUnit Val;
664
665public:
666 /// Constructs an end iterator.
667 MCRegUnitIterator() = default;
668
670 assert(Reg.isPhysical());
671 // Decode the RegUnits MCRegisterDesc field.
672 unsigned RU = MCRI->get(Reg).RegUnits;
673 unsigned FirstRU = RU & ((1u << RegUnitBits) - 1);
674 unsigned Offset = RU >> RegUnitBits;
675 I.init(FirstRU, MCRI->DiffLists + Offset);
676 Val = MCRegUnit(*I);
677 }
678
679 const MCRegUnit &operator*() const { return Val; }
680
681 using iterator_adaptor_base::operator++;
683 Val = MCRegUnit(*++I);
684 return *this;
685 }
686
687 /// Returns true if this iterator is not yet at the end.
688 bool isValid() const { return I.isValid(); }
689};
690
691/// MCRegUnitMaskIterator enumerates a list of register units and their
692/// associated lane masks for Reg. The register units are in ascending
693/// numerical order.
695 MCRegUnitIterator RUIter;
696 const LaneBitmask *MaskListIter;
697
698public:
700
701 /// Constructs an iterator that traverses the register units and their
702 /// associated LaneMasks in Reg.
704 : RUIter(Reg, MCRI) {
705 uint16_t Idx = MCRI->get(Reg).RegUnitLaneMasks;
706 MaskListIter = &MCRI->RegUnitMaskSequences[Idx];
707 }
708
709 /// Returns a (RegUnit, LaneMask) pair.
710 std::pair<MCRegUnit, LaneBitmask> operator*() const {
711 return std::make_pair(*RUIter, *MaskListIter);
712 }
713
714 /// Returns true if this iterator is not yet at the end.
715 bool isValid() const { return RUIter.isValid(); }
716
717 /// Moves to the next position.
719 ++MaskListIter;
720 ++RUIter;
721 return *this;
722 }
723};
724
725// Each register unit has one or two root registers. The complete set of
726// registers containing a register unit is the union of the roots and their
727// super-registers. All registers aliasing Unit can be visited like this:
728//
729// for (MCRegUnitRootIterator RI(Unit, MCRI); RI.isValid(); ++RI) {
730// for (MCSuperRegIterator SI(*RI, MCRI, true); SI.isValid(); ++SI)
731// visit(*SI);
732// }
733
734/// MCRegUnitRootIterator enumerates the root registers of a register unit.
736 uint16_t Reg0 = 0;
737 uint16_t Reg1 = 0;
738
739public:
741
742 MCRegUnitRootIterator(MCRegUnit RegUnit, const MCRegisterInfo *MCRI) {
743 assert(static_cast<unsigned>(RegUnit) < MCRI->getNumRegUnits() &&
744 "Invalid register unit");
745 Reg0 = MCRI->RegUnitRoots[static_cast<unsigned>(RegUnit)][0];
746 Reg1 = MCRI->RegUnitRoots[static_cast<unsigned>(RegUnit)][1];
747 }
748
749 /// Dereference to get the current root register.
750 unsigned operator*() const {
751 return Reg0;
752 }
753
754 /// Check if the iterator is at the end of the list.
755 bool isValid() const {
756 return Reg0;
757 }
758
759 /// Preincrement to move to the next root register.
761 assert(isValid() && "Cannot move off the end of the list.");
762 Reg0 = Reg1;
763 Reg1 = 0;
764 return *this;
765 }
766};
767
768/// MCRegAliasIterator enumerates all registers aliasing Reg.
770private:
771 const MCPhysReg *It = nullptr;
772 const MCPhysReg *End = nullptr;
773
774public:
776 bool IncludeSelf) {
777 ArrayRef<MCPhysReg> Cache = MCRI->getCachedAliasesOf(Reg);
778 assert(Cache.back() == Reg);
779 It = Cache.begin();
780 End = Cache.end();
781 if (!IncludeSelf)
782 --End;
783 }
784
785 bool isValid() const { return It != End; }
786
787 MCRegister operator*() const { return *It; }
788
790 assert(isValid() && "Cannot move off the end of the list.");
791 ++It;
792 return *this;
793 }
794};
795
798 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSubRegIterator());
799}
800
803 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSubRegIterator());
804}
805
808 return make_range({Reg, this, /*IncludeSelf=*/false}, MCSuperRegIterator());
809}
810
813 return make_range({Reg, this, /*IncludeSelf=*/true}, MCSuperRegIterator());
814}
815
821
823 return enum_seq(static_cast<MCRegUnit>(0),
824 static_cast<MCRegUnit>(getNumRegUnits()),
826}
827
832
833} // end namespace llvm
834
835#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...
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: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.
Definition Types.h:26
@ 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:2244
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:1945
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
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