InstVisitor.h revision a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===- llvm/Support/InstVisitor.h - Define instruction visitors -*- C++ -*-===//
263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
763b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus
10b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
11b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#ifndef LLVM_SUPPORT_INSTVISITOR_H
12b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#define LLVM_SUPPORT_INSTVISITOR_H
13b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
14d423fb5cbfdf9268899039ee49a0b3e09f661ca9Chris Lattner#include "llvm/Function.h"
15fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner#include "llvm/Instructions.h"
16ad5c296792e8db7afed68023909ea42f9ddcb454Alkis Evlogimenos#include "llvm/Module.h"
17c25e7581b9b8088910da31702d4ca21c4734c6d7Torok Edwin#include "llvm/Support/ErrorHandling.h"
18be583b914d8156b99d3da264d5adca37fee8dbc9John Criswell
19d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
20d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
21b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner// We operate on opaque instruction classes, so forward declare all instruction
22b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner// types now...
23b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner//
24b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#define HANDLE_INST(NUM, OPCODE, CLASS)   class CLASS;
25b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#include "llvm/Instruction.def"
26b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
270e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner#define DELEGATE(CLASS_TO_VISIT) \
28fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner  return static_cast<SubClass*>(this)-> \
29fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner               visit##CLASS_TO_VISIT(static_cast<CLASS_TO_VISIT&>(I))
300e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner
310e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner
32ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// @brief Base class for instruction visitors
33ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
34bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// Instruction visitors are used when you want to perform different actions
35bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// for different kinds of instructions without having to use lots of casts
36bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// and a big switch statement (in your code, that is).
37ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
38ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// To define your own visitor, inherit from this class, specifying your
39ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// new type for the 'SubClass' template parameter, and "override" visitXXX
40bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// functions in your class. I say "override" because this class is defined
41fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman/// in terms of statically resolved overloading, not virtual functions.
42fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman///
43fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman/// For example, here is a visitor that counts the number of malloc
44ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// instructions processed:
45ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
46ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///  /// Declare the class.  Note that we derive from InstVisitor instantiated
47ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///  /// with _our new subclasses_ type.
48ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///  ///
49a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///  struct CountAllocaVisitor : public InstVisitor<CountAllocaVisitor> {
50ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///    unsigned Count;
51a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///    CountAllocaVisitor() : Count(0) {}
52ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
53a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///    void visitAllocaInst(AllocaInst &AI) { ++Count; }
54ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///  };
55ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
56ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///  And this class would be used like this:
57a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///    CountAllocaVisitor CAV;
58a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///    CAV.visit(function);
59a276c603b82a11b0bf0b59f0517a69e4b63adeabVictor Hernandez///    NumAllocas = CAV.Count;
60ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
61ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// The defined has 'visit' methods for Instruction, and also for BasicBlock,
62bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// Function, and Module, which recursively process all contained instructions.
63ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
64ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// Note that if you don't implement visitXXX for some instruction type,
65ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// the visitXXX method for instruction superclass will be invoked. So
66ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// if instructions are added in the future, they will be automatically
67bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson/// supported, if you handle one of their superclasses.
68ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
69fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman/// The optional second template argument specifies the type that instruction
70fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman/// visitation functions should return. If you specify this, you *MUST* provide
71ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// an implementation of visitInstruction though!.
72ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus///
73ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// Note that this class is specifically designed as a template to avoid
74ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// virtual function call overhead.  Defining and using an InstVisitor is just
75ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// as efficient as having your own switch statement over the instruction
76ef27d899fd6518b7e8da1eec9f76d7beb631b3d8Vladimir Prus/// opcode.
77536fe85d6d7915915e7b8c4e6eefc2bce701505dChris Lattnertemplate<typename SubClass, typename RetTy=void>
78e26057a376f04e20da6c7217d19eaa184767cb1dReid Spencerclass InstVisitor {
79b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //===--------------------------------------------------------------------===//
80b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // Interface code - This is the public interface of the InstVisitor that you
81b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // use to visit instructions...
82b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
83b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
84e26057a376f04e20da6c7217d19eaa184767cb1dReid Spencerpublic:
85b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // Generic visit method - Allow visitation to all instructions in a range
86b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  template<class Iterator>
87b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  void visit(Iterator Start, Iterator End) {
88b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner    while (Start != End)
89fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner      static_cast<SubClass*>(this)->visit(*Start++);
90b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  }
91b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
92004caf4ded406c5699eb575337b0ed865483126eChris Lattner  // Define visitors for functions and basic blocks...
93b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
942dd5c96866406711cf20a6bb677a7d147ad3ac3dMisha Brukman  void visit(Module &M) {
95fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner    static_cast<SubClass*>(this)->visitModule(M);
962dd5c96866406711cf20a6bb677a7d147ad3ac3dMisha Brukman    visit(M.begin(), M.end());
972dd5c96866406711cf20a6bb677a7d147ad3ac3dMisha Brukman  }
987e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visit(Function &F) {
99fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner    static_cast<SubClass*>(this)->visitFunction(F);
1007e70829632f82de15db187845666aaca6e04b792Chris Lattner    visit(F.begin(), F.end());
1017296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner  }
1027e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visit(BasicBlock &BB) {
103fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner    static_cast<SubClass*>(this)->visitBasicBlock(BB);
1047e70829632f82de15db187845666aaca6e04b792Chris Lattner    visit(BB.begin(), BB.end());
1057296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner  }
106b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
1077e70829632f82de15db187845666aaca6e04b792Chris Lattner  // Forwarding functions so that the user can visit with pointers AND refs.
1087e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visit(Module       *M)  { visit(*M); }
1097e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visit(Function     *F)  { visit(*F); }
1107e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visit(BasicBlock   *BB) { visit(*BB); }
1117e70829632f82de15db187845666aaca6e04b792Chris Lattner  RetTy visit(Instruction *I)  { return visit(*I); }
1127e70829632f82de15db187845666aaca6e04b792Chris Lattner
113b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // visit - Finally, code to visit an instruction...
114b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
1157e70829632f82de15db187845666aaca6e04b792Chris Lattner  RetTy visit(Instruction &I) {
1167e70829632f82de15db187845666aaca6e04b792Chris Lattner    switch (I.getOpcode()) {
117c23197a26f34f559ea9797de51e187087c039c42Torok Edwin    default: llvm_unreachable("Unknown instruction type encountered!");
118b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner      // Build the switch statement using the Instruction.def file...
119b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#define HANDLE_INST(NUM, OPCODE, CLASS) \
120fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner    case Instruction::OPCODE: return \
121fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner           static_cast<SubClass*>(this)-> \
122fc4addafb51fe085bc6c9b0677e685f19ec75bfcChris Lattner                      visit##OPCODE(static_cast<CLASS&>(I));
123b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#include "llvm/Instruction.def"
124b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner    }
125b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  }
126b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
127b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //===--------------------------------------------------------------------===//
128b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // Visitation functions... these functions provide default fallbacks in case
129b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // the user does not specify what to do for a particular instruction type.
130b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // The default behavior is to generalize the instruction type to its subtype
131b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // and try visiting the subtype.  All of this should be inlined perfectly,
132b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // because there are no virtual functions to get in the way.
133b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
1347296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner
1357296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner  // When visiting a module, function or basic block directly, these methods get
1367296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner  // called to indicate when transitioning into a new unit.
1377296e93f08f7495dbe3f25e35bff0b616b438e19Chris Lattner  //
1382dd5c96866406711cf20a6bb677a7d147ad3ac3dMisha Brukman  void visitModule    (Module &M) {}
1397e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visitFunction  (Function &F) {}
1407e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visitBasicBlock(BasicBlock &BB) {}
1410e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner
1420e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // Define instruction specific visitor functions that can be overridden to
1430e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // handle SPECIFIC instructions.  These functions automatically define
1440e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // visitMul to proxy to visitBinaryOperator for instance in case the user does
1450e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // not need this generality.
1460e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  //
1470e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // The one problem case we have to handle here though is that the PHINode
1480e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // class and opcode name are the exact same.  Because of this, we cannot
1490e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // define visitPHINode (the inst version) to forward to visitPHINode (the
1500e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // generic version) without multiply defined symbols and recursion.  To handle
1510e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  // this, we do not autoexpand "Other" instructions, we do it manually.
1520e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner  //
1530e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner#define HANDLE_INST(NUM, OPCODE, CLASS) \
1547e70829632f82de15db187845666aaca6e04b792Chris Lattner    RetTy visit##OPCODE(CLASS &I) { DELEGATE(CLASS); }
1550e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner#include "llvm/Instruction.def"
1560e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner
157b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // Specific Instruction type classes... note that all of the casts are
1585560c9d49ccae132cabf1155f18aa0480dce3edaMisha Brukman  // necessary because we use the instruction classes as opaque types...
159b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
160a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitReturnInst(ReturnInst &I)            { DELEGATE(TerminatorInst);}
161a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitBranchInst(BranchInst &I)            { DELEGATE(TerminatorInst);}
162a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitSwitchInst(SwitchInst &I)            { DELEGATE(TerminatorInst);}
163a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitIndirectBrInst(IndirectBrInst &I)    { DELEGATE(TerminatorInst);}
164a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitInvokeInst(InvokeInst &I)            { DELEGATE(TerminatorInst);}
165a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitResumeInst(ResumeInst &I)            { DELEGATE(TerminatorInst);}
166a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitUnreachableInst(UnreachableInst &I)  { DELEGATE(TerminatorInst);}
167a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitICmpInst(ICmpInst &I)                { DELEGATE(CmpInst);}
168a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFCmpInst(FCmpInst &I)                { DELEGATE(CmpInst);}
169a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitAllocaInst(AllocaInst &I)            { DELEGATE(UnaryInstruction);}
170a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitLoadInst(LoadInst     &I)            { DELEGATE(UnaryInstruction);}
171a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitStoreInst(StoreInst   &I)            { DELEGATE(Instruction);}
172a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitAtomicCmpXchgInst(AtomicCmpXchgInst &I) { DELEGATE(Instruction);}
173a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitAtomicRMWInst(AtomicRMWInst &I)      { DELEGATE(Instruction);}
174a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFenceInst(FenceInst   &I)            { DELEGATE(Instruction);}
175a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction);}
176a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitPHINode(PHINode       &I)            { DELEGATE(Instruction);}
177a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitTruncInst(TruncInst &I)              { DELEGATE(CastInst);}
178a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitZExtInst(ZExtInst &I)                { DELEGATE(CastInst);}
179a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitSExtInst(SExtInst &I)                { DELEGATE(CastInst);}
180a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFPTruncInst(FPTruncInst &I)          { DELEGATE(CastInst);}
181a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFPExtInst(FPExtInst &I)              { DELEGATE(CastInst);}
182a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFPToUIInst(FPToUIInst &I)            { DELEGATE(CastInst);}
183a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitFPToSIInst(FPToSIInst &I)            { DELEGATE(CastInst);}
184a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitUIToFPInst(UIToFPInst &I)            { DELEGATE(CastInst);}
185a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitSIToFPInst(SIToFPInst &I)            { DELEGATE(CastInst);}
186a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitPtrToIntInst(PtrToIntInst &I)        { DELEGATE(CastInst);}
187a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitIntToPtrInst(IntToPtrInst &I)        { DELEGATE(CastInst);}
188a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitBitCastInst(BitCastInst &I)          { DELEGATE(CastInst);}
189a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitSelectInst(SelectInst &I)            { DELEGATE(Instruction);}
190a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitCallInst(CallInst     &I)            { DELEGATE(Instruction);}
191a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitVAArgInst(VAArgInst   &I)            { DELEGATE(UnaryInstruction);}
1923da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
193a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
194a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction);}
195a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
196a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitInsertValueInst(InsertValueInst &I)  { DELEGATE(Instruction); }
197a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitLandingPadInst(LandingPadInst &I)    { DELEGATE(Instruction); }
198b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
199bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson  // Next level propagators: If the user does not overload a specific
200b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // instruction type, they can overload one of these to get the whole class
201b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // of instructions...
202b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
203a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitCastInst(CastInst &I)                { DELEGATE(UnaryInstruction);}
204a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitBinaryOperator(BinaryOperator &I)    { DELEGATE(Instruction);}
205a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitCmpInst(CmpInst &I)                  { DELEGATE(Instruction);}
206a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitTerminatorInst(TerminatorInst &I)    { DELEGATE(Instruction);}
207a87a75fd806cd9bd74b44f9ec1ab4b0435bb2791Chandler Carruth  RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
208b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
209b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // If the user wants a 'default' case, they can choose to override this
210bb2ead6e5f1f901b25cf79b7a8752dce3cfd5c23Bob Wilson  // function.  If this function is not overloaded in the user's subclass, then
211b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  // this instruction just gets ignored.
212b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner  //
213536fe85d6d7915915e7b8c4e6eefc2bce701505dChris Lattner  // Note that you MUST override this function if your return type is not void.
214536fe85d6d7915915e7b8c4e6eefc2bce701505dChris Lattner  //
2157e70829632f82de15db187845666aaca6e04b792Chris Lattner  void visitInstruction(Instruction &I) {}  // Ignore unhandled instructions
216b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner};
217b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner
2180e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner#undef DELEGATE
2190e743b83976dd9b31c8fc7ad19f61c30b743dedfChris Lattner
220d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
221d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
222b4c5f83eacbdb7643f9efada8fd281ef77a662c3Chris Lattner#endif
223