SVF
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
MTAResultValidator Class Reference

#include <MTAResultValidator.h>

Public Types

typedef int INTERLEV_FLAG
 

Public Member Functions

 MTAResultValidator (MHP *mh)
 
 ~MTAResultValidator ()
 
void analyze ()
 

Protected Member Functions

std::vector< std::string > & split (const std::string &s, char delim, std::vector< std::string > &elems)
 
std::vector< std::string > split (const std::string &s, char delim)
 
NodeID getIntArg (const Instruction *inst, unsigned int arg_num)
 
std::vector< std::string > getStringArg (const Instruction *inst, unsigned int arg_num)
 
CallStrCxt getCxtArg (const Instruction *inst, unsigned int arg_num)
 
const InstructiongetPreviousMemoryAccessInst (const Instruction *I)
 
bool matchCxt (const CallStrCxt cxt1, const CallStrCxt cxt2) const
 
void dumpCxt (const CallStrCxt &cxt) const
 
void dumpInterlev (NodeBS &lev)
 
std::string getOutput (const char *scenario, bool analysisRes)
 
std::string getOutputforInterlevAnalysis (const char *scenario, INTERLEV_FLAG analysisRes)
 
bool collectCallsiteTargets ()
 
bool collectCxtThreadTargets ()
 
bool collectTCTTargets ()
 
bool collectInterleavingTargets ()
 
bool validateCxtThread ()
 
bool validateTCT ()
 
INTERLEV_FLAG validateInterleaving ()
 

Private Attributes

Map< NodeID, const CallInst * > csnumToInstMap
 
Map< NodeID, CallStrCxt > vthdToCxt
 
Map< NodeID, NodeID > vthdTorthd
 
Map< NodeID, NodeID > rthdTovthd
 
Map< NodeID, Set< NodeID > > rthdToChildren
 
MHP::InstToThreadStmtSetMap instToTSMap
 
MHP::ThreadStmtToThreadInterleav threadStmtToInterLeaving
 
ThreadAPI * tdAPI
 
ThreadCallGraph * tcg
 
MHP * mhp
 

Static Private Attributes

static constexpr char const * CXT_THREAD = "CXT_THREAD"
 Map a statement to its thread interleavings. More...
 
static constexpr char const * INTERLEV_ACCESS = "INTERLEV_ACCESS"
 
static constexpr char const * TCT_ACCESS = "TCT_ACCESS"
 
static const INTERLEV_FLAG INTERLEV_TRUE = 0x01
 Constant INTERLEV_FLAG values. More...
 
static const INTERLEV_FLAG INTERLEV_IMPRECISE = 0x02
 
static const INTERLEV_FLAG INTERLEV_UNSOUND = 0x04
 

Detailed Description

Validate the result of context-sensitive analysis, including context-sensitive thread detection and thread interleaving.

Definition at line 21 of file MTAResultValidator.h.

Member Typedef Documentation

◆ INTERLEV_FLAG

Definition at line 25 of file MTAResultValidator.h.

Constructor & Destructor Documentation

◆ MTAResultValidator()

MTAResultValidator::MTAResultValidator ( MHP *  mh)
inline

Definition at line 26 of file MTAResultValidator.h.

26  :
27  mhp(mh)
28  {
29  tcg = mhp->getThreadCallGraph();
30  tdAPI = tcg->getThreadAPI();
31  }
ThreadCallGraph * tcg

◆ ~MTAResultValidator()

MTAResultValidator::~MTAResultValidator ( )
inline

Definition at line 33 of file MTAResultValidator.h.

34  {
35  }

Member Function Documentation

◆ analyze()

void MTAResultValidator::analyze ( )

Definition at line 18 of file MTAResultValidator.cpp.

19 {
20 
21  std::string errstring;
23  return;
25  return;
26 
27  errstring = getOutput("Validate CxtThread:", validateCxtThread());
28  outs() << "======" << errstring << "======\n";
29 
30  if (!collectTCTTargets())
31  return;
32  errstring = getOutput("Validate TCT: ", validateTCT());
33  outs() << "======" << errstring << "======\n";
34 
36  return;
37  errstring = getOutputforInterlevAnalysis("Validate Interleaving:", validateInterleaving());
38  outs() << "======" << errstring << "======\n";
39 }
std::string getOutputforInterlevAnalysis(const char *scenario, INTERLEV_FLAG analysisRes)
INTERLEV_FLAG validateInterleaving()
std::string getOutput(const char *scenario, bool analysisRes)
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47

◆ collectCallsiteTargets()

bool MTAResultValidator::collectCallsiteTargets ( )
protected

Definition at line 183 of file MTAResultValidator.cpp.

