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

Validate the result of concurrent analysis. More...

#include <MTAResultValidator.h>

Inheritance diagram for RaceResultValidator:
SVF::LockValidator SVF::MHPValidator

Classes

class  AccessPair
 

Public Types

typedef int RC_FLAG
 

Public Member Functions

virtual ~RaceResultValidator ()
 Destructor. More...
 
void init (SVFModule *M)
 Initialization. More...
 
void analyze ()
 Analysis. More...
 
void release ()
 Release resource. More...
 
bool hasValidationTarget () const
 Check if the input program has validation target. More...
 

Protected Member Functions

void collectValidationTargets ()
 
void validateAll ()
 Perform validation for all targets. More...
 
std::string getOutput (const char *scenario, bool analysisRes, bool expectedRes)
 Get the validation result string of a single validation scenario. More...
 
virtual bool mayAccessAliases (const Instruction *I1, const Instruction *I2)
 
virtual bool mayHappenInParallel (const Instruction *I1, const Instruction *I2)
 
virtual bool protectedByCommonLocks (const Instruction *I1, const Instruction *I2)
 
virtual bool mayHaveDataRace (const Instruction *I1, const Instruction *I2)
 

Private Member Functions

const Instruction * getPreviousMemoryAccessInst (const Instruction *I)
 

Static Private Member Functions

static bool compare (const CallInst *CI1, const CallInst *CI2)
 

Private Attributes

SVFModule * M
 
std::vector< AccessPairaccessPairs
 
RC_FLAG selectedValidationScenarios
 

Static Private Attributes

static constexpr char const * RC_ACCESS = "RC_ACCESS"
 
static const RC_FLAG RC_MHP = 0x01
 Constant RC_FLAG values. More...
 
static const RC_FLAG RC_ALIASES = 0x02
 
static const RC_FLAG RC_PROTECTED = 0x04
 
static const RC_FLAG RC_RACE = 0x10
 

Detailed Description

Validate the result of concurrent analysis.

The properties to validate of two memory accesses include one or more of the following four: (1) they may accesses aliases; (2) they may happen in parallel; (3) they are protected by common lock(s); (4) they may cause a data race error. The ground truth are specified by the "RC_ACCESS" function in the target program.

Users may utilize this result validator to validate their analysis with one or more of the four properties, by inheriting the RCResultValidator class. The corresponding virtual function of the desired property should be overridden.

Definition at line 159 of file MTAResultValidator.h.

Member Typedef Documentation

◆ RC_FLAG

Definition at line 162 of file MTAResultValidator.h.

Constructor & Destructor Documentation

◆ ~RaceResultValidator()

virtual RaceResultValidator::~RaceResultValidator ( )
inlinevirtual

Destructor.

Definition at line 200 of file MTAResultValidator.h.

201  {
202  release();
203  }
void release()
Release resource.

Member Function Documentation

◆ analyze()

void RaceResultValidator::analyze ( )
inline

Analysis.

Definition at line 214 of file MTAResultValidator.h.

215  {
216  validateAll();
217  }
void validateAll()
Perform validation for all targets.

◆ collectValidationTargets()

void RaceResultValidator::collectValidationTargets ( )
inlineprotected

Collect the targets for validations. The targets should be memory access Instructions in pairs. The collected targets are stored in the member variable "accessPairs".

Definition at line 265 of file MTAResultValidator.h.

266  {
267  // Collect call sites of all RC_ACCESS function calls.
268  std::vector<const CallInst*> csInsts;
269  const Function *F = M.getFunction(RC_ACCESS);
270  if (!F) return;
271 
272  for (Value::const_use_iterator it = F->use_begin(), ie =
273  F->use_end(); it != ie; ++it)
274  {
275  const Use *u = &*it;
276  const Value *user = u->getUser();
277  const CallInst *csInst = SVFUtil::dyn_cast<CallInst>(user);
278  assert(csInst);
279  csInsts.push_back(csInst);
280  }
281  assert(csInsts.size() % 2 == 0 && "We should have RC_ACCESS called in pairs.");
282 
283  // Sort the validation sites according to their ids.
284  std::sort(csInsts.begin(), csInsts.end(), compare);
285 
286  // Generate access pairs.
287  for (int i = 0, e = csInsts.size(); i != e;)
288  {
289  const CallInst *CI1 = csInsts[i++];
290  const CallInst *CI2 = csInsts[i++];
291  const ConstantInt *C = SVFUtil::dyn_cast<ConstantInt>(CI1->getOperand(1));
292  assert(C);
293  const Instruction *I1 = getPreviousMemoryAccessInst(CI1);
294  const Instruction *I2 = getPreviousMemoryAccessInst(CI2);
295  assert(I1 && I2 && "RC_ACCESS should be placed immediately after the target memory access.");
296  RC_FLAG flags = C->getZExtValue();
297  accessPairs.push_back(AccessPair(I1, I2, flags));
298  }
299  }
llvm::Use Use
Definition: BasicTypes.h:87
static bool compare(const CallInst *CI1, const CallInst *CI2)
#define assert(ex)
Definition: util.h:141
llvm::CallInst CallInst
Definition: BasicTypes.h:143
const Instruction * getPreviousMemoryAccessInst(const Instruction *I)
llvm::ConstantInt ConstantInt
Definition: BasicTypes.h:153
llvm::Function Function
Definition: BasicTypes.h:76
llvm::Instruction Instruction
Definition: BasicTypes.h:79
static constexpr char const * RC_ACCESS
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
std::vector< AccessPair > accessPairs
llvm::Value Value
Definition: BasicTypes.h:78

