Skip to content

Commit

Permalink
MustBeExecutedContextExplorer::InstructionIteratorMap: use unique_ptr…
Browse files Browse the repository at this point in the history
… for values in this map to simplify memory management
  • Loading branch information
dwblaikie committed Apr 28, 2020
1 parent 3c89256 commit 89e2fe3
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions llvm/include/llvm/Analysis/MustExecute.h
Expand Up @@ -416,27 +416,22 @@ struct MustBeExecutedContextExplorer {
ExploreCFGBackward(ExploreCFGBackward), LIGetter(LIGetter),
DTGetter(DTGetter), PDTGetter(PDTGetter), EndIterator(*this, nullptr) {}

/// Clean up the dynamically allocated iterators.
~MustBeExecutedContextExplorer() {
DeleteContainerSeconds(InstructionIteratorMap);
}

/// Iterator-based interface. \see MustBeExecutedIterator.
///{
using iterator = MustBeExecutedIterator;
using const_iterator = const MustBeExecutedIterator;

/// Return an iterator to explore the context around \p PP.
iterator &begin(const Instruction *PP) {
auto *&It = InstructionIteratorMap[PP];
auto &It = InstructionIteratorMap[PP];
if (!It)
It = new iterator(*this, PP);
It.reset(new iterator(*this, PP));
return *It;
}

/// Return an iterator to explore the cached context around \p PP.
const_iterator &begin(const Instruction *PP) const {
return *InstructionIteratorMap.lookup(PP);
return *InstructionIteratorMap.find(PP)->second;
}

/// Return an universal end iterator.
Expand Down Expand Up @@ -544,7 +539,7 @@ struct MustBeExecutedContextExplorer {
DenseMap<const Function*, Optional<bool>> IrreducibleControlMap;

/// Map from instructions to associated must be executed iterators.
DenseMap<const Instruction *, MustBeExecutedIterator *>
DenseMap<const Instruction *, std::unique_ptr<MustBeExecutedIterator>>
InstructionIteratorMap;

/// A unique end iterator.
Expand Down

0 comments on commit 89e2fe3

Please sign in to comment.