-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdofunc.h
97 lines (73 loc) · 2.89 KB
/
dofunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef RENT_DOFUNC_H
#define RENT_DOFUNC_H
#include <llvm/IR/Function.h>
#include <unordered_map>
using namespace llvm;
bool ensuresArity(Function *fun);
// CAD<n>R(var) list access
struct ListAccess {
std::string varName; // variable in which the list is stored
bool isArgsVar; // is the variable (list) the "args" argument of the do_XXX function?
unsigned line; // line number at which (the load of the access) is
unsigned ncdrs; // number of "D"s in the expression
ListAccess() { markUnknown(); }
ListAccess(std::string varName, bool isArgsVar, unsigned line, unsigned ncdrs):
varName(varName), isArgsVar(isArgsVar), line(line), ncdrs(ncdrs) {}
bool isUnknown() const { return line == 0; }
void markUnknown() {
varName = "";
isArgsVar = false;
line = 0;
ncdrs = 0;
}
std::string str() {
if (isUnknown()) {
return "UNKNOWN";
}
std::string pref = "CA";
std::string suff = "):" + std::to_string(line);
for(unsigned i = 0; i < ncdrs; i++) {
pref += "D";
}
pref += "R(";
if (isArgsVar) {
pref += "<";
suff = ">" + suff;
}
return pref + varName + suff;
}
bool operator==(const ListAccess& other) const;
};
struct ListAccess_equal {
bool operator() (const ListAccess& lhs, const ListAccess& rhs) const;
};
struct ListAccess_hash {
size_t operator()(const ListAccess& t) const;
};
typedef std::unordered_map<ListAccess, unsigned, ListAccess_hash> ResolvedListAccessesTy;
typedef std::vector<std::string> ArgNamesTy;
struct DoFunctionInfo {
bool checkArityCalled; // on all returning paths
int effectiveArity; // maximum index of argument value used + 1
bool usesTags; // a tag may be used
bool computesArgsLength; // uses length on args (or some suffix of it)
bool primvalCalled; // uses "op" with PRIMVAL(op)
bool errorcallCalled; // uses "call" with errorcall
bool warningcallCalled; // uses "call" with errorcall
bool check1argCalled; // uses "call" and "args" with check1arg or check1arg2
bool complexUseOfArgs; // anything except loading arg value, arg tag, calling checkArity
bool complexUseOfOp; // any use except checkArity
bool complexUseOfCall;
bool complexUseOfEnv;
bool confused; // e.g. due to too many states
ResolvedListAccessesTy listAccesses;
ArgNamesTy argNames;
Function *fun;
// FIXME: the defaults are not really used/needed
DoFunctionInfo(Function *fun): fun(fun), checkArityCalled(false), effectiveArity(-1), usesTags(true), computesArgsLength(true),
primvalCalled(true), errorcallCalled(true), warningcallCalled(true), check1argCalled(true),
complexUseOfArgs(true), complexUseOfCall(true), complexUseOfEnv(true), confused(true), listAccesses() {}; // conservative defaults
std::string str();
};
DoFunctionInfo analyzeDoFunction(Function *fun, bool resolveListAccesses = true, bool resolveArgNames = true);
#endif