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

Commit 982e880

Browse files
author
Marina Yatsina
committed
ExecutionDepsFix refactoring:
- Changing LiveRegs to be a vector 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: I9cdd364bd7bf2a0bf61ea41a48d4bd310ec3bce4 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323090 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7dc5e85 commit 982e880

File tree

2 files changed

+46
-54
lines changed

2 files changed

+46
-54
lines changed

include/llvm/CodeGen/ExecutionDepsFix.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ class ReachingDefAnalysis : public MachineFunctionPass {
174174
const TargetInstrInfo *TII;
175175
const TargetRegisterInfo *TRI;
176176
unsigned NumRegUnits;
177-
LiveReg *LiveRegs;
177+
using LiveRegsDefInfo = std::vector<LiveReg>;
178+
LiveRegsDefInfo LiveRegs;
178179

179180
// Keeps clearance information for all registers. Note that this
180181
// is different from the usual definition notion of liveness. The CPU
181182
// doesn't care whether or not we consider a register killed.
182-
using OutRegsInfoMap = SmallVector<LiveReg *, 4>;
183+
using OutRegsInfoMap = SmallVector<LiveRegsDefInfo, 4>;
183184
OutRegsInfoMap MBBOutRegsInfos;
184185

185186
/// Current instruction number.
@@ -245,11 +246,12 @@ class ExecutionDomainFix : public MachineFunctionPass {
245246
const TargetRegisterInfo *TRI;
246247
std::vector<SmallVector<int, 1>> AliasMap;
247248
const unsigned NumRegs;
248-
LiveReg *LiveRegs;
249+
using LiveRegsDVInfo = std::vector<LiveReg>;
250+
LiveRegsDVInfo LiveRegs;
249251
// Keeps domain information for all registers. Note that this
250252
// is different from the usual definition notion of liveness. The CPU
251253
// doesn't care whether or not we consider a register killed.
252-
using OutRegsInfoMap = SmallVector<LiveReg *, 4>;
254+
using OutRegsInfoMap = SmallVector<LiveRegsDVInfo, 4>;
253255
OutRegsInfoMap MBBOutRegsInfos;
254256

255257
ReachingDefAnalysis *RDA;

lib/CodeGen/ExecutionDepsFix.cpp

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ DomainValue *ExecutionDomainFix::resolve(DomainValue *&DVRef) {
8888
/// Set LiveRegs[rx] = dv, updating reference counts.
8989
void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) {
9090
assert(unsigned(rx) < NumRegs && "Invalid index");
91-
assert(LiveRegs && "Must enter basic block first.");
91+
assert(!LiveRegs.empty() && "Must enter basic block first.");
9292

9393
if (LiveRegs[rx].Value == dv)
9494
return;
@@ -100,7 +100,7 @@ void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) {
100100
// Kill register rx, recycle or collapse any DomainValue.
101101
void ExecutionDomainFix::kill(int rx) {
102102
assert(unsigned(rx) < NumRegs && "Invalid index");
103-
assert(LiveRegs && "Must enter basic block first.");
103+
assert(!LiveRegs.empty() && "Must enter basic block first.");
104104
if (!LiveRegs[rx].Value)
105105
return;
106106

@@ -111,7 +111,7 @@ void ExecutionDomainFix::kill(int rx) {
111111
/// Force register rx into domain.
112112
void ExecutionDomainFix::force(int rx, unsigned domain) {
113113
assert(unsigned(rx) < NumRegs && "Invalid index");
114-
assert(LiveRegs && "Must enter basic block first.");
114+
assert(!LiveRegs.empty() && "Must enter basic block first.");
115115
if (DomainValue *dv = LiveRegs[rx].Value) {
116116
if (dv->isCollapsed())
117117
dv->addDomain(domain);
@@ -141,7 +141,7 @@ void ExecutionDomainFix::collapse(DomainValue *dv, unsigned domain) {
141141
dv->setSingleDomain(domain);
142142

143143
// If there are multiple users, give them new, unique DomainValues.
144-
if (LiveRegs && dv->Refs > 1)
144+
if (!LiveRegs.empty() && dv->Refs > 1)
145145
for (unsigned rx = 0; rx != NumRegs; ++rx)
146146
if (LiveRegs[rx].Value == dv)
147147
setLiveReg(rx, alloc(domain));
@@ -166,7 +166,7 @@ bool ExecutionDomainFix::merge(DomainValue *A, DomainValue *B) {
166166
B->Next = retain(A);
167167

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

188188
// Set up LiveRegs to represent registers entering MBB.
189-
if (!LiveRegs)
190-
LiveRegs = new LiveReg[NumRegUnits];
189+
if (LiveRegs.empty())
190+
LiveRegs.resize(NumRegUnits);
191191

192-
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
193-
LiveRegs[Unit].Def = ReachingDedDefaultVal;
192+
for (LiveReg &LiveRegDef : LiveRegs) {
193+
LiveRegDef.Def = ReachingDedDefaultVal;
194194
}
195195

196196
// This is the entry block.
@@ -212,10 +212,10 @@ void ReachingDefAnalysis::enterBasicBlock(
212212
for (MachineBasicBlock* pred : MBB->predecessors()) {
213213
assert(pred->getNumber() < MBBOutRegsInfos.size() &&
214214
"Should have pre-allocated MBBInfos for all MBBs");
215-
LiveReg *Incoming = MBBOutRegsInfos[pred->getNumber()];
215+
const LiveRegsDefInfo& Incoming = MBBOutRegsInfos[pred->getNumber()];
216216
// Incoming is null if this is a backedge from a BB
217217
// we haven't processed yet
218-
if (Incoming == nullptr)
218+
if (Incoming.empty())
219219
continue;
220220

221221
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
@@ -238,11 +238,11 @@ void ExecutionDomainFix::enterBasicBlock(
238238
MachineBasicBlock *MBB = TraversedMBB.MBB;
239239

240240
// Set up LiveRegs to represent registers entering MBB.
241-
if (!LiveRegs)
242-
LiveRegs = new LiveReg[NumRegs];
241+
if (LiveRegs.empty())
242+
LiveRegs.resize(NumRegs);
243243

244-
for (unsigned rx = 0; rx != NumRegs; ++rx) {
245-
LiveRegs[rx].Value = nullptr;
244+
for (LiveReg &LiveRegDef : LiveRegs) {
245+
LiveRegDef.Value = nullptr;
246246
}
247247

248248
// This is the entry block.
@@ -255,10 +255,10 @@ void ExecutionDomainFix::enterBasicBlock(
255255
for (MachineBasicBlock* pred : MBB->predecessors()) {
256256
assert(pred->getNumber() < MBBOutRegsInfos.size() &&
257257
"Should have pre-allocated MBBInfos for all MBBs");
258-
LiveReg *Incoming = MBBOutRegsInfos[pred->getNumber()];
258+
LiveRegsDVInfo& Incoming = MBBOutRegsInfos[pred->getNumber()];
259259
// Incoming is null if this is a backedge from a BB
260260
// we haven't processed yet
261-
if (Incoming == nullptr)
261+
if (Incoming.empty())
262262
continue;
263263

264264
for (unsigned rx = 0; rx != NumRegs; ++rx) {
@@ -293,7 +293,7 @@ void ExecutionDomainFix::enterBasicBlock(
293293

294294
void ReachingDefAnalysis::leaveBasicBlock(
295295
const LoopTraversal::TraversedMBBInfo &TraversedMBB) {
296-
assert(LiveRegs && "Must enter basic block first.");
296+
assert(!LiveRegs.empty() && "Must enter basic block first.");
297297
int MBBNumber = TraversedMBB.MBB->getNumber();
298298
assert(MBBNumber < MBBOutRegsInfos.size() && "Unexpected basic block number.");
299299
// Save register clearances at end of MBB - used by enterBasicBlock().
@@ -303,27 +303,24 @@ void ReachingDefAnalysis::leaveBasicBlock(
303303
// of the basic block for convenience. However, future use of this information
304304
// only cares about the clearance from the end of the block, so adjust
305305
// everything to be relative to the end of the basic block.
306-
for (unsigned i = 0, e = NumRegUnits; i != e; ++i)
307-
LiveRegs[i].Def -= CurInstr;
308-
LiveRegs = nullptr;
306+
for (LiveReg &OutLiveReg : MBBOutRegsInfos[MBBNumber])
307+
OutLiveReg.Def -= CurInstr;
308+
LiveRegs.clear();
309309
}
310310

311311
void ExecutionDomainFix::leaveBasicBlock(
312312
const LoopTraversal::TraversedMBBInfo &TraversedMBB) {
313-
assert(LiveRegs && "Must enter basic block first.");
313+
assert(!LiveRegs.empty() && "Must enter basic block first.");
314314
int MBBNumber = TraversedMBB.MBB->getNumber();
315315
assert(MBBNumber < MBBOutRegsInfos.size() && "Unexpected basic block number.");
316-
LiveReg *OldOutRegs = MBBOutRegsInfos[MBBNumber];
316+
LiveRegsDVInfo OldOutRegs = MBBOutRegsInfos[MBBNumber];
317317
// Save register clearances at end of MBB - used by enterBasicBlock().
318318
MBBOutRegsInfos[MBBNumber] = LiveRegs;
319-
if (OldOutRegs) {
320-
// This must be the second pass.
321-
// Release all the DomainValues instead of keeping them.
322-
for (unsigned i = 0, e = NumRegs; i != e; ++i)
323-
release(OldOutRegs[i].Value);
324-
delete[] OldOutRegs;
319+
for (LiveReg &OldLiveReg : OldOutRegs) {
320+
release(OldLiveReg.Value);
325321
}
326-
LiveRegs = nullptr;
322+
OldOutRegs.clear();
323+
LiveRegs.clear();
327324
}
328325

329326
bool ExecutionDomainFix::visitInstr(MachineInstr *MI) {
@@ -574,7 +571,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
574571

575572
// Scan the explicit use operands for incoming domains.
576573
SmallVector<int, 4> used;
577-
if (LiveRegs)
574+
if (!LiveRegs.empty())
578575
for (unsigned i = mi->getDesc().getNumDefs(),
579576
e = mi->getDesc().getNumOperands(); i != e; ++i) {
580577
MachineOperand &mo = mi->getOperand(i);
@@ -613,7 +610,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
613610
// incoming DomainValues that we want to merge.
614611
SmallVector<const LiveReg *, 4> Regs;
615612
for (int rx : used) {
616-
assert(LiveRegs && "no space allocated for live registers");
613+
assert(!LiveRegs.empty() && "no space allocated for live registers");
617614
LiveReg &LR = LiveRegs[rx];
618615
LR.Def = RDA->getReachingDef(mi, RC->getRegister(rx));
619616
// This useless DomainValue could have been missed above.
@@ -650,7 +647,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
650647

651648
// If latest didn't merge, it is useless now. Kill all registers using it.
652649
for (int i : used) {
653-
assert(LiveRegs && "no space allocated for live registers");
650+
assert(!LiveRegs.empty() && "no space allocated for live registers");
654651
if (LiveRegs[i].Value == Latest)
655652
kill(i);
656653
}
@@ -813,7 +810,7 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
813810
MF = &mf;
814811
TII = MF->getSubtarget().getInstrInfo();
815812
TRI = MF->getSubtarget().getRegisterInfo();
816-
LiveRegs = nullptr;
813+
LiveRegs.clear();
817814
assert(NumRegs == RC->getNumRegs() && "Bad regclass");
818815

819816
DEBUG(dbgs() << "********** FIX EXECUTION DOMAIN: "
@@ -845,7 +842,7 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
845842
}
846843

847844
// Initialize the MBBOutRegsInfos
848-
MBBOutRegsInfos.assign(mf.getNumBlockIDs(), nullptr);
845+
MBBOutRegsInfos.resize(mf.getNumBlockIDs());
849846

850847
// Traverse the basic blocks.
851848
LoopTraversal Traversal;
@@ -854,13 +851,11 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
854851
processBasicBlock(TraversedMBB);
855852
}
856853

857-
for (auto MBBOutRegs : MBBOutRegsInfos) {
858-
if (!MBBOutRegs)
859-
continue;
860-
for (unsigned i = 0, e = NumRegs; i != e; ++i)
861-
if (MBBOutRegs[i].Value)
862-
release(MBBOutRegs[i].Value);
863-
delete[] MBBOutRegs;
854+
for (LiveRegsDVInfo OutLiveRegs: MBBOutRegsInfos) {
855+
for (LiveReg OutLiveReg : OutLiveRegs) {
856+
if (OutLiveReg.Value)
857+
release(OutLiveReg.Value);
858+
}
864859
}
865860
MBBOutRegsInfos.clear();
866861
Avail.clear();
@@ -876,15 +871,15 @@ bool ReachingDefAnalysis::runOnMachineFunction(MachineFunction &mf) {
876871
TII = MF->getSubtarget().getInstrInfo();
877872
TRI = MF->getSubtarget().getRegisterInfo();
878873

879-
LiveRegs = nullptr;
874+
LiveRegs.clear();
880875
NumRegUnits = TRI->getNumRegUnits();
881876

882877
MBBReachingDefs.resize(mf.getNumBlockIDs());
883878

884879
DEBUG(dbgs() << "********** REACHING DEFINITION ANALYSIS **********\n");
885880

886881
// Initialize the MBBOutRegsInfos
887-
MBBOutRegsInfos.assign(mf.getNumBlockIDs(), nullptr);
882+
MBBOutRegsInfos.resize(mf.getNumBlockIDs());
888883

889884
// Traverse the basic blocks.
890885
LoopTraversal Traversal;
@@ -903,12 +898,7 @@ bool ReachingDefAnalysis::runOnMachineFunction(MachineFunction &mf) {
903898
}
904899

905900
void ReachingDefAnalysis::releaseMemory() {
906-
// Clear the LiveOuts vectors and collapse any remaining DomainValues.
907-
for (auto MBBOutRegs : MBBOutRegsInfos) {
908-
if (!MBBOutRegs)
909-
continue;
910-
delete[] MBBOutRegs;
911-
}
901+
// Clear the internal vectors.
912902
MBBOutRegsInfos.clear();
913903
MBBReachingDefs.clear();
914904
InstIds.clear();

0 commit comments

Comments
 (0)