@@ -92,20 +92,14 @@ bool MachineTraceMetricsWrapperPass::runOnMachineFunction(MachineFunction &MF) {
92
92
return false ;
93
93
}
94
94
95
- MachineTraceMetrics::MachineTraceMetrics (MachineFunction &MF,
96
- const MachineLoopInfo &LI) {
97
- std::fill (std::begin (Ensembles), std::end (Ensembles), nullptr );
98
- init (MF, LI);
99
- }
100
-
101
95
MachineTraceMetrics::~MachineTraceMetrics () { clear (); }
102
96
103
97
void MachineTraceMetrics::clear () {
104
98
MF = nullptr ;
105
99
BlockInfo.clear ();
106
- for (Ensemble * &E : Ensembles) {
107
- delete E;
108
- E = nullptr ;
100
+ for (auto &E : Ensembles) {
101
+ if (E)
102
+ E. reset () ;
109
103
}
110
104
}
111
105
@@ -422,27 +416,31 @@ MachineTraceMetrics::Ensemble *
422
416
MachineTraceMetrics::getEnsemble (MachineTraceStrategy strategy) {
423
417
assert (strategy < MachineTraceStrategy::TS_NumStrategies &&
424
418
" Invalid trace strategy enum" );
425
- Ensemble *&E = Ensembles[static_cast <size_t >(strategy)];
419
+ std::unique_ptr<MachineTraceMetrics::Ensemble> &E =
420
+ Ensembles[static_cast <size_t >(strategy)];
426
421
if (E)
427
- return E;
422
+ return E. get () ;
428
423
429
424
// Allocate new Ensemble on demand.
430
425
switch (strategy) {
431
426
case MachineTraceStrategy::TS_MinInstrCount:
432
- return (E = new MinInstrCountEnsemble (this ));
427
+ E = std::make_unique<MinInstrCountEnsemble>(MinInstrCountEnsemble (this ));
428
+ break ;
433
429
case MachineTraceStrategy::TS_Local:
434
- return (E = new LocalEnsemble (this ));
430
+ E = std::make_unique<LocalEnsemble>(LocalEnsemble (this ));
431
+ break ;
435
432
default : llvm_unreachable (" Invalid trace strategy enum" );
436
433
}
434
+ return E.get ();
437
435
}
438
436
439
437
void MachineTraceMetrics::invalidate (const MachineBasicBlock *MBB) {
440
438
LLVM_DEBUG (dbgs () << " Invalidate traces through " << printMBBReference (*MBB)
441
439
<< ' \n ' );
442
440
BlockInfo[MBB->getNumber ()].invalidate ();
443
- for (Ensemble * E : Ensembles)
441
+ for (auto & E : Ensembles)
444
442
if (E)
445
- E->invalidate (MBB);
443
+ E. get () ->invalidate (MBB);
446
444
}
447
445
448
446
bool MachineTraceMetrics::invalidate (
@@ -461,9 +459,9 @@ void MachineTraceMetrics::verifyAnalysis() const {
461
459
return ;
462
460
#ifndef NDEBUG
463
461
assert (BlockInfo.size () == MF->getNumBlockIDs () && " Outdated BlockInfo size" );
464
- for (Ensemble * E : Ensembles)
462
+ for (auto & E : Ensembles)
465
463
if (E)
466
- E->verify ();
464
+ E. get () ->verify ();
467
465
#endif
468
466
}
469
467
0 commit comments