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