LLVM 20.0.0git
|
Base class for instruction visitors. More...
#include "llvm/IR/InstVisitor.h"
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 78 of file InstVisitor.h.
|
inline |
Definition at line 102 of file InstVisitor.h.
References llvm::BasicBlock::begin(), llvm::BasicBlock::end(), llvm::InstVisitor< SubClass, RetTy >::visit(), and llvm::InstVisitor< SubClass, RetTy >::visitBasicBlock().
|
inline |
Definition at line 110 of file InstVisitor.h.
References llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 98 of file InstVisitor.h.
References F, llvm::InstVisitor< SubClass, RetTy >::visit(), and llvm::InstVisitor< SubClass, RetTy >::visitFunction().
|
inline |
Definition at line 109 of file InstVisitor.h.
References F, and llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 115 of file InstVisitor.h.
References I, and llvm_unreachable.
|
inline |
Definition at line 111 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 87 of file InstVisitor.h.
References End, and llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by llvm::IRSimilarity::IRInstructionMapper::convertToUnsignedVec(), llvm::findIndirectCalls(), llvm::findVTableAddrs(), DataScalarizerVisitor::visit(), and llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 94 of file InstVisitor.h.
References llvm::InstVisitor< SubClass, RetTy >::visit(), and llvm::InstVisitor< SubClass, RetTy >::visitModule().
|
inline |
Definition at line 108 of file InstVisitor.h.
References llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 188 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 168 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 171 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 172 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 143 of file InstVisitor.h.
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 264 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 187 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 232 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 270 of file InstVisitor.h.
References DELEGATE, I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 225 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 223 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 262 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 199 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 250 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 253 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 198 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 247 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 265 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 203 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 208 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 207 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 204 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 205 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 191 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 194 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 167 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 173 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 180 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 182 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 181 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 179 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 200 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 197 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 142 of file InstVisitor.h.
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 174 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 166 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 238 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 192 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 195 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 283 of file InstVisitor.h.
|
inline |
Definition at line 222 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 186 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 224 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 196 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 169 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 215 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 214 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 218 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 216 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 210 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 209 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 211 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 217 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 141 of file InstVisitor.h.
Referenced by llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Definition at line 175 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 185 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 241 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 229 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 189 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 178 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 193 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 184 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 170 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 235 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 256 of file InstVisitor.h.
References DELEGATE.
Referenced by llvm::InstVisitor< SubClass, RetTy >::visitBranchInst(), llvm::InstVisitor< SubClass, RetTy >::visitCallBase(), llvm::InstVisitor< SubClass, RetTy >::visitCatchReturnInst(), llvm::InstVisitor< SubClass, RetTy >::visitCatchSwitchInst(), llvm::InstVisitor< SubClass, RetTy >::visitCleanupReturnInst(), llvm::InstVisitor< SubClass, RetTy >::visitIndirectBrInst(), llvm::InstVisitor< SubClass, RetTy >::visitResumeInst(), llvm::InstVisitor< SubClass, RetTy >::visitReturnInst(), llvm::InstVisitor< SubClass, RetTy >::visitSwitchInst(), and llvm::InstVisitor< SubClass, RetTy >::visitUnreachableInst().
|
inline |
Definition at line 176 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 183 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 266 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 263 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 244 of file InstVisitor.h.
References I, and llvm::InstVisitor< SubClass, RetTy >::visitTerminator().
|
inline |
Definition at line 190 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 221 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 220 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 219 of file InstVisitor.h.
References DELEGATE.
|
inline |
Definition at line 177 of file InstVisitor.h.
References DELEGATE.