LLVM: lib/MC/MCRegisterInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
17#include
18#include
19#include
20
21using namespace llvm;
22
23namespace {
24
25
26class MCRegAliasIteratorImpl {
27private:
28 MCRegister Reg;
29 const MCRegisterInfo *MCRI;
30
31 MCRegUnitIterator RI;
32 MCRegUnitRootIterator RRI;
33 MCSuperRegIterator SI;
34
35public:
36 MCRegAliasIteratorImpl(MCRegister Reg, const MCRegisterInfo *MCRI)
37 : Reg(Reg), MCRI(MCRI) {
38
39
40 for (RI = MCRegUnitIterator(Reg, MCRI); RI.isValid(); ++RI) {
41 for (RRI = MCRegUnitRootIterator(*RI, MCRI); RRI.isValid(); ++RRI) {
42 for (SI = MCSuperRegIterator(*RRI, MCRI, true); SI.isValid(); ++SI) {
43 if (Reg != *SI)
44 return;
45 }
46 }
47 }
48 }
49
50 bool isValid() const { return RI.isValid(); }
51
53 assert(SI.isValid() && "Cannot dereference an invalid iterator.");
54 return *SI;
55 }
56
57 void advance() {
58
59 ++SI;
60 if (SI.isValid())
61 return;
62
63 ++RRI;
64 if (RRI.isValid()) {
65 SI = MCSuperRegIterator(*RRI, MCRI, true);
66 return;
67 }
68
69 ++RI;
70 if (RI.isValid()) {
71 RRI = MCRegUnitRootIterator(*RI, MCRI);
72 SI = MCSuperRegIterator(*RRI, MCRI, true);
73 }
74 }
75
76 MCRegAliasIteratorImpl &operator++() {
77 assert(isValid() && "Cannot move off the end of the list.");
78 do
79 advance();
80 while (isValid() && *SI == Reg);
81 return *this;
82 }
83};
84}
85
87 auto &Aliases = RegAliasesCache[R.id()];
88 if (!Aliases.empty())
89 return Aliases;
90
91 for (MCRegAliasIteratorImpl It(R, this); It.isValid(); ++It)
92 Aliases.push_back((*It).id());
93
94 sort(Aliases);
95 Aliases.erase(unique(Aliases), Aliases.end());
97 "MCRegAliasIteratorImpl includes Self!");
98
99
100
101
102 Aliases.push_back(R.id());
103 Aliases.shrink_to_fit();
104 return Aliases;
105}
106
112 return Super;
113 return 0;
114}
115
118 "This is not a subregister index");
119
120
123 if (*SRI == Idx)
124 return Sub;
125 ++SRI;
126 }
127 return 0;
128}
129
133
134
138 return *SRI;
139 ++SRI;
140 }
141 return 0;
142}
143
145 const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
146 unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
147
148 if (!M)
149 return -1;
152 if (I == M + Size || I->FromReg != Reg)
153 return -1;
154
155
156
157
158 return int64_t(int(I->ToReg));
159}
160
162 bool isEH) const {
163 const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
164 unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
165
166 if (!M)
167 return std::nullopt;
170 if (I != M + Size && I->FromReg == RegNum)
172 return std::nullopt;
173}
174
176
177
178
179
180
181
182
183
184 if (std::optional LRegNum = getLLVMRegNum(RegNum, true)) {
186 if (DwarfRegNum == -1)
187 return RegNum;
188 else
189 return DwarfRegNum;
190 }
191 return RegNum;
192}
193
196 if (I == L2SEHRegs.end())
197 return (int)Reg.id();
198 return I->second;
199}
200
202 if (L2CVRegs.empty())
203 report_fatal_error("target does not implement codeview register mapping");
205 if (I == L2CVRegs.end())
208 : Twine(Reg.id())));
209 return I->second;
210}
211
213
214 auto RangeA = regunits(RegA);
216 auto RangeB = regunits(RegB);
218 do {
219 if (*IA == *IB)
220 return true;
221 } while (*IA < *IB ? ++IA != EA : ++IB != EB);
222 return false;
223}
224
228 return true;
229 return false;
230}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
MCRegisterClass - Base class of TargetRegisterClass.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
Definition MCRegisterInfo.cpp:212
const MCRegisterDesc & get(MCRegister Reg) const
Provide a get method, equivalent to [], but more useful with a pointer to this object.
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg.
Definition MCRegisterInfo.cpp:108
int64_t getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const
Map a target EH register number to an equivalent DWARF register number.
Definition MCRegisterInfo.cpp:175
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
int getSEHRegNum(MCRegister Reg) const
Map a target register to an equivalent SEH register number.
Definition MCRegisterInfo.cpp:194
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.
friend class MCRegUnitRootIterator
bool isArtificialRegUnit(MCRegUnit Unit) const
Returns true when the given register unit is considered artificial.
Definition MCRegisterInfo.cpp:225
iterator_range< MCSubRegIterator > subregs(MCRegister Reg) const
Return an iterator range over all sub-registers of Reg, excluding Reg.
unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const
For a given register pair, return the sub-register index if the second register is a sub-register of ...
Definition MCRegisterInfo.cpp:130
bool isArtificial(MCRegister RegNo) const
Returns true if the given register is artificial, which means it represents a regunit that is not sep...
friend class MCRegUnitIterator
std::optional< MCRegister > getLLVMRegNum(uint64_t RegNum, bool isEH) const
Map a dwarf register back to a target register.
Definition MCRegisterInfo.cpp:161
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Definition MCRegisterInfo.cpp:116
virtual int64_t getDwarfRegNum(MCRegister Reg, bool isEH) const
Map a target register to an equivalent dwarf register number.
Definition MCRegisterInfo.cpp:144
int getCodeViewRegNum(MCRegister Reg) const
Map a target register to an equivalent CodeView register number.
Definition MCRegisterInfo.cpp:201
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is an optimization pass for GlobalISel generic memory operations.
APInt operator*(APInt a, uint64_t RHS)
auto unique(Range &&R, Predicate P)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be performed with a binary se...