Spatial
Simple Static Analysis in LLVM
PointsToBenchmark.h
Go to the documentation of this file.
1#ifndef POINTS_TO_BENCHMARK_H_
2#define POINTS_TO_BENCHMARK_H_
3#include "Benchmark.h"
4#include "llvm/IR/DebugInfoMetadata.h"
5#include "llvm/IR/Metadata.h"
6
7namespace spatial {
8
10 bool isSound;
11 std::map<llvm::Instruction *, std::vector<std::string>> TCResult;
12 std::map<llvm::BasicBlock *, std::vector<int>> PrecisionResult;
13
14public:
15 PointsToBenchmarkRunner() : BenchmarkRunner("PointsTo") { isSound = 1; }
16 std::vector<llvm::Value *> extract(llvm::Instruction *Inst);
17 friend std::ostream &operator<<(std::ostream &OS,
19 template <class Ty>
20 void evaluate(llvm::Instruction *Inst, std::set<Ty *>, Ty *);
21 bool CheckSoundness();
22 void evaluatePrecision(llvm::Function &);
23};
24
35template <class Ty>
36void PointsToBenchmarkRunner::evaluate(llvm::Instruction *I, std::set<Ty *> A,
37 Ty *B) {
38 llvm::CallInst *Inst = llvm::cast<llvm::CallInst>(I);
39 std::string Status, Expected;
40 llvm::StringRef FunctionName = Inst->getCalledFunction()->getName();
41
42 llvm::MDNode *MD = I->getMetadata("dbg");
43 int LineNo = llvm::cast<llvm::DILocation>(MD)->getLine();
44
45 if (FunctionName.contains("May"))
46 Expected = "MayPointsTo";
47 else if (FunctionName.contains("Must"))
48 Expected = "MustPointsTo";
49 else if (FunctionName.contains("DoesNot"))
50 Expected = "DoesNotPointsTo";
51
52 if (Expected == "MayPointsTo") {
53 Status = "Fail";
54 for (auto it = A.begin(); it != A.end(); it++) {
55 if (*it == B) {
56 Status = "Pass";
57 break;
58 }
59 }
60 } else if (Expected == "MustPointsTo") {
61 if (A.size() > 1 || A.size() == 0) {
62 Status = "Fail";
63 } else {
64 Status = "Pass";
65 for (auto it = A.begin(); it != A.end(); it++) {
66 if (*it != B) {
67 Status = "Fail";
68 break;
69 }
70 }
71 }
72 } else {
73 Status = "Pass";
74 for (auto it = A.begin(); it != A.end(); it++) {
75 if (*it == B) {
76 Status = "Fail";
77 break;
78 }
79 }
80 }
81 TCResult[Inst].push_back(Status);
82 TCResult[Inst].push_back(Expected);
83 TCResult[Inst].push_back(std::to_string(LineNo));
84}
85
86} // namespace spatial
87
88#endif
Definition: Benchmark.h:14
Definition: PointsToBenchmark.h:9
bool CheckSoundness()
Definition: PointsToBenchmark.cpp:37
friend std::ostream & operator<<(std::ostream &OS, const PointsToBenchmarkRunner &B)
Definition: PointsToBenchmark.cpp:49
void evaluatePrecision(llvm::Function &)
Definition: PointsToBenchmark.cpp:127
void evaluate(llvm::Instruction *Inst, std::set< Ty * >, Ty *)
This Function evaluates the predicates defined in testcases for pointer analysis.
Definition: PointsToBenchmark.h:36
PointsToBenchmarkRunner()
Definition: PointsToBenchmark.h:15
std::vector< llvm::Value * > extract(llvm::Instruction *Inst)
Definition: PointsToBenchmark.cpp:111
Definition: PointsToBenchmark.cpp:19