-
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
Conversation
svf/include/Graphs/BasicBlockG.h
Outdated
|
||
} | ||
|
||
SVFBasicBlock* addBasicBlock(const SVFFunction* f) |
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.
SVFFunction is a BasicBlock? It looks strange here.
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.
I'll rename it
SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(value); | ||
assert(it!=SVFBB2LLVMBB.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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for reminding. I write the classof()
svf/include/SVFIR/SVFValue.h
Outdated
} | ||
|
||
inline const std::vector<const SVFBasicBlock*>& getBasicBlockList() const | ||
inline std::vector<const SVFBasicBlock*> getBasicBlockList() const |
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.
what this method for? why use transform? too complicated.
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.
Yes. I remove it. For all places where this API is needed, I use iterator instead.
svf-llvm/lib/LLVMModule.cpp
Outdated
@@ -301,8 +300,7 @@ void LLVMModuleSet::createSVFFunction(const Function* func) | |||
|
|||
for (const BasicBlock& bb : *func) | |||
{ | |||
SVFBasicBlock* svfBB = basicBlockGraph->addBasicBlockToFunction(bb.getName().str(), svfFunc); | |||
svfFunc->addBasicBlock(svfBB); | |||
SVFBasicBlock* svfBB = svfFunc->addBasicBlock(bb.getName().str()); |
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.
directly use bbGraph->addBasicBlock(..)
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.
why not use bbGraph->addBasicBlock?
svf/include/SVFIR/SVFValue.h
Outdated
{ | ||
allBBs.push_back(bb); | ||
|
||
inline SVFBasicBlock* addBasicBlock(const std::string& bbName) { |
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 and use bbGraph::addBasicBlock.
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.
ok
{ | ||
id++; | ||
SVFBasicBlock* bb = new SVFBasicBlock(id, f); | ||
SVFBasicBlock* bb = new SVFBasicBlock(id, fun); |
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.
when use C++ new keyword, always remember to delete in the destructor.
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.
GenericGraph's destructor will delete every node from the IDToNodeMap.
We don't need to override the destructor.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1639 +/- ##
==========================================
+ Coverage 63.70% 63.74% +0.04%
==========================================
Files 245 247 +2
Lines 25999 26054 +55
Branches 4509 4511 +2
==========================================
+ Hits 16563 16609 +46
- Misses 9436 9445 +9
|
…lockGraph. And some related chages
--- base.log 2025-01-26 23:51:17.370759400 +1100 PTACallGraph Stats (Andersen analysis)****** Memory SSA Statistics****** |
--- log/redis-server.log 2025-01-27 10:30:57.091640744 +1100 PTACallGraph Stats (Andersen analysis)****** Memory SSA Statistics****** PTACallGraph Stats (Flow-sensitive analysis)****** Persistent Points-To Cache Statistics: flow-sensitive analysis bitvector |
return it->second; | ||
if (value->getNodeKind() == SVFBaseNode::BasicBlockKd) | ||
{ | ||
const SVFBasicBlock* bb = SVFUtil::cast<SVFBasicBlock>(value); |
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.
why we need two maps, SVFBB2LLVMBBMap and SVFBaseNode2LLVMValueMap?
@@ -159,8 +159,9 @@ void MHP::updateNonCandidateFunInterleaving() | |||
{ | |||
const CallStrCxt& curCxt = cts.getContext(); | |||
|
|||
for (const SVFBasicBlock* svfbb : fun->getBasicBlockList()) | |||
for (auto it : *fun) |
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.
Don't use auto and use explicit type and fix all others too.
} | ||
|
||
inline const SVFBasicBlock* getEntryBlock() const | ||
{ | ||
assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); | ||
return allBBs.front(); |
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.
assert no predecessor.
@@ -437,23 +438,19 @@ class SVFFunction : public SVFValue | |||
/// Carefully! 'back' is just the last basic block of function, | |||
/// but not necessarily a exit basic block | |||
/// more refer to: https://github.com/SVF-tools/SVF/pull/1262 | |||
return allBBs.back(); | |||
return std::prev(bbGraph->end())->second; |
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.
assert no sucessor
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
roll back
{ | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
remove this method.
@@ -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; |
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.
@@ -586,7 +586,7 @@ Set<const Value *> &ObjTypeInference::bwfindAllocOfVar(const Value *var) | |||
if (!callee->isDeclaration()) | |||
{ | |||
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee); | |||
const BasicBlock* exitBB = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB()); | |||
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB())); |
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.
use cast here or you need to add an assertion
@@ -893,7 +893,7 @@ Set<const Value *> &ObjTypeInference::bwFindAllocOrClsNameSources(const Value *s | |||
if (!callee->isDeclaration()) | |||
{ | |||
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee); | |||
const BasicBlock* exitBB = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB()); | |||
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB())); |
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.
see above
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.
const BasicBlock* exitBB = SVFUtil::dyn_cast(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
assert (exitBB && "exit bb is not a basic block?");
svf-llvm/lib/LLVMModule.cpp
Outdated
SVFBasicBlock* svfBB = | ||
new SVFBasicBlock(getSVFType(bb.getType()), svfFunc); | ||
svfFunc->addBasicBlock(svfBB); | ||
SVFBasicBlock* svfBB = bbGraph->addBasicBlock(bb.getName().str()); |
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.
put this line "SVFBasicBlock* svfBB = bbGraph->addBasicBlock(bb.getName().str());" into "addBasicBlockMap" and rename addBasicBlockMap to addBasicBlock
svf/include/SVFIR/SVFValue.h
Outdated
@@ -411,13 +422,14 @@ class SVFFunction : public SVFValue | |||
|
|||
inline bool hasBasicBlock() const | |||
{ | |||
return !allBBs.empty(); | |||
return bbGraph && bbGraph->getTotalNodeNum()>0; |
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.
bbGraph && bbGraph->begin() != bbGraph->end();
No description provided.