24
24
#include " llvm/CodeGen/TargetSchedule.h"
25
25
#include " llvm/CodeGen/TargetSubtargetInfo.h"
26
26
#include " llvm/InitializePasses.h"
27
- #include " llvm/MC/MCRegisterInfo.h"
28
27
#include " llvm/Pass.h"
29
28
#include " llvm/Support/Debug.h"
30
29
#include " llvm/Support/ErrorHandling.h"
31
30
#include " llvm/Support/Format.h"
32
31
#include " llvm/Support/raw_ostream.h"
33
- #include < algorithm>
34
- #include < cassert>
35
- #include < iterator>
36
- #include < tuple>
37
- #include < utility>
38
32
39
33
using namespace llvm ;
40
34
@@ -133,7 +127,7 @@ MachineTraceMetrics::getResources(const MachineBasicBlock *MBB) {
133
127
134
128
// Scale the resource cycles so they are comparable.
135
129
unsigned PROffset = MBB->getNumber () * PRKinds;
136
- for (unsigned K = 0 ; K != PRKinds; ++K)
130
+ for (unsigned K = 0 ; K < PRKinds; ++K)
137
131
ProcReleaseAtCycles[PROffset + K] =
138
132
PRCycles[K] * SchedModel.getResourceFactor (K);
139
133
@@ -146,15 +140,14 @@ MachineTraceMetrics::getProcReleaseAtCycles(unsigned MBBNum) const {
146
140
" getResources() must be called before getProcReleaseAtCycles()" );
147
141
unsigned PRKinds = SchedModel.getNumProcResourceKinds ();
148
142
assert ((MBBNum+1 ) * PRKinds <= ProcReleaseAtCycles.size ());
149
- return ArrayRef ( ProcReleaseAtCycles.data () + MBBNum * PRKinds, PRKinds) ;
143
+ return ArrayRef{ ProcReleaseAtCycles.data () + MBBNum * PRKinds, PRKinds} ;
150
144
}
151
145
152
146
// ===----------------------------------------------------------------------===//
153
147
// Ensemble utility functions
154
148
// ===----------------------------------------------------------------------===//
155
149
156
- MachineTraceMetrics::Ensemble::Ensemble (MachineTraceMetrics *ct)
157
- : MTM(*ct) {
150
+ MachineTraceMetrics::Ensemble::Ensemble (MachineTraceMetrics *CT) : MTM(*CT) {
158
151
BlockInfo.resize (MTM.BlockInfo .size ());
159
152
unsigned PRKinds = MTM.SchedModel .getNumProcResourceKinds ();
160
153
ProcResourceDepths.resize (MTM.BlockInfo .size () * PRKinds);
@@ -198,7 +191,7 @@ computeDepthResources(const MachineBasicBlock *MBB) {
198
191
// Compute per-resource depths.
199
192
ArrayRef<unsigned > PredPRDepths = getProcResourceDepths (PredNum);
200
193
ArrayRef<unsigned > PredPRCycles = MTM.getProcReleaseAtCycles (PredNum);
201
- for (unsigned K = 0 ; K != PRKinds; ++K)
194
+ for (unsigned K = 0 ; K < PRKinds; ++K)
202
195
ProcResourceDepths[PROffset + K] = PredPRDepths[K] + PredPRCycles[K];
203
196
}
204
197
@@ -231,7 +224,7 @@ computeHeightResources(const MachineBasicBlock *MBB) {
231
224
232
225
// Compute per-resource heights.
233
226
ArrayRef<unsigned > SuccPRHeights = getProcResourceHeights (SuccNum);
234
- for (unsigned K = 0 ; K != PRKinds; ++K)
227
+ for (unsigned K = 0 ; K < PRKinds; ++K)
235
228
ProcResourceHeights[PROffset + K] = SuccPRHeights[K] + PRCycles[K];
236
229
}
237
230
@@ -264,7 +257,7 @@ MachineTraceMetrics::Ensemble::
264
257
getProcResourceDepths (unsigned MBBNum) const {
265
258
unsigned PRKinds = MTM.SchedModel .getNumProcResourceKinds ();
266
259
assert ((MBBNum+1 ) * PRKinds <= ProcResourceDepths.size ());
267
- return ArrayRef ( ProcResourceDepths.data () + MBBNum * PRKinds, PRKinds) ;
260
+ return ArrayRef{ ProcResourceDepths.data () + MBBNum * PRKinds, PRKinds} ;
268
261
}
269
262
270
263
// / Get an array of processor resource heights for MBB. Indexed by processor
@@ -277,7 +270,7 @@ MachineTraceMetrics::Ensemble::
277
270
getProcResourceHeights (unsigned MBBNum) const {
278
271
unsigned PRKinds = MTM.SchedModel .getNumProcResourceKinds ();
279
272
assert ((MBBNum+1 ) * PRKinds <= ProcResourceHeights.size ());
280
- return ArrayRef ( ProcResourceHeights.data () + MBBNum * PRKinds, PRKinds) ;
273
+ return ArrayRef{ ProcResourceHeights.data () + MBBNum * PRKinds, PRKinds} ;
281
274
}
282
275
283
276
// ===----------------------------------------------------------------------===//
@@ -314,8 +307,8 @@ class MinInstrCountEnsemble : public MachineTraceMetrics::Ensemble {
314
307
const MachineBasicBlock *pickTraceSucc (const MachineBasicBlock*) override ;
315
308
316
309
public:
317
- MinInstrCountEnsemble (MachineTraceMetrics *mtm )
318
- : MachineTraceMetrics::Ensemble(mtm ) {}
310
+ MinInstrCountEnsemble (MachineTraceMetrics *MTM )
311
+ : MachineTraceMetrics::Ensemble(MTM ) {}
319
312
};
320
313
321
314
// / Pick only the current basic block for the trace and do not choose any
@@ -395,15 +388,15 @@ MinInstrCountEnsemble::pickTraceSucc(const MachineBasicBlock *MBB) {
395
388
396
389
// Get an Ensemble sub-class for the requested trace strategy.
397
390
MachineTraceMetrics::Ensemble *
398
- MachineTraceMetrics::getEnsemble (MachineTraceStrategy strategy ) {
399
- assert (strategy < MachineTraceStrategy::TS_NumStrategies &&
391
+ MachineTraceMetrics::getEnsemble (MachineTraceStrategy Strategy ) {
392
+ assert (Strategy < MachineTraceStrategy::TS_NumStrategies &&
400
393
" Invalid trace strategy enum" );
401
- Ensemble *&E = Ensembles[static_cast <size_t >(strategy )];
394
+ Ensemble *&E = Ensembles[static_cast <size_t >(Strategy )];
402
395
if (E)
403
396
return E;
404
397
405
398
// Allocate new Ensemble on demand.
406
- switch (strategy ) {
399
+ switch (Strategy ) {
407
400
case MachineTraceStrategy::TS_MinInstrCount:
408
401
return (E = new MinInstrCountEnsemble (this ));
409
402
case MachineTraceStrategy::TS_Local:
@@ -448,8 +441,9 @@ struct LoopBounds {
448
441
const MachineLoopInfo *Loops;
449
442
bool Downward = false ;
450
443
451
- LoopBounds (MutableArrayRef<MachineTraceMetrics::TraceBlockInfo> blocks,
452
- const MachineLoopInfo *loops) : Blocks(blocks), Loops(loops) {}
444
+ LoopBounds (MutableArrayRef<MachineTraceMetrics::TraceBlockInfo> Blocks,
445
+ const MachineLoopInfo *Loops)
446
+ : Blocks(Blocks), Loops(Loops) {}
453
447
};
454
448
455
449
} // end anonymous namespace
@@ -463,7 +457,7 @@ class po_iterator_storage<LoopBounds, true> {
463
457
LoopBounds &LB;
464
458
465
459
public:
466
- po_iterator_storage (LoopBounds &lb ) : LB(lb ) {}
460
+ po_iterator_storage (LoopBounds &LB ) : LB(LB ) {}
467
461
468
462
void finishPostorder (const MachineBasicBlock*) {}
469
463
@@ -546,7 +540,7 @@ MachineTraceMetrics::Ensemble::invalidate(const MachineBasicBlock *BadMBB) {
546
540
if (BadTBI.hasValidHeight ()) {
547
541
BadTBI.invalidateHeight ();
548
542
WorkList.push_back (BadMBB);
549
- do {
543
+ while (!WorkList. empty ()) {
550
544
const MachineBasicBlock *MBB = WorkList.pop_back_val ();
551
545
LLVM_DEBUG (dbgs () << " Invalidate " << printMBBReference (*MBB) << ' '
552
546
<< getName () << " height.\n " );
@@ -564,14 +558,14 @@ MachineTraceMetrics::Ensemble::invalidate(const MachineBasicBlock *BadMBB) {
564
558
// Verify that TBI.Succ is actually a *I successor.
565
559
assert ((!TBI.Succ || Pred->isSuccessor (TBI.Succ )) && " CFG changed" );
566
560
}
567
- } while (!WorkList. empty ());
561
+ }
568
562
}
569
563
570
564
// Invalidate depth resources of blocks below MBB.
571
565
if (BadTBI.hasValidDepth ()) {
572
566
BadTBI.invalidateDepth ();
573
567
WorkList.push_back (BadMBB);
574
- do {
568
+ while (!WorkList. empty ()) {
575
569
const MachineBasicBlock *MBB = WorkList.pop_back_val ();
576
570
LLVM_DEBUG (dbgs () << " Invalidate " << printMBBReference (*MBB) << ' '
577
571
<< getName () << " depth.\n " );
@@ -589,7 +583,7 @@ MachineTraceMetrics::Ensemble::invalidate(const MachineBasicBlock *BadMBB) {
589
583
// Verify that TBI.Pred is actually a *I predecessor.
590
584
assert ((!TBI.Pred || Succ->isPredecessor (TBI.Pred )) && " CFG changed" );
591
585
}
592
- } while (!WorkList. empty ());
586
+ }
593
587
}
594
588
595
589
// Clear any per-instruction data. We only have to do this for BadMBB itself
@@ -605,7 +599,7 @@ void MachineTraceMetrics::Ensemble::verify() const {
605
599
#ifndef NDEBUG
606
600
assert (BlockInfo.size () == MTM.MF ->getNumBlockIDs () &&
607
601
" Outdated BlockInfo size" );
608
- for (unsigned Num = 0 , e = BlockInfo.size (); Num != e ; ++Num) {
602
+ for (unsigned Num = 0 ; Num < BlockInfo.size (); ++Num) {
609
603
const TraceBlockInfo &TBI = BlockInfo[Num];
610
604
if (TBI.hasValidDepth () && TBI.Pred ) {
611
605
const MachineBasicBlock *MBB = MTM.MF ->getBlockNumbered (Num);
@@ -686,7 +680,7 @@ static bool getDataDeps(const MachineInstr &UseMI,
686
680
}
687
681
// Collect virtual register reads.
688
682
if (MO.readsReg ())
689
- Deps.push_back ( DataDep ( MRI, Reg, MO.getOperandNo () ));
683
+ Deps.emplace_back ( MRI, Reg, MO.getOperandNo ());
690
684
}
691
685
return HasPhysRegs;
692
686
}
@@ -702,10 +696,10 @@ static void getPHIDeps(const MachineInstr &UseMI,
702
696
if (!Pred)
703
697
return ;
704
698
assert (UseMI.isPHI () && UseMI.getNumOperands () % 2 && " Bad PHI" );
705
- for (unsigned i = 1 ; i != UseMI.getNumOperands (); i += 2 ) {
706
- if (UseMI.getOperand (i + 1 ).getMBB () == Pred) {
707
- Register Reg = UseMI.getOperand (i ).getReg ();
708
- Deps.push_back ( DataDep ( MRI, Reg, i) );
699
+ for (unsigned Idx = 1 ; Idx < UseMI.getNumOperands (); Idx += 2 ) {
700
+ if (UseMI.getOperand (Idx + 1 ).getMBB () == Pred) {
701
+ Register Reg = UseMI.getOperand (Idx ).getReg ();
702
+ Deps.emplace_back ( MRI, Reg, Idx );
709
703
return ;
710
704
}
711
705
}
@@ -739,7 +733,7 @@ static void updatePhysDepsDownwards(const MachineInstr *UseMI,
739
733
SparseSet<LiveRegUnit>::iterator I = RegUnits.find (Unit);
740
734
if (I == RegUnits.end ())
741
735
continue ;
742
- Deps.push_back ( DataDep ( I->MI , I->Op , MO.getOperandNo () ));
736
+ Deps.emplace_back ( I->MI , I->Op , MO.getOperandNo ());
743
737
break ;
744
738
}
745
739
}
@@ -852,14 +846,14 @@ computeInstrDepths(const MachineBasicBlock *MBB) {
852
846
// implies Head->HasValidInstrDepths, so we only need to start from the first
853
847
// block in the trace that needs to be recomputed.
854
848
SmallVector<const MachineBasicBlock*, 8 > Stack;
855
- do {
849
+ while (MBB) {
856
850
TraceBlockInfo &TBI = BlockInfo[MBB->getNumber ()];
857
851
assert (TBI.hasValidDepth () && " Incomplete trace" );
858
852
if (TBI.HasValidInstrDepths )
859
853
break ;
860
854
Stack.push_back (MBB);
861
855
MBB = TBI.Pred ;
862
- } while (MBB);
856
+ }
863
857
864
858
// FIXME: If MBB is non-null at this point, it is the last pre-computed block
865
859
// in the trace. We should track any live-out physregs that were defined in
@@ -880,7 +874,7 @@ computeInstrDepths(const MachineBasicBlock *MBB) {
880
874
LLVM_DEBUG ({
881
875
dbgs () << format (" %7u Instructions\n " , TBI.InstrDepth );
882
876
ArrayRef<unsigned > PRDepths = getProcResourceDepths (MBB->getNumber ());
883
- for (unsigned K = 0 ; K != PRDepths.size (); ++K)
877
+ for (unsigned K = 0 ; K < PRDepths.size (); ++K)
884
878
if (PRDepths[K]) {
885
879
unsigned Factor = MTM.SchedModel .getResourceFactor (K);
886
880
dbgs () << format (" %6uc @ " , MTM.getCycles (PRDepths[K]))
@@ -969,10 +963,8 @@ static bool pushDepHeight(const DataDep &Dep, const MachineInstr &UseMI,
969
963
Dep.UseOp );
970
964
971
965
// Update Heights[DefMI] to be the maximum height seen.
972
- MIHeightMap::iterator I;
973
- bool New;
974
- std::tie (I, New) = Heights.insert (std::make_pair (Dep.DefMI , UseHeight));
975
- if (New)
966
+ const auto &[I, Inserted] = Heights.insert ({Dep.DefMI , UseHeight});
967
+ if (Inserted)
976
968
return true ;
977
969
978
970
// DefMI has been pushed before. Give it the max height.
@@ -1010,15 +1002,15 @@ computeInstrHeights(const MachineBasicBlock *MBB) {
1010
1002
// The bottom of the trace may already be computed.
1011
1003
// Find the blocks that need updating.
1012
1004
SmallVector<const MachineBasicBlock*, 8 > Stack;
1013
- do {
1005
+ while (MBB) {
1014
1006
TraceBlockInfo &TBI = BlockInfo[MBB->getNumber ()];
1015
1007
assert (TBI.hasValidHeight () && " Incomplete trace" );
1016
1008
if (TBI.HasValidInstrHeights )
1017
1009
break ;
1018
1010
Stack.push_back (MBB);
1019
1011
TBI.LiveIns .clear ();
1020
1012
MBB = TBI.Succ ;
1021
- } while (MBB);
1013
+ }
1022
1014
1023
1015
// As we move upwards in the trace, keep track of instructions that are
1024
1016
// required by deeper trace instructions. Map MI -> height required so far.
@@ -1060,7 +1052,7 @@ computeInstrHeights(const MachineBasicBlock *MBB) {
1060
1052
LLVM_DEBUG ({
1061
1053
dbgs () << format (" %7u Instructions\n " , TBI.InstrHeight );
1062
1054
ArrayRef<unsigned > PRHeights = getProcResourceHeights (MBB->getNumber ());
1063
- for (unsigned K = 0 ; K != PRHeights.size (); ++K)
1055
+ for (unsigned K = 0 ; K < PRHeights.size (); ++K)
1064
1056
if (PRHeights[K]) {
1065
1057
unsigned Factor = MTM.SchedModel .getResourceFactor (K);
1066
1058
dbgs () << format (" %6uc @ " , MTM.getCycles (PRHeights[K]))
@@ -1145,7 +1137,7 @@ computeInstrHeights(const MachineBasicBlock *MBB) {
1145
1137
1146
1138
// Transfer the live regunits to the live-in list.
1147
1139
for (const LiveRegUnit &RU : RegUnits) {
1148
- TBI.LiveIns .push_back ( LiveInReg ( RU.RegUnit , RU.Cycle ) );
1140
+ TBI.LiveIns .emplace_back ( RU.RegUnit , RU.Cycle );
1149
1141
LLVM_DEBUG (dbgs () << ' ' << printRegUnit (RU.RegUnit , MTM.TRI ) << ' @'
1150
1142
<< RU.Cycle );
1151
1143
}
@@ -1205,7 +1197,7 @@ unsigned MachineTraceMetrics::Trace::getResourceDepth(bool Bottom) const {
1205
1197
ArrayRef<unsigned > PRDepths = TE.getProcResourceDepths (getBlockNum ());
1206
1198
if (Bottom) {
1207
1199
ArrayRef<unsigned > PRCycles = TE.MTM .getProcReleaseAtCycles (getBlockNum ());
1208
- for (unsigned K = 0 ; K != PRDepths.size (); ++K)
1200
+ for (unsigned K = 0 ; K < PRDepths.size (); ++K)
1209
1201
PRMax = std::max (PRMax, PRDepths[K] + PRCycles[K]);
1210
1202
} else {
1211
1203
for (unsigned PRD : PRDepths)
@@ -1235,9 +1227,8 @@ unsigned MachineTraceMetrics::Trace::getResourceLength(
1235
1227
unsigned PRMax = 0 ;
1236
1228
1237
1229
// Capture computing cycles from extra instructions
1238
- auto extraCycles = [this ](ArrayRef<const MCSchedClassDesc *> Instrs,
1239
- unsigned ResourceIdx)
1240
- ->unsigned {
1230
+ auto ExtraCycles = [this ](ArrayRef<const MCSchedClassDesc *> Instrs,
1231
+ unsigned ResourceIdx) -> unsigned {
1241
1232
unsigned Cycles = 0 ;
1242
1233
for (const MCSchedClassDesc *SC : Instrs) {
1243
1234
if (!SC->isValid ())
@@ -1255,12 +1246,12 @@ unsigned MachineTraceMetrics::Trace::getResourceLength(
1255
1246
return Cycles;
1256
1247
};
1257
1248
1258
- for (unsigned K = 0 ; K != PRDepths.size (); ++K) {
1249
+ for (unsigned K = 0 ; K < PRDepths.size (); ++K) {
1259
1250
unsigned PRCycles = PRDepths[K] + PRHeights[K];
1260
1251
for (const MachineBasicBlock *MBB : Extrablocks)
1261
1252
PRCycles += TE.MTM .getProcReleaseAtCycles (MBB->getNumber ())[K];
1262
- PRCycles += extraCycles (ExtraInstrs, K);
1263
- PRCycles -= extraCycles (RemoveInstrs, K);
1253
+ PRCycles += ExtraCycles (ExtraInstrs, K);
1254
+ PRCycles -= ExtraCycles (RemoveInstrs, K);
1264
1255
PRMax = std::max (PRMax, PRCycles);
1265
1256
}
1266
1257
// Convert to cycle count.
@@ -1292,9 +1283,9 @@ bool MachineTraceMetrics::Trace::isDepInTrace(const MachineInstr &DefMI,
1292
1283
1293
1284
void MachineTraceMetrics::Ensemble::print (raw_ostream &OS) const {
1294
1285
OS << getName () << " ensemble:\n " ;
1295
- for (unsigned i = 0 , e = BlockInfo.size (); i != e; ++i ) {
1296
- OS << " %bb." << i << ' \t ' ;
1297
- BlockInfo[i ].print (OS);
1286
+ for (unsigned Idx = 0 ; Idx < BlockInfo.size (); ++Idx ) {
1287
+ OS << " %bb." << Idx << ' \t ' ;
1288
+ BlockInfo[Idx ].print (OS);
1298
1289
OS << ' \n ' ;
1299
1290
}
1300
1291
}
0 commit comments