llvm.org GIT mirror llvm / 7384530
Add support to the InstVisitor for visiting a generic callsite. The visitor will now visit a CallInst and an InvokeInst with instruction-specific visitors, then visit a generic CallSite visitor, then delegate back to the Instruction visitor and the TerminatorInst visitors depending on whether a call or an invoke originally. This will be used in the soon-to-land inline cost rewrite. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153811 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 8 years ago
1 changed file(s) with 23 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1313 #include "llvm/Function.h"
1414 #include "llvm/Instructions.h"
1515 #include "llvm/Module.h"
16 #include "llvm/Support/CallSite.h"
1617 #include "llvm/Support/ErrorHandling.h"
1718
1819 namespace llvm {
160161 RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
161162 RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
162163 RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
163 RetTy visitInvokeInst(InvokeInst &I) { DELEGATE(TerminatorInst);}
164164 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
165165 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
166166 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
186186 RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
187187 RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
188188 RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
189 RetTy visitCallInst(CallInst &I) { DELEGATE(Instruction);}
190189 RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
191190 RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
192191 RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
195194 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
196195 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
197196
197 // Call and Invoke are slightly different as they delegate first through
198 // a generic CallSite visitor.
199 RetTy visitCallInst(CallInst &I) {
200 return static_cast(this)->visitCallSite(&I);
201 }
202 RetTy visitInvokeInst(InvokeInst &I) {
203 return static_cast(this)->visitCallSite(&I);
204 }
205
198206 // Next level propagators: If the user does not overload a specific
199207 // instruction type, they can overload one of these to get the whole class
200208 // of instructions...
205213 RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
206214 RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
207215
216 // Provide a special visitor for a 'callsite' that visits both calls and
217 // invokes. When unimplemented, properly delegates to either the terminator or
218 // regular instruction visitor.
219 RetTy visitCallSite(CallSite CS) {
220 assert(CS);
221 Instruction &I = *CS.getInstruction();
222 if (CS.isCall())
223 DELEGATE(Instruction);
224
225 assert(CS.isInvoke());
226 DELEGATE(TerminatorInst);
227 }
228
208229 // If the user wants a 'default' case, they can choose to override this
209230 // function. If this function is not overloaded in the user's subclass, then
210231 // this instruction just gets ignored.