@@ -90,29 +90,29 @@ void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) {
90
90
assert (unsigned (rx) < NumRegs && " Invalid index" );
91
91
assert (!LiveRegs.empty () && " Must enter basic block first." );
92
92
93
- if (LiveRegs[rx]. Value == dv)
93
+ if (LiveRegs[rx] == dv)
94
94
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);
98
98
}
99
99
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
103
assert (!LiveRegs.empty () && " Must enter basic block first." );
104
- if (!LiveRegs[rx]. Value )
104
+ if (!LiveRegs[rx])
105
105
return ;
106
106
107
- release (LiveRegs[rx]. Value );
108
- LiveRegs[rx]. Value = nullptr ;
107
+ release (LiveRegs[rx]);
108
+ LiveRegs[rx] = nullptr ;
109
109
}
110
110
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
114
assert (!LiveRegs.empty () && " Must enter basic block first." );
115
- if (DomainValue *dv = LiveRegs[rx]. Value ) {
115
+ if (DomainValue *dv = LiveRegs[rx]) {
116
116
if (dv->isCollapsed ())
117
117
dv->addDomain (domain);
118
118
else if (dv->hasDomain (domain))
@@ -121,8 +121,8 @@ void ExecutionDomainFix::force(int rx, unsigned domain) {
121
121
// This is an incompatible open DomainValue. Collapse it to whatever and
122
122
// force the new value into domain. This costs a domain crossing.
123
123
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);
126
126
}
127
127
} else {
128
128
// Set up basic collapsed DomainValue.
@@ -143,7 +143,7 @@ void ExecutionDomainFix::collapse(DomainValue *dv, unsigned domain) {
143
143
// If there are multiple users, give them new, unique DomainValues.
144
144
if (!LiveRegs.empty () && dv->Refs > 1 )
145
145
for (unsigned rx = 0 ; rx != NumRegs; ++rx)
146
- if (LiveRegs[rx]. Value == dv)
146
+ if (LiveRegs[rx] == dv)
147
147
setLiveReg (rx, alloc (domain));
148
148
}
149
149
@@ -167,7 +167,7 @@ bool ExecutionDomainFix::merge(DomainValue *A, DomainValue *B) {
167
167
168
168
for (unsigned rx = 0 ; rx != NumRegs; ++rx) {
169
169
assert (!LiveRegs.empty () && " no space allocated for live registers" );
170
- if (LiveRegs[rx]. Value == B)
170
+ if (LiveRegs[rx] == B)
171
171
setLiveReg (rx, A);
172
172
}
173
173
return true ;
@@ -186,12 +186,9 @@ void ReachingDefAnalysis::enterBasicBlock(
186
186
CurInstr = 0 ;
187
187
188
188
// Set up LiveRegs to represent registers entering MBB.
189
+ // Default values are 'nothing happened a long time ago'.
189
190
if (LiveRegs.empty ())
190
- LiveRegs.resize (NumRegUnits);
191
-
192
- for (LiveReg &LiveRegDef : LiveRegs) {
193
- LiveRegDef.Def = ReachingDedDefaultVal;
194
- }
191
+ LiveRegs.assign (NumRegUnits, ReachingDedDefaultVal);
195
192
196
193
// This is the entry block.
197
194
if (MBB->pred_empty ()) {
@@ -200,8 +197,8 @@ void ReachingDefAnalysis::enterBasicBlock(
200
197
// Treat function live-ins as if they were defined just before the first
201
198
// instruction. Usually, function arguments are set up immediately
202
199
// 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]);
205
202
}
206
203
}
207
204
DEBUG (dbgs () << printMBBReference (*MBB) << " : entry\n " );
@@ -220,9 +217,9 @@ void ReachingDefAnalysis::enterBasicBlock(
220
217
221
218
for (unsigned Unit = 0 ; Unit != NumRegUnits; ++Unit) {
222
219
// 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]);
226
223
}
227
224
}
228
225
@@ -238,12 +235,9 @@ void ExecutionDomainFix::enterBasicBlock(
238
235
MachineBasicBlock *MBB = TraversedMBB.MBB ;
239
236
240
237
// Set up LiveRegs to represent registers entering MBB.
238
+ // Set default domain values to 'no domain' (nullptr)
241
239
if (LiveRegs.empty ())
242
- LiveRegs.resize (NumRegs);
243
-
244
- for (LiveReg &LiveRegDef : LiveRegs) {
245
- LiveRegDef.Value = nullptr ;
246
- }
240
+ LiveRegs.assign (NumRegs, nullptr );
247
241
248
242
// This is the entry block.
249
243
if (MBB->pred_empty ()) {
@@ -262,26 +256,26 @@ void ExecutionDomainFix::enterBasicBlock(
262
256
continue ;
263
257
264
258
for (unsigned rx = 0 ; rx != NumRegs; ++rx) {
265
- DomainValue *pdv = resolve (Incoming[rx]. Value );
259
+ DomainValue *pdv = resolve (Incoming[rx]);
266
260
if (!pdv)
267
261
continue ;
268
- if (!LiveRegs[rx]. Value ) {
262
+ if (!LiveRegs[rx]) {
269
263
setLiveReg (rx, pdv);
270
264
continue ;
271
265
}
272
266
273
267
// We have a live DomainValue from more than one predecessor.
274
- if (LiveRegs[rx]. Value ->isCollapsed ()) {
268
+ if (LiveRegs[rx]->isCollapsed ()) {
275
269
// We are already collapsed, but predecessor is not. Force it.
276
- unsigned Domain = LiveRegs[rx]. Value ->getFirstDomain ();
270
+ unsigned Domain = LiveRegs[rx]->getFirstDomain ();
277
271
if (!pdv->isCollapsed () && pdv->hasDomain (Domain))
278
272
collapse (pdv, Domain);
279
273
continue ;
280
274
}
281
275
282
276
// Currently open, merge in predecessor.
283
277
if (!pdv->isCollapsed ())
284
- merge (LiveRegs[rx]. Value , pdv);
278
+ merge (LiveRegs[rx], pdv);
285
279
else
286
280
force (rx, pdv->getFirstDomain ());
287
281
}
@@ -303,8 +297,8 @@ void ReachingDefAnalysis::leaveBasicBlock(
303
297
// of the basic block for convenience. However, future use of this information
304
298
// only cares about the clearance from the end of the block, so adjust
305
299
// 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;
308
302
LiveRegs.clear ();
309
303
}
310
304
@@ -313,13 +307,11 @@ void ExecutionDomainFix::leaveBasicBlock(
313
307
assert (!LiveRegs.empty () && " Must enter basic block first." );
314
308
int MBBNumber = TraversedMBB.MBB ->getNumber ();
315
309
assert (MBBNumber < MBBOutRegsInfos.size () && " Unexpected basic block number." );
316
- LiveRegsDVInfo OldOutRegs = MBBOutRegsInfos[MBBNumber];
317
310
// 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);
321
313
}
322
- OldOutRegs. clear () ;
314
+ MBBOutRegsInfos[MBBNumber] = LiveRegs ;
323
315
LiveRegs.clear ();
324
316
}
325
317
@@ -461,7 +453,7 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) {
461
453
<< *MI);
462
454
463
455
// How many instructions since this reg unit was last written?
464
- LiveRegs[*Unit]. Def = CurInstr;
456
+ LiveRegs[*Unit] = CurInstr;
465
457
MBBReachingDefs[MBBNumber][*Unit].push_back (CurInstr);
466
458
}
467
459
}
@@ -577,7 +569,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
577
569
MachineOperand &mo = mi->getOperand (i);
578
570
if (!mo.isReg ()) continue ;
579
571
for (int rx : regIndices (mo.getReg ())) {
580
- DomainValue *dv = LiveRegs[rx]. Value ;
572
+ DomainValue *dv = LiveRegs[rx];
581
573
if (dv == nullptr )
582
574
continue ;
583
575
// Bitmask of domains that dv and available have in common.
@@ -608,37 +600,38 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
608
600
609
601
// Kill off any remaining uses that don't match available, and build a list of
610
602
// incoming DomainValues that we want to merge.
611
- SmallVector<const LiveReg * , 4 > Regs;
603
+ SmallVector<int , 4 > Regs;
612
604
for (int rx : used) {
613
605
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];
616
607
// This useless DomainValue could have been missed above.
617
- if (!LR. Value ->getCommonDomains (available)) {
608
+ if (!LR->getCommonDomains (available)) {
618
609
kill (rx);
619
610
continue ;
620
611
}
621
612
// 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));
625
618
});
626
- Regs.insert (I, &LR );
619
+ Regs.insert (I, rx );
627
620
}
628
621
629
622
// doms are now sorted in order of appearance. Try to merge them all, giving
630
623
// priority to the latest ones.
631
624
DomainValue *dv = nullptr ;
632
625
while (!Regs.empty ()) {
633
626
if (!dv) {
634
- dv = Regs.pop_back_val ()-> Value ;
627
+ dv = LiveRegs[ Regs.pop_back_val ()] ;
635
628
// Force the first dv to match the current instruction.
636
629
dv->AvailableDomains = dv->getCommonDomains (available);
637
630
assert (dv->AvailableDomains && " Domain should have been filtered" );
638
631
continue ;
639
632
}
640
633
641
- DomainValue *Latest = Regs.pop_back_val ()-> Value ;
634
+ DomainValue *Latest = LiveRegs[ Regs.pop_back_val ()] ;
642
635
// Skip already merged values.
643
636
if (Latest == dv || Latest->Next )
644
637
continue ;
@@ -648,7 +641,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
648
641
// If latest didn't merge, it is useless now. Kill all registers using it.
649
642
for (int i : used) {
650
643
assert (!LiveRegs.empty () && " no space allocated for live registers" );
651
- if (LiveRegs[i]. Value == Latest)
644
+ if (LiveRegs[i] == Latest)
652
645
kill (i);
653
646
}
654
647
}
@@ -665,7 +658,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
665
658
for (MachineOperand &mo : mi->operands ()) {
666
659
if (!mo.isReg ()) continue ;
667
660
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)) {
669
662
kill (rx);
670
663
setLiveReg (rx, dv);
671
664
}
@@ -852,9 +845,9 @@ bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) {
852
845
}
853
846
854
847
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);
858
851
}
859
852
}
860
853
MBBOutRegsInfos.clear ();
0 commit comments