Passes.h

Go to the documentation of this file.
00001 //===-- Passes.h ------------------------------------------------*- C++ -*-===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef KLEE_PASSES_H
00011 #define KLEE_PASSES_H
00012 
00013 #include "llvm/Constants.h"
00014 #include "llvm/Instructions.h"
00015 #include "llvm/Module.h"
00016 #include "llvm/Pass.h"
00017 #include "llvm/CodeGen/IntrinsicLowering.h"
00018 
00019 namespace llvm {
00020   class Function;
00021   class Instruction;
00022   class Module;
00023   class TargetData;
00024   class Type;
00025 }
00026 
00027 namespace klee {
00028 
00031 class RaiseAsmPass : public llvm::ModulePass {
00032   static char ID;
00033 
00034   llvm::Function *getIntrinsic(llvm::Module &M,
00035                                unsigned IID,
00036                                const llvm::Type **Tys,
00037                                unsigned NumTys);
00038   llvm::Function *getIntrinsic(llvm::Module &M,
00039                                unsigned IID, 
00040                                const llvm::Type *Ty0) {
00041     return getIntrinsic(M, IID, &Ty0, 1);
00042   }
00043 
00044   bool runOnInstruction(llvm::Module &M, llvm::Instruction *I);
00045 
00046 public:
00047   RaiseAsmPass() : llvm::ModulePass((intptr_t) &ID) {}
00048   
00049   virtual bool runOnModule(llvm::Module &M);
00050 };
00051 
00052   // This is a module pass because it can add and delete module
00053   // variables (via intrinsic lowering).
00054 class IntrinsicCleanerPass : public llvm::ModulePass {
00055   static char ID;
00056   llvm::IntrinsicLowering *IL;
00057   bool LowerIntrinsics;
00058 
00059   bool runOnBasicBlock(llvm::BasicBlock &b);
00060 public:
00061   IntrinsicCleanerPass(const llvm::TargetData &TD,
00062                        bool LI=true)
00063     : llvm::ModulePass((intptr_t) &ID),
00064       IL(new llvm::IntrinsicLowering(TD)),
00065       LowerIntrinsics(LI) {}
00066   ~IntrinsicCleanerPass() { delete IL; } 
00067   
00068   virtual bool runOnModule(llvm::Module &M);
00069 };
00070   
00071   // performs two transformations which make interpretation
00072   // easier and faster.
00073   //
00074   // 1) Ensure that all the PHI nodes in a basic block have
00075   //    the incoming block list in the same order. Thus the
00076   //    incoming block index only needs to be computed once
00077   //    for each transfer.
00078   // 
00079   // 2) Ensure that no PHI node result is used as an argument to
00080   //    a subsequent PHI node in the same basic block. This allows
00081   //    the transfer to execute the instructions in order instead
00082   //    of in two passes.
00083 class PhiCleanerPass : public llvm::FunctionPass {
00084   static char ID;
00085 
00086 public:
00087   PhiCleanerPass() : llvm::FunctionPass((intptr_t) &ID) {}
00088   
00089   virtual bool runOnFunction(llvm::Function &f);
00090 };
00091   
00092 class DivCheckPass : public llvm::ModulePass {
00093   static char ID;
00094 public:
00095   DivCheckPass(): ModulePass((intptr_t) &ID) {}
00096   virtual bool runOnModule(llvm::Module &M);
00097 };
00098 
00102 class LowerSwitchPass : public llvm::FunctionPass {
00103 public:
00104   static char ID; // Pass identification, replacement for typeid
00105   LowerSwitchPass() : FunctionPass((intptr_t) &ID) {} 
00106   
00107   virtual bool runOnFunction(llvm::Function &F);
00108   
00109   struct SwitchCase {
00110     llvm ::Constant *value;
00111     llvm::BasicBlock *block;
00112     
00113     SwitchCase() : value(0), block(0) { }
00114     SwitchCase(llvm::Constant *v, llvm::BasicBlock *b) :
00115       value(v), block(b) { }
00116   };
00117   
00118   typedef std::vector<SwitchCase>           CaseVector;
00119   typedef std::vector<SwitchCase>::iterator CaseItr;
00120   
00121 private:
00122   void processSwitchInst(llvm::SwitchInst *SI);
00123   void switchConvert(CaseItr begin,
00124                      CaseItr end,
00125                      llvm::Value *value,
00126                      llvm::BasicBlock *origBlock,
00127                      llvm::BasicBlock *defaultBlock);
00128 };
00129 
00130 }
00131 
00132 #endif

Generated on Fri Jun 5 03:31:32 2009 for klee by  doxygen 1.5.8