@@ -88,7 +88,7 @@ DomainValue *ExecutionDomainFix::resolve(DomainValue *&DVRef) {
88
88
// / Set LiveRegs[rx] = dv, updating reference counts.
89
89
void ExecutionDomainFix::setLiveReg (int rx, DomainValue *dv) {
90
90
assert (unsigned (rx) < NumRegs && " Invalid index" );
91
- assert (LiveRegs && " Must enter basic block first." );
91
+ assert (! LiveRegs. empty () && " Must enter basic block first." );
92
92
93
93
if (LiveRegs[rx].Value == dv)
94
94
return ;
@@ -100,7 +100,7 @@ void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) {
100
100
// Kill register rx, recycle or collapse any DomainValue.
101
101
void ExecutionDomainFix::kill (int rx) {
102
102
assert (unsigned (rx) < NumRegs && " Invalid index" );
103
- assert (LiveRegs && " Must enter basic block first." );
103
+ assert (! LiveRegs. empty () && " Must enter basic block first." );
104
104
if (!LiveRegs[rx].Value )
105
105
return ;
106
106
@@ -111,7 +111,7 @@ void ExecutionDomainFix::kill(int rx) {
111
111
// / Force register rx into domain.
112
112
void ExecutionDomainFix::force (int rx, unsigned domain) {
113
113
assert (unsigned (rx) < NumRegs && " Invalid index" );
114
- assert (LiveRegs && " Must enter basic block first." );
114
+ assert (! LiveRegs. empty () && " Must enter basic block first." );
115
115
if (DomainValue *dv = LiveRegs[rx].Value ) {
116
116
if (dv->isCollapsed ())
117
117
dv->addDomain (domain);
@@ -141,7 +141,7 @@ void ExecutionDomainFix::collapse(DomainValue *dv, unsigned domain) {
141
141
dv->setSingleDomain (domain);
142
142
143
143
// If there are multiple users, give them new, unique DomainValues.
144
- if (LiveRegs && dv->Refs > 1 )
144
+ if (! LiveRegs. empty () && dv->Refs > 1 )
145
145
for (unsigned rx = 0 ; rx != NumRegs; ++rx)
146
146
if (LiveRegs[rx].Value == dv)
147
147
setLiveReg (rx, alloc (domain));
@@ -166,7 +166,7 @@ bool ExecutionDomainFix::merge(DomainValue *A, DomainValue *B) {
166
166
B->Next = retain (A);
167
167
168
168
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" );
170
170
if (LiveRegs[rx].Value == B)
171
171
setLiveReg (rx, A);
172
172
}
@@ -186,11 +186,11 @@ void ReachingDefAnalysis::enterBasicBlock(
186
186
CurInstr = 0 ;
187
187
188
188
// Set up LiveRegs to represent registers entering MBB.
189
- if (! LiveRegs)
190
- LiveRegs = new LiveReg[ NumRegUnits] ;
189
+ if (LiveRegs. empty () )
190
+ LiveRegs. resize ( NumRegUnits) ;
191
191
192
- for (unsigned Unit = 0 ; Unit != NumRegUnits; ++Unit ) {
193
- LiveRegs[Unit] .Def = ReachingDedDefaultVal;
192
+ for (LiveReg &LiveRegDef : LiveRegs ) {
193
+ LiveRegDef .Def = ReachingDedDefaultVal;
194
194
}
195
195
196
196
// This is the entry block.
@@ -212,10 +212,10 @@ void ReachingDefAnalysis::enterBasicBlock(
212
212
for (MachineBasicBlock* pred : MBB->predecessors ()) {
213
213
assert (pred->getNumber () < MBBOutRegsInfos.size () &&
214
214
" Should have pre-allocated MBBInfos for all MBBs" );
215
- LiveReg * Incoming = MBBOutRegsInfos[pred->getNumber ()];
215
+ const LiveRegsDefInfo& Incoming = MBBOutRegsInfos[pred->getNumber ()];
216
216
// Incoming is null if this is a backedge from a BB
217
217
// we haven't processed yet
218
- if (Incoming == nullptr )
218
+ if (Incoming. empty () )
219
219
continue ;
220
220
221
221
for (unsigned Unit = 0 ; Unit != NumRegUnits; ++Unit) {
@@ -238,11 +238,11 @@ void ExecutionDomainFix::enterBasicBlock(
238
238
MachineBasicBlock *MBB = TraversedMBB.MBB ;
239
239
240
240
// Set up LiveRegs to represent registers entering MBB.
241
- if (! LiveRegs)
242
- LiveRegs = new LiveReg[ NumRegs] ;
241
+ if (LiveRegs. empty () )
242
+ LiveRegs. resize ( NumRegs) ;
243
243
244
- for (unsigned rx = 0 ; rx != NumRegs; ++rx ) {
245
- LiveRegs[rx] .Value = nullptr ;
244
+ for (LiveReg &LiveRegDef : LiveRegs ) {
245
+ LiveRegDef .Value = nullptr ;
246
246
}
247
247
248
248
// This is the entry block.
@@ -255,10 +255,10 @@ void ExecutionDomainFix::enterBasicBlock(
255
255
for (MachineBasicBlock* pred : MBB->predecessors ()) {
256
256
assert (pred->getNumber () < MBBOutRegsInfos.size () &&
257
257
" Should have pre-allocated MBBInfos for all MBBs" );
258
- LiveReg * Incoming = MBBOutRegsInfos[pred->getNumber ()];
258
+ LiveRegsDVInfo& Incoming = MBBOutRegsInfos[pred->getNumber ()];
259
259
// Incoming is null if this is a backedge from a BB
260
260
// we haven't processed yet
261
- if (Incoming == nullptr )
261
+ if (Incoming. empty () )
262
262
continue ;
263
263
264
264
for (unsigned rx = 0 ; rx != NumRegs; ++rx) {
@@ -293,7 +293,7 @@ void ExecutionDomainFix::enterBasicBlock(
293
293
294
294
void ReachingDefAnalysis::leaveBasicBlock (
295
295
const LoopTraversal::TraversedMBBInfo &TraversedMBB) {
296
- assert (LiveRegs && " Must enter basic block first." );
296
+ assert (! LiveRegs. empty () && " Must enter basic block first." );
297
297
int MBBNumber = TraversedMBB.MBB ->getNumber ();
298
298
assert (MBBNumber < MBBOutRegsInfos.size () && " Unexpected basic block number." );
299
299
// Save register clearances at end of MBB - used by enterBasicBlock().
@@ -303,27 +303,24 @@ void ReachingDefAnalysis::leaveBasicBlock(
303
303
// of the basic block for convenience. However, future use of this information
304
304
// only cares about the clearance from the end of the block, so adjust
305
305
// 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 () ;
309
309
}
310
310
311
311
void ExecutionDomainFix::leaveBasicBlock (
312
312
const LoopTraversal::TraversedMBBInfo &TraversedMBB) {
313
- assert (LiveRegs && " Must enter basic block first." );
313
+ assert (! LiveRegs. empty () && " Must enter basic block first." );
314
314
int MBBNumber = TraversedMBB.MBB ->getNumber ();
315
315
assert (MBBNumber < MBBOutRegsInfos.size () && " Unexpected basic block number." );
316
- LiveReg * OldOutRegs = MBBOutRegsInfos[MBBNumber];
316
+ LiveRegsDVInfo OldOutRegs = MBBOutRegsInfos[MBBNumber];
317
317
// Save register clearances at end of MBB - used by enterBasicBlock().
318
318
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 );
325
321
}
326
- LiveRegs = nullptr ;
322
+ OldOutRegs.clear ();
323
+ LiveRegs.clear ();
327
324
}
328
325
329
326
bool ExecutionDomainFix::visitInstr (MachineInstr *MI) {
@@ -574,7 +571,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
574
571
575
572
// Scan the explicit use operands for incoming domains.
576
573
SmallVector<int , 4 > used;
577
- if (LiveRegs)
574
+ if (! LiveRegs. empty () )
578
575
for (unsigned i = mi->getDesc ().getNumDefs (),
579
576
e = mi->getDesc ().getNumOperands (); i != e; ++i) {
580
577
MachineOperand &mo = mi->getOperand (i);
@@ -613,7 +610,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
613
610
// incoming DomainValues that we want to merge.
614
611
SmallVector<const LiveReg *, 4 > Regs;
615
612
for (int rx : used) {
616
- assert (LiveRegs && " no space allocated for live registers" );
613
+ assert (! LiveRegs. empty () && " no space allocated for live registers" );
617
614
LiveReg &LR = LiveRegs[rx];
618
615
LR.Def = RDA->getReachingDef (mi, RC->getRegister (rx));
619
616
// This useless DomainValue could have been missed above.
@@ -650,7 +647,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
650
647
651
648
// If latest didn't merge, it is useless now. Kill all registers using it.
652
649
for (int i : used) {
653
- assert (LiveRegs && " no space allocated for live registers" );
650
+ assert (! LiveRegs. empty () && " no space allocated for live registers" );
654
651
if (LiveRegs[i].Value == Latest)
655
652
kill (i);
656
653
}
@@ -813,7 +810,7 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
813
810
MF = &mf;
814
811
TII = MF->getSubtarget ().getInstrInfo ();
815
812
TRI = MF->getSubtarget ().getRegisterInfo ();
816
- LiveRegs = nullptr ;
813
+ LiveRegs. clear () ;
817
814
assert (NumRegs == RC->getNumRegs () && " Bad regclass" );
818
815
819
816
DEBUG (dbgs () << " ********** FIX EXECUTION DOMAIN: "
@@ -845,7 +842,7 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
845
842
}
846
843
847
844
// Initialize the MBBOutRegsInfos
848
- MBBOutRegsInfos.assign (mf.getNumBlockIDs (), nullptr );
845
+ MBBOutRegsInfos.resize (mf.getNumBlockIDs ());
849
846
850
847
// Traverse the basic blocks.
851
848
LoopTraversal Traversal;
@@ -854,13 +851,11 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
854
851
processBasicBlock (TraversedMBB);
855
852
}
856
853
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
+ }
864
859
}
865
860
MBBOutRegsInfos.clear ();
866
861
Avail.clear ();
@@ -876,15 +871,15 @@ bool ReachingDefAnalysis::runOnMachineFunction(MachineFunction &mf) {
876
871
TII = MF->getSubtarget ().getInstrInfo ();
877
872
TRI = MF->getSubtarget ().getRegisterInfo ();
878
873
879
- LiveRegs = nullptr ;
874
+ LiveRegs. clear () ;
880
875
NumRegUnits = TRI->getNumRegUnits ();
881
876
882
877
MBBReachingDefs.resize (mf.getNumBlockIDs ());
883
878
884
879
DEBUG (dbgs () << " ********** REACHING DEFINITION ANALYSIS **********\n " );
885
880
886
881
// Initialize the MBBOutRegsInfos
887
- MBBOutRegsInfos.assign (mf.getNumBlockIDs (), nullptr );
882
+ MBBOutRegsInfos.resize (mf.getNumBlockIDs ());
888
883
889
884
// Traverse the basic blocks.
890
885
LoopTraversal Traversal;
@@ -903,12 +898,7 @@ bool ReachingDefAnalysis::runOnMachineFunction(MachineFunction &mf) {
903
898
}
904
899
905
900
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.
912
902
MBBOutRegsInfos.clear ();
913
903
MBBReachingDefs.clear ();
914
904
InstIds.clear ();
0 commit comments