LLVM API Documentation
#include <InstVisitor.h>
Inheritance diagram for llvm::InstVisitor< SubClass, RetTy >:
Instruction visitors are used when you want to perform different action for different kinds of instruction without without having to use lots of casts and a big switch statement (in your code that is).
To define your own visitor, inherit from this class, specifying your new type for the 'SubClass' template parameter, and "override" visitXXX functions in your class. I say "overriding" because this class is defined in terms of statically resolved overloading, not virtual functions.
For example, here is a visitor that counts the number of malloc instructions processed:
/ Declare the class. Note that we derive from InstVisitor instantiated / with _our new subclasses_ type. / struct CountMallocVisitor : public InstVisitor<CountMallocVisitor> { unsigned Count; CountMallocVisitor() : Count(0) {}
void visitMallocInst(MallocInst *MI) { ++Count; } };
And this class would be used like this: CountMallocVistor CMV; CMV.visit(function); NumMallocs = CMV.Count;
The defined has 'visit' methods for Instruction, and also for BasicBlock, Function, and Module, which recursively process all conained instructions.
Note that if you don't implement visitXXX for some instruction type, the visitXXX method for instruction superclass will be invoked. So if instructions are added in the future, they will be automatically supported, if you handle on of their superclasses.
The optional second template argument specifies the type that instruction visitation functions should return. If you specify this, you *MUST* provide an implementation of visitInstruction though!.
Note that this class is specifically designed as a template to avoid virtual function call overhead. Defining and using an InstVisitor is just as efficient as having your own switch statement over the instruction opcode.
Definition at line 241 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | Iterator | Start, | |
Iterator | End | |||
) | [inline] |
Definition at line 250 of file InstVisitor.h.
Referenced by SCCPSolver::ResolveBranchesIn(), llvm::Interpreter::run(), and SCCPSolver::Solve().
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | Module & | M | ) | [inline] |
Definition at line 257 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | Function & | F | ) | [inline] |
Definition at line 261 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | BasicBlock & | BB | ) | [inline] |
Definition at line 265 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | Module * | M | ) | [inline] |
Definition at line 271 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | Function * | F | ) | [inline] |
Definition at line 272 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visit | ( | BasicBlock * | BB | ) | [inline] |
Definition at line 273 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visit | ( | Instruction * | I | ) | [inline] |
Definition at line 274 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visit | ( | Instruction & | I | ) | [inline] |
Definition at line 278 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visitModule | ( | Module & | M | ) | [inline] |
Definition at line 462 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visitFunction | ( | Function & | F | ) | [inline] |
Definition at line 463 of file InstVisitor.h.
void llvm::InstVisitor< SubClass, RetTy >::visitBasicBlock | ( | BasicBlock & | BB | ) | [inline] |
Definition at line 464 of file InstVisitor.h.
llvm::InstVisitor< SubClass, RetTy >::HANDLE_MEMORY_INST | ( | 21 | , | |
Malloc | , | |||
MallocInst | ||||
) |
AllocaInst llvm::InstVisitor< SubClass, RetTy >::HANDLE_MEMORY_INST | ( | 24 | , | |
Load | , | |||
LoadInst | ||||
) |
AllocaInst PHINode llvm::InstVisitor< SubClass, RetTy >::HANDLE_OTHER_INST | ( | 28 | , | |
Cast | , | |||
CastInst | ||||
) |
AllocaInst PHINode CallInst llvm::InstVisitor< SubClass, RetTy >::HANDLE_OTHER_INST | ( | 30 | , | |
Shl | , | |||
ShiftInst | ||||
) |
AllocaInst PHINode CallInst SelectInst llvm::InstVisitor< SubClass, RetTy >::HANDLE_OTHER_INST | ( | 35 | , | |
UserOp1 | , | |||
Instruction | ||||
) |
AllocaInst PHINode CallInst SelectInst VAArgInst llvm::InstVisitor< SubClass, RetTy >::HANDLE_OTHER_INST | ( | 38 | , | |
ExtractElement | , | |||
ExtractElementInst | ||||
) |
AllocaInst PHINode CallInst SelectInst VAArgInst InsertElementInst llvm::InstVisitor< SubClass, RetTy >::HANDLE_OTHER_INST | ( | 40 | , | |
ShuffleVector | , | |||
ShuffleVectorInst | ||||
) | [inline] |
Definition at line 619 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitBranchInst | ( | BranchInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSwitchInst | ( | SwitchInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitInvokeInst | ( | InvokeInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitUnwindInst | ( | UnwindInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitUnreachableInst | ( | UnreachableInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSetCondInst | ( | SetCondInst & | I | ) | [inline] |
Definition at line 651 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMallocInst | ( | MallocInst & | I | ) | [inline] |
Definition at line 652 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAllocaInst | ( | AllocaInst & | I | ) | [inline] |
Definition at line 653 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFreeInst | ( | FreeInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitLoadInst | ( | LoadInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitStoreInst | ( | StoreInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitGetElementPtrInst | ( | GetElementPtrInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitPHINode | ( | PHINode & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCastInst | ( | CastInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSelectInst | ( | SelectInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCallInst | ( | CallInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitShiftInst | ( | ShiftInst & | I | ) | [inline] |
Definition at line 662 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitVAArgInst | ( | VAArgInst & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitExtractElementInst | ( | ExtractElementInst & | I | ) | [inline] |
Definition at line 664 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitInsertElementInst | ( | InsertElementInst & | I | ) | [inline] |
Definition at line 665 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitShuffleVectorInst | ( | ShuffleVectorInst & | I | ) | [inline] |
Definition at line 666 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitTerminatorInst | ( | TerminatorInst & | I | ) | [inline] |
Definition at line 672 of file InstVisitor.h.
RetTy llvm::InstVisitor< SubClass, RetTy >::visitBinaryOperator | ( | BinaryOperator & | I | ) | [inline] |
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAllocationInst | ( | AllocationInst & | I | ) | [inline] |
void llvm::InstVisitor< SubClass, RetTy >::visitInstruction | ( | Instruction & | I | ) | [inline] |
llvm::InstVisitor< SubClass, RetTy >::Alloca |
Definition at line 596 of file InstVisitor.h.
AllocaInst llvm::InstVisitor< SubClass, RetTy >::PHI |
Definition at line 604 of file InstVisitor.h.
AllocaInst PHINode llvm::InstVisitor< SubClass, RetTy >::Call |
Definition at line 606 of file InstVisitor.h.
AllocaInst PHINode CallInst llvm::InstVisitor< SubClass, RetTy >::Select |
Definition at line 612 of file InstVisitor.h.
AllocaInst PHINode CallInst SelectInst llvm::InstVisitor< SubClass, RetTy >::VAArg |
Definition at line 616 of file InstVisitor.h.
AllocaInst PHINode CallInst SelectInst VAArgInst llvm::InstVisitor< SubClass, RetTy >::InsertElement |
Definition at line 618 of file InstVisitor.h.