Spatial
Simple Static Analysis in LLVM
ValueContext.h
Go to the documentation of this file.
1#ifndef VALUECONTEXT_H
2#define VALUECONTEXT_H
3
4#include "map"
5#include "vector"
6#include "llvm/IR/Function.h"
7#include "llvm/IR/Instructions.h"
8
9namespace spatial {
10
11using Context = int;
12
13template <class DataflowValue> class ValueContext {
14private:
15 Context C;
16 DataflowValue BI;
17 DataflowValue Top;
18 std::map<std::pair<llvm::Function *, DataflowValue>, Context>
19 DataFlowToContext;
20 std::map<Context, DataflowValue> Result;
21 std::map<llvm::Function *, std::vector<Context>> FunctionToContexts;
22 std::map<Context, std::vector<std::pair<Context, llvm::Instruction *>>>
23 ContextGraph;
24
25public:
26 std::map<Context, std::map<llvm::Instruction *, DataflowValue>> getDataFlowIn,
28
29 ValueContext(DataflowValue BI, DataflowValue Top);
30 DataflowValue getBI();
31 DataflowValue getTop();
32 std::vector<std::pair<Context, llvm::Instruction *>>
34 int getSavedContext(llvm::Function *Func, DataflowValue BI);
35 int initializeContext(llvm::Function *Func, DataflowValue BI);
36 void setResult(Context C, DataflowValue Value);
37 DataflowValue getResult(Context C);
38 void updateContextGraph(Context Src, Context Dest,
39 llvm::Instruction *CallSite);
40 std::vector<Context> getContexts(llvm::Function *Func);
41};
42
43template <class DataflowValue>
44ValueContext<DataflowValue>::ValueContext(DataflowValue BI, DataflowValue Top) {
45 this->BI = BI;
46 this->Top = Top;
47 this->C = 0;
48}
49
50template <class DataflowValue>
52 return BI;
53};
54
55template <class DataflowValue>
57 return Top;
58};
59
60template <class DataflowValue>
61std::vector<std::pair<Context, llvm::Instruction *>>
63 return ContextGraph[Src];
64}
65
66template <class DataflowValue>
68 DataflowValue BI) {
69 if (this->DataFlowToContext.find(std::make_pair(Func, BI)) !=
70 this->DataFlowToContext.end()) {
71 return this->DataFlowToContext[std::make_pair(Func, BI)];
72 }
73 return -1;
74}
75
76template <class DataflowValue>
78 DataflowValue BI) {
79 DataFlowToContext[std::make_pair(Func, BI)] = this->C;
80 this->Result[this->C] = this->getTop();
81 int temp = this->C;
82 FunctionToContexts[Func].push_back(temp);
83 this->C += 1;
84 return temp;
85}
86
87template <class DataflowValue>
88void ValueContext<DataflowValue>::setResult(Context C, DataflowValue Value) {
89 this->Result[C] = Value;
90}
91
92template <class DataflowValue>
94 return this->Result[C];
95}
96
97template <class DataflowValue>
99 Context Src, Context Dest, llvm::Instruction *CallSite) {
100 this->ContextGraph[Dest].push_back(std::make_pair(Src, CallSite));
101}
102
103template <class DataflowValue>
104std::vector<Context>
106 return FunctionToContexts[Func];
107}
108
109} // namespace spatial
110
111#endif
Definition: ValueContext.h:13
int getSavedContext(llvm::Function *Func, DataflowValue BI)
Definition: ValueContext.h:67
std::map< Context, std::map< llvm::Instruction *, DataflowValue > > getDataFlowIn
Definition: ValueContext.h:26
DataflowValue getResult(Context C)
Definition: ValueContext.h:93
std::vector< Context > getContexts(llvm::Function *Func)
Definition: ValueContext.h:105
void updateContextGraph(Context Src, Context Dest, llvm::Instruction *CallSite)
Definition: ValueContext.h:98
DataflowValue getTop()
Definition: ValueContext.h:56
void setResult(Context C, DataflowValue Value)
Definition: ValueContext.h:88
DataflowValue getBI()
Definition: ValueContext.h:51
std::vector< std::pair< Context, llvm::Instruction * > > getContextChild(Context Src)
Definition: ValueContext.h:62
ValueContext(DataflowValue BI, DataflowValue Top)
Definition: ValueContext.h:44
std::map< Context, std::map< llvm::Instruction *, DataflowValue > > getDataFlowOut
Definition: ValueContext.h:27
int initializeContext(llvm::Function *Func, DataflowValue BI)
Definition: ValueContext.h:77
Definition: PointsToBenchmark.cpp:19
int Context
Definition: ValueContext.h:11