-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncPtrAnalyse.h
87 lines (53 loc) · 2.17 KB
/
FuncPtrAnalyse.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
#include <llvm/Pass.h>
#include <map>
#include <set>
#include <vector>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IntrinsicInst.h>
///!TODO TO BE COMPLETED BY YOU FOR ASSIGNMENT 3
using namespace llvm;
class FuncPtrPass : public ModulePass {
public:
static char ID; // Pass identification, replacement for typeid
FuncPtrPass() : ModulePass(ID) {}
typedef std::set<Value*> FuncPtrSet;
typedef std::map<Value*, FuncPtrSet> Env;
std::map<BasicBlock*, Env> envs;
Env *_currEnv;
std::map<Function *, std::map<Instruction *, Env>> argsEnv; // Record function arguments which is a pointer
Env returned; // Record the values each func may return.
std::map<Function *, std::map<Instruction *, Env>> globalEnvPerFunc; // A global record of FuncPtrSetMap at each function and its callsite
std::map<Function *, Env> dirtyEnvPerFunc;
std::map<Instruction *, Value *> allocated; // Record the value created by allocation instructions.
std::set<Value *> dirtyValues; // during a function...
void markDirty(Value *p)
{
dirtyValues.insert(p);
}
#define currEnv (*_currEnv)
bool runOnModule(Module &M) override;
bool iterate(Module &M);
Env meet(BasicBlock *bb);
bool dispatchInst(Instruction &inst);
bool visitPhiNode(PHINode *phiNode);
bool visitCall(CallInst *callInst);
bool visitAlloc(AllocaInst *allocaInst);
bool visitGetElementPtr(GetElementPtrInst* getElementPtrInst);
bool visitLoad(LoadInst *loadInst);
bool visitStore(StoreInst *storeInst);
bool visitReturn(ReturnInst *returnInst);
bool visitBitcast(BitCastInst *bitCastInst);
bool visitMemCopy(MemCpyInst *copyInst);
Value *createAllocValue(Instruction *allloc);
Env passArgs(Function *func);
bool isFunctionPointer(Type *type);
FuncPtrSet wrappedPtrSet(Value *value);
bool setUnion(FuncPtrSet &dst, const FuncPtrSet &src);
bool isLLVMBuiltIn(CallInst *callInst);
void envUnion(Env &dst, const Env &src);
void updateEnv(Env &dst, const Env &src);
// Debug tools
void printSet(const FuncPtrSet &s);
void printEnv(Env &env);
void printCalls(Module &M);
};