From 745a957f9dc562477cbe587fb3fa8305713b51b3 Mon Sep 17 00:00:00 2001 From: Martin Braenne Date: Mon, 3 Apr 2023 14:45:13 +0000 Subject: [clang][dataflow] Add `create()` methods to `Environment` and `DataflowAnalysisContext`. These methods provide a less verbose way of allocating `StorageLocation`s and `Value`s than the existing `takeOwnership(make_unique(...))` pattern. In addition, because allocation of `StorageLocation`s and `Value`s now happens within the `DataflowAnalysisContext`, the `create()` open up the possibility of using `BumpPtrAllocator` to allocate these objects if it turns out this helps performance. Reviewed By: ymandel, xazax.hun, gribozavr2 Differential Revision: https://reviews.llvm.org/D147302 --- .../FlowSensitive/DataflowAnalysisContext.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp') diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp index 57169ba..5a49ef1 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp @@ -59,10 +59,9 @@ StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) { : getReferencedFields(Type); for (const FieldDecl *Field : Fields) FieldLocs.insert({Field, &createStorageLocation(Field->getType())}); - return takeOwnership( - std::make_unique(Type, std::move(FieldLocs))); + return create(Type, std::move(FieldLocs)); } - return takeOwnership(std::make_unique(Type)); + return create(Type); } StorageLocation & @@ -90,8 +89,7 @@ DataflowAnalysisContext::getOrCreateNullPointerValue(QualType PointeeType) { auto Res = NullPointerVals.try_emplace(CanonicalPointeeType, nullptr); if (Res.second) { auto &PointeeLoc = createStorageLocation(CanonicalPointeeType); - Res.first->second = - &takeOwnership(std::make_unique(PointeeLoc)); + Res.first->second = &create(PointeeLoc); } return *Res.first->second; } @@ -112,8 +110,7 @@ BoolValue &DataflowAnalysisContext::getOrCreateConjunction(BoolValue &LHS, auto Res = ConjunctionVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), nullptr); if (Res.second) - Res.first->second = - &takeOwnership(std::make_unique(LHS, RHS)); + Res.first->second = &create(LHS, RHS); return *Res.first->second; } @@ -125,15 +122,14 @@ BoolValue &DataflowAnalysisContext::getOrCreateDisjunction(BoolValue &LHS, auto Res = DisjunctionVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), nullptr); if (Res.second) - Res.first->second = - &takeOwnership(std::make_unique(LHS, RHS)); + Res.first->second = &create(LHS, RHS); return *Res.first->second; } BoolValue &DataflowAnalysisContext::getOrCreateNegation(BoolValue &Val) { auto Res = NegationVals.try_emplace(&Val, nullptr); if (Res.second) - Res.first->second = &takeOwnership(std::make_unique(Val)); + Res.first->second = &create(Val); return *Res.first->second; } @@ -144,8 +140,7 @@ BoolValue &DataflowAnalysisContext::getOrCreateImplication(BoolValue &LHS, auto Res = ImplicationVals.try_emplace(std::make_pair(&LHS, &RHS), nullptr); if (Res.second) - Res.first->second = - &takeOwnership(std::make_unique(LHS, RHS)); + Res.first->second = &create(LHS, RHS); return *Res.first->second; } @@ -157,8 +152,7 @@ BoolValue &DataflowAnalysisContext::getOrCreateIff(BoolValue &LHS, auto Res = BiconditionalVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), nullptr); if (Res.second) - Res.first->second = - &takeOwnership(std::make_unique(LHS, RHS)); + Res.first->second = &create(LHS, RHS); return *Res.first->second; } -- cgit v1.1