Use size_t instead of long to represent memory usage. long is 32 bits
[oota-llvm.git] / include / llvm / Support / InstVisitor.h
index 883a6fe4afcb058c8c40cd2ed8be36072641d2ab..6eef0f9a1060a7cc00103eecb52457f851a1e271 100644 (file)
@@ -1,4 +1,11 @@
-//===- llvm/Support/InstVisitor.h - Define instruction visitors --*- C++ -*--=//
+//===- 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"
+
+namespace llvm {
 
 // We operate on opaque instruction classes, so forward declare all instruction
 // types now...
 #include "llvm/Instruction.def"
 
 // Forward declare the intermediate types...
-class TerminatorInst; class UnaryOperator; class BinaryOperator;
-class AllocationInst; class MemAccessInst;
-
+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
-
+class InstVisitor {
   //===--------------------------------------------------------------------===//
   // Interface code - This is the public interface of the InstVisitor that you
   // use to visit instructions...
   //
 
+public:
   // Generic visit method - Allow visitation to all instructions in a range
   template<class Iterator>
   void visit(Iterator Start, Iterator End) {
@@ -76,7 +84,7 @@ struct InstVisitor {
       ((SubClass*)this)->visit(*Start++);
   }
 
-  // Define visitors for modules, functions and basic blocks...
+  // Define visitors for functions and basic blocks...
   //
   void visit(Module &M) {
     ((SubClass*)this)->visitModule(M);
@@ -101,13 +109,12 @@ struct InstVisitor {
   //
   RetTy visit(Instruction &I) {
     switch (I.getOpcode()) {
+    default: assert(0 && "Unknown instruction type encountered!");
+             abort();
       // Build the switch statement using the Instruction.def file...
 #define HANDLE_INST(NUM, OPCODE, CLASS) \
     case Instruction::OPCODE:return ((SubClass*)this)->visit##OPCODE((CLASS&)I);
 #include "llvm/Instruction.def"
-
-    default: assert(0 && "Unknown instruction type encountered!");
-             abort();
     }
   }
 
@@ -140,48 +147,39 @@ struct InstVisitor {
   //
 #define HANDLE_INST(NUM, OPCODE, CLASS) \
     RetTy visit##OPCODE(CLASS &I) { DELEGATE(CLASS); }
-#define HANDLE_OTHER_INST(NUM, OPCODE, CLASS)   // Ignore "other" instructions
 #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 visitUserOp1(Instruction &I) { DELEGATE(Instruction); }
-  RetTy visitUserOp2(Instruction &I) { DELEGATE(Instruction); }
-
-  
   // Specific Instruction type classes... note that all of the casts are
-  // neccesary because we use the instruction classes as opaque types...
+  // necessary because we use the instruction classes as opaque types...
   //
   RetTy visitReturnInst(ReturnInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitBranchInst(BranchInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitSwitchInst(SwitchInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitInvokeInst(InvokeInst &I)              { DELEGATE(TerminatorInst);}
-  RetTy visitGenericUnaryInst(GenericUnaryInst &I)  { DELEGATE(UnaryOperator); }
-  RetTy visitGenericBinaryInst(GenericBinaryInst &I){ DELEGATE(BinaryOperator);}
+  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);}
-  RetTy visitFreeInst(FreeInst   &I)                { DELEGATE(Instruction); }
-  RetTy visitLoadInst(LoadInst   &I)                { DELEGATE(MemAccessInst); }
-  RetTy visitStoreInst(StoreInst  &I)               { DELEGATE(MemAccessInst); }
-  RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(MemAccessInst); }
-  RetTy visitPHINode(PHINode    &I)                 { DELEGATE(Instruction); }
-  RetTy visitCastInst(CastInst   &I)                { DELEGATE(Instruction); }
-  RetTy visitCallInst(CallInst   &I)                { DELEGATE(Instruction); }
-  RetTy visitShiftInst(ShiftInst  &I)               { DELEGATE(Instruction); }
-
-  // Next level propogators... if the user does not overload a specific
+  RetTy visitFreeInst(FreeInst     &I)              { DELEGATE(Instruction); }
+  RetTy visitLoadInst(LoadInst     &I)              { DELEGATE(Instruction); }
+  RetTy visitStoreInst(StoreInst   &I)              { DELEGATE(Instruction); }
+  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); }
+  RetTy visitVAArgInst(VAArgInst   &I)              { DELEGATE(Instruction); }
+
+  // Next level propagators... if the user does not overload a specific
   // instruction type, they can overload one of these to get the whole class
   // of instructions...
   //
   RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction); }
-  RetTy visitUnaryOperator (UnaryOperator  &I) { DELEGATE(Instruction); }
   RetTy visitBinaryOperator(BinaryOperator &I) { DELEGATE(Instruction); }
   RetTy visitAllocationInst(AllocationInst &I) { DELEGATE(Instruction); }
-  RetTy visitMemAccessInst (MemAccessInst  &I) { DELEGATE(Instruction); }
 
   // If the user wants a 'default' case, they can choose to override this
   // function.  If this function is not overloaded in the users subclass, then
@@ -194,4 +192,6 @@ struct InstVisitor {
 
 #undef DELEGATE
 
+} // End llvm namespace
+
 #endif