klee
Passes.h
Go to the documentation of this file.
1//===-- Passes.h ------------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_PASSES_H
11#define KLEE_PASSES_H
12
13#include "klee/Config/Version.h"
14
15#include "llvm/ADT/Triple.h"
16#include "llvm/CodeGen/IntrinsicLowering.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/Instructions.h"
19#include "llvm/IR/Module.h"
20#include "llvm/Pass.h"
21
22namespace llvm {
23class Function;
24class Instruction;
25class Module;
26class DataLayout;
27class TargetLowering;
28class Type;
29} // namespace llvm
30
31namespace klee {
32
35class RaiseAsmPass : public llvm::ModulePass {
36 static char ID;
37
38 const llvm::TargetLowering *TLI;
39
40 llvm::Triple triple;
41
42 llvm::Function *getIntrinsic(llvm::Module &M, unsigned IID, llvm::Type **Tys,
43 unsigned NumTys);
44 llvm::Function *getIntrinsic(llvm::Module &M, unsigned IID, llvm::Type *Ty0) {
45 return getIntrinsic(M, IID, &Ty0, 1);
46 }
47
48 bool runOnInstruction(llvm::Module &M, llvm::Instruction *I);
49
50public:
51 RaiseAsmPass() : llvm::ModulePass(ID), TLI(0) {}
52
53 bool runOnModule(llvm::Module &M) override;
54};
55
56// This is a module pass because it can add and delete module
57// variables (via intrinsic lowering).
58class IntrinsicCleanerPass : public llvm::ModulePass {
59 static char ID;
60 const llvm::DataLayout &DataLayout;
61 llvm::IntrinsicLowering *IL;
62
63 bool runOnBasicBlock(llvm::BasicBlock &b, llvm::Module &M);
64
65public:
66 IntrinsicCleanerPass(const llvm::DataLayout &TD)
67 : llvm::ModulePass(ID), DataLayout(TD),
68 IL(new llvm::IntrinsicLowering(TD)) {}
70
71 bool runOnModule(llvm::Module &M) override;
72};
73
74// performs two transformations which make interpretation
75// easier and faster.
76//
77// 1) Ensure that all the PHI nodes in a basic block have
78// the incoming block list in the same order. Thus the
79// incoming block index only needs to be computed once
80// for each transfer.
81//
82// 2) Ensure that no PHI node result is used as an argument to
83// a subsequent PHI node in the same basic block. This allows
84// the transfer to execute the instructions in order instead
85// of in two passes.
86class PhiCleanerPass : public llvm::FunctionPass {
87 static char ID;
88
89public:
90 PhiCleanerPass() : llvm::FunctionPass(ID) {}
91
92 bool runOnFunction(llvm::Function &f) override;
93};
94
95class DivCheckPass : public llvm::ModulePass {
96 static char ID;
97
98public:
99 DivCheckPass() : ModulePass(ID) {}
100 bool runOnModule(llvm::Module &M) override;
101};
102
117class OvershiftCheckPass : public llvm::ModulePass {
118 static char ID;
119
120public:
121 OvershiftCheckPass() : ModulePass(ID) {}
122 bool runOnModule(llvm::Module &M) override;
123};
124
128class LowerSwitchPass : public llvm::FunctionPass {
129public:
130 static char ID; // Pass identification, replacement for typeid
131 LowerSwitchPass() : FunctionPass(ID) {}
132
133 bool runOnFunction(llvm::Function &F) override;
134
135 struct SwitchCase {
136 llvm ::Constant *value;
137 llvm::BasicBlock *block;
138
139 SwitchCase() : value(0), block(0) {}
140 SwitchCase(llvm::Constant *v, llvm::BasicBlock *b) : value(v), block(b) {}
141 };
142
143 typedef std::vector<SwitchCase> CaseVector;
144 typedef std::vector<SwitchCase>::iterator CaseItr;
145
146private:
147 void processSwitchInst(llvm::SwitchInst *SI);
148 void switchConvert(CaseItr begin, CaseItr end, llvm::Value *value,
149 llvm::BasicBlock *origBlock,
150 llvm::BasicBlock *defaultBlock);
151};
152
158class InstructionOperandTypeCheckPass : public llvm::ModulePass {
159private:
161
162public:
163 static char ID;
165 : llvm::ModulePass(ID), instructionOperandsConform(true) {}
166 bool runOnModule(llvm::Module &M) override;
168};
169
173class FunctionAliasPass : public llvm::ModulePass {
174
175public:
176 static char ID;
177 FunctionAliasPass() : llvm::ModulePass(ID) {}
178 bool runOnModule(llvm::Module &M) override;
179
180private:
181 static const llvm::FunctionType *getFunctionType(const llvm::GlobalValue *gv);
182 static bool checkType(const llvm::GlobalValue *match, const llvm::GlobalValue *replacement);
183 static bool tryToReplace(llvm::GlobalValue *match, llvm::GlobalValue *replacement);
184 static bool isFunctionOrGlobalFunctionAlias(const llvm::GlobalValue *gv);
185
186};
187
188#ifdef USE_WORKAROUND_LLVM_PR39177
192class WorkaroundLLVMPR39177Pass : public llvm::ModulePass {
193public:
194 static char ID;
195 WorkaroundLLVMPR39177Pass() : llvm::ModulePass(ID) {}
196 bool runOnModule(llvm::Module &M) override;
197};
198#endif
199
201class OptNonePass : public llvm::ModulePass {
202public:
203 static char ID;
204 OptNonePass() : llvm::ModulePass(ID) {}
205 bool runOnModule(llvm::Module &M) override;
206};
207} // namespace klee
208
209#endif /* KLEE_PASSES_H */
static char ID
Definition: Passes.h:96
bool runOnModule(llvm::Module &M) override
Definition: Checks.cpp:37
static const llvm::FunctionType * getFunctionType(const llvm::GlobalValue *gv)
static bool checkType(const llvm::GlobalValue *match, const llvm::GlobalValue *replacement)
bool runOnModule(llvm::Module &M) override
static char ID
Definition: Passes.h:176
static bool isFunctionOrGlobalFunctionAlias(const llvm::GlobalValue *gv)
static bool tryToReplace(llvm::GlobalValue *match, llvm::GlobalValue *replacement)
bool runOnModule(llvm::Module &M) override
const llvm::DataLayout & DataLayout
Definition: Passes.h:60
bool runOnBasicBlock(llvm::BasicBlock &b, llvm::Module &M)
IntrinsicCleanerPass(const llvm::DataLayout &TD)
Definition: Passes.h:66
llvm::IntrinsicLowering * IL
Definition: Passes.h:61
void processSwitchInst(llvm::SwitchInst *SI)
Definition: LowerSwitch.cpp:96
std::vector< SwitchCase > CaseVector
Definition: Passes.h:143
bool runOnFunction(llvm::Function &F) override
Definition: LowerSwitch.cpp:40
static char ID
Definition: Passes.h:130
void switchConvert(CaseItr begin, CaseItr end, llvm::Value *value, llvm::BasicBlock *origBlock, llvm::BasicBlock *defaultBlock)
Definition: LowerSwitch.cpp:58
std::vector< SwitchCase >::iterator CaseItr
Definition: Passes.h:144
Instruments every function that contains a KLEE function call as nonopt.
Definition: Passes.h:201
bool runOnModule(llvm::Module &M) override
Definition: OptNone.cpp:23
static char ID
Definition: Passes.h:203
bool runOnModule(llvm::Module &M) override
Definition: Checks.cpp:93
static char ID
Definition: Passes.h:87
bool runOnFunction(llvm::Function &f) override
Definition: PhiCleaner.cpp:18
llvm::Triple triple
Definition: Passes.h:40
bool runOnModule(llvm::Module &M) override
Definition: RaiseAsm.cpp:76
bool runOnInstruction(llvm::Module &M, llvm::Instruction *I)
Definition: RaiseAsm.cpp:39
const llvm::TargetLowering * TLI
Definition: Passes.h:38
llvm::Function * getIntrinsic(llvm::Module &M, unsigned IID, llvm::Type *Ty0)
Definition: Passes.h:44
llvm::Function * getIntrinsic(llvm::Module &M, unsigned IID, llvm::Type **Tys, unsigned NumTys)
static char ID
Definition: Passes.h:36
Definition: main.cpp:291
llvm::BasicBlock * block
Definition: Passes.h:137
SwitchCase(llvm::Constant *v, llvm::BasicBlock *b)
Definition: Passes.h:140