39
39
#include " llvm/Support/raw_ostream.h"
40
40
#include " llvm/Transforms/Utils/ModuleUtils.h"
41
41
#include < algorithm>
42
+ #include < memory>
42
43
#include < string>
43
44
#include < utility>
44
45
using namespace llvm ;
@@ -77,9 +78,6 @@ namespace {
77
78
" GCOVProfiler asked to do nothing?" );
78
79
init ();
79
80
}
80
- ~GCOVProfiler () {
81
- DeleteContainerPointers (Funcs);
82
- }
83
81
const char *getPassName () const override {
84
82
return " GCOV Profiler" ;
85
83
}
@@ -141,7 +139,7 @@ namespace {
141
139
142
140
Module *M;
143
141
LLVMContext *Ctx;
144
- SmallVector<GCOVFunction * , 16 > Funcs;
142
+ SmallVector<std::unique_ptr< GCOVFunction> , 16 > Funcs;
145
143
};
146
144
}
147
145
@@ -499,19 +497,19 @@ void GCOVProfiler::emitProfileNotes() {
499
497
++It;
500
498
EntryBlock.splitBasicBlock (It);
501
499
502
- GCOVFunction *Func =
503
- new GCOVFunction (SP, &out, i, Options.UseCfgChecksum );
504
- Funcs.push_back (Func );
500
+ Funcs. push_back (
501
+ make_unique< GCOVFunction> (SP, &out, i, Options.UseCfgChecksum ) );
502
+ GCOVFunction &Func = * Funcs.back ( );
505
503
506
504
for (Function::iterator BB = F->begin (), E = F->end (); BB != E; ++BB) {
507
- GCOVBlock &Block = Func-> getBlock (BB);
505
+ GCOVBlock &Block = Func. getBlock (BB);
508
506
TerminatorInst *TI = BB->getTerminator ();
509
507
if (int successors = TI->getNumSuccessors ()) {
510
508
for (int i = 0 ; i != successors; ++i) {
511
- Block.addEdge (Func-> getBlock (TI->getSuccessor (i)));
509
+ Block.addEdge (Func. getBlock (TI->getSuccessor (i)));
512
510
}
513
511
} else if (isa<ReturnInst>(TI)) {
514
- Block.addEdge (Func-> getReturnBlock ());
512
+ Block.addEdge (Func. getReturnBlock ());
515
513
}
516
514
517
515
uint32_t Line = 0 ;
@@ -527,17 +525,15 @@ void GCOVProfiler::emitProfileNotes() {
527
525
Lines.addLine (Loc.getLine ());
528
526
}
529
527
}
530
- EdgeDestinations += Func-> getEdgeDestinations ();
528
+ EdgeDestinations += Func. getEdgeDestinations ();
531
529
}
532
530
533
531
FileChecksums.push_back (hash_value (EdgeDestinations));
534
532
out.write (" oncg" , 4 );
535
533
out.write (ReversedVersion, 4 );
536
534
out.write (reinterpret_cast <char *>(&FileChecksums.back ()), 4 );
537
535
538
- for (SmallVectorImpl<GCOVFunction *>::iterator I = Funcs.begin (),
539
- E = Funcs.end (); I != E; ++I) {
540
- GCOVFunction *Func = *I;
536
+ for (auto &Func : Funcs) {
541
537
Func->setCfgChecksum (FileChecksums.back ());
542
538
Func->writeOut ();
543
539
}
0 commit comments