llvm.org GIT mirror llvm / 84bcf93
Move the InstVisitor utility into VMCore where it belongs. It heavily depends on the IR infrastructure, there is no sense in it being off in Support land. This is in preparation to start working to expand InstVisitor into more special-purpose visitors that are still generic and can be re-used across different passes. The expansion will go into the Analylis tree though as nothing in VMCore needs it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168972 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
13 changed file(s) with 300 addition(s) and 300 deletion(s). Raw diff Collapse all Expand all
1515 #define LLVM_ANALYSIS_MEMORYBUILTINS_H
1616
1717 #include "llvm/IRBuilder.h"
18 #include "llvm/InstVisitor.h"
1819 #include "llvm/Operator.h"
1920 #include "llvm/ADT/DenseMap.h"
2021 #include "llvm/ADT/SmallPtrSet.h"
2122 #include "llvm/Support/DataTypes.h"
22 #include "llvm/Support/InstVisitor.h"
2323 #include "llvm/Support/TargetFolder.h"
2424 #include "llvm/Support/ValueHandle.h"
2525
0 //===- llvm/InstVisitor.h - Instruction visitor templates -------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9
10 #ifndef LLVM_INSTVISITOR_H
11 #define LLVM_INSTVISITOR_H
12
13 #include "llvm/Function.h"
14 #include "llvm/Instructions.h"
15 #include "llvm/Intrinsics.h"
16 #include "llvm/IntrinsicInst.h"
17 #include "llvm/Module.h"
18 #include "llvm/Support/CallSite.h"
19 #include "llvm/Support/ErrorHandling.h"
20
21 namespace llvm {
22
23 // We operate on opaque instruction classes, so forward declare all instruction
24 // types now...
25 //
26 #define HANDLE_INST(NUM, OPCODE, CLASS) class CLASS;
27 #include "llvm/Instruction.def"
28
29 #define DELEGATE(CLASS_TO_VISIT) \
30 return static_cast(this)-> \
31 visit##CLASS_TO_VISIT(static_cast(I))
32
33
34 /// @brief Base class for instruction visitors
35 ///
36 /// Instruction visitors are used when you want to perform different actions
37 /// for different kinds of instructions without having to use lots of casts
38 /// and a big switch statement (in your code, that is).
39 ///
40 /// To define your own visitor, inherit from this class, specifying your
41 /// new type for the 'SubClass' template parameter, and "override" visitXXX
42 /// functions in your class. I say "override" because this class is defined
43 /// in terms of statically resolved overloading, not virtual functions.
44 ///
45 /// For example, here is a visitor that counts the number of malloc
46 /// instructions processed:
47 ///
48 /// /// Declare the class. Note that we derive from InstVisitor instantiated
49 /// /// with _our new subclasses_ type.
50 /// ///
51 /// struct CountAllocaVisitor : public InstVisitor {
52 /// unsigned Count;
53 /// CountAllocaVisitor() : Count(0) {}
54 ///
55 /// void visitAllocaInst(AllocaInst &AI) { ++Count; }
56 /// };
57 ///
58 /// And this class would be used like this:
59 /// CountAllocaVisitor CAV;
60 /// CAV.visit(function);
61 /// NumAllocas = CAV.Count;
62 ///
63 /// The defined has 'visit' methods for Instruction, and also for BasicBlock,
64 /// Function, and Module, which recursively process all contained instructions.
65 ///
66 /// Note that if you don't implement visitXXX for some instruction type,
67 /// the visitXXX method for instruction superclass will be invoked. So
68 /// if instructions are added in the future, they will be automatically
69 /// supported, if you handle one of their superclasses.
70 ///
71 /// The optional second template argument specifies the type that instruction
72 /// visitation functions should return. If you specify this, you *MUST* provide
73 /// an implementation of visitInstruction though!.
74 ///
75 /// Note that this class is specifically designed as a template to avoid
76 /// virtual function call overhead. Defining and using an InstVisitor is just
77 /// as efficient as having your own switch statement over the instruction
78 /// opcode.
79 template
80 class InstVisitor {
81 //===--------------------------------------------------------------------===//
82 // Interface code - This is the public interface of the InstVisitor that you
83 // use to visit instructions...
84 //
85
86 public:
87 // Generic visit method - Allow visitation to all instructions in a range
88 template
89 void visit(Iterator Start, Iterator End) {
90 while (Start != End)
91 static_cast(this)->visit(*Start++);
92 }
93
94 // Define visitors for functions and basic blocks...
95 //
96 void visit(Module &M) {
97 static_cast(this)->visitModule(M);
98 visit(M.begin(), M.end());
99 }
100 void visit(Function &F) {
101 static_cast(this)->visitFunction(F);
102 visit(F.begin(), F.end());
103 }
104 void visit(BasicBlock &BB) {
105 static_cast(this)->visitBasicBlock(BB);
106 visit(BB.begin(), BB.end());
107 }
108
109 // Forwarding functions so that the user can visit with pointers AND refs.
110 void visit(Module *M) { visit(*M); }
111 void visit(Function *F) { visit(*F); }
112 void visit(BasicBlock *BB) { visit(*BB); }
113 RetTy visit(Instruction *I) { return visit(*I); }
114
115 // visit - Finally, code to visit an instruction...
116 //
117 RetTy visit(Instruction &I) {
118 switch (I.getOpcode()) {
119 default: llvm_unreachable("Unknown instruction type encountered!");
120 // Build the switch statement using the Instruction.def file...
121 #define HANDLE_INST(NUM, OPCODE, CLASS) \
122 case Instruction::OPCODE: return \
123 static_cast(this)-> \
124 visit##OPCODE(static_cast(I));
125 #include "llvm/Instruction.def"
126 }
127 }
128
129 //===--------------------------------------------------------------------===//
130 // Visitation functions... these functions provide default fallbacks in case
131 // the user does not specify what to do for a particular instruction type.
132 // The default behavior is to generalize the instruction type to its subtype
133 // and try visiting the subtype. All of this should be inlined perfectly,
134 // because there are no virtual functions to get in the way.
135 //
136
137 // When visiting a module, function or basic block directly, these methods get
138 // called to indicate when transitioning into a new unit.
139 //
140 void visitModule (Module &M) {}
141 void visitFunction (Function &F) {}
142 void visitBasicBlock(BasicBlock &BB) {}
143
144 // Define instruction specific visitor functions that can be overridden to
145 // handle SPECIFIC instructions. These functions automatically define
146 // visitMul to proxy to visitBinaryOperator for instance in case the user does
147 // not need this generality.
148 //
149 // These functions can also implement fan-out, when a single opcode and
150 // instruction have multiple more specific Instruction subclasses. The Call
151 // instruction currently supports this. We implement that by redirecting that
152 // instruction to a special delegation helper.
153 #define HANDLE_INST(NUM, OPCODE, CLASS) \
154 RetTy visit##OPCODE(CLASS &I) { \
155 if (NUM == Instruction::Call) \
156 return delegateCallInst(I); \
157 else \
158 DELEGATE(CLASS); \
159 }
160 #include "llvm/Instruction.def"
161
162 // Specific Instruction type classes... note that all of the casts are
163 // necessary because we use the instruction classes as opaque types...
164 //
165 RetTy visitReturnInst(ReturnInst &I) { DELEGATE(TerminatorInst);}
166 RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
167 RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
168 RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
169 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
170 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
171 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
172 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
173 RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
174 RetTy visitLoadInst(LoadInst &I) { DELEGATE(UnaryInstruction);}
175 RetTy visitStoreInst(StoreInst &I) { DELEGATE(Instruction);}
176 RetTy visitAtomicCmpXchgInst(AtomicCmpXchgInst &I) { DELEGATE(Instruction);}
177 RetTy visitAtomicRMWInst(AtomicRMWInst &I) { DELEGATE(Instruction);}
178 RetTy visitFenceInst(FenceInst &I) { DELEGATE(Instruction);}
179 RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction);}
180 RetTy visitPHINode(PHINode &I) { DELEGATE(Instruction);}
181 RetTy visitTruncInst(TruncInst &I) { DELEGATE(CastInst);}
182 RetTy visitZExtInst(ZExtInst &I) { DELEGATE(CastInst);}
183 RetTy visitSExtInst(SExtInst &I) { DELEGATE(CastInst);}
184 RetTy visitFPTruncInst(FPTruncInst &I) { DELEGATE(CastInst);}
185 RetTy visitFPExtInst(FPExtInst &I) { DELEGATE(CastInst);}
186 RetTy visitFPToUIInst(FPToUIInst &I) { DELEGATE(CastInst);}
187 RetTy visitFPToSIInst(FPToSIInst &I) { DELEGATE(CastInst);}
188 RetTy visitUIToFPInst(UIToFPInst &I) { DELEGATE(CastInst);}
189 RetTy visitSIToFPInst(SIToFPInst &I) { DELEGATE(CastInst);}
190 RetTy visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);}
191 RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
192 RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
193 RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
194 RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
195 RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
196 RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
197 RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction);}
198 RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
199 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
200 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
201
202 // Handle the special instrinsic instruction classes.
203 RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
204 RetTy visitDbgValueInst(DbgValueInst &I) { DELEGATE(DbgInfoIntrinsic);}
205 RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I) { DELEGATE(IntrinsicInst); }
206 RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
207 RetTy visitMemCpyInst(MemCpyInst &I) { DELEGATE(MemTransferInst); }
208 RetTy visitMemMoveInst(MemMoveInst &I) { DELEGATE(MemTransferInst); }
209 RetTy visitMemTransferInst(MemTransferInst &I) { DELEGATE(MemIntrinsic); }
210 RetTy visitMemIntrinsic(MemIntrinsic &I) { DELEGATE(IntrinsicInst); }
211 RetTy visitVAStartInst(VAStartInst &I) { DELEGATE(IntrinsicInst); }
212 RetTy visitVAEndInst(VAEndInst &I) { DELEGATE(IntrinsicInst); }
213 RetTy visitVACopyInst(VACopyInst &I) { DELEGATE(IntrinsicInst); }
214 RetTy visitIntrinsicInst(IntrinsicInst &I) { DELEGATE(CallInst); }
215
216 // Call and Invoke are slightly different as they delegate first through
217 // a generic CallSite visitor.
218 RetTy visitCallInst(CallInst &I) {
219 return static_cast(this)->visitCallSite(&I);
220 }
221 RetTy visitInvokeInst(InvokeInst &I) {
222 return static_cast(this)->visitCallSite(&I);
223 }
224
225 // Next level propagators: If the user does not overload a specific
226 // instruction type, they can overload one of these to get the whole class
227 // of instructions...
228 //
229 RetTy visitCastInst(CastInst &I) { DELEGATE(UnaryInstruction);}
230 RetTy visitBinaryOperator(BinaryOperator &I) { DELEGATE(Instruction);}
231 RetTy visitCmpInst(CmpInst &I) { DELEGATE(Instruction);}
232 RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
233 RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
234
235 // Provide a special visitor for a 'callsite' that visits both calls and
236 // invokes. When unimplemented, properly delegates to either the terminator or
237 // regular instruction visitor.
238 RetTy visitCallSite(CallSite CS) {
239 assert(CS);
240 Instruction &I = *CS.getInstruction();
241 if (CS.isCall())
242 DELEGATE(Instruction);
243
244 assert(CS.isInvoke());
245 DELEGATE(TerminatorInst);
246 }
247
248 // If the user wants a 'default' case, they can choose to override this
249 // function. If this function is not overloaded in the user's subclass, then
250 // this instruction just gets ignored.
251 //
252 // Note that you MUST override this function if your return type is not void.
253 //
254 void visitInstruction(Instruction &I) {} // Ignore unhandled instructions
255
256 private:
257 // Special helper function to delegate to CallInst subclass visitors.
258 RetTy delegateCallInst(CallInst &I) {
259 if (const Function *F = I.getCalledFunction()) {
260 switch ((Intrinsic::ID)F->getIntrinsicID()) {
261 default: DELEGATE(IntrinsicInst);
262 case Intrinsic::dbg_declare: DELEGATE(DbgDeclareInst);
263 case Intrinsic::dbg_value: DELEGATE(DbgValueInst);
264 case Intrinsic::memcpy: DELEGATE(MemCpyInst);
265 case Intrinsic::memmove: DELEGATE(MemMoveInst);
266 case Intrinsic::memset: DELEGATE(MemSetInst);
267 case Intrinsic::vastart: DELEGATE(VAStartInst);
268 case Intrinsic::vaend: DELEGATE(VAEndInst);
269 case Intrinsic::vacopy: DELEGATE(VACopyInst);
270 case Intrinsic::not_intrinsic: break;
271 }
272 }
273 DELEGATE(CallInst);
274 }
275
276 // An overload that will never actually be called, it is used only from dead
277 // code in the dispatching from opcodes to instruction subclasses.
278 RetTy delegateCallInst(Instruction &I) {
279 llvm_unreachable("delegateCallInst called for non-CallInst");
280 }
281 };
282
283 #undef DELEGATE
284
285 } // End llvm namespace
286
287 #endif
+0
-288
include/llvm/Support/InstVisitor.h less more
None //===- llvm/Support/InstVisitor.h - Define instruction visitors -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9
10 #ifndef LLVM_SUPPORT_INSTVISITOR_H
11 #define LLVM_SUPPORT_INSTVISITOR_H
12
13 #include "llvm/Function.h"
14 #include "llvm/Instructions.h"
15 #include "llvm/Intrinsics.h"
16 #include "llvm/IntrinsicInst.h"
17 #include "llvm/Module.h"
18 #include "llvm/Support/CallSite.h"
19 #include "llvm/Support/ErrorHandling.h"
20
21 namespace llvm {
22
23 // We operate on opaque instruction classes, so forward declare all instruction
24 // types now...
25 //
26 #define HANDLE_INST(NUM, OPCODE, CLASS) class CLASS;
27 #include "llvm/Instruction.def"
28
29 #define DELEGATE(CLASS_TO_VISIT) \
30 return static_cast(this)-> \
31 visit##CLASS_TO_VISIT(static_cast(I))
32
33
34 /// @brief Base class for instruction visitors
35 ///
36 /// Instruction visitors are used when you want to perform different actions
37 /// for different kinds of instructions without having to use lots of casts
38 /// and a big switch statement (in your code, that is).
39 ///
40 /// To define your own visitor, inherit from this class, specifying your
41 /// new type for the 'SubClass' template parameter, and "override" visitXXX
42 /// functions in your class. I say "override" because this class is defined
43 /// in terms of statically resolved overloading, not virtual functions.
44 ///
45 /// For example, here is a visitor that counts the number of malloc
46 /// instructions processed:
47 ///
48 /// /// Declare the class. Note that we derive from InstVisitor instantiated
49 /// /// with _our new subclasses_ type.
50 /// ///
51 /// struct CountAllocaVisitor : public InstVisitor {
52 /// unsigned Count;
53 /// CountAllocaVisitor() : Count(0) {}
54 ///
55 /// void visitAllocaInst(AllocaInst &AI) { ++Count; }
56 /// };
57 ///
58 /// And this class would be used like this:
59 /// CountAllocaVisitor CAV;
60 /// CAV.visit(function);
61 /// NumAllocas = CAV.Count;
62 ///
63 /// The defined has 'visit' methods for Instruction, and also for BasicBlock,
64 /// Function, and Module, which recursively process all contained instructions.
65 ///
66 /// Note that if you don't implement visitXXX for some instruction type,
67 /// the visitXXX method for instruction superclass will be invoked. So
68 /// if instructions are added in the future, they will be automatically
69 /// supported, if you handle one of their superclasses.
70 ///
71 /// The optional second template argument specifies the type that instruction
72 /// visitation functions should return. If you specify this, you *MUST* provide
73 /// an implementation of visitInstruction though!.
74 ///
75 /// Note that this class is specifically designed as a template to avoid
76 /// virtual function call overhead. Defining and using an InstVisitor is just
77 /// as efficient as having your own switch statement over the instruction
78 /// opcode.
79 template
80 class InstVisitor {
81 //===--------------------------------------------------------------------===//
82 // Interface code - This is the public interface of the InstVisitor that you
83 // use to visit instructions...
84 //
85
86 public:
87 // Generic visit method - Allow visitation to all instructions in a range
88 template
89 void visit(Iterator Start, Iterator End) {
90 while (Start != End)
91 static_cast(this)->visit(*Start++);
92 }
93
94 // Define visitors for functions and basic blocks...
95 //
96 void visit(Module &M) {
97 static_cast(this)->visitModule(M);
98 visit(M.begin(), M.end());
99 }
100 void visit(Function &F) {
101 static_cast(this)->visitFunction(F);
102 visit(F.begin(), F.end());
103 }
104 void visit(BasicBlock &BB) {
105 static_cast(this)->visitBasicBlock(BB);
106 visit(BB.begin(), BB.end());
107 }
108
109 // Forwarding functions so that the user can visit with pointers AND refs.
110 void visit(Module *M) { visit(*M); }
111 void visit(Function *F) { visit(*F); }
112 void visit(BasicBlock *BB) { visit(*BB); }
113 RetTy visit(Instruction *I) { return visit(*I); }
114
115 // visit - Finally, code to visit an instruction...
116 //
117 RetTy visit(Instruction &I) {
118 switch (I.getOpcode()) {
119 default: llvm_unreachable("Unknown instruction type encountered!");
120 // Build the switch statement using the Instruction.def file...
121 #define HANDLE_INST(NUM, OPCODE, CLASS) \
122 case Instruction::OPCODE: return \
123 static_cast(this)-> \
124 visit##OPCODE(static_cast(I));
125 #include "llvm/Instruction.def"
126 }
127 }
128
129 //===--------------------------------------------------------------------===//
130 // Visitation functions... these functions provide default fallbacks in case
131 // the user does not specify what to do for a particular instruction type.
132 // The default behavior is to generalize the instruction type to its subtype
133 // and try visiting the subtype. All of this should be inlined perfectly,
134 // because there are no virtual functions to get in the way.
135 //
136
137 // When visiting a module, function or basic block directly, these methods get
138 // called to indicate when transitioning into a new unit.
139 //
140 void visitModule (Module &M) {}
141 void visitFunction (Function &F) {}
142 void visitBasicBlock(BasicBlock &BB) {}
143
144 // Define instruction specific visitor functions that can be overridden to
145 // handle SPECIFIC instructions. These functions automatically define
146 // visitMul to proxy to visitBinaryOperator for instance in case the user does
147 // not need this generality.
148 //
149 // These functions can also implement fan-out, when a single opcode and
150 // instruction have multiple more specific Instruction subclasses. The Call
151 // instruction currently supports this. We implement that by redirecting that
152 // instruction to a special delegation helper.
153 #define HANDLE_INST(NUM, OPCODE, CLASS) \
154 RetTy visit##OPCODE(CLASS &I) { \
155 if (NUM == Instruction::Call) \
156 return delegateCallInst(I); \
157 else \
158 DELEGATE(CLASS); \
159 }
160 #include "llvm/Instruction.def"
161
162 // Specific Instruction type classes... note that all of the casts are
163 // necessary because we use the instruction classes as opaque types...
164 //
165 RetTy visitReturnInst(ReturnInst &I) { DELEGATE(TerminatorInst);}
166 RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
167 RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
168 RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
169 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
170 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
171 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
172 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
173 RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
174 RetTy visitLoadInst(LoadInst &I) { DELEGATE(UnaryInstruction);}
175 RetTy visitStoreInst(StoreInst &I) { DELEGATE(Instruction);}
176 RetTy visitAtomicCmpXchgInst(AtomicCmpXchgInst &I) { DELEGATE(Instruction);}
177 RetTy visitAtomicRMWInst(AtomicRMWInst &I) { DELEGATE(Instruction);}
178 RetTy visitFenceInst(FenceInst &I) { DELEGATE(Instruction);}
179 RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction);}
180 RetTy visitPHINode(PHINode &I) { DELEGATE(Instruction);}
181 RetTy visitTruncInst(TruncInst &I) { DELEGATE(CastInst);}
182 RetTy visitZExtInst(ZExtInst &I) { DELEGATE(CastInst);}
183 RetTy visitSExtInst(SExtInst &I) { DELEGATE(CastInst);}
184 RetTy visitFPTruncInst(FPTruncInst &I) { DELEGATE(CastInst);}
185 RetTy visitFPExtInst(FPExtInst &I) { DELEGATE(CastInst);}
186 RetTy visitFPToUIInst(FPToUIInst &I) { DELEGATE(CastInst);}
187 RetTy visitFPToSIInst(FPToSIInst &I) { DELEGATE(CastInst);}
188 RetTy visitUIToFPInst(UIToFPInst &I) { DELEGATE(CastInst);}
189 RetTy visitSIToFPInst(SIToFPInst &I) { DELEGATE(CastInst);}
190 RetTy visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);}
191 RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
192 RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
193 RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
194 RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
195 RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
196 RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
197 RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction);}
198 RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
199 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
200 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
201
202 // Handle the special instrinsic instruction classes.
203 RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
204 RetTy visitDbgValueInst(DbgValueInst &I) { DELEGATE(DbgInfoIntrinsic);}
205 RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I) { DELEGATE(IntrinsicInst); }
206 RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
207 RetTy visitMemCpyInst(MemCpyInst &I) { DELEGATE(MemTransferInst); }
208 RetTy visitMemMoveInst(MemMoveInst &I) { DELEGATE(MemTransferInst); }
209 RetTy visitMemTransferInst(MemTransferInst &I) { DELEGATE(MemIntrinsic); }
210 RetTy visitMemIntrinsic(MemIntrinsic &I) { DELEGATE(IntrinsicInst); }
211 RetTy visitVAStartInst(VAStartInst &I) { DELEGATE(IntrinsicInst); }
212 RetTy visitVAEndInst(VAEndInst &I) { DELEGATE(IntrinsicInst); }
213 RetTy visitVACopyInst(VACopyInst &I) { DELEGATE(IntrinsicInst); }
214 RetTy visitIntrinsicInst(IntrinsicInst &I) { DELEGATE(CallInst); }
215
216 // Call and Invoke are slightly different as they delegate first through
217 // a generic CallSite visitor.
218 RetTy visitCallInst(CallInst &I) {
219 return static_cast(this)->visitCallSite(&I);
220 }
221 RetTy visitInvokeInst(InvokeInst &I) {
222 return static_cast(this)->visitCallSite(&I);
223 }
224
225 // Next level propagators: If the user does not overload a specific
226 // instruction type, they can overload one of these to get the whole class
227 // of instructions...
228 //
229 RetTy visitCastInst(CastInst &I) { DELEGATE(UnaryInstruction);}
230 RetTy visitBinaryOperator(BinaryOperator &I) { DELEGATE(Instruction);}
231 RetTy visitCmpInst(CmpInst &I) { DELEGATE(Instruction);}
232 RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
233 RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
234
235 // Provide a special visitor for a 'callsite' that visits both calls and
236 // invokes. When unimplemented, properly delegates to either the terminator or
237 // regular instruction visitor.
238 RetTy visitCallSite(CallSite CS) {
239 assert(CS);
240 Instruction &I = *CS.getInstruction();
241 if (CS.isCall())
242 DELEGATE(Instruction);
243
244 assert(CS.isInvoke());
245 DELEGATE(TerminatorInst);
246 }
247
248 // If the user wants a 'default' case, they can choose to override this
249 // function. If this function is not overloaded in the user's subclass, then
250 // this instruction just gets ignored.
251 //
252 // Note that you MUST override this function if your return type is not void.
253 //
254 void visitInstruction(Instruction &I) {} // Ignore unhandled instructions
255
256 private:
257 // Special helper function to delegate to CallInst subclass visitors.
258 RetTy delegateCallInst(CallInst &I) {
259 if (const Function *F = I.getCalledFunction()) {
260 switch ((Intrinsic::ID)F->getIntrinsicID()) {
261 default: DELEGATE(IntrinsicInst);
262 case Intrinsic::dbg_declare: DELEGATE(DbgDeclareInst);
263 case Intrinsic::dbg_value: DELEGATE(DbgValueInst);
264 case Intrinsic::memcpy: DELEGATE(MemCpyInst);
265 case Intrinsic::memmove: DELEGATE(MemMoveInst);
266 case Intrinsic::memset: DELEGATE(MemSetInst);
267 case Intrinsic::vastart: DELEGATE(VAStartInst);
268 case Intrinsic::vaend: DELEGATE(VAEndInst);
269 case Intrinsic::vacopy: DELEGATE(VACopyInst);
270 case Intrinsic::not_intrinsic: break;
271 }
272 }
273 DELEGATE(CallInst);
274 }
275
276 // An overload that will never actually be called, it is used only from dead
277 // code in the dispatching from opcodes to instruction subclasses.
278 RetTy delegateCallInst(Instruction &I) {
279 llvm_unreachable("delegateCallInst called for non-CallInst");
280 }
281 };
282
283 #undef DELEGATE
284
285 } // End llvm namespace
286
287 #endif
1616 #include "llvm/Analysis/InstructionSimplify.h"
1717 #include "llvm/Support/CallSite.h"
1818 #include "llvm/Support/Debug.h"
19 #include "llvm/Support/InstVisitor.h"
2019 #include "llvm/Support/GetElementPtrTypeIterator.h"
2120 #include "llvm/Support/raw_ostream.h"
2221 #include "llvm/CallingConv.h"
22 #include "llvm/InstVisitor.h"
2323 #include "llvm/IntrinsicInst.h"
2424 #include "llvm/Operator.h"
2525 #include "llvm/GlobalAlias.h"
1212
1313 #define DEBUG_TYPE "instcount"
1414 #include "llvm/Analysis/Passes.h"
15 #include "llvm/InstVisitor.h"
1516 #include "llvm/Pass.h"
1617 #include "llvm/Function.h"
1718 #include "llvm/Support/Debug.h"
1819 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/InstVisitor.h"
2020 #include "llvm/Support/raw_ostream.h"
2121 #include "llvm/ADT/Statistic.h"
2222 using namespace llvm;
4646 #include "llvm/Target/TargetLibraryInfo.h"
4747 #include "llvm/Pass.h"
4848 #include "llvm/PassManager.h"
49 #include "llvm/InstVisitor.h"
4950 #include "llvm/IntrinsicInst.h"
5051 #include "llvm/Function.h"
5152 #include "llvm/Support/CallSite.h"
5253 #include "llvm/Support/Debug.h"
53 #include "llvm/Support/InstVisitor.h"
5454 #include "llvm/Support/raw_ostream.h"
5555 #include "llvm/ADT/STLExtras.h"
5656 using namespace llvm;
1313 #ifndef LLI_INTERPRETER_H
1414 #define LLI_INTERPRETER_H
1515
16 #include "llvm/DataLayout.h"
1617 #include "llvm/Function.h"
18 #include "llvm/InstVisitor.h"
1719 #include "llvm/ExecutionEngine/ExecutionEngine.h"
1820 #include "llvm/ExecutionEngine/GenericValue.h"
19 #include "llvm/DataLayout.h"
2021 #include "llvm/Support/CallSite.h"
2122 #include "llvm/Support/DataTypes.h"
2223 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/InstVisitor.h"
2424 #include "llvm/Support/raw_ostream.h"
2525 namespace llvm {
2626
1111
1212 #include "InstCombineWorklist.h"
1313 #include "llvm/IRBuilder.h"
14 #include "llvm/InstVisitor.h"
1415 #include "llvm/IntrinsicInst.h"
1516 #include "llvm/Operator.h"
1617 #include "llvm/Pass.h"
1718 #include "llvm/Analysis/ValueTracking.h"
18 #include "llvm/Support/InstVisitor.h"
1919 #include "llvm/Support/TargetFolder.h"
2020 #include "llvm/Transforms/Utils/SimplifyLibCalls.h"
2121
5050 #include "llvm/DataLayout.h"
5151 #include "llvm/Function.h"
5252 #include "llvm/InlineAsm.h"
53 #include "llvm/InstVisitor.h"
5354 #include "llvm/IntrinsicInst.h"
5455 #include "llvm/IRBuilder.h"
5556 #include "llvm/LLVMContext.h"
6667 #include "llvm/Support/CommandLine.h"
6768 #include "llvm/Support/Compiler.h"
6869 #include "llvm/Support/Debug.h"
69 #include "llvm/Support/InstVisitor.h"
7070 #include "llvm/Support/raw_ostream.h"
7171 #include "llvm/Transforms/Instrumentation.h"
7272 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
2121 #include "llvm/Transforms/IPO.h"
2222 #include "llvm/Constants.h"
2323 #include "llvm/DerivedTypes.h"
24 #include "llvm/InstVisitor.h"
2425 #include "llvm/Instructions.h"
2526 #include "llvm/Pass.h"
2627 #include "llvm/Analysis/ConstantFolding.h"
3031 #include "llvm/Support/CallSite.h"
3132 #include "llvm/Support/Debug.h"
3233 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/InstVisitor.h"
3434 #include "llvm/Support/raw_ostream.h"
3535 #include "llvm/ADT/DenseMap.h"
3636 #include "llvm/ADT/DenseSet.h"
3030 #include "llvm/DerivedTypes.h"
3131 #include "llvm/Function.h"
3232 #include "llvm/IRBuilder.h"
33 #include "llvm/InstVisitor.h"
3334 #include "llvm/Instructions.h"
3435 #include "llvm/IntrinsicInst.h"
3536 #include "llvm/LLVMContext.h"
4748 #include "llvm/Support/Debug.h"
4849 #include "llvm/Support/ErrorHandling.h"
4950 #include "llvm/Support/GetElementPtrTypeIterator.h"
50 #include "llvm/Support/InstVisitor.h"
5151 #include "llvm/Support/MathExtras.h"
5252 #include "llvm/Support/raw_ostream.h"
5353 #include "llvm/DataLayout.h"
4949 #include "llvm/Constants.h"
5050 #include "llvm/DerivedTypes.h"
5151 #include "llvm/InlineAsm.h"
52 #include "llvm/InstVisitor.h"
5253 #include "llvm/IntrinsicInst.h"
5354 #include "llvm/LLVMContext.h"
5455 #include "llvm/Metadata.h"
6162 #include "llvm/Support/CallSite.h"
6263 #include "llvm/Support/CFG.h"
6364 #include "llvm/Support/Debug.h"
64 #include "llvm/Support/InstVisitor.h"
6565 #include "llvm/ADT/SetVector.h"
6666 #include "llvm/ADT/SmallPtrSet.h"
6767 #include "llvm/ADT/SmallVector.h"
1313
1414 #include "llvm/BasicBlock.h"
1515 #include "llvm/Constant.h"
16 #include "llvm/InstVisitor.h"
1617 #include "llvm/Instructions.h"
1718 #include "llvm/Pass.h"
1819 #include "llvm/Type.h"
19 #include "llvm/Support/InstVisitor.h"
2020
2121 using namespace llvm;
2222