◆ compare()

static bool RaceResultValidator::compare ( const CallInst *  CI1,
const CallInst *  CI2 
)
inlinestaticprivate

Comparison function to sort the validation targets in ascending order of the validation id (i.e., the 1st argument of RC_ACCESS function call).

Definition at line 375 of file MTAResultValidator.h.

376  {
377  const Value *V1 = CI1->getOperand(0);
378  const Value *V2 = CI2->getOperand(0);
379  const ConstantInt *C1 = SVFUtil::dyn_cast<ConstantInt>(V1);
380  const ConstantInt *C2 = SVFUtil::dyn_cast<ConstantInt>(V2);
381  assert(0 != C1 && 0 != C2);
382  return C1->getZExtValue() < C2->getZExtValue();
383  }
#define assert(ex)
Definition: util.h:141
llvm::ConstantInt ConstantInt
Definition: BasicTypes.h:153
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

◆ getOutput()

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

Get the validation result string of a single validation scenario.

Definition at line 350 of file MTAResultValidator.h.

352  {
353  std::string ret(scenario);
354  ret += "\t";
355  if (expectedRes)
356  ret += " T: ";
357  else
358  ret += " F: ";
359  if (analysisRes == expectedRes)
360  ret += SVFUtil::sucMsg("SUCCESS");
361  else
362  ret += SVFUtil::errMsg("FAILURE");
363  return ret;
364  }
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

◆ getPreviousMemoryAccessInst()

const Instruction* RaceResultValidator::getPreviousMemoryAccessInst ( const Instruction *  I)
inlineprivate

Get the previous LoadInst or StoreInst from Instruction "I" in the same BasicBlock. Return nullptr if none exists.

Definition at line 390 of file MTAResultValidator.h.

392  {
393  I = I->getPrevNode();
394  while (I)
395  {
396  if (SVFUtil::isa<LoadInst>(I) || SVFUtil::isa<StoreInst>(I))
397  return I;
398  if (const Function *callee = SVFUtil::getCallee(I))
399  {
400  if (ExtAPI::EFT_L_A0__A0R_A1R == ExtAPI::getExtAPI()->get_type(callee)
401  || callee->getName().find("llvm.memset") != StringRef::npos)
402  return I;
403  }
404  I = I->getPrevNode();
405  }
406  return nullptr;
407  }
llvm::Function Function
Definition: BasicTypes.h:76
const SVFFunction * getCallee(const CallSite cs)
Return callee of a callsite. Return null if this is an indirect call.
Definition: SVFUtil.h:221

◆ hasValidationTarget()

bool RaceResultValidator::hasValidationTarget ( ) const
inline

Check if the input program has validation target.

Definition at line 225 of file MTAResultValidator.h.

226  {
227  return !accessPairs.empty();
228  }
std::vector< AccessPair > accessPairs

◆ init()

void RaceResultValidator::init ( SVFModule *  M)
inline

Initialization.

Definition at line 206 of file MTAResultValidator.h.

207  {
208  this->M = M;
211  }
static const RC_FLAG RC_ALIASES
static const RC_FLAG RC_PROTECTED
static const RC_FLAG RC_MHP
Constant RC_FLAG values.
static const RC_FLAG RC_RACE

◆ mayAccessAliases()

virtual bool RaceResultValidator::mayAccessAliases ( const Instruction *  I1,
const Instruction *  I2 
)
inlineprotectedvirtual

Interface to the specific validation properties. Override one or more to implement your own analysis.

Definition at line 234 of file MTAResultValidator.h.

236  {
238  return true;
239  }
static const RC_FLAG RC_ALIASES

◆ mayHappenInParallel()

virtual bool RaceResultValidator::mayHappenInParallel ( const Instruction *  I1,
const Instruction *  I2 
)
inlineprotectedvirtual

Definition at line 240 of file MTAResultValidator.h.

242  {
244  return true;
245  }
static const RC_FLAG RC_MHP
Constant RC_FLAG values.

◆ mayHaveDataRace()

virtual bool RaceResultValidator::mayHaveDataRace ( const Instruction *  I1,
const Instruction *  I2 
)
inlineprotectedvirtual

Definition at line 252 of file MTAResultValidator.h.

