LLVM  6.0.0svn
Public Member Functions | List of all members
llvm::InstVisitor< SubClass, RetTy > Class Template Reference

Base class for instruction visitors. More...

#include "llvm/IR/InstVisitor.h"

Inheritance diagram for llvm::InstVisitor< SubClass, RetTy >:
Inheritance graph
[legend]

Public Member Functions

template<class Iterator >
void visit (Iterator Start, Iterator End)
 
void visit (Module &M)
 
void visit (Function &F)
 
void visit (BasicBlock &BB)
 
void visit (Module *M)
 
void visit (Function *F)
 
void visit (BasicBlock *BB)
 
RetTy visit (Instruction *I)
 
RetTy visit (Instruction &I)
 
void visitModule (Module &M)
 
void visitFunction (Function &F)
 
void visitBasicBlock (BasicBlock &BB)
 
RetTy visitReturnInst (ReturnInst &I)
 
RetTy visitBranchInst (BranchInst &I)
 
RetTy visitSwitchInst (SwitchInst &I)
 
RetTy visitIndirectBrInst (IndirectBrInst &I)
 
RetTy visitResumeInst (ResumeInst &I)
 
RetTy visitUnreachableInst (UnreachableInst &I)
 
RetTy visitCleanupReturnInst (CleanupReturnInst &I)
 
RetTy visitCatchReturnInst (CatchReturnInst &I)
 
RetTy visitCatchSwitchInst (CatchSwitchInst &I)
 
RetTy visitICmpInst (ICmpInst &I)
 
RetTy visitFCmpInst (FCmpInst &I)
 
RetTy visitAllocaInst (AllocaInst &I)
 
RetTy visitLoadInst (LoadInst &I)
 
RetTy visitStoreInst (StoreInst &I)
 
RetTy visitAtomicCmpXchgInst (AtomicCmpXchgInst &I)
 
RetTy visitAtomicRMWInst (AtomicRMWInst &I)
 
RetTy visitFenceInst (FenceInst &I)
 
RetTy visitGetElementPtrInst (GetElementPtrInst &I)
 
RetTy visitPHINode (PHINode &I)
 
RetTy visitTruncInst (TruncInst &I)
 
RetTy visitZExtInst (ZExtInst &I)
 
RetTy visitSExtInst (SExtInst &I)
 
RetTy visitFPTruncInst (FPTruncInst &I)
 
RetTy visitFPExtInst (FPExtInst &I)
 
RetTy visitFPToUIInst (FPToUIInst &I)
 
RetTy visitFPToSIInst (FPToSIInst &I)
 
RetTy visitUIToFPInst (UIToFPInst &I)
 
RetTy visitSIToFPInst (SIToFPInst &I)
 
RetTy visitPtrToIntInst (PtrToIntInst &I)
 
RetTy visitIntToPtrInst (IntToPtrInst &I)
 
RetTy visitBitCastInst (BitCastInst &I)
 
RetTy visitAddrSpaceCastInst (AddrSpaceCastInst &I)
 
RetTy visitSelectInst (SelectInst &I)
 
RetTy visitVAArgInst (VAArgInst &I)
 
RetTy visitExtractElementInst (ExtractElementInst &I)
 
RetTy visitInsertElementInst (InsertElementInst &I)
 
RetTy visitShuffleVectorInst (ShuffleVectorInst &I)
 
RetTy visitExtractValueInst (ExtractValueInst &I)
 
RetTy visitInsertValueInst (InsertValueInst &I)
 
RetTy visitLandingPadInst (LandingPadInst &I)
 
RetTy visitFuncletPadInst (FuncletPadInst &I)
 
RetTy visitCleanupPadInst (CleanupPadInst &I)
 
RetTy visitCatchPadInst (CatchPadInst &I)
 
RetTy visitDbgDeclareInst (DbgDeclareInst &I)
 
RetTy visitDbgValueInst (DbgValueInst &I)
 
RetTy visitDbgInfoIntrinsic (DbgInfoIntrinsic &I)
 
