38using namespace SVFUtil;
44MHP::MHP(
TCT* t) : tcg(t->getThreadCallGraph()), tct(t), numOfTotalQueries(0), numOfMHPQueries(0),
45 interleavingTime(0), interleavingQueriesTime(0)
77 for (
const std::pair<const NodeID, TCTNode*>&
tpair : *
tct)
147 for (
const SVFFunction* fun :
module->getFunctionSet())
149 if (!tct->isCandidateFun(fun) && !isExtCall(fun))
151 const ICFGNode* entryNode = fun->getEntryBlock()->front();
185 assert((
curInst ==
curfun->getEntryBlock()->front()) &&
"curInst is not the entry of non candidate function.");
247 std::vector<const SVFBasicBlock*>
exitbbs;
272 std::vector<const SVFBasicBlock*>
exitbbs;
324 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(
edge))
326 for (PTACallGraphEdge::CallInstSet::const_iterator
cit = (
edge)->directCallsBegin(),
335 if(
outEdge->getDstNode()->getFun() ==
cts.getStmt()->getFun())
343 for (PTACallGraphEdge::CallInstSet::const_iterator
cit = (
edge)->indirectCallsBegin(),
352 if(
outEdge->getDstNode()->getFun() ==
cts.getStmt()->getFun())
371 if(
outEdge->getDstNode()->getFun() ==
cts.getStmt()->getFun())
390 for (
const unsigned i :
tds)
422 for (
const unsigned tid :
tds)
454 while (!worklist.
empty())
528 while (!worklist.
empty())
536 if (visited.find(
srcNode) == visited.end())
571 if (
ts1.getTid() !=
ts2.getTid())
573 if (
l1.test(
ts2.getTid()) &&
l2.test(
ts1.getTid()))
651 outs() <<
"( t" <<
pair.first.getTid()
652 <<
pair.first.getStmt()->toString() <<
" ) ==> [";
653 for (
unsigned i :
pair.second)
655 outs() <<
" " <<
i <<
" ";
723 for (
const std::pair<const NodeID, TCTNode*>&
tpair : *
tct)
794 for (ThreadCallGraph::ForkEdgeSet::const_iterator
cgIt =
getTCG()->getForkEdgeBegin(
cbn),
829 std::vector<const SVFBasicBlock *>
exitbbs;
860 std::vector<const SVFBasicBlock*>
exitbbs;
885 for (PTACallGraph::CallGraphEdgeSet::const_iterator
cgIt =
getTCG()->getCallEdgeBegin(
cbn),
910 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(
edge))
912 for (PTACallGraphEdge::CallInstSet::const_iterator
cit =
edge->directCallsBegin(),
930 for (PTACallGraphEdge::CallInstSet::const_iterator
cit =
edge->indirectCallsBegin(),
990 while (!worklist.
empty())
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
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 PTACallGraph::FunctionSet & getCallee(const ICFGNode *inst, PTACallGraph::FunctionSet &callees)
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)
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 matchCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Match context.
CxtStmt popFromCTSWorkList()
void addToHBPair(NodeID tid1, NodeID tid2)
ThreadCallGraph * getTCG() const
ThreadCallGraph.
void addToPartial(NodeID tid1, NodeID tid2)
void collectSCEVInfo()
functions
void clearFlagMap()
Clear flags.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Push calling context.
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
LoopBBs & getJoinLoop(const CallICFGNode *inst)
Get loop for join site.
const ICFGNode * getExitInstOfParentRoutineFun(NodeID tid) const
Get exit instruction of the start routine function of tid's parent thread.
bool isTDFork(const ICFGNode *call)
Whether it is a fork site.
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.
bool isAliasedForkJoin(const CallICFGNode *forkSite, const CallICFGNode *joinSite)
Whether it is a matched fork join pair.
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 GEdgeSetTy & getInEdges() const
iterator OutEdgeBegin()
iterators
GEdgeSetTy::const_iterator const_iterator
virtual const SVFFunction * 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
void analyze()
Start analysis here.
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 rmInterleavingThread(const CxtThreadStmt &tgr, const NodeBS &tids, const ICFGNode *joinsite)
virtual bool mayHappenInParallelCache(const ICFGNode *i1, const ICFGNode *i2)
FuncPairToBool nonCandidateFuncMHPRelMap
void printInterleaving()
Print interleaving results.
void updateSiblingThreads(NodeID tid)
u32_t numOfTotalQueries
Total number of queries.
Set< CxtThreadStmt > CxtThreadStmtSet
void handleNonCandidateFun(const CxtThreadStmt &cts)
Handle non-candidate function.
SVFLoopAndDomInfo::LoopBBs LoopBBs
void handleJoin(const CxtThreadStmt &cts, NodeID rootTid)
Handle join.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Push calling context.
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.
InstToThreadStmtSetMap instToTSMap
Map a statement to its thread interleavings.
virtual ~MHP()
Destructor.
bool isHBPair(NodeID tid1, NodeID tid2)
Whether thread t1 happens before t2 based on ForkJoin Analysis.
bool isTDFork(const ICFGNode *call)
Whether it is a fork site.
void handleRet(const CxtThreadStmt &cts)
Handle return.
virtual bool executedByTheSameThread(const ICFGNode *i1, const ICFGNode *i2)
bool matchCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Match context.
virtual bool mayHappenInParallel(const ICFGNode *i1, const ICFGNode *i2)
Interface to query whether two instructions may happen-in-parallel.
const CxtThreadStmtSet & getThreadStmtSet(const ICFGNode *inst) const
Get/has ThreadStmt.
void handleFork(const CxtThreadStmt &cts, NodeID rootTid)
Handle fork.
const LoopBBs & getJoinInSymmetricLoop(const CallStrCxt &cxt, const ICFGNode *call) const
Whether a context-sensitive join satisfies symmetric loop pattern.
bool isConnectedfromMain(const SVFFunction *fun)
Whether the function is connected from main function in thread call graph.
ForkJoinAnalysis * fja
ForJoin Analysis.
bool hasJoinInSymmetricLoop(const CallStrCxt &cxt, const ICFGNode *call) const
Whether a context-sensitive join satisfies symmetric loop pattern.
bool hasThreadStmtSet(const ICFGNode *inst) const
double interleavingQueriesTime
u32_t numOfMHPQueries
Number of queries are answered as may-happen-in-parallel.
void updateNonCandidateFunInterleaving()
bool isMustJoin(const NodeID curTid, const ICFGNode *joinsite)
Whether a join site must join a thread t.
std::pair< const SVFFunction *, const SVFFunction * > FuncPair
CxtThreadStmt popFromCTSWorkList()
const PTACallGraph::FunctionSet & getCallee(const CallICFGNode *inst, PTACallGraph::FunctionSet &callees)
void analyzeInterleaving()
Analyze thread interleaving.
NodeBS getDirAndIndJoinedTid(const CallStrCxt &cxt, const ICFGNode *call)
Return thread id(s) which are directly or indirectly joined at this join site.
void updateAncestorThreads(NodeID tid)
Update Ancestor and sibling threads.
virtual bool mayHappenInParallelInst(const ICFGNode *i1, const ICFGNode *i2)
void handleIntra(const CxtThreadStmt &cts)
Handle intra.
void handleCall(const CxtThreadStmt &cts, NodeID rootTid)
Handle call.
ThreadStmtToThreadInterleav threadStmtToTheadInterLeav
bool isTDJoin(const ICFGNode *call)
Whether it is a join site.
static const Option< bool > PrintInterLev
const SVFFunction * getFunction() const
Get function of this call node.
CallGraphEdgeSet::const_iterator getCallEdgeEnd(const CallICFGNode *inst) const
CallGraphEdgeSet::const_iterator getCallEdgeBegin(const CallICFGNode *inst) const
Set< const SVFFunction * > FunctionSet
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
bool hasCallGraphEdge(const CallICFGNode *inst) const
Get call graph edge via call instruction.
NodeID getId() const
Get ID.
const ICFGNode * back() const
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
static double getClk(bool mark=false)
const std::string & getName() const
const CxtThread & getCxtThread() const
Get CxtThread.
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
bool isJoinSiteInRecursion(const CallICFGNode *join) const
Whether a join site is in recursion.
const SVFFunction * getStartRoutineOfCxtThread(const CxtThread &ct) const
get the start routine function of a thread
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
ThreadCreateEdgeSet::const_iterator getChildrenBegin(const TCTNode *node) const
Get children and parent nodes.
NodeID getParentThread(NodeID tid) const
Get parent thread.
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
const NodeBS getSiblingThread(NodeID tid) const
Get sibling threads.
const CallStrCxt & getCxtOfCxtThread(const CxtThread &ct) const
get the context of a thread at its spawning site (fork site)
bool isCandidateFun(const PTACallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
const NodeBS getAncestorThread(NodeID tid) const
Get all ancestor threads.
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
ThreadCreateEdgeSet::const_iterator getChildrenEnd(const TCTNode *node) const
Set< const PTACallGraphNode * > PTACGNodeSet
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
bool isExtCall(const SVFFunction *fun)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
bool isRetInstNode(const ICFGNode *node)
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