Static Value-Flow Analysis
Annotator.h
Go to the documentation of this file.
1 /*
2  * Annotator.h
3  *
4  * Created on: May 4, 2014
5  * Author: Yulei Sui
6  */
7 
8 #ifndef ANNOTATOR_H_
9 #define ANNOTATOR_H_
10 
11 #include <SVF-LLVM/BasicTypes.h> // TODO: Remove LLVM Header
12 #include "SVFIR/SVFValue.h"
13 #include <vector>
14 
15 namespace SVF
16 {
17 
21 class Annotator
22 {
23 
24 public:
27  {
28  SB_SLICESOURCE = "SOURCE_";
29  SB_SLICESINK = "SINK_";
30  SB_FESIBLE = "FESIBLE_";
31  SB_INFESIBLE = "INFESIBLE_";
32 
33  DR_NOT_CHECK = "DRNOTCHECK_";
34  DR_CHECK = "DRCHECK_";
35  }
36 
38  virtual ~Annotator()
39  {
40  }
41 
43 
44  inline bool hasSBSourceFlag(Instruction* inst) const
45  {
46  std::vector<Value* > values;
47  return evalMDTag(inst, inst, SB_SLICESOURCE, values);
48  }
49 
50  inline bool hasSBSinkFlag(Instruction* inst) const
51  {
52  std::vector<Value* > values;
53  return evalMDTag(inst, inst, SB_SLICESINK, values);
54  }
56 
58 
59  inline bool hasDRNotCheckFlag(Instruction* inst) const
60  {
61  //std::vector<Value* > values;
62  //return evalMDTag(inst, inst, DR_NOT_CHECK, values);
63  return inst->getMetadata(DR_NOT_CHECK);
64  }
65 
66  inline bool hasDRNotCheckFlag(const Instruction* inst) const
67  {
68  //std::vector<Value* > values;
69  //return evalMDTag(inst, inst, DR_NOT_CHECK, values);
70  return inst->getMetadata(DR_NOT_CHECK);
71  }
72 
73  inline bool hasDRCheckFlag(Instruction* inst) const
74  {
75  //std::vector<Value* > values;
76  //return evalMDTag(inst, inst, DR_CHECK, values);
77  return inst->getMetadata(DR_CHECK);
78  }
79 
80  inline bool hasDRCheckFlag(const Instruction* inst) const
81  {
82  //std::vector<Value* > values;
83  //return evalMDTag(inst, inst, DR_CHECK, values);
84  return inst->getMetadata(DR_CHECK);
85  }
87 
89 
90  inline void addMDTag(Instruction* inst, std::string str)
91  {
92  addMDTag(inst, inst, str);
93  }
94  inline void removeMDTag(Instruction* inst, std::string str)
95  {
96  removeMDTag(inst, inst, str);
97  }
99 
101 
102  inline void addMDTag(Instruction* inst, Value* val, std::string str)
104  {
105  assert(!val->getType()->isVoidTy() && "expecting non-void value for MD!");
106  std::vector<Value* > values;
107  //std::vector<llvm::Metadata *> metavalues;
108  // add the flag if we did not see it before
109  if (evalMDTag(inst, val, str, values) == false)
110  {
111 
112  values.push_back(val);
113  //llvm::ArrayRef<llvm::Metadata*> ar(metavalues);
114  // FIXME: delete the old MDNode
115  inst->setMetadata(str, MDNode::get(inst->getContext(), nullptr));
116  //inst->setMetadata(str, llvm::MDNode::get(inst->getContext(), ar));
117  }
118  }
119 
121  inline void removeMDTag(Instruction* inst, Value* val, std::string str)
122  {
123  assert(!val->getType()->isVoidTy() && "expecting non-void value for MD!");
124  std::vector<Value* > values;
125 
126  // remove the flag if it is there
127  if (evalMDTag(inst, val, str, values) == true)
128  {
129  llvm::ArrayRef<Value* > ar(values);
130  // FIXME: delete the old MDNode
131  //inst->setMetadata(str, llvm::MDNode::get(inst->getContext(), ar));
132  }
133  }
135 
136 private:
137 
139  inline bool evalMDTag(const Instruction* inst, const Value* val, std::string str,
140  std::vector<Value* >&) const
141  {
142 
143  assert(val && "value should not be null");
144 
145  bool hasFlag = false;
146  if (MDNode *mdNode = inst->getMetadata(str))
147  {
149  for (unsigned k = 0; k < mdNode->getNumOperands(); ++k)
150  {
151  //Value* v = mdNode->getOperand(k);
152  // if (v == val)
153  // hasFlag = true;
154  //else
155  // values.push_back(v);
156  }
157  }
158  return hasFlag;
159  }
160 
161 protected:
162 
164 
165  const char* SB_SLICESOURCE;
166  const char* SB_SLICESINK;
167  const char* SB_FESIBLE;
168  const char* SB_INFESIBLE;
170 
172 
173  const char* DR_NOT_CHECK;
174  const char* DR_CHECK;
176 };
177 
178 } // End namespace SVF
179 
180 #endif /* ANNOTATOR_H_ */
const char *const string
Definition: cJSON.h:172
const char * SB_SLICESOURCE
Saber annotations.
Definition: Annotator.h:165
bool hasDRNotCheckFlag(const Instruction *inst) const
Definition: Annotator.h:66
bool evalMDTag(const Instruction *inst, const Value *val, std::string str, std::vector< Value * > &) const
evaluate llvm metadata
Definition: Annotator.h:139
void removeMDTag(Instruction *inst, std::string str)
Definition: Annotator.h:94
const char * SB_SLICESINK
Definition: Annotator.h:166
bool hasSBSourceFlag(Instruction *inst) const
SB Has flag methods.
Definition: Annotator.h:44
const char * SB_INFESIBLE
Definition: Annotator.h:168
const char * DR_CHECK
Definition: Annotator.h:174
void removeMDTag(Instruction *inst, Value *val, std::string str)
remove flag from llvm metadata
Definition: Annotator.h:121
bool hasDRCheckFlag(Instruction *inst) const
Definition: Annotator.h:73
virtual ~Annotator()
Destructor.
Definition: Annotator.h:38
Annotator()
Constructor.
Definition: Annotator.h:26
bool hasDRCheckFlag(const Instruction *inst) const
Definition: Annotator.h:80
const char * SB_FESIBLE
Definition: Annotator.h:167
bool hasSBSinkFlag(Instruction *inst) const
Definition: Annotator.h:50
void addMDTag(Instruction *inst, std::string str)
Simple add/remove meta data information.
Definition: Annotator.h:90
bool hasDRNotCheckFlag(Instruction *inst) const
Race Detection Has flag methods.
Definition: Annotator.h:59
const char * DR_NOT_CHECK
Race Detection annotations.
Definition: Annotator.h:173
for isBitcode
Definition: BasicTypes.h:68
llvm::Instruction Instruction
Definition: BasicTypes.h:87
llvm::Value Value
LLVM Basic classes.
Definition: BasicTypes.h:82
llvm::MDNode MDNode
Definition: BasicTypes.h:112