ClearBlue
SymbolicExprGraphBuilder.h
1 /*
2  * SEG construction wrapper.
3  *
4  * Author: Fan Gang, qingkai
5  */
6 
7 #ifndef IR_SEG_SYMBOLICEXPRGRAPHBUILDER_H
8 #define IR_SEG_SYMBOLICEXPRGRAPHBUILDER_H
9 
10 #include <llvm/IR/Function.h>
11 #include <llvm/IR/Operator.h>
12 #include <llvm/Pass.h>
13 #include <mutex>
14 #include <string>
15 #include <unordered_map>
16 
17 #include "Analysis/Bitcode/TSDataLayout.h"
18 #include "IR/SEG/SEGMapBase.h"
19 #include "IR/SEG/SymbolicExprGraph.h"
20 #include "Language/Spec/Memory.h"
21 
22 using namespace llvm;
23 
24 class SEGOperandNode;
25 class SEGLoadMemNode;
26 class SEGStoreMemNode;
27 class CFGReachabilityAnalysis;
28 class ControlDependenceAnalysis;
29 class DebugInfoAnalysis;
30 class FalconAA;
31 class FunctionPropertyPass;
32 class TypeInference;
33 class AADriver;
34 
35 class SymbolicExprGraphBuilder : public ModulePass, public SEGMapBase {
36 public:
37  static char ID;
40 
41  void getAnalysisUsage(AnalysisUsage &) const;
42 
43  bool runOnModule(Module &);
44 
47  SymbolicExprGraph *getOrCreateSymbolicExprGraph(Function *F);
48 
50  SEGOperandNode *getNode(Value *val);
51 
53  std::vector<std::pair<Value *, SEGRegionNode *>>
54  loadPtrAt(Value *Ptr, pp_offset_t Off, Instruction *Loc);
55 
56  std::unordered_set<pp_offset_t> getAllocStoredZeroOff(Value *Alloc,
57  Instruction *Loc) const;
58 
59  std::set<Value *> getEscapeAllocSites(Function *Func) const;
60 
61  Value *getEscapeToAlloc(Function *Func, Function *Callee, Value *CalleeObj,
62  Instruction *CS) const;
63 
64 private:
67  CFGReachabilityAnalysis *CRA = nullptr;
68  ControlDependenceAnalysis *CDGs = nullptr;
69 
70  TSDataLayout *TSDL = nullptr;
71  DebugInfoAnalysis *DIA = nullptr;
72  FalconAA *Falcon = nullptr;
73  AADriver *AA = nullptr;
74  FunctionPropertyPass *FPP = nullptr;
75  TypeInference *INFER = nullptr;
77 
78 private:
79  typedef std::unordered_map<Value *, kvec<SEGLoadMemNode *>>
80  ValueLoadMemNodesMapTy;
81  typedef std::unordered_map<Value *, kvec<SEGStoreMemNode *>>
82  ValueStoreMemNodesMapTy;
83 
87  void matchLoadStore(SymbolicExprGraph *, ValueLoadMemNodesMapTy *,
88  ValueStoreMemNodesMapTy *);
89 
90  void labelBackEdge(Module &M);
91 
93  SymbolicExprGraph *buildSymbolicExprGraph(Function &F);
94 
96  void modelIntrinsics(CallSite CS, SymbolicExprGraph *G);
97 
99  void modelInstruction(Instruction &I, BasicBlock *, SymbolicExprGraph *G);
100 
102  SEGOperandNode *modelConstantExpr(ConstantExpr *CE, SymbolicExprGraph *G);
103 
105  SEGOpcodeNode *modelGEPOperator(GEPOperator *GEP, BasicBlock *B,
106  SymbolicExprGraph *G);
107 
110  SEGOpcodeNode::CodeKind getOpcode(int LLVMInstOpcode, int Predicate = 0);
111 
113  SEGOperandNode *findOrCreateNode(SymbolicExprGraph *SEG, Value *V);
114 };
115 
116 #endif
SEGStoreMemNode
Definition: SEGStoreMemNode.h:23
SEGOperandNode
Definition: SymbolicExprGraph.h:456
SEGOpcodeNode::CodeKind
CodeKind
Definition: SymbolicExprGraph.h:522
SEGMapBase
Definition: SEGMapBase.h:22
SymbolicExprGraph
Definition: SymbolicExprGraph.h:710
SymbolicExprGraphBuilder
Definition: SymbolicExprGraphBuilder.h:35
SEGOpcodeNode
Definition: SymbolicExprGraph.h:519
SEGLoadMemNode
Definition: SEGLoadMemNode.h:21