Skip to content

Commit f0f467a

Browse files
author
Krzysztof Parzyszek
committed
[RDF] Cache register aliases in PhysicalRegisterInfo
This improves performance of PhysicalRegisterInfo::makeRegRef.
1 parent 47fe1b6 commit f0f467a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

llvm/include/llvm/CodeGen/RDFRegisters.h

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ namespace rdf {
132132
return MaskInfos[Register::stackSlot2Index(MaskId)].Units;
133133
}
134134

135+
const BitVector &getUnitAliases(uint32_t U) const {
136+
return AliasInfos[U].Regs;
137+
}
138+
135139
RegisterRef mapTo(RegisterRef RR, unsigned R) const;
136140
const TargetRegisterInfo &getTRI() const { return TRI; }
137141

@@ -146,12 +150,16 @@ namespace rdf {
146150
struct MaskInfo {
147151
BitVector Units;
148152
};
153+
struct AliasInfo {
154+
BitVector Regs;
155+
};
149156

150157
const TargetRegisterInfo &TRI;
151158
IndexedSet<const uint32_t*> RegMasks;
152159
std::vector<RegInfo> RegInfos;
153160
std::vector<UnitInfo> UnitInfos;
154161
std::vector<MaskInfo> MaskInfos;
162+
std::vector<AliasInfo> AliasInfos;
155163

156164
bool aliasRR(RegisterRef RA, RegisterRef RB) const;
157165
bool aliasRM(RegisterRef RR, RegisterRef RM) const;

llvm/lib/CodeGen/RDFRegisters.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ PhysicalRegisterInfo::PhysicalRegisterInfo(const TargetRegisterInfo &tri,
9292
}
9393
MaskInfos[M].Units = PU.flip();
9494
}
95+
96+
AliasInfos.resize(TRI.getNumRegUnits());
97+
for (uint32_t U = 0, NU = TRI.getNumRegUnits(); U != NU; ++U) {
98+
BitVector AS(TRI.getNumRegs());
99+
for (MCRegUnitRootIterator R(U, &TRI); R.isValid(); ++R)
100+
for (MCSuperRegIterator S(*R, &TRI, true); S.isValid(); ++S)
101+
AS.set(*S);
102+
AliasInfos[U].Regs = AS;
103+
}
95104
}
96105

97106
std::set<RegisterId> PhysicalRegisterInfo::getAliasSet(RegisterId Reg) const {
@@ -317,26 +326,17 @@ RegisterRef RegisterAggr::makeRegRef() const {
317326
if (U < 0)
318327
return RegisterRef();
319328

320-
auto AliasedRegs = [this] (uint32_t Unit, BitVector &Regs) {
321-
for (MCRegUnitRootIterator R(Unit, &PRI.getTRI()); R.isValid(); ++R)
322-
for (MCSuperRegIterator S(*R, &PRI.getTRI(), true); S.isValid(); ++S)
323-
Regs.set(*S);
324-
};
325-
326329
// Find the set of all registers that are aliased to all the units
327330
// in this aggregate.
328331

329332
// Get all the registers aliased to the first unit in the bit vector.
330-
BitVector Regs(PRI.getTRI().getNumRegs());
331-
AliasedRegs(U, Regs);
333+
BitVector Regs = PRI.getUnitAliases(U);
332334
U = Units.find_next(U);
333335

334336
// For each other unit, intersect it with the set of all registers
335337
// aliased that unit.
336338
while (U >= 0) {
337-
BitVector AR(PRI.getTRI().getNumRegs());
338-
AliasedRegs(U, AR);
339-
Regs &= AR;
339+
Regs &= PRI.getUnitAliases(U);
340340
U = Units.find_next(U);
341341
}
342342

0 commit comments

Comments
 (0)