Skip to content
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

add SVFBasicBlock. BasicBlockEdge, Graph #1639

Merged
merged 12 commits into from
Jan 27, 2025
8 changes: 5 additions & 3 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "SVFIR/SVFValue.h"
#include "SVFIR/SVFModule.h"
#include "Util/Options.h"
#include "Graphs/BasicBlockG.h"

namespace SVF
{
Expand Down Expand Up @@ -180,8 +181,9 @@ class LLVMModuleSet
inline void addBasicBlockMap(const BasicBlock* bb, SVFBasicBlock* svfBB)
{
LLVMBB2SVFBB[bb] = svfBB;
setValueAttr(bb,svfBB);
SVFBaseNode2LLVMValue[svfBB] = bb;
}

inline void addInstructionMap(const Instruction* inst, SVFInstruction* svfInst)
{
LLVMInst2SVFInst[inst] = svfInst;
Expand Down Expand Up @@ -246,7 +248,7 @@ class LLVMModuleSet
const Value* getLLVMValue(const SVFBaseNode* value) const
{
SVFBaseNode2LLVMValueMap ::const_iterator it = SVFBaseNode2LLVMValue.find(value);
assert(it!=SVFBaseNode2LLVMValue.end() && "can't find corresponding llvm value!");
assert(it != SVFBaseNode2LLVMValue.end() && "can't find corresponding llvm value!");
return it->second;
}

Expand All @@ -264,7 +266,7 @@ class LLVMModuleSet
return it->second;
}

inline SVFBasicBlock* getSVFBasicBlock(const BasicBlock* bb) const
SVFBasicBlock* getSVFBasicBlock(const BasicBlock* bb)
{
LLVMBB2SVFBBMap::const_iterator it = LLVMBB2SVFBB.find(bb);
assert(it!=LLVMBB2SVFBB.end() && "SVF BasicBlock not found!");
Expand Down
8 changes: 3 additions & 5 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ void LLVMModuleSet::createSVFFunction(const Function* func)
getSVFType(func->getFunctionType())),
func->isDeclaration(), LLVMUtil::isIntrinsicFun(func),
func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo);
BasicBlockGraph* bbGraph = new BasicBlockGraph(svfFunc);
svfFunc->setBasicBlockGraph(bbGraph);
svfModule->addFunctionSet(svfFunc);
addFunctionMap(func, svfFunc);

Expand All @@ -298,9 +300,7 @@ void LLVMModuleSet::createSVFFunction(const Function* func)

for (const BasicBlock& bb : *func)
{
SVFBasicBlock* svfBB =
new SVFBasicBlock(getSVFType(bb.getType()), svfFunc);
svfFunc->addBasicBlock(svfBB);
SVFBasicBlock* svfBB = bbGraph->addBasicBlock(bb.getName().str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this line "SVFBasicBlock* svfBB = bbGraph->addBasicBlock(bb.getName().str());" into "addBasicBlockMap" and rename addBasicBlockMap to addBasicBlock

addBasicBlockMap(&bb, svfBB);
for (const Instruction& inst : bb)
{
Expand Down Expand Up @@ -1365,8 +1365,6 @@ SVFValue* LLVMModuleSet::getSVFValue(const Value* value)
{
if (const Function* fun = SVFUtil::dyn_cast<Function>(value))
return getSVFFunction(fun);
else if (const BasicBlock* bb = SVFUtil::dyn_cast<BasicBlock>(value))
return getSVFBasicBlock(bb);
else if(const Instruction* inst = SVFUtil::dyn_cast<Instruction>(value))
return getSVFInstruction(inst);
else if (const Argument* arg = SVFUtil::dyn_cast<Argument>(value))
Expand Down
16 changes: 12 additions & 4 deletions svf-llvm/lib/LLVMUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,6 @@
{
rawstr << "Function: " << fun->getName() << " ";
}
else if (const SVFBasicBlock* bb = SVFUtil::dyn_cast<SVFBasicBlock>(this))
{
rawstr << "BasicBlock: " << bb->getName() << " ";
}
else
{
auto llvmVal = LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(this);
Expand All @@ -742,6 +738,18 @@
return rawstr.str();
}

const std::string SVFBasicBlock::toString() const

Check warning on line 741 in svf-llvm/lib/LLVMUtil.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/LLVMUtil.cpp#L741

Added line #L741 was not covered by tests
{
std::string str;
llvm::raw_string_ostream rawstr(str);
auto llvmVal = LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(this);

Check warning on line 745 in svf-llvm/lib/LLVMUtil.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/LLVMUtil.cpp#L745

Added line #L745 was not covered by tests
if (llvmVal)
rawstr << " " << *llvmVal << " ";

Check warning on line 747 in svf-llvm/lib/LLVMUtil.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/LLVMUtil.cpp#L747

Added line #L747 was not covered by tests
else
rawstr << " No llvmVal found";
rawstr << this->getSourceLoc();
return rawstr.str();

Check warning on line 751 in svf-llvm/lib/LLVMUtil.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/LLVMUtil.cpp#L749-L751

Added lines #L749 - L751 were not covered by tests
}

const std::string SVFBaseNode::valueOnlyToString() const
{
Expand Down
6 changes: 2 additions & 4 deletions svf-llvm/lib/ObjTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,7 @@ Set<const Value *> &ObjTypeInference::bwfindAllocOfVar(const Value *var)
if (!callee->isDeclaration())
{
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
const BasicBlock* exitBB = SVFUtil::cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roll back

svfFunc->getExitBB()));
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cast here or you need to add an assertion

const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?");
Expand Down Expand Up @@ -894,8 +893,7 @@ Set<const Value *> &ObjTypeInference::bwFindAllocOrClsNameSources(const Value *s
if (!callee->isDeclaration())
{
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
const BasicBlock* exitBB = SVFUtil::cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(
svfFunc->getExitBB()));
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const BasicBlock* exitBB = SVFUtil::dyn_cast(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
assert (exitBB && "exit bb is not a basic block?");

const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?");
Expand Down
Loading
Loading