SVF
|
#include <PathCondAllocator.h>
Public Types | |
typedef DdNode | Condition |
typedef Map< u32_t, Condition * > | CondPosMap |
map a branch to its Condition More... | |
typedef Map< const BasicBlock *, CondPosMap > | BBCondMap |
typedef Map< const Condition *, const Instruction *> | CondToTermInstMap |
typedef Set< const BasicBlock * > | BasicBlockSet |
typedef Map< const Function *, BasicBlockSet > | FunToExitBBsMap |
map a function to all its basic blocks calling program exit More... | |
typedef Map< const BasicBlock *, Condition * > | BBToCondMap |
map a basic block to its condition during control-flow guard computation More... | |
typedef FIFOWorkList< const BasicBlock * > | CFWorkList |
worklist for control-flow guard computation More... | |
typedef Map< u32_t, Condition * > | IndexToConditionMap |
Public Member Functions | |
PathCondAllocator () | |
Constructor. More... | |
virtual | ~PathCondAllocator () |
Destructor. More... | |
void | allocate (const SVFModule *module) |
Perform path allocation. More... | |
const Instruction * | getCondInst (const Condition *cond) const |
Get llvm conditional expression. More... | |
DominatorTree * | getDT (const Function *fun) |
Get dominators. More... | |
PostDominatorTree * | getPostDT (const Function *fun) |
Get Postdominators. More... | |
LoopInfo * | getLoopInfo (const Function *f) |
Get LoopInfo. More... | |
void | printPathCond () |
Print out the path condition information. More... | |
Condition * | condAnd (Condition *lhs, Condition *rhs) |
Condition operations. More... | |
Condition * | condOr (Condition *lhs, Condition *rhs) |
Condition * | condNeg (Condition *cond) |
Condition * | getTrueCond () const |
Condition * | getFalseCond () const |
Condition * | getCond (u32_t i) const |
Given an index, get its condition. More... | |
NodeBS | exactCondElem (Condition *cond) |
Iterator every element of the bdd. More... | |
void | markForRelease (Condition *cond) |
Decrease reference counting for the bdd. More... | |
void | printDbg (Condition *cond) |
Print debug information for this condition. More... | |
std::string | dumpCond (Condition *cond) const |
virtual Condition * | ComputeIntraVFGGuard (const BasicBlock *src, const BasicBlock *dst) |
Guard Computation for a value-flow (between two basic blocks) More... | |
virtual Condition * | ComputeInterCallVFGGuard (const BasicBlock *src, const BasicBlock *dst, const BasicBlock *callBB) |
virtual Condition * | ComputeInterRetVFGGuard (const BasicBlock *src, const BasicBlock *dst, const BasicBlock *retBB) |
virtual Condition * | getPHIComplementCond (const BasicBlock *BB1, const BasicBlock *BB2, const BasicBlock *BB0) |
void | clearCFCond () |
void | setCurEvalVal (const Value *val) |
Set current value for branch condition evaluation. More... | |
const Value * | getCurEvalVal () const |
Get current value for branch condition evaluation. More... | |
Static Public Member Functions | |
static Condition * | trueCond () |
static Condition * | falseCond () |
static u32_t | getMemUsage () |
Statistics. More... | |
static u32_t | getCondNum () |
static u32_t | getMaxLiveCondNumber () |
Static Public Attributes | |
static u32_t | totalCondNum = 0 |
Protected Attributes | |
BBCondMap | bbConds |
map basic block to its successors/predecessors branch conditions More... | |
IndexToConditionMap | indexToDDNodeMap |
Static Protected Attributes | |
static BddCondManager * | bddCondMgr = nullptr |
bbd manager More... | |
Private Member Functions | |
virtual void | allocateForBB (const BasicBlock &bb) |
Allocate path condition for every basic block. More... | |
Condition * | createNewCond (u32_t i) |
Create new BDD condition. More... | |
Condition * | newCond (const Instruction *inst) |
Allocate a new condition. More... | |
void | destroy () |
Release memory. More... | |
void | setBranchCond (const BasicBlock *bb, const BasicBlock *succ, Condition *cond) |
Get/Set a branch condition, and its terminator instruction. More... | |
Condition * | getBranchCond (const BasicBlock *bb, const BasicBlock *succ) const |
Get branch condition. More... | |
Condition * | getEvalBrCond (const BasicBlock *bb, const BasicBlock *succ) |
Get a condition, evaluate the value for conditions if necessary (e.g., testNull like express) More... | |
Condition * | evaluateBranchCond (const BasicBlock *bb, const BasicBlock *succ, const Value *val) |
Evaluate branch conditions. More... | |
Condition * | evaluateLoopExitBranch (const BasicBlock *bb, const BasicBlock *succ) |
Evaluate loop exit branch. More... | |
Condition * | evaluateTestNullLikeExpr (const BranchInst *brInst, const BasicBlock *succ, const Value *val) |
Return branch condition after evaluating test null like expression. More... | |
Condition * | evaluateProgExit (const BranchInst *brInst, const BasicBlock *succ) |
Return condition when there is a branch calls program exit. More... | |
void | collectBBCallingProgExit (const BasicBlock &bb) |
Collect basic block contains program exit function call. More... | |
bool | isBBCallsProgExit (const BasicBlock *bb) |
bool | isEQCmp (const CmpInst *cmp) const |
Evaluate test null/not null like expressions. More... | |
bool | isNECmp (const CmpInst *cmp) const |
Return true if the predicate of this compare instruction is not equal. More... | |
bool | isTestNullExpr (const Value *test, const Value *val) const |
Return true if this is a test null expression. More... | |
bool | isTestNotNullExpr (const Value *test, const Value *val) const |
Return true if this is a test not null expression. More... | |
bool | isTestContainsNullAndTheValue (const CmpInst *cmp, const Value *val) const |
Return true if two values on the predicate are what we want. More... | |
bool | setCFCond (const BasicBlock *bb, Condition *cond) |
Get/Set control-flow conditions. More... | |
Condition * | getCFCond (const BasicBlock *bb) const |
Static Private Member Functions | |
static BddCondManager * | getBddCondManager () |
Used internally, not supposed to be exposed to other classes. More... | |
Private Attributes | |
CondToTermInstMap | condToInstMap |
map a condition to its corresponding llvm instruction More... | |
PTACFInfoBuilder | cfInfoBuilder |
map a function to its loop info More... | |
FunToExitBBsMap | funToExitBBsMap |
map a function to all its basic blocks calling program exit More... | |
BBToCondMap | bbToCondMap |
map a basic block to its path condition starting from root More... | |
const Value * | curEvalVal |
current llvm value to evaluate branch condition when computing guards More... | |
PathCondAllocator allocates conditions for each basic block of a certain CFG.
Definition at line 44 of file PathCondAllocator.h.
typedef Set<const BasicBlock*> SVF::PathCondAllocator::BasicBlockSet |
Definition at line 54 of file PathCondAllocator.h.
typedef Map<const BasicBlock*, CondPosMap > SVF::PathCondAllocator::BBCondMap |
Definition at line 52 of file PathCondAllocator.h.
typedef Map<const BasicBlock*, Condition*> SVF::PathCondAllocator::BBToCondMap |
map a basic block to its condition during control-flow guard computation
Definition at line 56 of file PathCondAllocator.h.
typedef FIFOWorkList<const BasicBlock*> SVF::PathCondAllocator::CFWorkList |
worklist for control-flow guard computation
Definition at line 57 of file PathCondAllocator.h.
Definition at line 50 of file PathCondAllocator.h.
typedef Map<u32_t,Condition*> SVF::PathCondAllocator::CondPosMap |
map a branch to its Condition
Definition at line 51 of file PathCondAllocator.h.
typedef Map<const Condition*, const Instruction* > SVF::PathCondAllocator::CondToTermInstMap |
Definition at line 53 of file PathCondAllocator.h.
typedef Map<const Function*, BasicBlockSet> SVF::PathCondAllocator::FunToExitBBsMap |
map a function to all its basic blocks calling program exit
Definition at line 55 of file PathCondAllocator.h.
Definition at line 59 of file PathCondAllocator.h.
|
inline |
Constructor.
Definition at line 62 of file PathCondAllocator.h.
|
inlinevirtual |
void PathCondAllocator::allocate | ( | const SVFModule * | M | ) |
Perform path allocation.
Allocate path condition for each branch
Definition at line 52 of file PathCondAllocator.cpp.
|
privatevirtual |
Allocate path condition for every basic block.
Allocate conditions for a basic block and propagate its condition to its successors.
TODO: handle BranchInst and SwitchInst individually here!!
Definition at line 80 of file PathCondAllocator.cpp.
|
inline |
Definition at line 186 of file PathCondAllocator.h.
|
private |
Collect basic block contains program exit function call.
Whether this basic block contains program exit function call
Definition at line 359 of file PathCondAllocator.cpp.
|
virtual |
Compute calling inter-procedural guards between two SVFGNodes (from caller to callee) src –c1–> callBB –true–> funEntryBB –c2–> dst the InterCallVFGGuard is c1 ^ c2
Definition at line 418 of file PathCondAllocator.cpp.
|
virtual |
Compute return inter-procedural guards between two SVFGNodes (from callee to caller) src –c1–> funExitBB –true–> retBB –c2–> dst the InterRetVFGGuard is c1 ^ c2
Definition at line 433 of file PathCondAllocator.cpp.
|
virtual |
Guard Computation for a value-flow (between two basic blocks)
Compute intra-procedural guards between two SVFGNodes (inside same function)
if the dstBB is the eligible loop exit of the current basic block we can early terminate the computation
calculate the branch condition if succ post dominate bb, then we get brCond quicker by using postDT note that we assume loop exit always post dominate loop bodys which means loops are approximated only once.
Definition at line 446 of file PathCondAllocator.cpp.
Condition operations.
Definition at line 126 of file PathCondAllocator.h.
Definition at line 134 of file PathCondAllocator.h.
Definition at line 130 of file PathCondAllocator.h.
Create new BDD condition.
Definition at line 278 of file PathCondAllocator.h.
|
private |
Release memory.
Release memory
Definition at line 502 of file PathCondAllocator.cpp.
|
inline |
Definition at line 170 of file PathCondAllocator.h.
|
private |
Evaluate branch conditions.
Evaluate the branch condtion
(1) Evaluate a branch when it reaches a program exit (2) Evaluate a branch when it is loop exit branch (3) Evaluate a branch when it is a test null like condition
Definition at line 285 of file PathCondAllocator.cpp.
|
private |
Evaluate loop exit branch.
Evaluate loop exit branch to be true if bb is loop header and succ is the only exit basic block outside the loop (excluding exit bbs which call program exit) for all other case, we conservatively evaluate false for now
exclude exit bb which calls program exit
if the dst dominate all other loop exit bbs, then dst can certainly be reached
Definition at line 245 of file PathCondAllocator.cpp.
|
private |
Return condition when there is a branch calls program exit.
Evaluate condition for program exit (e.g., exit(0))
then branch calls program exit
else branch calls program exit
no branch call program exit
Definition at line 201 of file PathCondAllocator.cpp.
|
private |
Return branch condition after evaluating test null like expression.
Evaluate null like expression for source-sink related bug detection in SABER
Definition at line 171 of file PathCondAllocator.cpp.
Iterator every element of the bdd.
Definition at line 154 of file PathCondAllocator.h.
|
inlinestatic |
Definition at line 76 of file PathCondAllocator.h.
|
inlinestaticprivate |
Used internally, not supposed to be exposed to other classes.
Definition at line 295 of file PathCondAllocator.h.
|
private |
Get branch condition.
Get a branch condition
Definition at line 136 of file PathCondAllocator.cpp.
|
inlineprivate |
Definition at line 266 of file PathCondAllocator.h.
Given an index, get its condition.
Definition at line 147 of file PathCondAllocator.h.
|
inline |
Get llvm conditional expression.
Definition at line 101 of file PathCondAllocator.h.
|
inlinestatic |
Definition at line 87 of file PathCondAllocator.h.
|
inline |
Get current value for branch condition evaluation.
Definition at line 196 of file PathCondAllocator.h.
|
inline |
Get dominators.
Definition at line 109 of file PathCondAllocator.h.
|
inlineprivate |
Get a condition, evaluate the value for conditions if necessary (e.g., testNull like express)
Definition at line 217 of file PathCondAllocator.h.
|
inline |
Definition at line 142 of file PathCondAllocator.h.
Get LoopInfo.
Definition at line 119 of file PathCondAllocator.h.
|
inlinestatic |
Definition at line 91 of file PathCondAllocator.h.
|
inlinestatic |
Statistics.
Definition at line 83 of file PathCondAllocator.h.
|
virtual |
Get complement condition (from B1 to B0) according to a complementBB (BB2) at a phi e.g., B0: dstBB; B1:incomingBB; B2:complementBB
Get complement phi condition e.g., B0: dstBB; B1:incomingBB; B2:complementBB Assume B0 (phi node) is the successor of both B1 and B2. If B1 dominates B2, and B0 not dominate B2 then condition from B1–>B0 = neg(B1–>B2)^(B1–>B0)
avoid both BB0 and BB1 dominate BB2 (e.g., while loop), then BB2 is not necessaryly a complement BB
Definition at line 398 of file PathCondAllocator.cpp.
|
inline |
Get Postdominators.
Definition at line 114 of file PathCondAllocator.h.
|
inline |
Definition at line 138 of file PathCondAllocator.h.
|
private |
Whether this basic block contains program exit function call
Definition at line 376 of file PathCondAllocator.cpp.
|
private |
Evaluate test null/not null like expressions.
Return true if the predicate of this compare instruction is equal
Definition at line 316 of file PathCondAllocator.cpp.
|
private |
Return true if the predicate of this compare instruction is not equal.
Definition at line 321 of file PathCondAllocator.cpp.
|
private |
Return true if two values on the predicate are what we want.
Definition at line 344 of file PathCondAllocator.cpp.
Return true if this is a test not null expression.
Definition at line 335 of file PathCondAllocator.cpp.
Return true if this is a test null expression.
Definition at line 326 of file PathCondAllocator.cpp.
|
inline |
Decrease reference counting for the bdd.
Definition at line 161 of file PathCondAllocator.h.
|
inlineprivate |
Allocate a new condition.
Definition at line 286 of file PathCondAllocator.h.
|
inline |
Print debug information for this condition.
Definition at line 166 of file PathCondAllocator.h.
void PathCondAllocator::printPathCond | ( | ) |
Print out the path condition information.
Print path conditions
Definition at line 511 of file PathCondAllocator.cpp.
|
private |
Get/Set a branch condition, and its terminator instruction.
Set branch condition
Set a branch condition
we only care about basic blocks have more than one successor
FIXME: llvm getNumSuccessors allows duplicated block in the successors, it makes this assertion fail In this case we may waste a condition allocation, because the overwrite of the previous cond
Definition at line 154 of file PathCondAllocator.cpp.
|
inlineprivate |
Get/Set control-flow conditions.
Definition at line 257 of file PathCondAllocator.h.
|
inline |
Set current value for branch condition evaluation.
Definition at line 191 of file PathCondAllocator.h.
|
inlinestatic |
Definition at line 71 of file PathCondAllocator.h.
|
protected |
map basic block to its successors/predecessors branch conditions
Definition at line 313 of file PathCondAllocator.h.
|
private |
map a basic block to its path condition starting from root
Definition at line 308 of file PathCondAllocator.h.
|
staticprotected |
bbd manager
Definition at line 312 of file PathCondAllocator.h.
|
private |
map a function to its loop info
Definition at line 306 of file PathCondAllocator.h.
|
private |
map a condition to its corresponding llvm instruction
Definition at line 305 of file PathCondAllocator.h.
|
private |
current llvm value to evaluate branch condition when computing guards
Definition at line 309 of file PathCondAllocator.h.
|
private |
map a function to all its basic blocks calling program exit
Definition at line 307 of file PathCondAllocator.h.
|
protected |
Definition at line 314 of file PathCondAllocator.h.
|
static |
Definition at line 48 of file PathCondAllocator.h.