RetTy visitMemSetInst (MemSetInst &I)
 
RetTy visitMemCpyInst (MemCpyInst &I)
 
RetTy visitMemMoveInst (MemMoveInst &I)
 
RetTy visitMemTransferInst (MemTransferInst &I)
 
RetTy visitMemIntrinsic (MemIntrinsic &I)
 
RetTy visitVAStartInst (VAStartInst &I)
 
RetTy visitVAEndInst (VAEndInst &I)
 
RetTy visitVACopyInst (VACopyInst &I)
 
RetTy visitIntrinsicInst (IntrinsicInst &I)
 
RetTy visitCallInst (CallInst &I)
 
RetTy visitInvokeInst (InvokeInst &I)
 
RetTy visitCastInst (CastInst &I)
 
RetTy visitBinaryOperator (BinaryOperator &I)
 
RetTy visitCmpInst (CmpInst &I)
 
RetTy visitTerminatorInst (TerminatorInst &I)
 
RetTy visitUnaryInstruction (UnaryInstruction &I)
 
RetTy visitCallSite (CallSite CS)
 
void visitInstruction (Instruction &I)
 

Detailed Description

template<typename SubClass, typename RetTy = void>
class llvm::InstVisitor< SubClass, RetTy >

Base class for instruction visitors.

Instruction visitors are used when you want to perform different actions for different kinds of instructions 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 "override" 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 CountAllocaVisitor : public InstVisitor<CountAllocaVisitor> { unsigned Count; CountAllocaVisitor() : Count(0) {}

void visitAllocaInst(AllocaInst &AI) { ++Count; } };

And this class would be used like this: CountAllocaVisitor CAV; CAV.visit(function); NumAllocas = CAV.Count;

The defined has 'visit' methods for Instruction, and also for BasicBlock, Function, and Module, which recursively process all contained 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 one 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 81 of file InstVisitor.h.

Member Function Documentation

◆ visit() [1/9]

template<typename SubClass, typename RetTy = void>
template<class Iterator >
void llvm::InstVisitor< SubClass, RetTy >::visit ( Iterator  Start,
Iterator  End 
)
inline