184 {
185  for (SVFModule::const_iterator fi = tcg->getModule().begin(), efi = tcg->getModule().end(); fi != efi; ++fi)
186  {
187  for (Function::const_iterator bi = (*fi)->begin(), ebi = (*fi)->end(); bi != ebi; ++bi)
188  {
189  const BasicBlock* bb = &*bi;
190  if (!bb->getName().str().compare(0, 2, "cs"))
191  {
192  NodeID csnum = atoi(bb->getName().str().substr(2).c_str());
193  const Instruction* inst = &bb->front();
194  while (1)
195  {
196  if (SVFUtil::isa<CallInst>(inst))
197  {
198  break;
199  }
200  inst = inst->getNextNode();
201  assert(inst && "Wrong cs label, cannot find callsite");
202  }
203  const CallInst *csInst = SVFUtil::dyn_cast<CallInst>(inst);
204  csnumToInstMap[csnum] = csInst;
205  }
206  }
207  }
208  if (csnumToInstMap.empty())
209  return false;
210  return true;
211 }
iterator begin()
Iterators.
Definition: GenericGraph.h:365
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
llvm::CallInst CallInst
Definition: BasicTypes.h:143
llvm::Instruction Instruction
Definition: BasicTypes.h:79
ThreadCallGraph * tcg
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
FunctionSetType::const_iterator const_iterator
Definition: SVFModule.h:49
Map< NodeID, const CallInst * > csnumToInstMap

◆ collectCxtThreadTargets()

bool MTAResultValidator::collectCxtThreadTargets ( )
protected

Definition at line 213 of file MTAResultValidator.cpp.

214 {
215  const Function *F = tcg->getModule().getFunction(CXT_THREAD);
216  if (!F)
217  return false;
218 
219  // Push main thread into vthdToCxt;
220  CallStrCxt main_cxt;
221  vthdToCxt[0] = main_cxt;
222 
223  // Collect call sites of all CXT_THREAD function calls.
224 
225  for (Value::const_use_iterator it = F->use_begin(), ie = F->use_end(); it != ie; ++it)
226  {
227  const Use *u = &*it;
228  const Value *user = u->getUser();
229  const Instruction *inst = SVFUtil::dyn_cast<Instruction>(user);
230 
231  NodeID vthdnum = getIntArg(inst, 0);
232  CallStrCxt cxt = getCxtArg(inst, 1);
233 
234  vthdToCxt[vthdnum] = cxt;
235  }
236  return true;
237 }
llvm::Use Use
Definition: BasicTypes.h:87
u32_t NodeID
Definition: SVFBasicTypes.h:80
static constexpr char const * CXT_THREAD
Map a statement to its thread interleavings.
llvm::Function Function
Definition: BasicTypes.h:76
NodeID getIntArg(const Instruction *inst, unsigned int arg_num)
llvm::Instruction Instruction
Definition: BasicTypes.h:79
Map< NodeID, CallStrCxt > vthdToCxt
SmallVector16 CallStrCxt
ThreadCallGraph * tcg
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
CallStrCxt getCxtArg(const Instruction *inst, unsigned int arg_num)
llvm::Value Value
Definition: BasicTypes.h:78

◆ collectInterleavingTargets()

bool MTAResultValidator::collectInterleavingTargets ( )
protected

Definition at line 265 of file MTAResultValidator.cpp.

266 {
267 
268  // Collect call sites of all INTERLEV_ACCESS function calls.
269  const Function *F = tcg->getModule().getFunction(INTERLEV_ACCESS);
270  if (!F)
271  return false;
272 
273  for (Value::const_use_iterator it = F->use_begin(), ie = F->use_end(); it != ie; ++it)
274  {
275  const Use *u = &*it;
276  const Value *user = u->getUser();
277  const Instruction *inst = SVFUtil::dyn_cast<Instruction>(user);
278 
279  NodeID vthdnum = getIntArg(inst, 0);
280  NodeID rthdnum = vthdTorthd[vthdnum];
281  CallStrCxt x = getCxtArg(inst, 1);
282  std::vector<std::string> y = getStringArg(inst, 2);
283 
284  // Record given interleaving
285  NodeBS lev;
286  // Push thread itself into interleaving set
287  lev.set(rthdnum);
288  // Find rthd of given vthd and push it into interleaving set
289  for (std::vector<std::string>::iterator i = y.begin(); i != y.end(); i++)
290  {
291  lev.set(vthdTorthd[atoi((*i).c_str())]);
292  }
293 
294  const Instruction* memInst = getPreviousMemoryAccessInst(inst);
295  CxtThreadStmt cts(rthdnum, x, memInst);
296  instToTSMap[memInst].insert(cts);
297  threadStmtToInterLeaving[cts] = lev;
298  }
299  return true;
300 }
llvm::Use Use
Definition: BasicTypes.h:87
static constexpr char const * INTERLEV_ACCESS
u32_t NodeID
Definition: SVFBasicTypes.h:80
MHP::InstToThreadStmtSetMap instToTSMap
MHP::ThreadStmtToThreadInterleav threadStmtToInterLeaving
Map< NodeID, NodeID > vthdTorthd
llvm::Function Function
Definition: BasicTypes.h:76
NodeID getIntArg(const Instruction *inst, unsigned int arg_num)
llvm::Instruction Instruction
Definition: BasicTypes.h:79
SmallVector16 CallStrCxt
std::vector< std::string > getStringArg(const Instruction *inst, unsigned int arg_num)
const Instruction * getPreviousMemoryAccessInst(const Instruction *I)
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87
ThreadCallGraph * tcg
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
CallStrCxt getCxtArg(const Instruction *inst, unsigned int arg_num)
llvm::Value Value
Definition: BasicTypes.h:78

◆ collectTCTTargets()

bool MTAResultValidator::collectTCTTargets ( )
protected

Definition at line 239 of file MTAResultValidator.cpp.

240 {
241 
242  // Collect call sites of all TCT_ACCESS function calls.
243  const Function *F = tcg->getModule().getFunction(TCT_ACCESS);
244  if (!F)
245  return false;
246 
247  for (Value::const_use_iterator it = F->use_begin(), ie = F->use_end(); it != ie; ++it)
248  {
249  const Use *u = &*it;
250  const Value *user = u->getUser();
251  const Instruction *inst = SVFUtil::dyn_cast<Instruction>(user);
252 
253  NodeID vthdnum = getIntArg(inst, 0);
254  NodeID rthdnum = vthdTorthd[vthdnum];
255  std::vector<std::string> x = getStringArg(inst, 1);
256 
257  for (std::vector<std::string>::iterator i = x.begin(); i != x.end(); i++)
258  {
259  rthdToChildren[rthdnum].insert(vthdTorthd[atoi((*i).c_str())]);
260  }
261  }
262  return true;
263 }
llvm::Use Use
Definition: BasicTypes.h:87
u32_t NodeID
Definition: SVFBasicTypes.h:80
Map< NodeID, Set< NodeID > > rthdToChildren
Map< NodeID, NodeID > vthdTorthd
llvm::Function Function
Definition: BasicTypes.h:76
NodeID getIntArg(const Instruction *inst, unsigned int arg_num)
llvm::Instruction Instruction
Definition: BasicTypes.h:79
std::vector< std::string > getStringArg(const Instruction *inst, unsigned int arg_num)
ThreadCallGraph * tcg
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
llvm::Value Value
Definition: BasicTypes.h:78
static constexpr char const * TCT_ACCESS

◆ dumpCxt()

void MTAResultValidator::dumpCxt ( const CallStrCxt cxt) const
protected

Definition at line 157 of file MTAResultValidator.cpp.

158 {
159  std::string str;
160  raw_string_ostream rawstr(str);
161  rawstr << "[:";
162  for (CallStrCxt::const_iterator it = cxt.begin(), eit = cxt.end(); it != eit; ++it)
163  {
164  rawstr << " ' " << *it << " ' ";
165  rawstr << *(tcg->getCallSite(*it).getInstruction());
166  rawstr << " call " << tcg->getCallSite(*it).getCaller()->getName() << "-->" << tcg->getCalleeOfCallSite(*it)->getName() << ", \n";
167  }
168  rawstr << " ]";
169  outs() << "max cxt = " << cxt.size() << rawstr.str() << "\n";
170 }
const llvm::StringRef getName() const
const SVFFunction * getCaller() const
Return callsite.
Definition: ICFGNode.h:400
const SVFFunction * getCalleeOfCallSite(CallSiteID id) const
Definition: PTACallGraph.h:370
llvm::raw_string_ostream raw_string_ostream
Definition: BasicTypes.h:100
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
const CallBlockNode * getCallSite(CallSiteID id) const
Definition: PTACallGraph.h:362
ThreadCallGraph * tcg

◆ dumpInterlev()

void MTAResultValidator::dumpInterlev ( NodeBS lev)
protected

Definition at line 172 of file MTAResultValidator.cpp.

173 {
174  outs() << " [ ";
175  for (NodeBS::iterator it = lev.begin(), eit = lev.end(); it != eit; it++)
176  {
177  NodeID id = *it;
178  outs() << rthdTovthd[id] << ", ";
179  }
180  outs() << "]\n";
181 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
Map< NodeID, NodeID > rthdTovthd
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47

◆ getCxtArg()

CallStrCxt MTAResultValidator::getCxtArg ( const Instruction inst,
unsigned int  arg_num 
)
protected

Definition at line 84 of file MTAResultValidator.cpp.

85 {
86  std::vector<std::string> x = getStringArg(inst, arg_num);
87  CallStrCxt cxt;
88  if (0 == x.size())
89  return cxt;
90  // Deal with the the second argument that records all callsites
91  for (std::vector<std::string>::iterator i = x.begin(); i != x.end(); i++)
92  {
93  std::vector<std::string> y = split((*i), '.');
94  y[0].erase(y[0].find("cs"), 2);
95 
96  const Function* callee = tcg->getModule().getFunction(y[1]);
97  CallSite cs = SVFUtil::getLLVMCallSite(csnumToInstMap[atoi(y[0].c_str())]);
98  assert(callee && "callee error");
99  CallSiteID csId = tcg->getCallSiteID(cs, callee);
100  cxt.push_back(csId);
101  }
102  return cxt;
103 }
#define assert(ex)
Definition: util.h:141
CallSiteID getCallSiteID(const CallBlockNode *cs, const SVFFunction *callee) const
Definition: PTACallGraph.h:343
llvm::Function Function
Definition: BasicTypes.h:76
SmallVector16 CallStrCxt
std::vector< std::string > getStringArg(const Instruction *inst, unsigned int arg_num)
unsigned CallSiteID
Definition: SVFBasicTypes.h:83
CallSite getLLVMCallSite(const Instruction *inst)
Return LLVM callsite given a instruction.
Definition: SVFUtil.h:183
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
ThreadCallGraph * tcg
Map< NodeID, const CallInst * > csnumToInstMap

◆ getIntArg()

NodeID MTAResultValidator::getIntArg ( const Instruction inst,
unsigned int  arg_num 
)
protected

Definition at line 58 of file MTAResultValidator.cpp.

59 {
60  assert(SVFUtil::isa<CallInst>(inst) && "getFirstIntArg: inst is not a callinst");
63  assert((arg_num < cs.arg_size()) && "Does not has this argument");
64  return (NodeID) x->getSExtValue();
65 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
llvm::ConstantInt ConstantInt
Definition: BasicTypes.h:153
Value * getArgument(unsigned ArgNo) const
Definition: BasicTypes.h:318
unsigned arg_size() const
Definition: BasicTypes.h:322
CallSite getLLVMCallSite(const Instruction *inst)
Return LLVM callsite given a instruction.
Definition: SVFUtil.h:183
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343

◆ getOutput()

std::string MTAResultValidator::getOutput ( const char *  scenario,
bool  analysisRes 
)
inlineprotected

Definition at line 117 of file MTAResultValidator.cpp.

118 {
119  std::string ret(scenario);
120  ret += "\t";
121 
122  if (analysisRes)
123  ret += SVFUtil::sucMsg("SUCCESS");
124  else
125  ret += SVFUtil::errMsg("FAILURE");
126  return ret;
127 }
std::string sucMsg(std::string msg)
Returns successful message by converting a string into green string output.
Definition: SVFUtil.cpp:54
std::string errMsg(std::string msg)
Print error message by converting a string into red string output.
Definition: SVFUtil.cpp:76

◆ getOutputforInterlevAnalysis()

std::string MTAResultValidator::getOutputforInterlevAnalysis ( const char *  scenario,
INTERLEV_FLAG  analysisRes 
)
inlineprotected

Definition at line 129 of file MTAResultValidator.cpp.

130 {
131  std::string ret(scenario);
132  ret += "\t";
133  switch (analysisRes)
134  {
135  case INTERLEV_TRUE:
136  ret += SVFUtil::sucMsg("SUCCESS");
137  break;
138  case INTERLEV_UNSOUND:
139  ret += SVFUtil::bugMsg2("UNSOUND");
140  break;
141  case INTERLEV_IMPRECISE:
142  ret += SVFUtil::bugMsg1("IMPRECISE");
143  break;
144  default:
145  ret += SVFUtil::errMsg("FAILURE");
146  }
147  return ret;
148 }
static const INTERLEV_FLAG INTERLEV_UNSOUND
std::string bugMsg2(std::string msg)
Definition: SVFUtil.cpp:86
std::string sucMsg(std::string msg)
Returns successful message by converting a string into green string output.
Definition: SVFUtil.cpp:54
static const INTERLEV_FLAG INTERLEV_IMPRECISE
static const INTERLEV_FLAG INTERLEV_TRUE
Constant INTERLEV_FLAG values.
std::string errMsg(std::string msg)
Print error message by converting a string into red string output.
Definition: SVFUtil.cpp:76
std::string bugMsg1(std::string msg)
Definition: SVFUtil.cpp:81

◆ getPreviousMemoryAccessInst()

const Instruction * MTAResultValidator::getPreviousMemoryAccessInst ( const Instruction I)
protected

Definition at line 105 of file MTAResultValidator.cpp.

106 {
107  I = I->getPrevNode();
108  while (I)
109  {
110  if (SVFUtil::isa<LoadInst>(I) || SVFUtil::isa<StoreInst>(I))
111  return I;
112  I = I->getPrevNode();
113  }
114  return nullptr;
115 }

◆ getStringArg()

std::vector< std::string > MTAResultValidator::getStringArg ( const Instruction inst,
unsigned int  arg_num 
)
protected

Definition at line 67 of file MTAResultValidator.cpp.

68 {
69  assert(SVFUtil::isa<CallInst>(inst) && "getFirstIntArg: inst is not a callinst");
71  assert((arg_num < cs.arg_size()) && "Does not has this argument");
73  const Constant* arrayinst = SVFUtil::dyn_cast<Constant>(gepinst->getOperand(0));
74  const ConstantDataArray* cxtarray = SVFUtil::dyn_cast<ConstantDataArray>(arrayinst->getOperand(0));
75  if (!cxtarray)
76  {
77  std::vector<std::string> strvec;
78  return strvec;
79  }
80  const StringRef vthdcxtstring = cxtarray->getAsCString();
81  return split(vthdcxtstring.str(), ',');
82 }
#define assert(ex)
Definition: util.h:141
Value * getArgument(unsigned ArgNo) const
Definition: BasicTypes.h:318
llvm::ConstantDataArray ConstantDataArray
Definition: BasicTypes.h:133
llvm::StringRef StringRef
Definition: BasicTypes.h:102
llvm::GetElementPtrInst GetElementPtrInst
Definition: BasicTypes.h:149
unsigned arg_size() const
Definition: BasicTypes.h:322
llvm::Constant Constant
Definition: BasicTypes.h:123
CallSite getLLVMCallSite(const Instruction *inst)
Return LLVM callsite given a instruction.
Definition: SVFUtil.h:183
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343

◆ matchCxt()

bool MTAResultValidator::matchCxt ( const CallStrCxt  cxt1,
const CallStrCxt  cxt2 
) const
protected

Definition at line 150 of file MTAResultValidator.cpp.

151 {
152  if (cxt1.size() != cxt2.size())
153  return false;
154  return std::equal(cxt1.begin(), cxt1.end(), cxt2.begin());
155 }

◆ split() [1/2]

std::vector< std::string > & MTAResultValidator::split ( const std::string &  s,
char  delim,
std::vector< std::string > &  elems 
)
protected

Definition at line 41 of file MTAResultValidator.cpp.

42 {
43  std::stringstream ss(s);
44  std::string item;
45  while (std::getline(ss, item, delim))
46  {
47  elems.push_back(item);
48  }
49  return elems;
50 }

◆ split() [2/2]

std::vector< std::string > MTAResultValidator::split ( const std::string &  s,
char  delim 
)
protected

Definition at line 52 of file MTAResultValidator.cpp.

53 {
54  std::vector<std::string> elems;
55  split(s, delim, elems);
56  return elems;
57 }
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)

◆ validateCxtThread()

bool MTAResultValidator::validateCxtThread ( )
protected

Definition at line 302 of file MTAResultValidator.cpp.

303 {
304 
305  bool res = true;
306  TCT* tct = mhp->getTCT();
307  if (tct->getTCTNodeNum() != vthdToCxt.size())
308  {
309  res = false;
310  if (Options::PrintValidRes)
311  {
312  outs() << "\nValidate CxtThread: The number of CxtThread is different from given result!!!\n";
313  outs() << "Given threads:\t" << vthdToCxt.size() << "\nAnalysis result:\t" << tct->getTCTNodeNum() << "\n";
314  }
315  }
316 
317  Set<int> visitedvthd;
318 
319  for (NodeID i = 0; i < tct->getTCTNodeNum(); i++)
320  {
321  const CxtThread rthd = tct->getTCTNode(i)->getCxtThread();
322  bool matched = false;
323  for (Map<NodeID, CallStrCxt>::iterator j = vthdToCxt.begin(), ej = vthdToCxt.end(); j != ej; j++)
324  {
325  NodeID vthdid = (*j).first;
326  if (matchCxt(rthd.getContext(), vthdToCxt[vthdid]))
327  {
328  if (visitedvthd.find(vthdid) != visitedvthd.end())
329  {
330  res = false;
331  if (Options::PrintValidRes)
332  {
333  outs() << "\nValidate CxtThread: Repeat real CxtThread !!!\n";
334  rthd.dump();
335  tct->getTCTNode(vthdTorthd[vthdid])->getCxtThread().dump();
336  }
337  }
338  vthdTorthd[vthdid] = i;
339  rthdTovthd[i] = vthdid;
340  visitedvthd.insert(vthdid);
341  matched = true;
342  break;
343  }
344  }
345  if (!matched)
346  {
347  res = false;
348  if (Options::PrintValidRes)
349  {
350  outs() << "\nValidate CxtThread: Cannot match real CxtThread !!!\n";
351  rthd.dump();
352  }
353  }
354  }
355  if (visitedvthd.size() != vthdToCxt.size())
356  {
357  res = false;
358  if (Options::PrintValidRes)
359  {
360  outs() << "\nValidate CxtThread: Some given CxtThreads cannot be found !!!\n";
361  for (Map<NodeID, CallStrCxt>::iterator j = vthdToCxt.begin(), ej = vthdToCxt.end(); j != ej; j++)
362  {
363  NodeID vthdid = (*j).first;
364  if (visitedvthd.find(vthdid) == visitedvthd.end())
365  {
366  dumpCxt(vthdToCxt[vthdid]);
367  }
368  }
369  }
370  }
371  return res;
372 }
const CallStrCxt & getContext() const
Return context of the thread.
Definition: CxtStmt.h:205
u32_t NodeID
Definition: SVFBasicTypes.h:80
u32_t getTCTNodeNum() const
Get Statistics.
Definition: TCT.h:203
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: SVFBasicTypes.h:98
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
Definition: TCT.h:160
const CxtThread & getCxtThread() const
Get CxtThread.
Definition: TCT.h:81
Map< NodeID, NodeID > vthdTorthd
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: SVFBasicTypes.h:93
Map< NodeID, NodeID > rthdTovthd
Map< NodeID, CallStrCxt > vthdToCxt
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
TCT * getTCT() const
Get Thread Creation Tree.
Definition: MHP.h:62
Definition: TCT.h:115
void dump() const
Dump CxtThread.
Definition: CxtStmt.h:278
void dumpCxt(const CallStrCxt &cxt) const
bool matchCxt(const CallStrCxt cxt1, const CallStrCxt cxt2) const

◆ validateInterleaving()

MTAResultValidator::INTERLEV_FLAG MTAResultValidator::validateInterleaving ( )
protected

Definition at line 425 of file MTAResultValidator.cpp.

426 {
428 
429  for (MHP::InstToThreadStmtSetMap::iterator seti = instToTSMap.begin(), eseti = instToTSMap.end(); seti != eseti; ++seti)
430  {
431  const Instruction* inst = (*seti).first;
432 
433  const MHP::CxtThreadStmtSet& tsSet = mhp->getThreadStmtSet(inst);
434 
435  if ((*seti).second.size() != tsSet.size())
436  {
437  if (Options::PrintValidRes)
438  {
439  outs() << "\nValidate Interleaving: Wrong at (" << SVFUtil::getSourceLoc(inst) << ")\n";
440  outs() << "Reason: The number of thread running on stmt is wrong\n";
441  outs() << "\n----Given threads:\n";
442  for (MHP::CxtThreadStmtSet::iterator thdlevi = (*seti).second.begin(), ethdlevi = (*seti).second.end(); thdlevi != ethdlevi;
443  ++thdlevi)
444  {
445  outs() << "TID " << rthdTovthd[(*thdlevi).getTid()] << ": ";
446  dumpCxt((*thdlevi).getContext());
447  }
448  outs() << "\n----Analysis threads:\n";
449  for (MHP::CxtThreadStmtSet::const_iterator it = tsSet.begin(), eit = tsSet.end(); it != eit; ++it)
450  {
451  outs() << "TID " << rthdTovthd[(*it).getTid()] << ": ";
452  dumpCxt((*it).getContext());
453  }
454  outs() << "\n";
455  }
457  }
458 
459  for (MHP::CxtThreadStmtSet::const_iterator it = tsSet.begin(), eit = tsSet.end(); it != eit; ++it)
460  {
461  const CxtThreadStmt& ts = *it;
462  bool matched = false;
463  for (MHP::CxtThreadStmtSet::iterator it2 = (*seti).second.begin(), eit2 = (*seti).second.end(); it2 != eit2; ++it2)
464  {
465  const CxtThreadStmt& ts2 = *it2;
466 
467  if (ts2.getTid() == ts.getTid() && matchCxt(ts2.getContext(), ts.getContext()))
468  {
469  matched = true;
470  NodeBS lev = mhp->getInterleavingThreads(ts);
471  NodeBS lev2 = threadStmtToInterLeaving[ts2];
472  if (lev != lev2)
473  {
474  if (Options::PrintValidRes)
475  {
476  outs() << "\nValidate Interleaving: Wrong at (" << SVFUtil::getSourceLoc(inst) << ")\n";
477  outs() << "Reason: thread interleaving on stmt is wrong\n";
478  dumpCxt(ts.getContext());
479  outs() << "Given result: \tTID " << rthdTovthd[ts.getTid()];
480  dumpInterlev(lev2);
481  outs() << "Analysis result: \tTID " << rthdTovthd[ts.getTid()];
482  dumpInterlev(lev);
483  }
484 
487 
488  if (lev.count() >= lev2.count())
489  {
490  bool findeveryelement = true;
491  for (NodeBS::iterator it = lev2.begin(), eit = lev2.end(); it != eit; it++)
492  {
493  if (!lev.test(*it))
494  {
495  findeveryelement = false;
496  break;
497  }
498  }
499  if (!findeveryelement)
501  }
502  else
504  }
505  }
506  }
507 
508  if (!matched)
509  {
510  if (Options::PrintValidRes)
511  {
512  outs() << "\nValidate Interleaving: Wrong at (" << SVFUtil::getSourceLoc(inst) << ")\n";
513  outs() << "Reason: analysis thread cxt is not matched by given thread cxt\n";
514  dumpCxt(ts.getContext());
515  NodeBS lev = mhp->getInterleavingThreads(ts);
516 
517  outs() << "Analysis result: \tTID " << rthdTovthd[ts.getTid()];
518  dumpInterlev(lev);
519  }
521  }
522  }
523  }
524  return res;
525 }
static const INTERLEV_FLAG INTERLEV_UNSOUND
MHP::InstToThreadStmtSetMap instToTSMap
std::string getSourceLoc(const Value *val)
Return source code including line number and file name from debug information.
Definition: SVFUtil.cpp:259
NodeID getTid() const
Return current context.
Definition: CxtStmt.h:139
MHP::ThreadStmtToThreadInterleav threadStmtToInterLeaving
Map< NodeID, NodeID > rthdTovthd
llvm::Instruction Instruction
Definition: BasicTypes.h:79
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
const NodeBS & getInterleavingThreads(const CxtThreadStmt &cts)
Get interleaving thread for statement inst.
Definition: MHP.h:89
const CallStrCxt & getContext() const
Return current context.
Definition: CxtStmt.h:57
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87
static const INTERLEV_FLAG INTERLEV_IMPRECISE
static const INTERLEV_FLAG INTERLEV_TRUE
Constant INTERLEV_FLAG values.
void dumpCxt(const CallStrCxt &cxt) const
void dumpInterlev(NodeBS &lev)
Set< CxtThreadStmt > CxtThreadStmtSet
Definition: MHP.h:34
bool matchCxt(const CallStrCxt cxt1, const CallStrCxt cxt2) const
const CxtThreadStmtSet & getThreadStmtSet(const Instruction *inst) const
Get/has ThreadStmt.
Definition: MHP.h:101

◆ validateTCT()

bool MTAResultValidator::validateTCT ( )
protected

Definition at line 374 of file MTAResultValidator.cpp.

375 {
376  bool res = true;
377 
378  TCT* tct = mhp->getTCT();
379  for (NodeID i = 0; i < tct->getTCTNodeNum(); i++)
380  {
381  bool res_node = true;
382  TCTNode* pnode = tct->getTCTNode(i);
383  for (TCT::ThreadCreateEdgeSet::const_iterator ci = tct->getChildrenBegin(pnode), cei = tct->getChildrenEnd(pnode); ci != cei;
384  ci++)
385  {
386  NodeID tid = (*ci)->getDstID();
387  if (rthdToChildren[i].find(tid) == rthdToChildren[i].end())
388  {
389  res = false;
390  res_node = false;
391  }
392  }
393 
394  for (Set<NodeID>::iterator j = rthdToChildren[i].begin(), ej = rthdToChildren[i].end(); j != ej; j++)
395  {
396  NodeID gid = *j;
397  if (!tct->hasGraphEdge(pnode, tct->getTCTNode(gid), TCTEdge::ThreadCreateEdge))
398  {
399  res = false;
400  res_node = false;
401  }
402  }
403  if ((!res_node) && Options::PrintValidRes)
404  {
405  outs() << "Validate TCT: Wrong at TID " << rthdTovthd[i] << "\n";
406  outs() << "Given children: \t";
407  for (Set<NodeID>::iterator j = rthdToChildren[i].begin(), ej = rthdToChildren[i].end(); j != ej; j++)
408  {
409  NodeID gid = *j;
410  outs() << rthdTovthd[gid] << ", ";
411  }
412  outs() << "\nAnalysis children:\t";
413  for (TCT::ThreadCreateEdgeSet::const_iterator ci = tct->getChildrenBegin(pnode), cei = tct->getChildrenEnd(pnode); ci != cei;
414  ci++)
415  {
416  NodeID tid = (*ci)->getDstID();
417  outs() << rthdTovthd[tid] << ", ";
418  }
419  outs() << "\n";
420  }
421  }
422  return res;
423 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
ThreadCreateEdgeSet::const_iterator getChildrenBegin(const TCTNode *node) const
Get children and parent nodes.
Definition: TCT.h:171
TCTEdge * hasGraphEdge(TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind) const
Whether we have aleady created this call graph edge.
Definition: TCT.cpp:561
u32_t getTCTNodeNum() const
Get Statistics.
Definition: TCT.h:203
Map< NodeID, Set< NodeID > > rthdToChildren
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
Definition: TCT.h:160
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: SVFBasicTypes.h:93
Map< NodeID, NodeID > rthdTovthd
ThreadCreateEdgeSet::const_iterator getChildrenEnd(const TCTNode *node) const
Definition: TCT.h:175
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
TCT * getTCT() const
Get Thread Creation Tree.
Definition: MHP.h:62
Definition: TCT.h:115

Member Data Documentation

◆ csnumToInstMap

Map<NodeID, const CallInst*> MTAResultValidator::csnumToInstMap
private

Definition at line 116 of file MTAResultValidator.h.

◆ CXT_THREAD

constexpr char const* MTAResultValidator::CXT_THREAD = "CXT_THREAD"
staticprivate

Map a statement to its thread interleavings.

Definition at line 126 of file MTAResultValidator.h.

◆ instToTSMap

MHP::InstToThreadStmtSetMap MTAResultValidator::instToTSMap
private

Definition at line 123 of file MTAResultValidator.h.

◆ INTERLEV_ACCESS

constexpr char const* MTAResultValidator::INTERLEV_ACCESS = "INTERLEV_ACCESS"
staticprivate

Definition at line 127 of file MTAResultValidator.h.

◆ INTERLEV_IMPRECISE

const INTERLEV_FLAG MTAResultValidator::INTERLEV_IMPRECISE = 0x02
staticprivate

Definition at line 137 of file MTAResultValidator.h.

◆ INTERLEV_TRUE

const INTERLEV_FLAG MTAResultValidator::INTERLEV_TRUE = 0x01
staticprivate

Constant INTERLEV_FLAG values.

Definition at line 136 of file MTAResultValidator.h.

◆ INTERLEV_UNSOUND

const INTERLEV_FLAG MTAResultValidator::INTERLEV_UNSOUND = 0x04
staticprivate

Definition at line 138 of file MTAResultValidator.h.

◆ mhp

MHP* MTAResultValidator::mhp
private

Definition at line 132 of file MTAResultValidator.h.

◆ rthdToChildren

Map<NodeID, Set<NodeID> > MTAResultValidator::rthdToChildren
private

Definition at line 121 of file MTAResultValidator.h.

◆ rthdTovthd

Map<NodeID, NodeID> MTAResultValidator::rthdTovthd
private

Definition at line 119 of file MTAResultValidator.h.

◆ tcg

ThreadCallGraph* MTAResultValidator::tcg
private

Definition at line 131 of file MTAResultValidator.h.

◆ TCT_ACCESS

constexpr char const* MTAResultValidator::TCT_ACCESS = "TCT_ACCESS"
staticprivate

Definition at line 128 of file MTAResultValidator.h.

◆ tdAPI

ThreadAPI* MTAResultValidator::tdAPI
private

Definition at line 130 of file MTAResultValidator.h.

◆ threadStmtToInterLeaving

MHP::ThreadStmtToThreadInterleav MTAResultValidator::threadStmtToInterLeaving
private

Definition at line 124 of file MTAResultValidator.h.

◆ vthdToCxt

Map<NodeID, CallStrCxt> MTAResultValidator::vthdToCxt
private

Definition at line 117 of file MTAResultValidator.h.

◆ vthdTorthd

Map<NodeID, NodeID> MTAResultValidator::vthdTorthd
private

Definition at line 118 of file MTAResultValidator.h.


The documentation for this class was generated from the following files: