Skip to content

Commit

Permalink
Merge pull request #1275 from jumormt/12.8
Browse files Browse the repository at this point in the history
Build CFBasicBlockG based on SVFBasicBlocks rather than ICFG
  • Loading branch information
yuleisui authored Dec 8, 2023
2 parents b41323d + e972fd9 commit cdd2063
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions svf/lib/Util/CFBasicBlockGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
#include "Util/CFBasicBlockGBuilder.h"

#include <SVFIR/SVFIR.h>

namespace SVF
{

Expand All @@ -40,50 +42,76 @@ namespace SVF
void CFBasicBlockGBuilder::initCFBasicBlockGNodes(ICFG *icfg,
Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes)
{
for (const auto &node : *icfg)
for (const auto &func : *PAG::getPAG()->getModule())
{
CFBasicBlockNode *pNode;
if (const SVFBasicBlock *bb = node.second->getBB())
for(const auto& bb: *func)
{
if (const CallICFGNode *callNode = SVFUtil::dyn_cast<CallICFGNode>(node.second))
{
// Create a new CFBasicBlockNode for the CallICFGNode
pNode = new CFBasicBlockNode({callNode});
bbToNodes[bb].push_back(pNode);
_CFBasicBlockG->addCFBBNode(pNode);

// Create a new CFBasicBlockNode for the corresponding RetICFGNode
auto *retNode = new CFBasicBlockNode({callNode->getRetICFGNode()});
bbToNodes[bb].push_back(retNode);
_CFBasicBlockG->addCFBBNode(retNode);
}
else if (!SVFUtil::isa<RetICFGNode>(node.second))
for(const auto& inst: *bb)
{
if (bbToNodes.find(bb) == bbToNodes.end())
if(SVFUtil::isIntrinsicInst(inst)) continue;
const ICFGNode* icfgNode = icfg->getICFGNode(inst);
if (const CallICFGNode *callNode = SVFUtil::dyn_cast<CallICFGNode>(icfgNode))
{
// Create a new CFBasicBlockNode for the non-CallICFGNode
pNode = new CFBasicBlockNode({node.second});
bbToNodes[node.second->getBB()] = {pNode};
// Create a new CFBasicBlockNode for the CallICFGNode
CFBasicBlockNode* pNode = new CFBasicBlockNode({callNode});
bbToNodes[bb].push_back(pNode);
_CFBasicBlockG->addCFBBNode(pNode);

// Create a new CFBasicBlockNode for the corresponding RetICFGNode
auto *retNode = new CFBasicBlockNode({callNode->getRetICFGNode()});
bbToNodes[bb].push_back(retNode);
_CFBasicBlockG->addCFBBNode(retNode);
}
else
{
pNode = bbToNodes[node.second->getBB()].back();
if (!SVFUtil::isa<RetICFGNode>(pNode->getICFGNodes()[0]))
if (bbToNodes.find(bb) == bbToNodes.end())
{
// Add the non-CallICFGNode to the existing CFBasicBlockNode
pNode->addNode(node.second);
// Create a new CFBasicBlockNode for the non-CallICFGNode
CFBasicBlockNode* pNode = new CFBasicBlockNode({icfgNode});
bbToNodes[bb] = {pNode};
_CFBasicBlockG->addCFBBNode(pNode);
}
else
{
// Create a new CFBasicBlockNode for the non-CallICFGNode
pNode = new CFBasicBlockNode({node.second});
bbToNodes[node.second->getBB()].push_back(pNode);
_CFBasicBlockG->addCFBBNode(pNode);
CFBasicBlockNode* pNode = bbToNodes[bb].back();
if (!SVFUtil::isa<RetICFGNode>(pNode->getICFGNodes()[0]))
{
// Add the non-CallICFGNode to the existing CFBasicBlockNode
pNode->addNode(icfgNode);
}
else
{
// Create a new CFBasicBlockNode for the non-CallICFGNode
pNode = new CFBasicBlockNode({icfgNode});
bbToNodes[bb].push_back(pNode);
_CFBasicBlockG->addCFBBNode(pNode);
}
}
}
}
}

if(const FunEntryICFGNode* funEntryNode = icfg->getFunEntryICFGNode(func))
{
if(const SVFBasicBlock* bb = funEntryNode->getBB())
{
std::vector<CFBasicBlockNode *>& nodes = bbToNodes[bb];
CFBasicBlockNode* pNode = new CFBasicBlockNode({funEntryNode});
nodes.insert(nodes.begin(), pNode);
_CFBasicBlockG->addCFBBNode(pNode);
}
}

if(const FunExitICFGNode* funExitNode = icfg->getFunExitICFGNode(func))
{
if(const SVFBasicBlock* bb = funExitNode->getBB())
{
std::vector<CFBasicBlockNode *>& nodes = bbToNodes[bb];
CFBasicBlockNode* pNode = new CFBasicBlockNode({funExitNode});
nodes.push_back(pNode);
_CFBasicBlockG->addCFBBNode(pNode);
}
}
}
}

Expand Down

0 comments on commit cdd2063

Please sign in to comment.