◆ visit() [2/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( Module M)
inline

Definition at line 97 of file InstVisitor.h.

◆ visit() [3/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( Function F)
inline

Definition at line 101 of file InstVisitor.h.

◆ visit() [4/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( BasicBlock BB)
inline

Definition at line 105 of file InstVisitor.h.

◆ visit() [5/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( Module M)
inline

◆ visit() [6/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( Function F)
inline

◆ visit() [7/9]

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visit ( BasicBlock BB)
inline

◆ visit() [8/9]

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visit ( Instruction I)
inline

◆ visit() [9/9]

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visit ( Instruction I)
inline

Definition at line 118 of file InstVisitor.h.

◆ visitAddrSpaceCastInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAddrSpaceCastInst ( AddrSpaceCastInst I)
inline

Definition at line 200 of file InstVisitor.h.

◆ visitAllocaInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAllocaInst ( AllocaInst I)
inline

Definition at line 180 of file InstVisitor.h.

◆ visitAtomicCmpXchgInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAtomicCmpXchgInst ( AtomicCmpXchgInst I)
inline

Definition at line 183 of file InstVisitor.h.

◆ visitAtomicRMWInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitAtomicRMWInst ( AtomicRMWInst I)
inline

Definition at line 184 of file InstVisitor.h.

◆ visitBasicBlock()

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visitBasicBlock ( BasicBlock BB)
inline

◆ visitBinaryOperator()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitBinaryOperator ( BinaryOperator I)
inline

Definition at line 241 of file InstVisitor.h.

◆ visitBitCastInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitBitCastInst ( BitCastInst I)
inline

Definition at line 199 of file InstVisitor.h.

◆ visitBranchInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitBranchInst ( BranchInst I)
inline

Definition at line 170 of file InstVisitor.h.

◆ visitCallInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCallInst ( CallInst I)
inline

Definition at line 229 of file InstVisitor.h.

◆ visitCallSite()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCallSite ( CallSite  CS)
inline

◆ visitCastInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCastInst ( CastInst I)
inline

Definition at line 240 of file InstVisitor.h.

◆ visitCatchPadInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCatchPadInst ( CatchPadInst I)
inline

Definition at line 211 of file InstVisitor.h.

◆ visitCatchReturnInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCatchReturnInst ( CatchReturnInst I)
inline

Definition at line 176 of file InstVisitor.h.

◆ visitCatchSwitchInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCatchSwitchInst ( CatchSwitchInst I)
inline

Definition at line 177 of file InstVisitor.h.

◆ visitCleanupPadInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCleanupPadInst ( CleanupPadInst I)
inline

Definition at line 210 of file InstVisitor.h.

◆ visitCleanupReturnInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCleanupReturnInst ( CleanupReturnInst I)
inline

Definition at line 175 of file InstVisitor.h.

◆ visitCmpInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitCmpInst ( CmpInst I)
inline

Definition at line 242 of file InstVisitor.h.

◆ visitDbgDeclareInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitDbgDeclareInst ( DbgDeclareInst I)
inline

Definition at line 214 of file InstVisitor.h.

◆ visitDbgInfoIntrinsic()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitDbgInfoIntrinsic ( DbgInfoIntrinsic I)
inline

Definition at line 216 of file InstVisitor.h.

◆ visitDbgValueInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitDbgValueInst ( DbgValueInst I)
inline

Definition at line 215 of file InstVisitor.h.

◆ visitExtractElementInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitExtractElementInst ( ExtractElementInst I)
inline

Definition at line 203 of file InstVisitor.h.

◆ visitExtractValueInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitExtractValueInst ( ExtractValueInst I)
inline

Definition at line 206 of file InstVisitor.h.

◆ visitFCmpInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFCmpInst ( FCmpInst I)
inline

Definition at line 179 of file InstVisitor.h.

◆ visitFenceInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFenceInst ( FenceInst I)
inline

Definition at line 185 of file InstVisitor.h.

◆ visitFPExtInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFPExtInst ( FPExtInst I)
inline

Definition at line 192 of file InstVisitor.h.

◆ visitFPToSIInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFPToSIInst ( FPToSIInst I)
inline

Definition at line 194 of file InstVisitor.h.

◆ visitFPToUIInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFPToUIInst ( FPToUIInst I)
inline

Definition at line 193 of file InstVisitor.h.

◆ visitFPTruncInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFPTruncInst ( FPTruncInst I)
inline

Definition at line 191 of file InstVisitor.h.

◆ visitFuncletPadInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitFuncletPadInst ( FuncletPadInst I)
inline

Definition at line 209 of file InstVisitor.h.

◆ visitFunction()

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visitFunction ( Function F)
inline

◆ visitGetElementPtrInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitGetElementPtrInst ( GetElementPtrInst I)
inline

Definition at line 186 of file InstVisitor.h.

◆ visitICmpInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitICmpInst ( ICmpInst I)
inline

Definition at line 178 of file InstVisitor.h.

◆ visitIndirectBrInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitIndirectBrInst ( IndirectBrInst I)
inline

Definition at line 172 of file InstVisitor.h.

◆ visitInsertElementInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitInsertElementInst ( InsertElementInst I)
inline

Definition at line 204 of file InstVisitor.h.

◆ visitInsertValueInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitInsertValueInst ( InsertValueInst I)
inline

Definition at line 207 of file InstVisitor.h.

◆ visitInstruction()

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visitInstruction ( Instruction I)
inline

Definition at line 265 of file InstVisitor.h.

◆ visitIntrinsicInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitIntrinsicInst ( IntrinsicInst I)
inline

Definition at line 225 of file InstVisitor.h.

◆ visitIntToPtrInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitIntToPtrInst ( IntToPtrInst I)
inline

Definition at line 198 of file InstVisitor.h.

◆ visitInvokeInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitInvokeInst ( InvokeInst I)
inline

Definition at line 232 of file InstVisitor.h.

◆ visitLandingPadInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitLandingPadInst ( LandingPadInst I)
inline

Definition at line 208 of file InstVisitor.h.

◆ visitLoadInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitLoadInst ( LoadInst I)
inline

Definition at line 181 of file InstVisitor.h.

◆ visitMemCpyInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMemCpyInst ( MemCpyInst I)
inline

Definition at line 218 of file InstVisitor.h.

◆ visitMemIntrinsic()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMemIntrinsic ( MemIntrinsic I)
inline

Definition at line 221 of file InstVisitor.h.

◆ visitMemMoveInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMemMoveInst ( MemMoveInst I)
inline

Definition at line 219 of file InstVisitor.h.

◆ visitMemSetInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMemSetInst ( MemSetInst I)
inline

Definition at line 217 of file InstVisitor.h.

◆ visitMemTransferInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitMemTransferInst ( MemTransferInst I)
inline

Definition at line 220 of file InstVisitor.h.

◆ visitModule()

template<typename SubClass, typename RetTy = void>
void llvm::InstVisitor< SubClass, RetTy >::visitModule ( Module M)
inline

◆ visitPHINode()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitPHINode ( PHINode I)
inline

Definition at line 187 of file InstVisitor.h.

◆ visitPtrToIntInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitPtrToIntInst ( PtrToIntInst I)
inline

Definition at line 197 of file InstVisitor.h.

◆ visitResumeInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitResumeInst ( ResumeInst I)
inline

Definition at line 173 of file InstVisitor.h.

◆ visitReturnInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitReturnInst ( ReturnInst I)
inline

Definition at line 169 of file InstVisitor.h.

◆ visitSelectInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSelectInst ( SelectInst I)
inline

Definition at line 201 of file InstVisitor.h.

◆ visitSExtInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSExtInst ( SExtInst I)
inline

Definition at line 190 of file InstVisitor.h.

◆ visitShuffleVectorInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitShuffleVectorInst ( ShuffleVectorInst I)
inline

Definition at line 205 of file InstVisitor.h.

◆ visitSIToFPInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSIToFPInst ( SIToFPInst I)
inline

Definition at line 196 of file InstVisitor.h.

◆ visitStoreInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitStoreInst ( StoreInst I)
inline

Definition at line 182 of file InstVisitor.h.

◆ visitSwitchInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitSwitchInst ( SwitchInst I)
inline

Definition at line 171 of file InstVisitor.h.

◆ visitTerminatorInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitTerminatorInst ( TerminatorInst I)
inline

Definition at line 243 of file InstVisitor.h.

◆ visitTruncInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitTruncInst ( TruncInst I)
inline

Definition at line 188 of file InstVisitor.h.

◆ visitUIToFPInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitUIToFPInst ( UIToFPInst I)
inline

Definition at line 195 of file InstVisitor.h.

◆ visitUnaryInstruction()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitUnaryInstruction ( UnaryInstruction I)
inline

Definition at line 244 of file InstVisitor.h.

◆ visitUnreachableInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitUnreachableInst ( UnreachableInst I)
inline

Definition at line 174 of file InstVisitor.h.

◆ visitVAArgInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitVAArgInst ( VAArgInst I)
inline

Definition at line 202 of file InstVisitor.h.

◆ visitVACopyInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitVACopyInst ( VACopyInst I)
inline

Definition at line 224 of file InstVisitor.h.

◆ visitVAEndInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitVAEndInst ( VAEndInst I)
inline

Definition at line 223 of file InstVisitor.h.

◆ visitVAStartInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitVAStartInst ( VAStartInst I)
inline

Definition at line 222 of file InstVisitor.h.

◆ visitZExtInst()

template<typename SubClass, typename RetTy = void>
RetTy llvm::InstVisitor< SubClass, RetTy >::visitZExtInst ( ZExtInst I)
inline

Definition at line 189 of file InstVisitor.h.


The documentation for this class was generated from the following file: