Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 8957ed6

Browse files
author
Marina Yatsina
committed
ExecutionDepsFix refactoring:
- Removing LiveRegs This is the one of multiple patches that fix bugzilla https://bugs.llvm.org/show_bug.cgi?id=33869 Most of the patches are intended at refactoring the existent code. Additional relevant reviews: https://reviews.llvm.org/D40330 https://reviews.llvm.org/D40332 https://reviews.llvm.org/D40333 https://reviews.llvm.org/D40334 Differential Revision: https://reviews.llvm.org/D40331 Change-Id: I8ab56d99951a6d6981542f68d94c1f624f3c9fbf git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323091 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 982e880 commit 8957ed6

File tree

2 files changed

+57
-71
lines changed

2 files changed

+57
-71
lines changed

include/llvm/CodeGen/ExecutionDepsFix.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,6 @@ struct DomainValue {
110110
}
111111
};
112112

113-
/// Information about a live register.
114-
struct LiveReg {
115-
/// Value currently in this register, or NULL when no value is being tracked.
116-
/// This counts as a DomainValue reference.
117-
DomainValue *Value;
118-
119-
/// Instruction that defined this register, relative to the beginning of the
120-
/// current basic block. When a LiveReg is used to represent a live-out
121-
/// register, this value is relative to the end of the basic block, so it
122-
/// will be a negative number.
123-
int Def;
124-
};
125-
126113
/// This class provides the basic blocks traversal order used by passes like
127114
/// ReachingDefAnalysis and ExecutionDomainFix.
128115
/// It identifies basic blocks that are part of loops and should to be visited twice
@@ -174,7 +161,11 @@ class ReachingDefAnalysis : public MachineFunctionPass {
174161
const TargetInstrInfo *TII;
175162
const TargetRegisterInfo *TRI;
176163
unsigned NumRegUnits;
177-
using LiveRegsDefInfo = std::vector<LiveReg>;
164+
/// Instruction that defined each register, relative to the beginning of the
165+
/// current basic block. When a LiveRegsDefInfo is used to represent a live-out
166+
/// register, this value is relative to the end of the basic block, so it
167+
/// will be a negative number.
168+
using LiveRegsDefInfo = std::vector<int>;
178169
LiveRegsDefInfo LiveRegs;
179170

180171
// Keeps clearance information for all registers. Note that this
@@ -246,7 +237,9 @@ class ExecutionDomainFix : public MachineFunctionPass {
246237
const TargetRegisterInfo *TRI;
247238
std::vector<SmallVector<int, 1>> AliasMap;
248239
const unsigned NumRegs;
249-
using LiveRegsDVInfo = std::vector<LiveReg>;
240+
/// Value currently in each register, or NULL when no value is being tracked.
241+
/// This counts as a DomainValue reference.
242+
using LiveRegsDVInfo = std::vector<DomainValue *>;
250243
LiveRegsDVInfo LiveRegs;
251244
// Keeps domain information for all registers. Note that this
252245
// is different from the usual definition notion of liveness. The CPU

lib/CodeGen/ExecutionDepsFix.cpp

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,29 @@ void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) {
9090
assert(unsigned(rx) < NumRegs && "Invalid index");
9191
assert(!LiveRegs.empty() && "Must enter basic block first.");
9292

93-
if (LiveRegs[rx].Value == dv)
93+
if (LiveRegs[rx] == dv)
9494
return;
95-
if (LiveRegs[rx].Value)
96-
release(LiveRegs[rx].Value);
97-
LiveRegs[rx].Value = retain(dv);
95+
if (LiveRegs[rx])
96+
release(LiveRegs[rx]);
97+
LiveRegs[rx] = retain(dv);
9898
}
9999

100100
// Kill register rx, recycle or collapse any DomainValue.
101101
void ExecutionDomainFix::kill(int rx) {
102102
assert(unsigned(rx) < NumRegs && "Invalid index");
103103
assert(!LiveRegs.empty() && "Must enter basic block first.");
104-
if (!LiveRegs[rx].Value)
104+
if (!LiveRegs[rx])
105105
return;
106106

107-
release(LiveRegs[rx].Value);
108-
LiveRegs[rx].Value = nullptr;
107+
release(LiveRegs[rx]);
108+
LiveRegs[rx] = nullptr;
109109
}
110110

111111
/// Force register rx into domain.
112112
void ExecutionDomainFix::force(int rx, unsigned domain) {
113113
assert(unsigned(rx) < NumRegs && "Invalid index");
114114
assert(!LiveRegs.empty() && "Must enter basic block first.");
115-
if (DomainValue *dv = LiveRegs[rx].Value) {
115+
if (DomainValue *dv = LiveRegs[rx]) {
116116
if (dv->isCollapsed())
117117
dv->addDomain(domain);
118118
else if (dv->hasDomain(domain))
@@ -121,8 +121,8 @@ void ExecutionDomainFix::force(int rx, unsigned domain) {
121121
// This is an incompatible open DomainValue. Collapse it to whatever and
122122
// force the new value into domain. This costs a domain crossing.
123123
collapse(dv, dv->getFirstDomain());
124-
assert(LiveRegs[rx].Value && "Not live after collapse?");
125-
LiveRegs[rx].Value->addDomain(domain);
124+
assert(LiveRegs[rx] && "Not live after collapse?");
125+
LiveRegs[rx]->addDomain(domain);
126126
}
127127
} else {
128128
// Set up basic collapsed DomainValue.
@@ -143,7 +143,7 @@ void ExecutionDomainFix::collapse(DomainValue *dv, unsigned domain) {
143143
// If there are multiple users, give them new, unique DomainValues.
144144
if (!LiveRegs.empty() && dv->Refs > 1)
145145
for (unsigned rx = 0; rx != NumRegs; ++rx)
146-
if (LiveRegs[rx].Value == dv)
146+
if (LiveRegs[rx] == dv)
147147
setLiveReg(rx, alloc(domain));
148148
}
149149

@@ -167,7 +167,7 @@ bool ExecutionDomainFix::merge(DomainValue *A, DomainValue *B) {
167167

168168
for (unsigned rx = 0; rx != NumRegs; ++rx) {
169169
assert(!LiveRegs.empty() && "no space allocated for live registers");
170-
if (LiveRegs[rx].Value == B)
170+
if (LiveRegs[rx] == B)
171171
setLiveReg(rx, A);
172172
}
173173
return true;
@@ -186,12 +186,9 @@ void ReachingDefAnalysis::enterBasicBlock(
186186
CurInstr = 0;
187187

188188
// Set up LiveRegs to represent registers entering MBB.
189+
// Default values are 'nothing happened a long time ago'.
189190
if (LiveRegs.empty())
190-
LiveRegs.resize(NumRegUnits);
191-
192-
for (LiveReg &LiveRegDef : LiveRegs) {
193-
LiveRegDef.Def = ReachingDedDefaultVal;
194-
}
191+
LiveRegs.assign(NumRegUnits, ReachingDedDefaultVal);
195192

196193
// This is the entry block.
197194
if (MBB->pred_empty()) {
@@ -200,8 +197,8 @@ void ReachingDefAnalysis::enterBasicBlock(
200197
// Treat function live-ins as if they were defined just before the first
201198
// instruction. Usually, function arguments are set up immediately
202199
// before the call.
203-
LiveRegs[*Unit].Def = -1;
204-
MBBReachingDefs[MBBNumber][*Unit].push_back(LiveRegs[*Unit].Def);
200+
LiveRegs[*Unit] = -1;
201+
MBBReachingDefs[MBBNumber][*Unit].push_back(LiveRegs[*Unit]);
205202
}
206203
}
207204
DEBUG(dbgs() << printMBBReference(*MBB) << ": entry\n");
@@ -220,9 +217,9 @@ void ReachingDefAnalysis::enterBasicBlock(
220217

221218
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
222219
// Use the most recent predecessor def for each register.
223-
LiveRegs[Unit].Def = std::max(LiveRegs[Unit].Def, Incoming[Unit].Def);
224-
if ((LiveRegs[Unit].Def != ReachingDedDefaultVal))
225-
MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit].Def);
220+
LiveRegs[Unit] = std::max(LiveRegs[Unit], Incoming[Unit]);
221+
if ((LiveRegs[Unit] != ReachingDedDefaultVal))
222+
MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
226223
}
227224
}
228225

@@ -238,12 +235,9 @@ void ExecutionDomainFix::enterBasicBlock(
238235
MachineBasicBlock *MBB = TraversedMBB.MBB;
239236

240237
// Set up LiveRegs to represent registers entering MBB.
238+
// Set default domain values to 'no domain' (nullptr)
241239
if (LiveRegs.empty())
242-
LiveRegs.resize(NumRegs);
243-
244-
for (LiveReg &LiveRegDef : LiveRegs) {
245-
LiveRegDef.Value = nullptr;
246-
}
240+
LiveRegs.assign(NumRegs, nullptr);
247241

248242
// This is the entry block.
249243
if (MBB->pred_empty()) {
@@ -262,26 +256,26 @@ void ExecutionDomainFix::enterBasicBlock(
262256
continue;
263257

264258
for (unsigned rx = 0; rx != NumRegs; ++rx) {
265-
DomainValue *pdv = resolve(Incoming[rx].Value);
259+
DomainValue *pdv = resolve(Incoming[rx]);
266260
if (!pdv)
267261
continue;
268-
if (!LiveRegs[rx].Value) {
262+
if (!LiveRegs[rx]) {
269263
setLiveReg(rx, pdv);
270264
continue;
271265
}
272266

273267
// We have a live DomainValue from more than one predecessor.
274-
if (LiveRegs[rx].Value->isCollapsed()) {
268+
if (LiveRegs[rx]->isCollapsed()) {
275269
// We are already collapsed, but predecessor is not. Force it.
276-
unsigned Domain = LiveRegs[rx].Value->getFirstDomain();
270+
unsigned Domain = LiveRegs[rx]->getFirstDomain();
277271
if (!pdv->isCollapsed() && pdv->hasDomain(Domain))
278272
collapse(pdv, Domain);
279273
continue;
280274
}
281275

282276
// Currently open, merge in predecessor.
283277
if (!pdv->isCollapsed())
284-
merge(LiveRegs[rx].Value, pdv);
278+
merge(LiveRegs[rx], pdv);
285279
else
286280
force(rx, pdv->getFirstDomain());
287281
}
@@ -303,8 +297,8 @@ void ReachingDefAnalysis::leaveBasicBlock(
303297
// of the basic block for convenience. However, future use of this information
304298
// only cares about the clearance from the end of the block, so adjust
305299
// everything to be relative to the end of the basic block.
306-
for (LiveReg &OutLiveReg : MBBOutRegsInfos[MBBNumber])
307-
OutLiveReg.Def -= CurInstr;
300+
for (int &OutLiveReg : MBBOutRegsInfos[MBBNumber])
301+
OutLiveReg -= CurInstr;
308302
LiveRegs.clear();
309303
}
310304

@@ -313,13 +307,11 @@ void ExecutionDomainFix::leaveBasicBlock(
313307
assert(!LiveRegs.empty() && "Must enter basic block first.");
314308
int MBBNumber = TraversedMBB.MBB->getNumber();
315309
assert(MBBNumber < MBBOutRegsInfos.size() && "Unexpected basic block number.");
316-
LiveRegsDVInfo OldOutRegs = MBBOutRegsInfos[MBBNumber];
317310
// Save register clearances at end of MBB - used by enterBasicBlock().
318-
MBBOutRegsInfos[MBBNumber] = LiveRegs;
319-
for (LiveReg &OldLiveReg : OldOutRegs) {
320-
release(OldLiveReg.Value);
311+
for (DomainValue *OldLiveReg : MBBOutRegsInfos[MBBNumber]) {
312+
release(OldLiveReg);
321313
}
322-
OldOutRegs.clear();
314+
MBBOutRegsInfos[MBBNumber] = LiveRegs;
323315
LiveRegs.clear();
324316
}
325317

@@ -461,7 +453,7 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) {
461453
<< *MI);
462454

463455
// How many instructions since this reg unit was last written?
464-
LiveRegs[*Unit].Def = CurInstr;
456+
LiveRegs[*Unit] = CurInstr;
465457
MBBReachingDefs[MBBNumber][*Unit].push_back(CurInstr);
466458
}
467459
}
@@ -577,7 +569,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
577569
MachineOperand &mo = mi->getOperand(i);
578570
if (!mo.isReg()) continue;
579571
for (int rx : regIndices(mo.getReg())) {
580-
DomainValue *dv = LiveRegs[rx].Value;
572+
DomainValue *dv = LiveRegs[rx];
581573
if (dv == nullptr)
582574
continue;
583575
// Bitmask of domains that dv and available have in common.
@@ -608,37 +600,38 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
608600

609601
// Kill off any remaining uses that don't match available, and build a list of
610602
// incoming DomainValues that we want to merge.
611-
SmallVector<const LiveReg *, 4> Regs;
603+
SmallVector<int, 4> Regs;
612604
for (int rx : used) {
613605
assert(!LiveRegs.empty() && "no space allocated for live registers");
614-
LiveReg &LR = LiveRegs[rx];
615-
LR.Def = RDA->getReachingDef(mi, RC->getRegister(rx));
606+
DomainValue *&LR = LiveRegs[rx];
616607
// This useless DomainValue could have been missed above.
617-
if (!LR.Value->getCommonDomains(available)) {
608+
if (!LR->getCommonDomains(available)) {
618609
kill(rx);
619610
continue;
620611
}
621612
// Sorted insertion.
622-
auto I = std::upper_bound(Regs.begin(), Regs.end(), &LR,
623-
[](const LiveReg *LHS, const LiveReg *RHS) {
624-
return LHS->Def < RHS->Def;
613+
// Enables giving priority to the latest domains during merging.
614+
auto I = std::upper_bound(Regs.begin(), Regs.end(), rx,
615+
[&](int LHS, const int RHS) {
616+
return RDA->getReachingDef(mi, RC->getRegister(LHS)) <
617+
RDA->getReachingDef(mi, RC->getRegister(RHS));
625618
});
626-
Regs.insert(I, &LR);
619+
Regs.insert(I, rx);
627620
}
628621

629622
// doms are now sorted in order of appearance. Try to merge them all, giving
630623
// priority to the latest ones.
631624
DomainValue *dv = nullptr;
632625
while (!Regs.empty()) {
633626
if (!dv) {
634-
dv = Regs.pop_back_val()->Value;
627+
dv = LiveRegs[Regs.pop_back_val()];
635628
// Force the first dv to match the current instruction.
636629
dv->AvailableDomains = dv->getCommonDomains(available);
637630
assert(dv->AvailableDomains && "Domain should have been filtered");
638631
continue;
639632
}
640633

641-
DomainValue *Latest = Regs.pop_back_val()->Value;
634+
DomainValue *Latest = LiveRegs[Regs.pop_back_val()];
642635
// Skip already merged values.
643636
if (Latest == dv || Latest->Next)
644637
continue;
@@ -648,7 +641,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
648641
// If latest didn't merge, it is useless now. Kill all registers using it.
649642
for (int i : used) {
650643
assert(!LiveRegs.empty() && "no space allocated for live registers");
651-
if (LiveRegs[i].Value == Latest)
644+
if (LiveRegs[i] == Latest)
652645
kill(i);
653646
}
654647
}
@@ -665,7 +658,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
665658
for (MachineOperand &mo : mi->operands()) {
666659
if (!mo.isReg()) continue;
667660
for (int rx : regIndices(mo.getReg())) {
668-
if (!LiveRegs[rx].Value || (mo.isDef() && LiveRegs[rx].Value != dv)) {
661+
if (!LiveRegs[rx] || (mo.isDef() && LiveRegs[rx] != dv)) {
669662
kill(rx);
670663
setLiveReg(rx, dv);
671664
}
@@ -852,9 +845,9 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
852845
}
853846

854847
for (LiveRegsDVInfo OutLiveRegs: MBBOutRegsInfos) {
855-
for (LiveReg OutLiveReg : OutLiveRegs) {
856-
if (OutLiveReg.Value)
857-
release(OutLiveReg.Value);
848+
for (DomainValue *OutLiveReg : OutLiveRegs) {
849+
if (OutLiveReg)
850+
release(OutLiveReg);
858851
}
859852
}
860853
MBBOutRegsInfos.clear();

0 commit comments

Comments
 (0)