From d1bab8df5f6ceca3885b49140984da09bcd638c0 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 23 Nov 2023 20:10:43 +0000 Subject: [PATCH] Make the tbr header local --- lib/Differentiator/ReverseModeVisitor.cpp | 2 +- lib/Differentiator/TBRAnalyzer.cpp | 2 +- .../clad => lib}/Differentiator/TBRAnalyzer.h | 38 +++++++++---------- 3 files changed, 19 insertions(+), 23 deletions(-) rename {include/clad => lib}/Differentiator/TBRAnalyzer.h (93%) diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 63fa4021e..b497abe26 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -8,12 +8,12 @@ #include "ConstantFolder.h" +#include "TBRAnalyzer.h" #include "clad/Differentiator/DiffPlanner.h" #include "clad/Differentiator/ErrorEstimator.h" #include "clad/Differentiator/ExternalRMVSource.h" #include "clad/Differentiator/MultiplexExternalRMVSource.h" #include "clad/Differentiator/StmtClone.h" -#include "clad/Differentiator/TBRAnalyzer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" diff --git a/lib/Differentiator/TBRAnalyzer.cpp b/lib/Differentiator/TBRAnalyzer.cpp index 247a60dfe..90a522341 100644 --- a/lib/Differentiator/TBRAnalyzer.cpp +++ b/lib/Differentiator/TBRAnalyzer.cpp @@ -1,4 +1,4 @@ -#include "clad/Differentiator/TBRAnalyzer.h" +#include "TBRAnalyzer.h" using namespace clang; diff --git a/include/clad/Differentiator/TBRAnalyzer.h b/lib/Differentiator/TBRAnalyzer.h similarity index 93% rename from include/clad/Differentiator/TBRAnalyzer.h rename to lib/Differentiator/TBRAnalyzer.h index 5e74e9b3b..c68f4ba6b 100644 --- a/include/clad/Differentiator/TBRAnalyzer.h +++ b/lib/Differentiator/TBRAnalyzer.h @@ -27,7 +27,7 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { /// and object fields. using ProfileID = clad_compat::FoldingSetNodeID; - ProfileID getProfileID(const Expr* E) const{ + ProfileID getProfileID(const Expr* E) const { ProfileID profID; E->Profile(profID, m_Context, /* Canonical */ true); return profID; @@ -40,22 +40,19 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { } struct ProfileIDHash { - size_t operator()(const ProfileID& x) const { - return x.ComputeHash(); - } + size_t operator()(const ProfileID& x) const { return x.ComputeHash(); } }; - struct VarData; - using ArrMap = - std::unordered_map; + using ArrMap = std::unordered_map; // NOLINTBEGIN(cppcoreguidelines-pro-type-union-access) /// Stores all the necessary information about one variable. Fundamental type /// variables need only one bit. An object/array needs a separate VarData for /// each field/element. Reference type variables store the clang::Expr* they - /// refer to. UNDEFINED is used whenever the type of a node cannot be determined. + /// refer to. UNDEFINED is used whenever the type of a node cannot be + /// determined. /// /// FIXME: Pointers to objects are considered OBJ_TYPE for simplicity. This /// approach might cause problems when the support for pointers is added. @@ -82,7 +79,7 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { VarData() = default; VarData(const VarData& other) = delete; - VarData(VarData&& other) noexcept: type(other.type) { + VarData(VarData&& other) noexcept : type(other.type) { *this = std::move(other); } VarData& operator=(const VarData& other) = delete; @@ -105,9 +102,8 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { /// Erases all children VarData's of this VarData. ~VarData() { - if (type == OBJ_TYPE || type == ARR_TYPE) { + if (type == OBJ_TYPE || type == ARR_TYPE) val.m_ArrData.reset(); - } } }; // NOLINTEND(cppcoreguidelines-pro-type-union-access) @@ -120,8 +116,7 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { /// when 'a[k].y' is set to required). Takes unwrapped sequence of /// indices/members of the expression being overlaid and the index of of the /// current index/member. - void overlay(VarData& targetData, - llvm::SmallVector& IDSequence, + void overlay(VarData& targetData, llvm::SmallVector& IDSequence, size_t i); /// Returns true if there is at least one required to store node among /// child nodes. @@ -173,7 +168,8 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { VarsData() = default; VarsData(const VarsData& other) = default; ~VarsData() = default; - VarsData(VarsData&& other) noexcept : data(std::move(other.data)), prev(other.prev) {} + VarsData(VarsData&& other) noexcept + : data(std::move(other.data)), prev(other.prev) {} VarsData& operator=(const VarsData& other) = delete; VarsData& operator=(VarsData&& other) noexcept { if (&data == &other.data) { @@ -189,24 +185,24 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor { iterator end() { return data.end(); } VarData& operator[](const clang::VarDecl* VD) { return data[VD]; } iterator find(const clang::VarDecl* VD) { return data.find(VD); } - void clear() { - data.clear(); - } + void clear() { data.clear(); } }; - /// Collects the data from 'varsData' and its predecessors until /// 'limit' into one map ('limit' VarsData is not included). /// If 'limit' is 'nullptr', data is collected starting with /// the entry CFG block. /// Note: the returned VarsData contains original data from /// the predecessors (NOT copies). It should not be modified. - std::unordered_map - static collectDataFromPredecessors(VarsData* varsData, VarsData* limit = nullptr); + std::unordered_map< + const clang::VarDecl*, + VarData*> static collectDataFromPredecessors(VarsData* varsData, + VarsData* limit = nullptr); /// Finds the lowest common ancestor of two VarsData /// (based on the prev field in VarsData). - static VarsData* findLowestCommonAncestor(VarsData* varsData1, VarsData* varsData2); + static VarsData* findLowestCommonAncestor(VarsData* varsData1, + VarsData* varsData2); /// Merges mergeData into targetData. Should be called /// after mergeData is passed and the corresponding CFG