From 44c0630f0fd1288c68da6c0c7d30f75f928a2e8a Mon Sep 17 00:00:00 2001 From: Martin Mory Date: Wed, 22 Dec 2021 22:32:12 +0100 Subject: [PATCH 1/3] identifier renames and further clang-tidy minor fixes of IfdsIde FF/EF helpers --- .../DataFlowSolver/IfdsIde/DefaultSeeds.h | 10 +- .../DataFlowSolver/IfdsIde/EdgeFact.h | 2 +- .../IfdsIde/EdgeFunctionComposer.h | 29 +- .../DataFlowSolver/IfdsIde/EdgeFunctions.h | 105 ++--- .../IfdsIde/FlowEdgeFunctionCache.h | 389 +++++++++--------- .../DataFlowSolver/IfdsIde/FlowFactWrapper.h | 4 +- .../DataFlowSolver/IfdsIde/FlowFunctions.h | 244 ++++++----- .../IfdsIde/EdgeFunctionComposerTest.cpp | 12 +- .../EdgeFunctionSingletonFactoryTest.cpp | 8 +- 9 files changed, 396 insertions(+), 407 deletions(-) diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h index aaaf1b7eeb..a1cdc2cb11 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h @@ -25,12 +25,12 @@ namespace psr { template class DefaultSeeds { public: - static std::map> make(std::vector node, D zeroNode) { - std::map> res; - for (N n : node) { - res.insert(n, std::set{zeroNode}); + static std::map> make(std::vector Nodes, D ZeroNode) { + std::map> Result; + for (N Node : Nodes) { + Result.insert(Node, {ZeroNode}); } - return res; + return Result; } }; diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFact.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFact.h index 88e0e51602..0766f004ee 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFact.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFact.h @@ -19,7 +19,7 @@ namespace psr { class EdgeFact { public: virtual ~EdgeFact() = default; - virtual void print(std::ostream &os) const = 0; + virtual void print(std::ostream &OS) const = 0; }; static inline std::ostream &operator<<(std::ostream &OS, const EdgeFact &E) { diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposer.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposer.h index d54cdcfa38..e22577cb6a 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposer.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposer.h @@ -39,8 +39,8 @@ class EdgeFunctionComposer private: // For debug purpose only - const unsigned EFComposer_Id; - static inline unsigned CurrEFComposer_Id = 0; + const unsigned EFComposerId; + static inline unsigned CurrEFComposerId = 0; // NOLINT protected: /// First edge function @@ -49,8 +49,8 @@ class EdgeFunctionComposer EdgeFunctionPtrType G; public: - EdgeFunctionComposer(EdgeFunctionPtrType F, EdgeFunctionPtrType G) - : EFComposer_Id(++CurrEFComposer_Id), F(F), G(G) {} + EdgeFunctionComposer(EdgeFunctionPtrType &F, EdgeFunctionPtrType &G) + : EFComposerId(++CurrEFComposerId), F(F), G(G) {} ~EdgeFunctionComposer() override = default; @@ -58,8 +58,8 @@ class EdgeFunctionComposer * Target value computation is implemented as * G(F(source)) */ - L computeTarget(L source) override { - return G->computeTarget(F->computeTarget(source)); + L computeTarget(L Source) override { + return G->computeTarget(F->computeTarget(Source)); } /** @@ -69,29 +69,30 @@ class EdgeFunctionComposer * However, it is advised to immediately reduce the resulting edge function * by providing an own implementation of this function. */ - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override { - if (auto *EI = dynamic_cast *>(secondFunction.get())) { + EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override { + if (auto *EI = dynamic_cast *>(SecondFunction.get())) { return this->shared_from_this(); } - if (auto *AB = dynamic_cast *>(secondFunction.get())) { + if (auto *AB = dynamic_cast *>(SecondFunction.get())) { return this->shared_from_this(); } - return F->composeWith(G->composeWith(secondFunction)); + return F->composeWith(G->composeWith(SecondFunction)); } // virtual EdgeFunctionPtrType // joinWith(EdgeFunctionPtrType otherFunction) = 0; - bool equal_to(EdgeFunctionPtrType other) const override { - if (auto EFC = dynamic_cast *>(other.get())) { + bool equal_to // NOLINT - would break too many client analyses + (EdgeFunctionPtrType Other) const override { + if (auto EFC = dynamic_cast *>(Other.get())) { return F->equal_to(EFC->F) && G->equal_to(EFC->G); } return false; } - void print(std::ostream &OS, bool isForDebug = false) const override { + void print(std::ostream &OS, bool /*IsForDebug = false*/) const override { OS << "COMP[ " << F.get()->str() << " , " << G.get()->str() - << " ] (EF:" << EFComposer_Id << ')'; + << " ] (EF:" << EFComposerId << ')'; } }; diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h index b5fc36867d..e9209602b1 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h @@ -67,8 +67,8 @@ template class EdgeFunction { // function is used to extend an edge function in order to construct so-called // jump functions that describe the effects of everlonger sequences of code. // - virtual EdgeFunctionPtrType - composeWith(EdgeFunctionPtrType secondFunction) = 0; + [[nodiscard]] virtual EdgeFunctionPtrType + composeWith(EdgeFunctionPtrType SecondFunction) = 0; // // This function describes the join of the two edge functions this and @@ -80,7 +80,8 @@ template class EdgeFunction { virtual bool equal_to(EdgeFunctionPtrType OtherFunction) const = 0; - virtual void print(std::ostream &OS, bool IsForDebug = false) const { + virtual void print(std::ostream &OS, + [[maybe_unused]] bool IsForDebug = false) const { OS << "EdgeFunction"; } @@ -111,31 +112,34 @@ class AllTop : public EdgeFunction, using typename EdgeFunction::EdgeFunctionPtrType; private: - const L topElement; + const L TopElement; public: - AllTop(L topElement) : topElement(topElement) {} + AllTop(const L TopElement) : TopElement(std::move(TopElement)) {} ~AllTop() override = default; - L computeTarget(L source) override { return topElement; } + L computeTarget(L /*Source*/) override { return TopElement; } - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override { + EdgeFunctionPtrType + composeWith(EdgeFunctionPtrType /*SecondFunction*/) override { return this->shared_from_this(); } - EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override { - return otherFunction; + EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override { + return OtherFunction; } - bool equal_to(EdgeFunctionPtrType other) const override { - if (auto *alltop = dynamic_cast *>(other.get())) { - return (alltop->topElement == topElement); + [[nodiscard]] bool equal_to // NOLINT - would break too many client analyses + (EdgeFunctionPtrType Other) const override { + if (auto *Alltop = dynamic_cast *>(Other.get())) { + return (Alltop->TopElement == TopElement); } return false; } - void print(std::ostream &OS, bool isForDebug = false) const override { + void print(std::ostream &OS, + [[maybe_unused]] bool IsForDebug = false) const override { OS << "AllTop"; } }; @@ -149,47 +153,48 @@ class AllBottom : public EdgeFunction, using typename EdgeFunction::EdgeFunctionPtrType; private: - const L bottomElement; + const L BottomElement; public: - AllBottom(L bottomElement) : bottomElement(bottomElement) {} + AllBottom(const L BottomElement) : BottomElement(std::move(BottomElement)) {} ~AllBottom() override = default; - L computeTarget(L source) override { return bottomElement; } + L computeTarget(L /*Source*/) override { return BottomElement; } - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override { - if (auto *ab = dynamic_cast *>(secondFunction.get())) { + EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override { + if (auto *AB = dynamic_cast *>(SecondFunction.get())) { return this->shared_from_this(); } - if (auto *ei = dynamic_cast *>(secondFunction.get())) { + if (auto *EI = dynamic_cast *>(SecondFunction.get())) { return this->shared_from_this(); } - return secondFunction->composeWith(this->shared_from_this()); + return SecondFunction->composeWith(this->shared_from_this()); } - EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override { - if (otherFunction.get() == this || - otherFunction->equal_to(this->shared_from_this())) { + EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override { + if (OtherFunction.get() == this || + OtherFunction->equal_to(this->shared_from_this())) { return this->shared_from_this(); } - if (auto *alltop = dynamic_cast *>(otherFunction.get())) { + if (auto *Alltop = dynamic_cast *>(OtherFunction.get())) { return this->shared_from_this(); } - if (auto *ei = dynamic_cast *>(otherFunction.get())) { + if (auto *EI = dynamic_cast *>(OtherFunction.get())) { return this->shared_from_this(); } return this->shared_from_this(); } - bool equal_to(EdgeFunctionPtrType other) const override { - if (auto *allbottom = dynamic_cast *>(other.get())) { - return (allbottom->bottomElement == bottomElement); + [[nodiscard]] bool equal_to // NOLINT - would break too many client analyses + (EdgeFunctionPtrType Other) const override { + if (auto *AB = dynamic_cast *>(Other.get())) { + return (AB->BottomElement == BottomElement); } return false; } - void print(std::ostream &OS, bool isForDebug = false) const override { + void print(std::ostream &OS, bool /*IsForDebug = false*/) const override { OS << "AllBottom"; } }; @@ -204,44 +209,45 @@ class EdgeIdentity : public EdgeFunction, EdgeIdentity() = default; public: - EdgeIdentity(const EdgeIdentity &ei) = delete; + EdgeIdentity(const EdgeIdentity &EI) = delete; - EdgeIdentity &operator=(const EdgeIdentity &ei) = delete; + EdgeIdentity &operator=(const EdgeIdentity &EI) = delete; ~EdgeIdentity() override = default; - L computeTarget(L source) override { return source; } + L computeTarget(L Source) override { return Source; } - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override { - return secondFunction; + EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override { + return SecondFunction; } - EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override { - if ((otherFunction.get() == this) || - otherFunction->equal_to(this->shared_from_this())) { + EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override { + if ((OtherFunction.get() == this) || + OtherFunction->equal_to(this->shared_from_this())) { return this->shared_from_this(); } - if (auto *ab = dynamic_cast *>(otherFunction.get())) { - return otherFunction; + if (auto *AB = dynamic_cast *>(OtherFunction.get())) { + return OtherFunction; } - if (auto *at = dynamic_cast *>(otherFunction.get())) { + if (auto *AT = dynamic_cast *>(OtherFunction.get())) { return this->shared_from_this(); } // do not know how to join; hence ask other function to decide on this - return otherFunction->joinWith(this->shared_from_this()); + return OtherFunction->joinWith(this->shared_from_this()); } - bool equal_to(EdgeFunctionPtrType other) const override { - return this == other.get(); + [[nodiscard]] bool equal_to // NOLINT - would break too many client analyses + (EdgeFunctionPtrType Other) const override { + return this == Other.get(); } static EdgeFunctionPtrType getInstance() { // implement singleton C++11 thread-safe (see Scott Meyers) - static EdgeFunctionPtrType instance(new EdgeIdentity()); - return instance; + static EdgeFunctionPtrType Instance(new EdgeIdentity()); + return Instance; } - void print(std::ostream &OS, bool isForDebug = false) const override { + void print(std::ostream &OS, bool /*IsForDebug = false*/) const override { OS << "EdgeIdentity"; } }; @@ -520,11 +526,10 @@ class EdgeFunctionSingletonFactory { auto SearchVal = Storage.find(K); if (SearchVal != Storage.end() && !SearchVal->second.expired()) { return SearchVal->second.lock(); - } else { - auto NewEdgeFunc = std::make_shared(K); - Storage[K] = NewEdgeFunc; - return NewEdgeFunc; } + auto NewEdgeFunc = std::make_shared(K); + Storage[K] = NewEdgeFunc; + return NewEdgeFunc; } // Initialize a cleaner thread to automatically remove unused/expired diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowEdgeFunctionCache.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowEdgeFunctionCache.h index 2c28ac8d53..9ca5130d64 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowEdgeFunctionCache.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowEdgeFunctionCache.h @@ -98,10 +98,10 @@ class FlowEdgeFunctionCache { using InnerEdgeFunctionMapType = EquivalenceClassMap; - IDETabulationProblem &problem; + IDETabulationProblem &Problem; // Auto add zero - bool autoAddZero; - d_t zeroValue; + bool AutoAddZero; + d_t ZV; struct NormalEdgeFlowData { NormalEdgeFlowData(FlowFunctionPtrType Val) @@ -137,9 +137,9 @@ class FlowEdgeFunctionCache { // edge function factory functions. FlowEdgeFunctionCache( IDETabulationProblem &Problem) - : problem(Problem), - autoAddZero(problem.getIFDSIDESolverConfig().autoAddZero()), - zeroValue(problem.getZeroValue()) { + : Problem(Problem), + AutoAddZero(Problem.getIFDSIDESolverConfig().autoAddZero()), + ZV(Problem.getZeroValue()) { PAMM_GET_INSTANCE; REG_COUNTER("Normal-FF Construction", 0, PAMM_SEVERITY_LEVEL::Full); REG_COUNTER("Normal-FF Cache Hit", 0, PAMM_SEVERITY_LEVEL::Full); @@ -181,15 +181,15 @@ class FlowEdgeFunctionCache { FlowEdgeFunctionCache & operator=(FlowEdgeFunctionCache &&FEFC) noexcept = default; - FlowFunctionPtrType getNormalFlowFunction(n_t curr, n_t succ) { + FlowFunctionPtrType getNormalFlowFunction(n_t Curr, n_t Succ) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Normal flow function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Curr Inst : " << problem.NtoString(curr); + << "(N) Curr Inst : " << Problem.NtoString(Curr); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Succ Inst : " << problem.NtoString(succ)); - auto Key = createEdgeFunctionInstKey(curr, succ); + << "(N) Succ Inst : " << Problem.NtoString(Succ)); + auto Key = createEdgeFunctionInstKey(Curr, Succ); auto SearchNormalFlowFunction = NormalFunctionCache.find(Key); if (SearchNormalFlowFunction != NormalFunctionCache.end()) { LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -198,38 +198,35 @@ class FlowEdgeFunctionCache { INC_COUNTER("Normal-FF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); if (SearchNormalFlowFunction->second.FlowFuncPtr != nullptr) { return SearchNormalFlowFunction->second.FlowFuncPtr; - } else { - auto ff = - (autoAddZero) - ? std::make_shared>( - problem.getNormalFlowFunction(curr, succ), zeroValue) - : problem.getNormalFlowFunction(curr, succ); - SearchNormalFlowFunction->second.FlowFuncPtr = ff; - return ff; } - } else { - INC_COUNTER("Normal-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ff = (autoAddZero) + auto FF = (AutoAddZero) ? std::make_shared>( - problem.getNormalFlowFunction(curr, succ), zeroValue) - : problem.getNormalFlowFunction(curr, succ); - NormalFunctionCache.insert(std::make_pair(Key, NormalEdgeFlowData(ff))); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Flow function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - return ff; + Problem.getNormalFlowFunction(Curr, Succ), ZV) + : Problem.getNormalFlowFunction(Curr, Succ); + SearchNormalFlowFunction->second.FlowFuncPtr = FF; + return FF; } + INC_COUNTER("Normal-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto FF = (AutoAddZero) + ? std::make_shared>( + Problem.getNormalFlowFunction(Curr, Succ), ZV) + : Problem.getNormalFlowFunction(Curr, Succ); + NormalFunctionCache.insert(std::make_pair(Key, NormalEdgeFlowData(FF))); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Flow function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + return FF; } - FlowFunctionPtrType getCallFlowFunction(n_t callSite, f_t destFun) { + FlowFunctionPtrType getCallFlowFunction(n_t CallSite, f_t DestFun) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Call flow function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Stmt : " << problem.NtoString(callSite); + << "(N) Call Stmt : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(F) Dest Fun : " << problem.FtoString(destFun)); - auto Key = std::tie(callSite, destFun); + << "(F) Dest Fun : " << Problem.FtoString(DestFun)); + auto Key = std::tie(CallSite, DestFun); auto SearchCallFlowFunction = CallFlowFunctionCache.find(Key); if (SearchCallFlowFunction != CallFlowFunctionCache.end()) { LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -237,35 +234,33 @@ class FlowEdgeFunctionCache { BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); INC_COUNTER("Call-FF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); return SearchCallFlowFunction->second; - } else { - INC_COUNTER("Call-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ff = - (autoAddZero) - ? std::make_shared>( - problem.getCallFlowFunction(callSite, destFun), zeroValue) - : problem.getCallFlowFunction(callSite, destFun); - CallFlowFunctionCache.insert(std::make_pair(Key, ff)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Flow function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - return ff; } + INC_COUNTER("Call-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto FF = (AutoAddZero) + ? std::make_shared>( + Problem.getCallFlowFunction(CallSite, DestFun), ZV) + : Problem.getCallFlowFunction(CallSite, DestFun); + CallFlowFunctionCache.insert(std::make_pair(Key, FF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Flow function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + return FF; } - FlowFunctionPtrType getRetFlowFunction(n_t callSite, f_t calleeFun, - n_t exitInst, n_t retSite) { + FlowFunctionPtrType getRetFlowFunction(n_t CallSite, f_t CalleeFun, + n_t ExitInst, n_t RetSite) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Return flow function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Site : " << problem.NtoString(callSite); + << "(N) Call Site : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(F) Callee : " << problem.FtoString(calleeFun); + << "(F) Callee : " << Problem.FtoString(CalleeFun); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Exit Stmt : " << problem.NtoString(exitInst); + << "(N) Exit Stmt : " << Problem.NtoString(ExitInst); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Ret Site : " << problem.NtoString(retSite)); - auto Key = std::tie(callSite, calleeFun, exitInst, retSite); + << "(N) Ret Site : " << Problem.NtoString(RetSite)); + auto Key = std::tie(CallSite, CalleeFun, ExitInst, RetSite); auto SearchReturnFlowFunction = ReturnFlowFunctionCache.find(Key); if (SearchReturnFlowFunction != ReturnFlowFunctionCache.end()) { LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -273,38 +268,37 @@ class FlowEdgeFunctionCache { BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); INC_COUNTER("Return-FF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); return SearchReturnFlowFunction->second; - } else { - INC_COUNTER("Return-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ff = (autoAddZero) - ? std::make_shared>( - problem.getRetFlowFunction(callSite, calleeFun, - exitInst, retSite), - zeroValue) - : problem.getRetFlowFunction(callSite, calleeFun, exitInst, - retSite); - ReturnFlowFunctionCache.insert(std::make_pair(Key, ff)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Flow function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - return ff; } + INC_COUNTER("Return-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto FF = (AutoAddZero) + ? std::make_shared>( + Problem.getRetFlowFunction(CallSite, CalleeFun, + ExitInst, RetSite), + ZV) + : Problem.getRetFlowFunction(CallSite, CalleeFun, ExitInst, + RetSite); + ReturnFlowFunctionCache.insert(std::make_pair(Key, FF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Flow function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + return FF; } - FlowFunctionPtrType getCallToRetFlowFunction(n_t callSite, n_t retSite, - std::set callees) { + FlowFunctionPtrType getCallToRetFlowFunction(n_t CallSite, n_t RetSite, + const std::set Callees) { PAMM_GET_INSTANCE; LOG_IF_ENABLE( BOOST_LOG_SEV(lg::get(), DEBUG) << "Call-to-Return flow function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Site : " << problem.NtoString(callSite); + << "(N) Call Site : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Ret Site : " << problem.NtoString(retSite); + << "(N) Ret Site : " << Problem.NtoString(RetSite); BOOST_LOG_SEV(lg::get(), DEBUG) << "(F) Callee's : "; for (auto callee - : callees) { - BOOST_LOG_SEV(lg::get(), DEBUG) << " " << problem.FtoString(callee); + : Callees) { + BOOST_LOG_SEV(lg::get(), DEBUG) << " " << Problem.FtoString(callee); }); - auto Key = std::tie(callSite, retSite, callees); + auto Key = std::tie(CallSite, RetSite, Callees); auto SearchCallToRetFlowFunction = CallToRetFlowFunctionCache.find(Key); if (SearchCallToRetFlowFunction != CallToRetFlowFunctionCache.end()) { LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -312,56 +306,54 @@ class FlowEdgeFunctionCache { BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); INC_COUNTER("CallToRet-FF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); return SearchCallToRetFlowFunction->second; - } else { - INC_COUNTER("CallToRet-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ff = - (autoAddZero) - ? std::make_shared>( - problem.getCallToRetFlowFunction(callSite, retSite, - callees), - zeroValue) - : problem.getCallToRetFlowFunction(callSite, retSite, callees); - CallToRetFlowFunctionCache.insert(std::make_pair(Key, ff)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Flow function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - return ff; } + INC_COUNTER("CallToRet-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto FF = + (AutoAddZero) + ? std::make_shared>( + Problem.getCallToRetFlowFunction(CallSite, RetSite, Callees), + ZV) + : Problem.getCallToRetFlowFunction(CallSite, RetSite, Callees); + CallToRetFlowFunctionCache.insert(std::make_pair(Key, FF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Flow function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + return FF; } - FlowFunctionPtrType getSummaryFlowFunction(n_t callSite, f_t destFun) { + FlowFunctionPtrType getSummaryFlowFunction(n_t CallSite, f_t DestFun) { // PAMM_GET_INSTANCE; // INC_COUNTER("Summary-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Summary flow function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Stmt : " << problem.NtoString(callSite); + << "(N) Call Stmt : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(F) Dest Mthd : " << problem.FtoString(destFun); + << "(F) Dest Mthd : " << Problem.FtoString(DestFun); BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - auto ff = problem.getSummaryFlowFunction(callSite, destFun); - return ff; + auto FF = Problem.getSummaryFlowFunction(CallSite, DestFun); + return FF; } - EdgeFunctionPtrType getNormalEdgeFunction(n_t curr, d_t currNode, n_t succ, - d_t succNode) { + EdgeFunctionPtrType getNormalEdgeFunction(n_t Curr, d_t CurrNode, n_t Succ, + d_t SuccNode) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Normal edge function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Curr Inst : " << problem.NtoString(curr); + << "(N) Curr Inst : " << Problem.NtoString(Curr); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Curr Node : " << problem.DtoString(currNode); + << "(D) Curr Node : " << Problem.DtoString(CurrNode); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Succ Inst : " << problem.NtoString(succ); + << "(N) Succ Inst : " << Problem.NtoString(Succ); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Succ Node : " << problem.DtoString(succNode)); + << "(D) Succ Node : " << Problem.DtoString(SuccNode)); - EdgeFuncInstKey OuterMapKey = createEdgeFunctionInstKey(curr, succ); + EdgeFuncInstKey OuterMapKey = createEdgeFunctionInstKey(Curr, Succ); auto SearchInnerMap = NormalFunctionCache.find(OuterMapKey); if (SearchInnerMap != NormalFunctionCache.end()) { auto SearchEdgeFunc = SearchInnerMap->second.EdgeFunctionMap.find( - createEdgeFunctionNodeKey(currNode, succNode)); + createEdgeFunctionNodeKey(CurrNode, SuccNode)); if (SearchEdgeFunc != SearchInnerMap->second.EdgeFunctionMap.end()) { INC_COUNTER("Normal-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -373,48 +365,48 @@ class FlowEdgeFunctionCache { return SearchEdgeFunc->second; } INC_COUNTER("Normal-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getNormalEdgeFunction(curr, currNode, succ, succNode); + auto EF = Problem.getNormalEdgeFunction(Curr, CurrNode, Succ, SuccNode); SearchInnerMap->second.EdgeFunctionMap.insert( - createEdgeFunctionNodeKey(currNode, succNode), ef); + createEdgeFunctionNodeKey(CurrNode, SuccNode), EF); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Edge function constructed"; BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; + << "Provide Edge Function: " << EF->str()); + return EF; } INC_COUNTER("Normal-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getNormalEdgeFunction(curr, currNode, succ, succNode); + auto EF = Problem.getNormalEdgeFunction(Curr, CurrNode, Succ, SuccNode); NormalFunctionCache.try_emplace( OuterMapKey, NormalEdgeFlowData(InnerEdgeFunctionMapType{std::make_pair( - createEdgeFunctionNodeKey(currNode, succNode), ef)})); + createEdgeFunctionNodeKey(CurrNode, SuccNode), EF)})); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Edge function constructed"; BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; + << "Provide Edge Function: " << EF->str()); + return EF; } - EdgeFunctionPtrType getCallEdgeFunction(n_t callSite, d_t srcNode, - f_t destinationFunction, - d_t destNode) { + EdgeFunctionPtrType getCallEdgeFunction(n_t CallSite, d_t SrcNode, + f_t DestinationFunction, + d_t DestNode) { PAMM_GET_INSTANCE; LOG_IF_ENABLE( BOOST_LOG_SEV(lg::get(), DEBUG) << "Call edge function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Stmt : " << problem.NtoString(callSite); + << "(N) Call Stmt : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Src Node : " << problem.DtoString(srcNode); + << "(D) Src Node : " << Problem.DtoString(SrcNode); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(F) Dest Fun : " << problem.FtoString(destinationFunction); + << "(F) Dest Fun : " << Problem.FtoString(DestinationFunction); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Dest Node : " << problem.DtoString(destNode)); - auto Key = std::tie(callSite, srcNode, destinationFunction, destNode); + << "(D) Dest Node : " << Problem.DtoString(DestNode)); + auto Key = std::tie(CallSite, SrcNode, DestinationFunction, DestNode); auto SearchCallEdgeFunction = CallEdgeFunctionCache.find(Key); if (SearchCallEdgeFunction != CallEdgeFunctionCache.end()) { INC_COUNTER("Call-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); @@ -425,40 +417,39 @@ class FlowEdgeFunctionCache { << "Provide Edge Function: " << SearchCallEdgeFunction->second->str()); return SearchCallEdgeFunction->second; - } else { - INC_COUNTER("Call-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getCallEdgeFunction(callSite, srcNode, - destinationFunction, destNode); - CallEdgeFunctionCache.insert(std::make_pair(Key, ef)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Edge function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; } + INC_COUNTER("Call-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto EF = Problem.getCallEdgeFunction(CallSite, SrcNode, + DestinationFunction, DestNode); + CallEdgeFunctionCache.insert(std::make_pair(Key, EF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Edge function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Provide Edge Function: " << EF->str()); + return EF; } - EdgeFunctionPtrType getReturnEdgeFunction(n_t callSite, f_t calleeFunction, - n_t exitInst, d_t exitNode, - n_t reSite, d_t retNode) { + EdgeFunctionPtrType getReturnEdgeFunction(n_t CallSite, f_t CalleeFunction, + n_t ExitInst, d_t ExitNode, + n_t RetSite, d_t RetNode) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Return edge function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Site : " << problem.NtoString(callSite); + << "(N) Call Site : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(F) Callee : " << problem.FtoString(calleeFunction); + << "(F) Callee : " << Problem.FtoString(CalleeFunction); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Exit Stmt : " << problem.NtoString(exitInst); + << "(N) Exit Stmt : " << Problem.NtoString(ExitInst); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Exit Node : " << problem.DtoString(exitNode); + << "(D) Exit Node : " << Problem.DtoString(ExitNode); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Ret Site : " << problem.NtoString(reSite); + << "(N) Ret Site : " << Problem.NtoString(RetSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Ret Node : " << problem.DtoString(retNode)); - auto Key = - std::tie(callSite, calleeFunction, exitInst, exitNode, reSite, retNode); + << "(D) Ret Node : " << Problem.DtoString(RetNode)); + auto Key = std::tie(CallSite, CalleeFunction, ExitInst, ExitNode, RetSite, + RetNode); auto SearchReturnEdgeFunction = ReturnEdgeFunctionCache.find(Key); if (SearchReturnEdgeFunction != ReturnEdgeFunctionCache.end()) { INC_COUNTER("Return-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); @@ -469,45 +460,44 @@ class FlowEdgeFunctionCache { << "Provide Edge Function: " << SearchReturnEdgeFunction->second->str()); return SearchReturnEdgeFunction->second; - } else { - INC_COUNTER("Return-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getReturnEdgeFunction( - callSite, calleeFunction, exitInst, exitNode, reSite, retNode); - ReturnEdgeFunctionCache.insert(std::make_pair(Key, ef)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Edge function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; } + INC_COUNTER("Return-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto EF = Problem.getReturnEdgeFunction(CallSite, CalleeFunction, ExitInst, + ExitNode, RetSite, RetNode); + ReturnEdgeFunctionCache.insert(std::make_pair(Key, EF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Edge function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Provide Edge Function: " << EF->str()); + return EF; } - EdgeFunctionPtrType getCallToRetEdgeFunction(n_t callSite, d_t callNode, - n_t retSite, d_t retSiteNode, - std::set callees) { + EdgeFunctionPtrType getCallToRetEdgeFunction(n_t CallSite, d_t CallNode, + n_t RetSite, d_t RetSiteNode, + const std::set &Callees) { PAMM_GET_INSTANCE; LOG_IF_ENABLE( BOOST_LOG_SEV(lg::get(), DEBUG) << "Call-to-Return edge function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Site : " << problem.NtoString(callSite); + << "(N) Call Site : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Call Node : " << problem.DtoString(callNode); + << "(D) Call Node : " << Problem.DtoString(CallNode); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Ret Site : " << problem.NtoString(retSite); + << "(N) Ret Site : " << Problem.NtoString(RetSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Ret Node : " << problem.DtoString(retSiteNode); + << "(D) Ret Node : " << Problem.DtoString(RetSiteNode); BOOST_LOG_SEV(lg::get(), DEBUG) << "(F) Callee's : "; for (auto callee - : callees) { - BOOST_LOG_SEV(lg::get(), DEBUG) << " " << problem.FtoString(callee); + : Callees) { + BOOST_LOG_SEV(lg::get(), DEBUG) << " " << Problem.FtoString(callee); }); - EdgeFuncInstKey OuterMapKey = createEdgeFunctionInstKey(callSite, retSite); + EdgeFuncInstKey OuterMapKey = createEdgeFunctionInstKey(CallSite, RetSite); auto SearchInnerMap = CallToRetEdgeFunctionCache.find(OuterMapKey); if (SearchInnerMap != CallToRetEdgeFunctionCache.end()) { auto SearchEdgeFunc = SearchInnerMap->second.find( - createEdgeFunctionNodeKey(callNode, retSiteNode)); + createEdgeFunctionNodeKey(CallNode, RetSiteNode)); if (SearchEdgeFunc != SearchInnerMap->second.end()) { INC_COUNTER("CallToRet-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) @@ -519,51 +509,51 @@ class FlowEdgeFunctionCache { return SearchEdgeFunc->second; } INC_COUNTER("CallToRet-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getCallToRetEdgeFunction(callSite, callNode, retSite, - retSiteNode, callees); + auto EF = Problem.getCallToRetEdgeFunction(CallSite, CallNode, RetSite, + RetSiteNode, Callees); SearchInnerMap->second.insert( - createEdgeFunctionNodeKey(callNode, retSiteNode), ef); + createEdgeFunctionNodeKey(CallNode, RetSiteNode), EF); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Edge function constructed"; BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; + << "Provide Edge Function: " << EF->str()); + return EF; } INC_COUNTER("CallToRet-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getCallToRetEdgeFunction(callSite, callNode, retSite, - retSiteNode, callees); + auto EF = Problem.getCallToRetEdgeFunction(CallSite, CallNode, RetSite, + RetSiteNode, Callees); CallToRetEdgeFunctionCache.emplace( OuterMapKey, InnerEdgeFunctionMapType{std::make_pair( - createEdgeFunctionNodeKey(callNode, retSiteNode), ef)}); + createEdgeFunctionNodeKey(CallNode, RetSiteNode), EF)}); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Edge function constructed"; BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; + << "Provide Edge Function: " << EF->str()); + return EF; } - EdgeFunctionPtrType getSummaryEdgeFunction(n_t callSite, d_t callNode, - n_t retSite, d_t retSiteNode) { + EdgeFunctionPtrType getSummaryEdgeFunction(n_t CallSite, d_t CallNode, + n_t RetSite, d_t RetSiteNode) { PAMM_GET_INSTANCE; LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Summary edge function factory call"; BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Call Site : " << problem.NtoString(callSite); + << "(N) Call Site : " << Problem.NtoString(CallSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Call Node : " << problem.DtoString(callNode); + << "(D) Call Node : " << Problem.DtoString(CallNode); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(N) Ret Site : " << problem.NtoString(retSite); + << "(N) Ret Site : " << Problem.NtoString(RetSite); BOOST_LOG_SEV(lg::get(), DEBUG) - << "(D) Ret Node : " << problem.DtoString(retSiteNode); + << "(D) Ret Node : " << Problem.DtoString(RetSiteNode); BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - auto Key = std::tie(callSite, callNode, retSite, retSiteNode); + auto Key = std::tie(CallSite, CallNode, RetSite, RetSiteNode); auto SearchSummaryEdgeFunction = SummaryEdgeFunctionCache.find(Key); if (SearchSummaryEdgeFunction != SummaryEdgeFunctionCache.end()) { INC_COUNTER("Summary-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full); @@ -574,18 +564,17 @@ class FlowEdgeFunctionCache { << "Provide Edge Function: " << SearchSummaryEdgeFunction->second->str()); return SearchSummaryEdgeFunction->second; - } else { - INC_COUNTER("Summary-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); - auto ef = problem.getSummaryEdgeFunction(callSite, callNode, retSite, - retSiteNode); - SummaryEdgeFunctionCache.insert(std::make_pair(Key, ef)); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Edge function constructed"; - BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Provide Edge Function: " << ef->str()); - return ef; } + INC_COUNTER("Summary-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full); + auto EF = Problem.getSummaryEdgeFunction(CallSite, CallNode, RetSite, + RetSiteNode); + SummaryEdgeFunctionCache.insert(std::make_pair(Key, EF)); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Edge function constructed"; + BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); + LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) + << "Provide Edge Function: " << EF->str()); + return EF; } void print() { @@ -690,23 +679,23 @@ class FlowEdgeFunctionCache { } private: - inline EdgeFuncInstKey createEdgeFunctionInstKey(n_t n1, n_t n2) { - uint64_t val = 0; - val |= KeyCompressor.getCompressedID(n1); - val <<= 32; - val |= KeyCompressor.getCompressedID(n2); - return val; + inline EdgeFuncInstKey createEdgeFunctionInstKey(n_t Lhs, n_t Rhs) { + uint64_t Val = 0; + Val |= KeyCompressor.getCompressedID(Lhs); + Val <<= 32; + Val |= KeyCompressor.getCompressedID(Rhs); + return Val; } - inline EdgeFuncNodeKey createEdgeFunctionNodeKey(d_t d1, d_t d2) { + inline EdgeFuncNodeKey createEdgeFunctionNodeKey(d_t Lhs, d_t Rhs) { if constexpr (std::is_base_of_v>) { - uint64_t val = 0; - val |= KeyCompressor.getCompressedID(d1); - val <<= 32; - val |= KeyCompressor.getCompressedID(d2); - return val; + uint64_t Val = 0; + Val |= KeyCompressor.getCompressedID(Lhs); + Val <<= 32; + Val |= KeyCompressor.getCompressedID(Rhs); + return Val; } else { - return std::make_pair(d1, d2); + return std::make_pair(Lhs, Rhs); } } }; diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFactWrapper.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFactWrapper.h index fbb45068ba..e5d06ea360 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFactWrapper.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFactWrapper.h @@ -106,9 +106,9 @@ template class FlowFactManager { } template - std::set getOrCreateFlowFacts(Args &&...args) { + std::set getOrCreateFlowFacts(Args &&...Arguments) { std::set Ret; - (Ret.insert(getOrCreateFlowFact(std::forward(args))), ...); + (Ret.insert(getOrCreateFlowFact(std::forward(Arguments))), ...); return Ret; } }; diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFunctions.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFunctions.h index 3b8d08c221..2118120e6a 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFunctions.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFunctions.h @@ -71,11 +71,11 @@ class Identity : public FlowFunction { Identity(const Identity &i) = delete; Identity &operator=(const Identity &i) = delete; // simply return what the user provides - container_type computeTargets(D source) override { return {source}; } + container_type computeTargets(D Source) override { return {Source}; } static std::shared_ptr getInstance() { - static std::shared_ptr instance = + static std::shared_ptr Instance = std::shared_ptr(new Identity); - return instance; + return Instance; } private: @@ -87,20 +87,20 @@ class LambdaFlow : public FlowFunction { public: using typename FlowFunction::container_type; - LambdaFlow(Fn &&f) : flow(std::move(f)) {} - LambdaFlow(const Fn &f) : flow(f) {} - virtual ~LambdaFlow() = default; - container_type computeTargets(D source) override { return flow(source); } + LambdaFlow(Fn &&F) : Flow(std::move(F)) {} + LambdaFlow(const Fn &F) : Flow(F) {} + ~LambdaFlow() override = default; + container_type computeTargets(D Source) override { return Flow(Source); } private: // std::function flow; - Fn flow; + Fn Flow; }; template > -typename FlowFunction::FlowFunctionPtrType makeLambdaFlow(Fn &&fn) { +typename FlowFunction::FlowFunctionPtrType makeLambdaFlow(Fn &&F) { return std::make_shared, Container>>( - std::forward(fn)); + std::forward(F)); } template > @@ -111,41 +111,42 @@ class Compose : public FlowFunction { using typename FlowFunction::container_type; - Compose(const std::vector> &funcs) : funcs(funcs) {} + Compose(const std::vector> &Funcs) : Funcs(Funcs) {} virtual ~Compose() = default; - container_type computeTargets(const D &source) override { - container_type current(source); - for (const FlowFunctionType &func : funcs) { - container_type next; - for (const D &d : current) { - container_type target = func.computeTargets(d); - next.insert(target.begin(), target.end()); + container_type computeTargets(const D &Source) override { + container_type Current(Source); + for (const FlowFunctionType &Func : Funcs) { + container_type Next; + for (const D &Fact : Current) { + container_type Target = Func.computeTargets(Fact); + Next.insert(Target.begin(), Target.end()); } - current = next; + Current = Next; } - return current; + return Current; } static FlowFunctionPtrType - compose(const std::vector &funcs) { - std::vector vec; - for (const FlowFunctionType &func : funcs) { - if (func != Identity::getInstance()) { - vec.insert(func); + compose(const std::vector &Funcs) { + std::vector Vec; + for (const FlowFunctionType &Func : Funcs) { + if (Func != Identity::getInstance()) { + Vec.insert(Func); } } - if (vec.size == 1) { - return vec[0]; - } else if (vec.empty()) { + if (Vec.size() == 1) { // NOLINT(readability-container-size-empty) + return Vec[0]; + } + if (Vec.empty()) { return Identity::getInstance(); } - return std::make_shared(vec); + return std::make_shared(Vec); } protected: - const std::vector funcs; + const std::vector Funcs; }; //===----------------------------------------------------------------------===// @@ -156,19 +157,18 @@ class Gen : public FlowFunction { using typename FlowFunction::container_type; protected: - D genValue; - D zeroValue; + D GenValue; + D ZeroValue; public: - Gen(D genValue, D zeroValue) : genValue(genValue), zeroValue(zeroValue) {} - virtual ~Gen() = default; - - container_type computeTargets(D source) override { - if (source == zeroValue) { - return {source, genValue}; - } else { - return {source}; + Gen(D GenValue, D ZeroValue) : GenValue(GenValue), ZeroValue(ZeroValue) {} + ~Gen() override = default; + + container_type computeTargets(D Source) override { + if (Source == ZeroValue) { + return {Source, GenValue}; } + return {Source}; } }; @@ -182,7 +182,7 @@ class GenIf : public FlowFunction { using typename FlowFunction::container_type; GenIf(D GenValue, std::function Predicate) - : GenValues({GenValue}), Predicate(Predicate) {} + : GenValues({GenValue}), Predicate(std::move(Predicate)) {} GenIf(container_type GenValues, std::function Predicate) : GenValues(std::move(GenValues)), Predicate(Predicate) {} @@ -195,9 +195,8 @@ class GenIf : public FlowFunction { ToGenerate.insert(Source); ToGenerate.insert(GenValues.begin(), GenValues.end()); return ToGenerate; - } else { - return {Source}; } + return {Source}; } protected: @@ -210,21 +209,20 @@ class GenAll : public FlowFunction { public: using typename FlowFunction::container_type; - GenAll(container_type genValues, D zeroValue) - : genValues(genValues), zeroValue(zeroValue) {} - virtual ~GenAll() = default; - container_type computeTargets(D source) override { - if (source == zeroValue) { - genValues.insert(source); - return genValues; - } else { - return {source}; + GenAll(container_type GenValues, D ZeroValue) + : GenValues(std::move(GenValues)), ZeroValue(ZeroValue) {} + ~GenAll() override = default; + container_type computeTargets(D Source) override { + if (Source == ZeroValue) { + GenValues.insert(Source); + return GenValues; } + return {Source}; } protected: - container_type genValues; - D zeroValue; + container_type GenValues; + D ZeroValue; }; //===----------------------------------------------------------------------===// @@ -235,18 +233,17 @@ class Kill : public FlowFunction { public: using typename FlowFunction::container_type; - Kill(D killValue) : killValue(killValue) {} - virtual ~Kill() = default; - container_type computeTargets(D source) override { - if (source == killValue) { + Kill(D KillValue) : KillValue(KillValue) {} + ~Kill() override = default; + container_type computeTargets(D Source) override { + if (Source == KillValue) { return {}; - } else { - return {source}; } + return {Source}; } protected: - D killValue; + D KillValue; }; /// \brief Kills all facts for which the given predicate evaluates to true. @@ -256,14 +253,13 @@ class KillIf : public FlowFunction { public: using typename FlowFunction::container_type; - KillIf(std::function Predicate) : Predicate(Predicate) {} - virtual ~KillIf() = default; - container_type computeTargets(D source) override { - if (Predicate(source)) { + KillIf(std::function Predicate) : Predicate(std::move(Predicate)) {} + ~KillIf() override = default; + container_type computeTargets(D Source) override { + if (Predicate(Source)) { return {}; - } else { - return {source}; } + return {Source}; } protected: @@ -275,18 +271,17 @@ class KillMultiple : public FlowFunction { public: using typename FlowFunction::container_type; - KillMultiple(std::set killValues) : killValues(killValues) {} - virtual ~KillMultiple() = default; - container_type computeTargets(D source) override { - if (killValues.find(source) != killValues.end()) { + KillMultiple(std::set KillValues) : KillValues(std::move(KillValues)) {} + ~KillMultiple() override = default; + container_type computeTargets(D Source) override { + if (KillValues.find(Source) != KillValues.end()) { return {}; - } else { - return {source}; } + return {Source}; } protected: - container_type killValues; + container_type KillValues; }; template > @@ -294,14 +289,16 @@ class KillAll : public FlowFunction { public: using typename FlowFunction::container_type; - virtual ~KillAll() = default; - KillAll(const KillAll &k) = delete; - KillAll &operator=(const KillAll &k) = delete; - container_type computeTargets(D source) override { return container_type(); } + ~KillAll() override = default; + KillAll(const KillAll &K) = delete; + KillAll &operator=(const KillAll &K) = delete; + container_type computeTargets(D /*Source*/) override { + return container_type(); + } static std::shared_ptr> getInstance() { - static std::shared_ptr instance = + static std::shared_ptr Instance = std::shared_ptr(new KillAll); - return instance; + return Instance; } private: @@ -316,19 +313,19 @@ class GenAndKillAllOthers : public FlowFunction { public: using typename FlowFunction::container_type; - GenAndKillAllOthers(D genValue, D zeroValue) - : genValue(genValue), zeroValue(zeroValue) {} - virtual ~GenAndKillAllOthers() = default; - container_type computeTargets(D source) override { - if (source == zeroValue) { - return {zeroValue, genValue}; + GenAndKillAllOthers(D GenValue, D ZeroValue) + : GenValue(GenValue), ZeroValue(ZeroValue) {} + ~GenAndKillAllOthers() override = default; + container_type computeTargets(D Source) override { + if (Source == ZeroValue) { + return {ZeroValue, GenValue}; } return {}; } private: - D genValue; - D zeroValue; + D GenValue; + D ZeroValue; }; template > @@ -336,21 +333,20 @@ class GenAllAndKillAllOthers : public FlowFunction { public: using typename FlowFunction::container_type; - GenAllAndKillAllOthers(container_type genValues, D zeroValue) - : genValues(genValues), zeroValue(zeroValue) {} - virtual ~GenAllAndKillAllOthers() = default; - container_type computeTargets(D source) override { - if (source == zeroValue) { - genValues.insert(source); - return genValues; - } else { - return {}; + GenAllAndKillAllOthers(const container_type &GenValues, D ZeroValue) + : GenValues(GenValues), ZeroValue(ZeroValue) {} + ~GenAllAndKillAllOthers() override = default; + container_type computeTargets(D Source) override { + if (Source == ZeroValue) { + GenValues.insert(Source); + return GenValues; } + return {}; } protected: - container_type genValues; - D zeroValue; + container_type GenValues; + D ZeroValue; }; //===----------------------------------------------------------------------===// @@ -361,21 +357,21 @@ class Transfer : public FlowFunction { public: using typename FlowFunction::container_type; - Transfer(D toValue, D fromValue) : toValue(toValue), fromValue(fromValue) {} + Transfer(D ToValue, D FromValue) : ToValue(ToValue), FromValue(FromValue) {} virtual ~Transfer() = default; - container_type computeTargets(D source) override { - if (source == fromValue) { - return {source, toValue}; - } else if (source == toValue) { + container_type computeTargets(D Source) override { + if (Source == FromValue) { + return {Source, ToValue}; + } + if (Source == ToValue) { return {}; - } else { - return {source}; } + return {Source}; } protected: - D toValue; - D fromValue; + D ToValue; + D FromValue; }; template > @@ -390,16 +386,15 @@ class Union : public FlowFunction { if (FlowFuncs.empty()) { return std::vector( {Identity::getInstance()}); - } else { - return FlowFuncs; } + return FlowFuncs; }()) {} - virtual ~Union() = default; - container_type computeTargets(D source) override { + ~Union() override = default; + container_type computeTargets(D Source) override { container_type Result; for (const auto &FlowFunc : FlowFuncs) { - container_type target = FlowFunc->computeTargets(source); - Result.insert(target.begin(), target.end()); + container_type Target = FlowFunc->computeTargets(Source); + Result.insert(Target.begin(), Target.end()); } return Result; } @@ -414,21 +409,20 @@ class ZeroedFlowFunction : public FlowFunction { using typename FlowFunction::FlowFunctionPtrType; public: - ZeroedFlowFunction(FlowFunctionPtrType ff, D zv) - : delegate(ff), zerovalue(zv) {} - container_type computeTargets(D source) override { - if (source == zerovalue) { - container_type result = delegate->computeTargets(source); - result.insert(zerovalue); - return result; - } else { - return delegate->computeTargets(source); + ZeroedFlowFunction(FlowFunctionPtrType FF, D ZV) + : Delegate(std::move(FF)), ZeroValue(ZV) {} + container_type computeTargets(D Source) override { + if (Source == ZeroValue) { + container_type Result = Delegate->computeTargets(Source); + Result.insert(ZeroValue); + return Result; } + return Delegate->computeTargets(Source); } private: - FlowFunctionPtrType delegate; - D zerovalue; + FlowFunctionPtrType Delegate; + D ZeroValue; }; //===----------------------------------------------------------------------===// diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp index dc7ee8f2b7..b37c0dade4 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp @@ -16,9 +16,9 @@ static unsigned CurrAddTwoEfId = 0; struct MyEFC : EdgeFunctionComposer { MyEFC(std::shared_ptr> F, std::shared_ptr> G) - : EdgeFunctionComposer(std::move(F), std::move(G)){}; + : EdgeFunctionComposer(F, G){}; std::shared_ptr> - joinWith(std::shared_ptr> OtherFunction) override { + joinWith(std::shared_ptr> /*OtherFunction*/) override { return std::make_shared>(-1); }; }; @@ -35,13 +35,13 @@ struct MulTwoEF : EdgeFunction, std::enable_shared_from_this { return std::make_shared(this->shared_from_this(), SecondFunction); } std::shared_ptr> - joinWith(std::shared_ptr> OtherFunction) override { + joinWith(std::shared_ptr> /*OtherFunction*/) override { return std::make_shared>(-1); }; bool equal_to(std::shared_ptr> Other) const override { return this == Other.get(); } - void print(std::ostream &Os, bool IsForDebug = false) const override { + void print(std::ostream &Os, bool /*IsForDebug = false*/) const override { Os << "MulTwoEF_" << MulTwoEfId; } }; @@ -58,13 +58,13 @@ struct AddTwoEF : EdgeFunction, std::enable_shared_from_this { return std::make_shared(this->shared_from_this(), SecondFunction); } std::shared_ptr> - joinWith(std::shared_ptr> OtherFunction) override { + joinWith(std::shared_ptr> /*OtherFunction*/) override { return std::make_shared>(-1); }; bool equal_to(std::shared_ptr> Other) const override { return this == Other.get(); } - void print(std::ostream &Os, bool IsForDebug = false) const override { + void print(std::ostream &Os, bool /*IsForDebug = false*/) const override { Os << "AddTwoEF_" << AddTwoEfId; } }; diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp index d851d07533..bfca79e282 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp @@ -17,17 +17,17 @@ struct TestEdgeFunction return EdgeFunctionSingletonFactory::getCacheData(); } - int computeTarget(int Source) override { return 42; } + int computeTarget(int /*Source*/) override { return 42; } - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override { + EdgeFunctionPtrType composeWith(EdgeFunctionPtrType /*SecondFunction*/) override { return this->shared_from_this(); }; - EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override { + EdgeFunctionPtrType joinWith(EdgeFunctionPtrType /*OtherFunction*/) override { return this->shared_from_this(); } - bool equal_to(EdgeFunctionPtrType OtherFunction) const override { + bool equal_to(EdgeFunctionPtrType /*OtherFunction*/) const override { return false; }; From e698649eefb45c743fc71350bbb915546db60492 Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Fri, 24 Dec 2021 15:17:07 +0100 Subject: [PATCH 2/3] Update unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../IfdsIde/EdgeFunctionSingletonFactoryTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp index bfca79e282..26cc465be8 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionSingletonFactoryTest.cpp @@ -19,7 +19,8 @@ struct TestEdgeFunction int computeTarget(int /*Source*/) override { return 42; } - EdgeFunctionPtrType composeWith(EdgeFunctionPtrType /*SecondFunction*/) override { + EdgeFunctionPtrType + composeWith(EdgeFunctionPtrType /*SecondFunction*/) override { return this->shared_from_this(); }; From 8ee1a8a49b79aa269a29bbea3ff2ad99503f1838 Mon Sep 17 00:00:00 2001 From: Philipp Schubert Date: Tue, 4 Jan 2022 14:43:17 +0100 Subject: [PATCH 3/3] minor --- include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h | 2 +- .../DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h index f280e1fac6..f0f0f00515 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/DefaultSeeds.h @@ -28,7 +28,7 @@ template class DefaultSeeds { static std::map> make(std::vector Nodes, D ZeroNode) { std::map> Result; for (N Node : Nodes) { - Result.insert(Node, {ZeroNode}); + Result.insert(std::move(Node), {ZeroNode}); } return Result; } diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp index b37c0dade4..76e0d396f0 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctionComposerTest.cpp @@ -17,6 +17,7 @@ struct MyEFC : EdgeFunctionComposer { MyEFC(std::shared_ptr> F, std::shared_ptr> G) : EdgeFunctionComposer(F, G){}; + std::shared_ptr> joinWith(std::shared_ptr> /*OtherFunction*/) override { return std::make_shared>(-1);