OpenMPOpt::RuntimeFunctionInfo::UsesMap: Use unique_ptr for values to simplify memory management

This commit is contained in:
David Blaikie 2020-04-28 12:26:09 -07:00
parent 89e2fe3210
commit 95e570725a
1 changed files with 7 additions and 5 deletions

View File

@ -62,7 +62,6 @@ struct OpenMPOpt {
/// Generic information that describes a runtime function /// Generic information that describes a runtime function
struct RuntimeFunctionInfo { struct RuntimeFunctionInfo {
~RuntimeFunctionInfo() { DeleteContainerSeconds(UsesMap); }
/// The kind, as described by the RuntimeFunction enum. /// The kind, as described by the RuntimeFunction enum.
RuntimeFunction Kind; RuntimeFunction Kind;
@ -87,16 +86,19 @@ struct OpenMPOpt {
/// Return the vector of uses in function \p F. /// Return the vector of uses in function \p F.
UseVector &getOrCreateUseVector(Function *F) { UseVector &getOrCreateUseVector(Function *F) {
UseVector *&UV = UsesMap[F]; std::unique_ptr<UseVector> &UV = UsesMap[F];
if (!UV) if (!UV)
UV = new UseVector(); UV = std::make_unique<UseVector>();
return *UV; return *UV;
} }
/// Return the vector of uses in function \p F or `nullptr` if there are /// Return the vector of uses in function \p F or `nullptr` if there are
/// none. /// none.
const UseVector *getUseVector(Function &F) const { const UseVector *getUseVector(Function &F) const {
return UsesMap.lookup(&F); auto I = UsesMap.find(&F);
if (I != UsesMap.end())
return I->second.get();
return nullptr;
} }
/// Return how many functions contain uses of this runtime function. /// Return how many functions contain uses of this runtime function.
@ -134,7 +136,7 @@ struct OpenMPOpt {
private: private:
/// Map from functions to all uses of this runtime function contained in /// Map from functions to all uses of this runtime function contained in
/// them. /// them.
DenseMap<Function *, UseVector *> UsesMap; DenseMap<Function *, std::unique_ptr<UseVector>> UsesMap;
}; };
/// Run all OpenMP optimizations on the underlying SCC/ModuleSlice. /// Run all OpenMP optimizations on the underlying SCC/ModuleSlice.