-
Notifications
You must be signed in to change notification settings - Fork 439
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
Changes from 6 commits
624fc5f
bb53f4c
e4c7163
879bc0d
342f37a
2dd6775
d97854b
66508f7
3776a6a
7d63f80
82f79c9
8727fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
#include "SVFIR/SVFValue.h" | ||
#include "SVFIR/SVFModule.h" | ||
#include "Util/Options.h" | ||
#include "Graphs/BasicBlockG.h" | ||
|
||
namespace SVF | ||
{ | ||
|
@@ -56,6 +57,7 @@ class LLVMModuleSet | |
typedef Map<const Function*, SVFFunction*> LLVMFun2SVFFunMap; | ||
typedef Map<const Function*, CallGraphNode*> LLVMFun2CallGraphNodeMap; | ||
typedef Map<const BasicBlock*, SVFBasicBlock*> LLVMBB2SVFBBMap; | ||
typedef Map<const SVFBasicBlock*, const BasicBlock*> SVFBB2LLVMBBMap; | ||
typedef Map<const Instruction*, SVFInstruction*> LLVMInst2SVFInstMap; | ||
typedef Map<const Argument*, SVFArgument*> LLVMArgument2SVFArgumentMap; | ||
typedef Map<const Constant*, SVFConstant*> LLVMConst2SVFConstMap; | ||
|
@@ -92,6 +94,7 @@ class LLVMModuleSet | |
LLVMFun2SVFFunMap LLVMFunc2SVFFunc; ///< Map an LLVM Function to an SVF Function | ||
LLVMFun2CallGraphNodeMap LLVMFunc2CallGraphNode; ///< Map an LLVM Function to an CallGraph Node | ||
LLVMBB2SVFBBMap LLVMBB2SVFBB; | ||
SVFBB2LLVMBBMap SVFBB2LLVMBB; | ||
LLVMInst2SVFInstMap LLVMInst2SVFInst; | ||
LLVMArgument2SVFArgumentMap LLVMArgument2SVFArgument; | ||
LLVMConst2SVFConstMap LLVMConst2SVFConst; | ||
|
@@ -180,8 +183,9 @@ class LLVMModuleSet | |
inline void addBasicBlockMap(const BasicBlock* bb, SVFBasicBlock* svfBB) | ||
{ | ||
LLVMBB2SVFBB[bb] = svfBB; | ||
setValueAttr(bb,svfBB); | ||
SVFBB2LLVMBB[svfBB] = bb; | ||
} | ||
|
||
inline void addInstructionMap(const Instruction* inst, SVFInstruction* svfInst) | ||
{ | ||
LLVMInst2SVFInst[inst] = svfInst; | ||
|
@@ -245,9 +249,19 @@ 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!"); | ||
return it->second; | ||
if (value->getNodeKind() == SVFBaseNode::BasicBlockKd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use isa<> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for reminding. I write the classof() |
||
{ | ||
const SVFBasicBlock* bb = SVFUtil::cast<SVFBasicBlock>(value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we need two maps, SVFBB2LLVMBBMap and SVFBaseNode2LLVMValueMap? |
||
SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(bb); | ||
assert(it!=SVFBB2LLVMBB.end() && "can't find corresponding llvm value!"); | ||
return it->second; | ||
} | ||
else | ||
{ | ||
SVFBaseNode2LLVMValueMap ::const_iterator it = SVFBaseNode2LLVMValue.find(value); | ||
assert(it != SVFBaseNode2LLVMValue.end() && "can't find corresponding llvm value!"); | ||
return it->second; | ||
} | ||
} | ||
|
||
inline CallGraphNode* getCallGraphNode(const Function* fun) const | ||
|
@@ -264,13 +278,20 @@ 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!"); | ||
return it->second; | ||
} | ||
|
||
const BasicBlock* getLLVMBasicBlock(const SVFBasicBlock* bb) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this method. |
||
{ | ||
SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(bb); | ||
assert(it!=SVFBB2LLVMBB.end() && "LLVM BasicBlock not found!"); | ||
return it->second; | ||
} | ||
|
||
inline SVFInstruction* getSVFInstruction(const Instruction* inst) const | ||
{ | ||
LLVMInst2SVFInstMap::const_iterator it = LLVMInst2SVFInst.find(inst); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
|
@@ -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 = svfFunc->addBasicBlock(bb.getName().str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. directly use bbGraph->addBasicBlock(..) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use bbGraph->addBasicBlock? |
||
addBasicBlockMap(&bb, svfBB); | ||
for (const Instruction& inst : bb) | ||
{ | ||
|
@@ -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)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. roll back |
||
svfFunc->getExitBB())); | ||
const BasicBlock* exitBB = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB()); | ||
const Value *pValue = &exitBB->back(); | ||
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue); | ||
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?"); | ||
|
@@ -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 = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB()); | ||
const Value *pValue = &exitBB->back(); | ||
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue); | ||
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this map.