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 "Analysis/CallGraph/CBCallGraph.h"
19 #include "IR/SEG/SEGMapBase.h"
20 #include "IR/SEG/SymbolicExprGraph.h"
21 #include "Language/Spec/Memory.h"
22 
23 using namespace llvm;
24 
25 class SEGOperandNode;
26 class SEGLoadMemNode;
27 class SEGStoreMemNode;
28 class CFGReachabilityAnalysis;
29 class ControlDependenceAnalysis;
30 class DebugInfoAnalysis;
31 class FalconAA;
32 class FunctionPropertyPass;
33 class TypeInference;
34 class CBCallGraphWrapper;
35 
36 namespace FalconPlus {
37 class FalconAA;
38 }
39 
40 class SymbolicExprGraphBuilder : public ModulePass, public SEGMapBase {
41 public:
42  static char ID;
45 
46  void getAnalysisUsage(AnalysisUsage &) const;
47 
48  bool runOnModule(Module &);
49 
52  SymbolicExprGraph *getOrCreateSymbolicExprGraph(Function *F);
53 
55  SEGOperandNode *getNode(Value *val);
56 
57 private:
60  CFGReachabilityAnalysis *CRA = nullptr;
61  ControlDependenceAnalysis *CDGs = nullptr;
62 
63  TSDataLayout *TSDL = nullptr;
64  DebugInfoAnalysis *DIA = nullptr;
65  FalconAA *Falcon = nullptr;
66  FalconPlus::FalconAA *FalconPlus = nullptr;
67  FunctionPropertyPass *FPP = nullptr;
68  TypeInference *INFER = nullptr;
69  CBCallGraphWrapper *CGWrapper = nullptr;
71 
72 private:
73  typedef std::unordered_map<Value *, kvec<SEGLoadMemNode *>>
74  ValueLoadMemNodesMapTy;
75  typedef std::unordered_map<Value *, kvec<SEGStoreMemNode *>>
76  ValueStoreMemNodesMapTy;
77 
81  void matchLoadStore(SymbolicExprGraph *, ValueLoadMemNodesMapTy *,
82  ValueStoreMemNodesMapTy *);
83 
84  void labelBackEdge(Module &M);
85 
87  SymbolicExprGraph *buildSymbolicExprGraph(Function &F);
88 
90  void modelIntrinsics(CallSite CS, SymbolicExprGraph *G);
91 
93  void modelInstruction(Instruction &I, BasicBlock *, SymbolicExprGraph *G);
94 
96  SEGOperandNode *modelConstantExpr(ConstantExpr *CE, SymbolicExprGraph *G);
97 
99  SEGOpcodeNode *modelGEPOperator(GEPOperator *GEP, BasicBlock *B,
100  SymbolicExprGraph *G);
101 
104  SEGOpcodeNode::CodeKind getOpcode(int LLVMInstOpcode, int Predicate = 0);
105 
107  SEGOperandNode *findOrCreateNode(SymbolicExprGraph *SEG, Value *V);
108 };
109 
110 #endif
SEGStoreMemNode
Definition: SEGStoreMemNode.h:23
SEGOperandNode
Definition: SymbolicExprGraph.h:456
SEGOpcodeNode::CodeKind
CodeKind
Definition: SymbolicExprGraph.h:522
SEGMapBase
Definition: SEGMapBase.h:20
SymbolicExprGraph
Definition: SymbolicExprGraph.h:708
SymbolicExprGraphBuilder
Definition: SymbolicExprGraphBuilder.h:40
SEGOpcodeNode
Definition: SymbolicExprGraph.h:519
SEGLoadMemNode
Definition: SEGLoadMemNode.h:21