49using namespace SVFUtil;
54MHP::MHP(
TCT* t) : tcg(t->getThreadCallGraph()), tct(t), numOfTotalQueries(0), numOfMHPQueries(0),
55 interleavingTime(0), interleavingQueriesTime(0)
94 if (
join.getContext() !=
cts.getContext())
101 flow.intersectWithComplement(
119template<
class ICFGGraph,
class CGGraph>
133template<
class ICFGGraph,
class CGGraph>
136 for (
const std::pair<const NodeID, TCTNode*>&
tpair : *
tct)
179 else if (SVFUtil::dyn_cast<FunExitICFGNode>(
curInst))
201template<
class ICFGGraph,
class CGGraph>
239template<
class ICFGGraph,
class CGGraph>
262template<
class ICFGGraph,
class CGGraph>
293template<
class ICFGGraph,
class CGGraph>
314 std::vector<const SVFBasicBlock*>
exitbbs;
339 std::vector<const SVFBasicBlock*>
exitbbs;
357template<
class ICFGGraph,
class CGGraph>
410 assert(
false &&
"cts.getStmt() is not a CallICFGNode!");
417template<
class ICFGGraph,
class CGGraph>
421 std::vector<const CallGraphEdge*>
inEdges;
425 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(
edgeConst))
429 for (CallGraphEdge::CallInstSet::const_iterator
cit = (
edge)->directCallsBegin(),
436 std::vector<const ICFGNode*>
succ;
440 if(dst->getFun() == (*cit)->getFun())
459 for (CallGraphEdge::CallInstSet::const_iterator
cit = (
edge)->indirectCallsBegin(),
466 std::vector<const ICFGNode*>
succ;
470 if(dst->getFun() == (*cit)->getFun())
495template<
class ICFGGraph,
class CGGraph>
502 std::vector<const ICFGNode*>
succ;
506 if(dst->getFun() ==
cts.getStmt()->getFun())
520template<
class ICFGGraph,
class CGGraph>
536 std::vector<const ICFGNode*>
succ;
541 if(dst->getFun() ==
forkInst->getFun())
564template<
class ICFGGraph,
class CGGraph>
603 while (!worklist.
empty())
677 while (!worklist.
empty())
685 if (visited.find(
srcNode) == visited.end())
720 if (
ts1.getTid() !=
ts2.getTid())
722 if (
l1.test(
ts2.getTid()) &&
l2.test(
ts1.getTid()))
800 outs() <<
"( t" <<
pair.first.getTid()
801 <<
pair.first.getStmt()->toString() <<
" ) ==> [";
802 for (
unsigned i :
pair.second)
804 outs() <<
" " <<
i <<
" ";
872 for (
const std::pair<const NodeID, TCTNode*>&
tpair : *
tct)
926 else if (SVFUtil::dyn_cast<FunExitICFGNode>(
curInst))
965 for (ThreadCallGraph::ForkEdgeSet::const_iterator
cgIt =
getTCG()->getForkEdgeBegin(
cbn),
998 SVFUtil::cast<CallICFGNode>(
joinSite)) &&
1003 std::vector<const SVFBasicBlock *>
exitbbs;
1025 std::vector<const SVFBasicBlock*>
exitbbs;
1040 SVFUtil::cast<CallICFGNode>(
joinSite)))
1060 for (CallGraph::CallGraphEdgeSet::const_iterator
cgIt =
getTCG()->getCallEdgeBegin(
cbn),
1085 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(
edge))
1087 for (CallGraphEdge::CallInstSet::const_iterator
cit =
edge->directCallsBegin(),
1116 for (CallGraphEdge::CallInstSet::const_iterator
cit =
edge->indirectCallsBegin(),
1187 while (!worklist.
empty())
1305template void MHP::analyze<ICFG*, CallGraph*>(
ICFG*,
CallGraph*);
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
const FunObjVar * getFunction() const
Get function of this call node.
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
CallGraphEdgeSet::const_iterator getCallEdgeBegin(const CallICFGNode *inst) const
bool hasCallGraphEdge(const CallICFGNode *inst) const
Get call graph edge via call instruction.
Set< const FunObjVar * > FunctionSet
CallGraphEdgeSet::const_iterator getCallEdgeEnd(const CallICFGNode *inst) const
const std::string toString() const override
const ICFGNode * getThread() const
Return forksite.
bool push(const Data &data)
void addToFullJoin(NodeID tid1, NodeID tid2)
full join and partial join
const SVFVar * getForkedThread(const CallICFGNode *call)
Get forked thread.
bool isAliasedForkJoin(const CallICFGNode *forkSite, const CallICFGNode *joinSite)
Whether it is a matched fork join pair.
ValDomain getMarkedFlag(const CxtStmt &cs)
Mark thread flags for cxtStmt.
void addToHPPair(NodeID tid1, NodeID tid2)
SVFLoopAndDomInfo::LoopBBs LoopBBs
void analyzeForkJoinPair()
bool hasJoinLoop(const CallICFGNode *inst)
const CallGraph::FunctionSet & getCallee(const ICFGNode *inst, CallGraph::FunctionSet &callees)
void addSymmetricLoopJoin(const CxtStmt &cs, LoopBBs &lp)
Add inloop join.
void handleRet(const CxtStmt &cts)
Handle return.
NodeBS getDirAndIndJoinedTid(const CxtStmt &cs)
Get directly and indirectly joined threadIDs based on a context-sensitive join site.
bool matchAndPopCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Match context.
CxtStmt popFromCTSWorkList()
bool hasCxtStmtsFromInst(const ICFGNode *inst) const
void addToHBPair(NodeID tid1, NodeID tid2)
ThreadCallGraph * getTCG() const
ThreadCallGraph.
void addToPartial(NodeID tid1, NodeID tid2)
void collectSCEVInfo()
functions
void clearFlagMap()
Clear flags.
bool isHBPair(NodeID tid1, NodeID tid2)
Whether thread t1 happens-before thread t2.
void addDirectlyJoinTID(const CxtStmt &cs, NodeID tid)
maps a context-sensitive join site to a thread id
const SVFVar * getJoinedThread(const CallICFGNode *call)
Get joined thread.
LoopBBs & getJoinLoop(const CallICFGNode *inst)
Get loop for join site.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
const CxtStmtToLoopMap & getSymmetricLoopJoins() const
All SCEV-symmetric in-loop joins and their loop blocks.
bool isTDFork(const ICFGNode *call)
Whether it is a fork site.
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt call)
If lhs is a suffix of rhs, including equal.
bool isFullJoin(NodeID tid1, NodeID tid2)
Whether t1 fully joins t2.
CxtStmtToTIDMap dirAndIndJoinMap
maps a context-sensitive join site to directly and indirectly joined thread ids
void handleCall(const CxtStmt &cts, NodeID rootTid)
Handle call.
bool hasJoinInSymmetricLoop(const CxtStmt &cs) const
bool sameLoopTripCount(const ICFGNode *forkSite, const ICFGNode *joinSite)
Same loop trip count.
bool isTDJoin(const ICFGNode *call)
Whether it is a join site.
void markCxtStmtFlag(const CxtStmt &tgr, ValDomain flag)
Initialize TDAlive and TDDead flags.
CxtStmtWorkList cxtStmtList
context-sensitive statement worklist
const LoopBBs & getJoinInSymmetricLoop(const CxtStmt &cs) const
Whether a context-sensitive join satisfies symmetric loop pattern.
ThreadAPI::ForkJoinAliasCache forkJoinAliasCache
void handleIntra(const CxtStmt &cts)
Handle intra.
void handleFork(const CxtStmt &cts, NodeID rootTid)
Handle fork.
NodeBS & getDirectlyJoinedTid(const CxtStmt &cs)
Get directly joined threadIDs based on a context-sensitive join site.
void handleJoin(const CxtStmt &cts, NodeID rootTid)
Handle join.
bool isSameSCEV(const ICFGNode *forkSite, const ICFGNode *joinSite)
Return true if the fork and join have the same SCEV.
const CxtStmtSet & getCxtStmtsFromInst(const ICFGNode *inst) const
Get CxtStmtSet for an instruction.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
const GEdgeSetTy & getInEdges() const
iterator OutEdgeBegin()
iterators
GEdgeSetTy::const_iterator const_iterator
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
virtual const std::string toString() const
CxtThreadStmtWorkList cxtStmtList
CxtThreadStmt worklist.
bool isRecurFullJoin(NodeID parentTid, NodeID curTid)
Thread curTid can be fully joined by parentTid recursively.
bool isMultiForkedThread(NodeID curTid)
A thread is a multiForked thread if it is in a loop or recursion.
void handleRet(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle return.
void rmInterleavingThread(const CxtThreadStmt &tgr, const NodeBS &tids, const ICFGNode *joinsite)
virtual bool mayHappenInParallelCache(const ICFGNode *i1, const ICFGNode *i2)
void analyze(ICFGGraph icfg, CGGraph cg)
BBToSymJoinsMap bbToSymJoins
Map a statement to its thread interleavings.
FuncPairToBool nonCandidateFuncMHPRelMap
NodeBS edgeFlow(const CxtThreadStmt &cts, const ICFGNode *dst)
void printInterleaving()
Print interleaving results.
bool matchAndPopCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Match context.
u32_t numOfTotalQueries
Total number of queries.
Set< CxtThreadStmt > CxtThreadStmtSet
void analyzeInterleaving(ICFGGraph icfg, CGGraph cg)
Analyze thread interleaving.
std::pair< const FunObjVar *, const FunObjVar * > FuncPair
SVFLoopAndDomInfo::LoopBBs LoopBBs
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt call)
If lhs is a suffix of rhs, including equal.
void updateSiblingThreads(ICFGGraph icfg, CGGraph cg, NodeID tid)
void handleFork(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle fork.
void updateAncestorThreads(ICFGGraph icfg, CGGraph cg, NodeID tid)
Update Ancestor and sibling threads.
void handleCall(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle call.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
ThreadCallGraph * tcg
TCG.
void addInterleavingThread(const CxtThreadStmt &tgr, NodeID tid)
Add/Remove interleaving thread for statement inst.
const NodeBS & getInterleavingThreads(const CxtThreadStmt &cts)
Get interleaving thread for statement inst.
virtual ~MHP()
Destructor.
bool isHBPair(NodeID tid1, NodeID tid2)
Whether thread t1 happens before t2 based on ForkJoin Analysis.
ThreadStmtToThreadInterleav threadStmtToThreadInterLeav
bool isTDFork(const ICFGNode *call)
Whether it is a fork site.
void addInterleavingBits(const CxtThreadStmt &tgr, const NodeBS &bits)
virtual bool executedByTheSameThread(const ICFGNode *i1, const ICFGNode *i2)
virtual bool mayHappenInParallel(const ICFGNode *i1, const ICFGNode *i2)
Interface to query whether two instructions may happen-in-parallel.
void buildSymJoinKillTables()
const CxtThreadStmtSet & getThreadStmtSet(const ICFGNode *inst) const
Get/has ThreadStmt.
const LoopBBs & getJoinInSymmetricLoop(const CallStrCxt &cxt, const ICFGNode *call) const
Whether a context-sensitive join satisfies symmetric loop pattern.
void handleJoin(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle join.
ForkJoinAnalysis * fja
ForJoin Analysis.
bool hasJoinInSymmetricLoop(const CallStrCxt &cxt, const ICFGNode *call) const
Whether a context-sensitive join satisfies symmetric loop pattern.
const CallGraph::FunctionSet & getCallee(const CallICFGNode *inst, CallGraph::FunctionSet &callees)
bool hasThreadStmtSet(const ICFGNode *inst) const
SymJoinToLoopMap symJoinLoop
symmetric in-loop join -> its loop's blocks
double interleavingQueriesTime
u32_t numOfMHPQueries
Number of queries are answered as may-happen-in-parallel.
void updateNonCandidateFunInterleaving(ICFGGraph icfg, CGGraph cg)
bool isMustJoin(const NodeID curTid, const ICFGNode *joinsite)
Whether a join site must join a thread t.
bool isConnectedfromMain(const FunObjVar *fun)
Whether the function is connected from main function in thread call graph.
void handleIntra(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle intra.
CxtThreadStmt popFromCTSWorkList()
void handleNonCandidateFun(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle non-candidate function.
NodeBS getDirAndIndJoinedTid(const CallStrCxt &cxt, const ICFGNode *call)
Return thread id(s) which are directly or indirectly joined at this join site.
virtual bool mayHappenInParallelInst(const ICFGNode *i1, const ICFGNode *i2)
bool isTDJoin(const ICFGNode *call)
Whether it is a join site.
static const Option< bool > PrintInterLev
const_iterator end() const
const ICFGNode * back() const
static double getClk(bool mark=false)
NodeID getId() const
Get ID.
const CxtThread & getCxtThread() const
Get thread creation context, <fork site, call string context>
const NodeBS getAncestorThreads(NodeID tid) const
Get all ancestor threads.
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
bool isJoinSiteInRecursion(const CallICFGNode *join) const
Whether a join site is in recursion.
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
NodeBS getParentThreads(NodeID tid) const
Get parent threads.
PointerAnalysis * getPTA() const
Get PTA.
Set< const CallGraphNode * > PTACGNodeSet
ThreadCreateEdgeSet::const_iterator getChildrenBegin(const TCTNode *node) const
Get children and parent nodes.
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
const NodeBS getSiblingThread(NodeID tid) const
Get sibling threads.
bool isCandidateFun(const CallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
ThreadCreateEdgeSet::const_iterator getChildrenEnd(const TCTNode *node) const
const FunObjVar * getStartRoutineOfCxtThread(const CxtThread &ct) const
get the start routine function of a thread
const CallStrCxtSet & getCxtOfCxtThread(const CxtThread &ct) const
get the contexts of a thread at its spawning sites (fork sites)
bool isAliasedForkJoin(PointerAnalysis *pta, const SVFVar *forkArg, const SVFVar *joinArg) const
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
ThreadAPI * getThreadAPI() const
Thread API.
bool isProgEntryFunction(const FunObjVar *)
Program entry function e.g. main.
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
bool isExtCall(const FunObjVar *fun)
std::ostream & outs()
Overwrite llvm::outs()
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
llvm::IRBuilder IRBuilder
std::vector< u32_t > CallStrCxt