Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit cdb2808

Browse files
committed
Use unique_ptr to handle GlobalOpt's Evaluator members
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206790 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0df9abb commit cdb2808

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,22 +2271,16 @@ class Evaluator {
22712271
public:
22722272
Evaluator(const DataLayout *DL, const TargetLibraryInfo *TLI)
22732273
: DL(DL), TLI(TLI) {
2274-
ValueStack.push_back(new DenseMap<Value*, Constant*>);
2274+
ValueStack.push_back(make_unique<DenseMap<Value*, Constant*>>());
22752275
}
22762276

22772277
~Evaluator() {
2278-
DeleteContainerPointers(ValueStack);
2279-
while (!AllocaTmps.empty()) {
2280-
GlobalVariable *Tmp = AllocaTmps.back();
2281-
AllocaTmps.pop_back();
2282-
2278+
for (auto &Tmp : AllocaTmps)
22832279
// If there are still users of the alloca, the program is doing something
22842280
// silly, e.g. storing the address of the alloca somewhere and using it
22852281
// later. Since this is undefined, we'll just make it be null.
22862282
if (!Tmp->use_empty())
22872283
Tmp->replaceAllUsesWith(Constant::getNullValue(Tmp->getType()));
2288-
delete Tmp;
2289-
}
22902284
}
22912285

22922286
/// EvaluateFunction - Evaluate a call to function F, returning true if
@@ -2325,7 +2319,7 @@ class Evaluator {
23252319
/// ValueStack - As we compute SSA register values, we store their contents
23262320
/// here. The back of the vector contains the current function and the stack
23272321
/// contains the values in the calling frames.
2328-
SmallVector<DenseMap<Value*, Constant*>*, 4> ValueStack;
2322+
SmallVector<std::unique_ptr<DenseMap<Value*, Constant*>>, 4> ValueStack;
23292323

23302324
/// CallStack - This is used to detect recursion. In pathological situations
23312325
/// we could hit exponential behavior, but at least there is nothing
@@ -2340,7 +2334,7 @@ class Evaluator {
23402334
/// AllocaTmps - To 'execute' an alloca, we create a temporary global variable
23412335
/// to represent its body. This vector is needed so we can delete the
23422336
/// temporary globals when we are done.
2343-
SmallVector<GlobalVariable*, 32> AllocaTmps;
2337+
SmallVector<std::unique_ptr<GlobalVariable>, 32> AllocaTmps;
23442338

23452339
/// Invariants - These global variables have been marked invariant by the
23462340
/// static constructor.
@@ -2530,11 +2524,10 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
25302524
return false; // Cannot handle array allocs.
25312525
}
25322526
Type *Ty = AI->getType()->getElementType();
2533-
AllocaTmps.push_back(new GlobalVariable(Ty, false,
2534-
GlobalValue::InternalLinkage,
2535-
UndefValue::get(Ty),
2536-
AI->getName()));
2537-
InstResult = AllocaTmps.back();
2527+
AllocaTmps.push_back(
2528+
make_unique<GlobalVariable>(Ty, false, GlobalValue::InternalLinkage,
2529+
UndefValue::get(Ty), AI->getName()));
2530+
InstResult = AllocaTmps.back().get();
25382531
DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n");
25392532
} else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
25402533
CallSite CS(CurInst);
@@ -2638,12 +2631,12 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
26382631

26392632
Constant *RetVal = 0;
26402633
// Execute the call, if successful, use the return value.
2641-
ValueStack.push_back(new DenseMap<Value*, Constant*>);
2634+
ValueStack.push_back(make_unique<DenseMap<Value *, Constant *>>());
26422635
if (!EvaluateFunction(Callee, RetVal, Formals)) {
26432636
DEBUG(dbgs() << "Failed to evaluate function.\n");
26442637
return false;
26452638
}
2646-
delete ValueStack.pop_back_val();
2639+
ValueStack.pop_back();
26472640
InstResult = RetVal;
26482641

26492642
if (InstResult != NULL) {

0 commit comments

Comments
 (0)