Add support for shifts
[oota-llvm.git] / include / llvm / Support / InstVisitor.h
index f8298e313d83d94e891bf555ec560af61a1d0d8f..a9b3b7150656c159648d1851d473c8b0ecd16ff1 100644 (file)
@@ -1,4 +1,11 @@
 //===- llvm/Support/InstVisitor.h - Define instruction visitors -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This template class is used to define instruction visitors in a typesafe
 // manner without having to use lots of casts and a big switch statement (in
 #ifndef LLVM_SUPPORT_INSTVISITOR_H
 #define LLVM_SUPPORT_INSTVISITOR_H
 
-#include "llvm/Instruction.h"
+#include "llvm/Function.h"
+#include "llvm/Module.h"
 
-class Module;
+namespace llvm {
 
 // We operate on opaque instruction classes, so forward declare all instruction
 // types now...
@@ -57,15 +65,12 @@ class Module;
 class TerminatorInst; class BinaryOperator;
 class AllocationInst;
 
-
 #define DELEGATE(CLASS_TO_VISIT) \
   return ((SubClass*)this)->visit##CLASS_TO_VISIT((CLASS_TO_VISIT&)I)
 
 
 template<typename SubClass, typename RetTy=void>
 struct InstVisitor {
-  virtual ~InstVisitor() {}           // We are meant to be derived from
-
   //===--------------------------------------------------------------------===//
   // Interface code - This is the public interface of the InstVisitor that you
   // use to visit instructions...
@@ -80,6 +85,10 @@ struct InstVisitor {
 
   // Define visitors for functions and basic blocks...
   //
+  void visit(Module &M) {
+    ((SubClass*)this)->visitModule(M);
+    visit(M.begin(), M.end());
+  }
   void visit(Function &F) {
     ((SubClass*)this)->visitFunction(F);
     visit(F.begin(), F.end());
@@ -119,6 +128,7 @@ struct InstVisitor {
   // When visiting a module, function or basic block directly, these methods get
   // called to indicate when transitioning into a new unit.
   //
+  void visitModule    (Module &M) {}
   void visitFunction  (Function &F) {}
   void visitBasicBlock(BasicBlock &BB) {}
 
@@ -136,20 +146,8 @@ struct InstVisitor {
   //
 #define HANDLE_INST(NUM, OPCODE, CLASS) \
     RetTy visit##OPCODE(CLASS &I) { DELEGATE(CLASS); }
-#define HANDLE_OTHER_INST(NUM, OPCODE, CLASS)  // Handle "other" insts specially
 #include "llvm/Instruction.def"
 
-  // Implement all "other" instructions, except for PHINode
-  RetTy visitCast(CastInst &I)       { DELEGATE(CastInst);    }
-  RetTy visitCall(CallInst &I)       { DELEGATE(CallInst);    }
-  RetTy visitShr(ShiftInst &I)       { DELEGATE(ShiftInst);   }
-  RetTy visitShl(ShiftInst &I)       { DELEGATE(ShiftInst);   }
-  RetTy visitVANext(VANextInst &I)   { DELEGATE(VANextInst);  }
-  RetTy visitVAArg (VAArgInst &I)    { DELEGATE(VAArgInst);  }
-  RetTy visitUserOp1(Instruction &I) { DELEGATE(Instruction); }
-  RetTy visitUserOp2(Instruction &I) { DELEGATE(Instruction); }
-
-  
   // Specific Instruction type classes... note that all of the casts are
   // necessary because we use the instruction classes as opaque types...
   //
@@ -158,6 +156,7 @@ struct InstVisitor {
   RetTy visitSwitchInst(SwitchInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitInvokeInst(InvokeInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitUnwindInst(UnwindInst &I)              { DELEGATE(TerminatorInst);}
+  RetTy visitUnreachableInst(UnreachableInst &I)    { DELEGATE(TerminatorInst);}
   RetTy visitSetCondInst(SetCondInst &I)            { DELEGATE(BinaryOperator);}
   RetTy visitMallocInst(MallocInst &I)              { DELEGATE(AllocationInst);}
   RetTy visitAllocaInst(AllocaInst &I)              { DELEGATE(AllocationInst);}
@@ -167,6 +166,7 @@ struct InstVisitor {
   RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction); }
   RetTy visitPHINode(PHINode       &I)              { DELEGATE(Instruction); }
   RetTy visitCastInst(CastInst     &I)              { DELEGATE(Instruction); }
+  RetTy visitSelectInst(SelectInst &I)              { DELEGATE(Instruction); }
   RetTy visitCallInst(CallInst     &I)              { DELEGATE(Instruction); }
   RetTy visitShiftInst(ShiftInst   &I)              { DELEGATE(Instruction); }
   RetTy visitVANextInst(VANextInst &I)              { DELEGATE(Instruction); }
@@ -191,4 +191,6 @@ struct InstVisitor {
 
 #undef DELEGATE
 
+} // End llvm namespace
+
 #endif