254  {
256  return true;
257  }
static const RC_FLAG RC_RACE

◆ protectedByCommonLocks()

virtual bool RaceResultValidator::protectedByCommonLocks ( const Instruction *  I1,
const Instruction *  I2 
)
inlineprotectedvirtual

Definition at line 246 of file MTAResultValidator.h.

248  {
250  return true;
251  }
static const RC_FLAG RC_PROTECTED

◆ release()

void RaceResultValidator::release ( )
inline

Release resource.

Definition at line 220 of file MTAResultValidator.h.

221  {
222  }

◆ validateAll()

void RaceResultValidator::validateAll ( )
inlineprotected

Perform validation for all targets.

Definition at line 302 of file MTAResultValidator.h.

303  {
304  SVFUtil::outs() << SVFUtil::pasMsg(" --- Analysis Result Validation ---\n");
305 
306  // Iterate every memory access pair to perform the validation.
307  for (int i = 0, e = accessPairs.size(); i != e; ++i)
308  {
309  const AccessPair &ap = accessPairs[i];
310  const Instruction *I1 = ap.getInstruction1();
311  const Instruction *I2 = ap.getInstruction2();
312 
313  bool mhp = mayHappenInParallel(I1, I2);
314  bool alias = mayAccessAliases(I1, I2);
315  bool protect = protectedByCommonLocks(I1, I2);
316  bool racy = mayHaveDataRace(I1, I2);
317 
318  SVFUtil::outs() << "For the memory access pair at ("
319  << SVFUtil::getSourceLoc(I1) << ", "
320  << SVFUtil::getSourceLoc(I2) << ")\n";
322  {
323  SVFUtil::outs() << "\t"
324  << getOutput("ALIASES", alias, ap.isFlaged(RC_ALIASES))
325  << "\n";
326  }
328  {
329  SVFUtil::outs() << "\t"
330  << getOutput("MHP", mhp, ap.isFlaged(RC_MHP)) << "\n";
331  }
333  {
334  SVFUtil::outs() << "\t"
335  << getOutput("PROTECT", protect,
336  ap.isFlaged(RC_PROTECTED)) << "\n";
337  }
339  {
340  SVFUtil::outs() << "\t"
341  << getOutput("RACE", racy, ap.isFlaged(RC_RACE))
342  << "\n";
343  }
344  }
345 
346  SVFUtil::outs() << "\n";
347  }
virtual bool protectedByCommonLocks(const Instruction *I1, const Instruction *I2)
static const RC_FLAG RC_ALIASES
static const RC_FLAG RC_PROTECTED
std::string pasMsg(std::string msg)
Print each pass/phase message by converting a string into blue string output.
Definition: SVFUtil.cpp:99
virtual bool mayAccessAliases(const Instruction *I1, const Instruction *I2)
std::string getSourceLoc(const Value *val)
Return source code including line number and file name from debug information.
Definition: SVFUtil.cpp:259
static const RC_FLAG RC_MHP
Constant RC_FLAG values.
std::string getOutput(const char *scenario, bool analysisRes, bool expectedRes)
Get the validation result string of a single validation scenario.
llvm::Instruction Instruction
Definition: BasicTypes.h:79
virtual bool mayHaveDataRace(const Instruction *I1, const Instruction *I2)
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
virtual bool mayHappenInParallel(const Instruction *I1, const Instruction *I2)
std::vector< AccessPair > accessPairs
static const RC_FLAG RC_RACE

Member Data Documentation

◆ accessPairs

std::vector<AccessPair> RaceResultValidator::accessPairs
private

Definition at line 368 of file MTAResultValidator.h.

◆ M

SVFModule* RaceResultValidator::M
private

Definition at line 367 of file MTAResultValidator.h.

◆ RC_ACCESS

constexpr char const* RaceResultValidator::RC_ACCESS = "RC_ACCESS"
staticprivate

The name of the function which is used to specify the ground truth of the validation properties in the target program.

Definition at line 419 of file MTAResultValidator.h.

◆ RC_ALIASES

const RC_FLAG RaceResultValidator::RC_ALIASES = 0x02
staticprivate

Definition at line 412 of file MTAResultValidator.h.

◆ RC_MHP

const RC_FLAG RaceResultValidator::RC_MHP = 0x01
staticprivate

Constant RC_FLAG values.

Definition at line 411 of file MTAResultValidator.h.

◆ RC_PROTECTED

const RC_FLAG RaceResultValidator::RC_PROTECTED = 0x04
staticprivate

Definition at line 413 of file MTAResultValidator.h.

◆ RC_RACE

const RC_FLAG RaceResultValidator::RC_RACE = 0x10
staticprivate

Definition at line 414 of file MTAResultValidator.h.

◆ selectedValidationScenarios

RC_FLAG RaceResultValidator::selectedValidationScenarios
private

Definition at line 369 of file MTAResultValidator.h.


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