8000 refactor: change the value type in FunToExitBBMap from svfbb to bb to simplify code by jumormt · Pull Request #1677 · SVF-tools/SVF · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: change the value type in FunToExitBBMap from svfbb to bb to simplify code #1677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LLVMModuleSet
typedef OrderedMap<const Function*, NodeID> FunToIDMapTy;

typedef std::vector<const Function*> FunctionSet;
typedef Map<const Function*, const SVFBasicBlock*> FunToExitBBMap;
typedef Map<const Function*, const BasicBlock*> FunToExitBBMap;
typedef Map<const Function*, const Function *> FunToRealDefFunMap;

private:
Expand Down Expand Up @@ -173,7 +173,7 @@ class LLVMModuleSet

public:

inline const SVFBasicBlock* getFunExitBB(const Function* fun) const
inline const BasicBlock* getFunExitBB(const Function* fun) const
{
auto it = funToExitBB.find(fun);
if (it == funToExitBB.end()) return nullptr;
Expand Down Expand Up @@ -435,7 +435,7 @@ class LLVMModuleSet
funSet.push_back(svfFunc);
}

inline void setFunExitBB(const Function* fun, const SVFBasicBlock* bb)
inline void setFunExitBB(const Function* fun, const BasicBlock* bb)
{
funToExitBB[fun] = bb;
}
Expand Down
28 changes: 28 additions & 0 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,34 @@ void LLVMModuleSet::createSVFDataStructure()
addFunctionSet(func);
}

// set function exit block
for (const auto& func: funSet) {
for (Function::const_iterator bit = func->begin(), ebit = func->end(); bit != ebit; ++bit)
{
const BasicBlock* bb = &*bit;
/// set exit block: exit basic block must have no successors and have a return instruction
if (succ_size(bb) == 0)
{
if (LLVMUtil::basicBlockHasRetInst(bb))
{
assert((LLVMUtil::functionDoesNotRet(func) ||
SVFUtil::isa<ReturnInst>(bb->back())) &&
"last inst must be return inst");
setFunExitBB(func, bb);
}
}
}
// For no return functions, we set the last block as exit BB
// This ensures that each function that has definition must have an exit BB
if (func->size() != 0 && !getFunExitBB(func))
{
assert((LLVMUtil::functionDoesNotRet(func) ||
SVFUtil::isa<ReturnInst>(&func->back().back())) &&
"last inst must be return inst");
setFunExitBB(func, &func->back());
}
}

// Store annotations of functions in extapi.bc
for (const auto& pair : ExtFun2Annotations)
{
Expand Down
4 changes: 2 additions & 2 deletions svf-llvm/lib/ObjTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ Set<const Value *> &ObjTypeInference::bwfindAllocOfVar(const Value *var)
{

LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet();
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(llvmmodule->getLLVMValue(llvmmodule->getFunExitBB(callee)));
const BasicBlock* exitBB = llvmmodule->getFunExitBB(callee);
assert (exitBB && "exit bb is not a basic block?");
const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
Expand Down Expand Up @@ -934,7 +934,7 @@ Set<const Value *> &ObjTypeInference::bwFindAllocOrClsNameSources(const Value *s
if (!callee->isDeclaration())
{
LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet();
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(llvmmodule->getLLVMValue(llvmmodule->getFunExitBB(callee)));
const BasicBlock* exitBB = llvmmodule->getFunExitBB(callee);
assert (exitBB && "exit bb is not a basic block?");
const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
Expand Down
2 changes: 0 additions & 2 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ void SVFIRBuilder::initSVFBasicBlock(const Function* func)
SVFUtil::isa<ReturnInst>(bb->back())) &&
"last inst must be return inst");
svfFun->setExitBlock(svfbb);
llvmModuleSet()->setFunExitBB(func, svfbb);
}
}
}
Expand All @@ -255,7 +254,6 @@ void SVFIRBuilder::initSVFBasicBlock(const Function* func)
SVFUtil::isa<ReturnInst>(&func->back().back())) &&
"last inst must be return inst");
svfFun->setExitBlock(retBB);
llvmModuleSet()->setFunExitBB(func, retBB);
}
}

Expand Down
Loading
0