From 66508f76c7f29b0c3f1648bf5cd7355951c56a33 Mon Sep 17 00:00:00 2001 From: bjjwwang Date: Sun, 26 Jan 2025 22:18:38 +1100 Subject: [PATCH] remove SVFFunction::getBasicBlockList(), move addBasicBlock to BasicBlockGraph. And some related chages --- svf-llvm/include/SVF-LLVM/LLVMModule.h | 2 +- svf-llvm/lib/LLVMModule.cpp | 2 +- svf/include/Graphs/BasicBlockG.h | 10 ++++++++++ svf/include/SVFIR/SVFValue.h | 16 ---------------- svf/lib/MTA/LockAnalysis.cpp | 3 ++- svf/lib/MTA/MHP.cpp | 3 ++- svf/lib/MTA/MTA.cpp | 3 ++- svf/lib/Util/CallGraphBuilder.cpp | 9 ++++++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index b8d5fe6a1..fa812a9d8 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -249,7 +249,7 @@ class LLVMModuleSet const Value* getLLVMValue(const SVFBaseNode* value) const { - if (value->getNodeKind() == SVFBaseNode::BasicBlockKd) + if (SVFUtil::isa(value)) { const SVFBasicBlock* bb = SVFUtil::cast(value); SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(bb); diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 556fa789a..4b8377180 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -300,7 +300,7 @@ void LLVMModuleSet::createSVFFunction(const Function* func) for (const BasicBlock& bb : *func) { - SVFBasicBlock* svfBB = svfFunc->addBasicBlock(bb.getName().str()); + SVFBasicBlock* svfBB = bbGraph->addBasicBlock(bb.getName().str()); addBasicBlockMap(&bb, svfBB); for (const Instruction& inst : bb) { diff --git a/svf/include/Graphs/BasicBlockG.h b/svf/include/Graphs/BasicBlockG.h index ef203f950..3bfbdb004 100644 --- a/svf/include/Graphs/BasicBlockG.h +++ b/svf/include/Graphs/BasicBlockG.h @@ -112,6 +112,16 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy } + static inline bool classof(const SVFBaseNode* node) + { + return node->getNodeKind() == SVFBaseNode::BasicBlockKd; + } + + static inline bool classof(const SVFBasicBlock* node) + { + return true; + } + //@{ friend OutStream &operator<<(OutStream &o, const SVFBasicBlock&node) { diff --git a/svf/include/SVFIR/SVFValue.h b/svf/include/SVFIR/SVFValue.h index 8910a89fd..297508935 100644 --- a/svf/include/SVFIR/SVFValue.h +++ b/svf/include/SVFIR/SVFValue.h @@ -327,12 +327,6 @@ class SVFFunction : public SVFValue callGraphNode = cgn; } - - inline SVFBasicBlock* addBasicBlock(const std::string& bbName) { - SVFBasicBlock* bb = bbGraph->addBasicBlock(bbName); - return bb; - } - inline void addArgument(SVFArgument* arg) { allArgs.push_back(arg); @@ -457,16 +451,6 @@ class SVFFunction : public SVFValue return bbGraph->end(); } - inline std::vector getBasicBlockList() const - { - std::vector blockList; - blockList.reserve(bbGraph->getTotalNodeNum()); - std::transform(bbGraph->begin(), bbGraph->end(), std::back_inserter(blockList), - [](const BasicBlockGraph::IDToNodeMapTy::value_type& pair) { - return pair.second; - }); - return blockList; - } inline const std::vector& getReachableBBs() const { diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 755304272..abbec8792 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -72,8 +72,9 @@ void LockAnalysis::collectLockUnlocksites() for (const SVFFunction* F : tct->getSVFModule()->getFunctionSet()) { - for (const SVFBasicBlock* bb : F->getBasicBlockList()) + for (auto it : *F) { + const SVFBasicBlock* bb = it.second; for (const ICFGNode* icfgNode : bb->getICFGNodeList()) { if (isa(icfgNode) && tcg->getThreadAPI()->isTDRelease(cast(icfgNode))) diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index e9ef74ab6..b104a6d25 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -159,8 +159,9 @@ void MHP::updateNonCandidateFunInterleaving() { const CallStrCxt& curCxt = cts.getContext(); - for (const SVFBasicBlock* svfbb : fun->getBasicBlockList()) + for (auto it : *fun) { + const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* curNode : svfbb->getICFGNodeList()) { if (curNode == entryNode) diff --git a/svf/lib/MTA/MTA.cpp b/svf/lib/MTA/MTA.cpp index 0f614f255..5b6e671c3 100644 --- a/svf/lib/MTA/MTA.cpp +++ b/svf/lib/MTA/MTA.cpp @@ -139,8 +139,9 @@ void MTA::detect(SVFModule* module) for (const SVFFunction* F : module->getFunctionSet()) { // collect and create symbols inside the function body - for (const SVFBasicBlock* svfbb : F->getBasicBlockList()) + for (auto it : *F) { + const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* icfgNode : svfbb->getICFGNodeList()) { for(const SVFStmt* stmt : pag->getSVFStmtList(icfgNode)) diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 6c7a012db..5bda6882b 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -48,8 +48,9 @@ CallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) for (const auto& item : *callgraph) { - for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList()) + for (auto it : *(item.second)->getFunction()) { + const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* inst : svfbb->getICFGNodeList()) { if (SVFUtil::isNonInstricCallSite(inst)) @@ -80,8 +81,9 @@ ThreadCallGraph* CallGraphBuilder::buildThreadCallGraph() ThreadAPI* tdAPI = ThreadAPI::getThreadAPI(); for (const auto& item: *svfirCallGraph) { - for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList()) + for (auto it : *(item.second)->getFunction()) { + const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* inst : svfbb->getICFGNodeList()) { if (SVFUtil::isa(inst) && tdAPI->isTDFork(SVFUtil::cast(inst))) @@ -105,8 +107,9 @@ ThreadCallGraph* CallGraphBuilder::buildThreadCallGraph() // record join sites for (const auto& item: *svfirCallGraph) { - for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList()) + for (auto it : *(item.second)->getFunction()) { + const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* node : svfbb->getICFGNodeList()) { if (SVFUtil::isa(node) && tdAPI->isTDJoin(SVFUtil::cast(node)))