LLVM
8.0.1
|
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 81 of file InstVisitor.h.
|
inline |
Definition at line 90 of file InstVisitor.h.
Referenced by analyzeLoopUnrollCost(), llvm::createScalarizerPass(), llvm::findIndirectCalls(), INITIALIZE_PASS(), and llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 97 of file InstVisitor.h.
|
inline |
Definition at line 101 of file InstVisitor.h.
|
inline |
Definition at line 105 of file InstVisitor.h.
|
inline |
Definition at line 111 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 112 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 113 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 114 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 118 of file InstVisitor.h.
|
inline |
Definition at line 191 of file InstVisitor.h.
|
inline |
Definition at line 171 of file InstVisitor.h.
|
inline |
Definition at line 174 of file InstVisitor.h.
|
inline |
Definition at line 175 of file InstVisitor.h.
|
inline |
Definition at line 146 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 267 of file InstVisitor.h.
|
inline |
Definition at line 190 of file InstVisitor.h.
|
inline |
Definition at line 235 of file InstVisitor.h.
|
inline |
Definition at line 273 of file InstVisitor.h.
|
inline |
Definition at line 223 of file InstVisitor.h.
|
inline |
Definition at line 284 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitCallInst(), and llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitInvokeInst().
|
inline |
Definition at line 265 of file InstVisitor.h.
|
inline |
Definition at line 202 of file InstVisitor.h.
|
inline |
Definition at line 253 of file InstVisitor.h.
|
inline |
Definition at line 256 of file InstVisitor.h.
|
inline |
Definition at line 201 of file InstVisitor.h.
|
inline |
Definition at line 250 of file InstVisitor.h.
|
inline |
Definition at line 268 of file InstVisitor.h.
|
inline |
Definition at line 205 of file InstVisitor.h.
|
inline |
Definition at line 210 of file InstVisitor.h.
|
inline |
Definition at line 209 of file InstVisitor.h.
|
inline |
Definition at line 206 of file InstVisitor.h.
|
inline |
Definition at line 207 of file InstVisitor.h.
|
inline |
Definition at line 194 of file InstVisitor.h.
|
inline |
Definition at line 197 of file InstVisitor.h.
|
inline |
Definition at line 170 of file InstVisitor.h.
|
inline |
Definition at line 176 of file InstVisitor.h.
|
inline |
Definition at line 183 of file InstVisitor.h.
|
inline |
Definition at line 185 of file InstVisitor.h.
|
inline |
Definition at line 184 of file InstVisitor.h.
|
inline |
Definition at line 182 of file InstVisitor.h.
|
inline |
Definition at line 200 of file InstVisitor.h.
|
inline |
Definition at line 145 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 177 of file InstVisitor.h.
|
inline |
Definition at line 169 of file InstVisitor.h.
|
inline |
Definition at line 241 of file InstVisitor.h.
|
inline |
Definition at line 195 of file InstVisitor.h.
|
inline |
Definition at line 198 of file InstVisitor.h.
|
inline |
Definition at line 296 of file InstVisitor.h.
|
inline |
Definition at line 219 of file InstVisitor.h.
|
inline |
Definition at line 189 of file InstVisitor.h.
|
inline |
Definition at line 226 of file InstVisitor.h.
|
inline |
Definition at line 199 of file InstVisitor.h.
|
inline |
Definition at line 172 of file InstVisitor.h.
|
inline |
Definition at line 212 of file InstVisitor.h.
|
inline |
Definition at line 215 of file InstVisitor.h.
|
inline |
Definition at line 213 of file InstVisitor.h.
|
inline |
Definition at line 211 of file InstVisitor.h.
|
inline |
Definition at line 214 of file InstVisitor.h.
|
inline |
Definition at line 144 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visit().
|
inline |
Definition at line 178 of file InstVisitor.h.
|
inline |
Definition at line 188 of file InstVisitor.h.
|
inline |
Definition at line 244 of file InstVisitor.h.
|
inline |
Definition at line 232 of file InstVisitor.h.
|
inline |
Definition at line 192 of file InstVisitor.h.
|
inline |
Definition at line 181 of file InstVisitor.h.
|
inline |
Definition at line 196 of file InstVisitor.h.
|
inline |
Definition at line 187 of file InstVisitor.h.
|
inline |
Definition at line 173 of file InstVisitor.h.
|
inline |
Definition at line 238 of file InstVisitor.h.
|
inline |
Definition at line 259 of file InstVisitor.h.
Referenced by llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitBranchInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitCallBase(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitCatchReturnInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitCatchSwitchInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitCleanupReturnInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitIndirectBrInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitResumeInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitReturnInst(), llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitSwitchInst(), and llvm::InstVisitor< ObjectSizeOffsetVisitor, SizeOffsetType >::visitUnreachableInst().
|
inline |
Definition at line 179 of file InstVisitor.h.
|
inline |
Definition at line 186 of file InstVisitor.h.
|
inline |
Definition at line 269 of file InstVisitor.h.
|
inline |
Definition at line 266 of file InstVisitor.h.
|
inline |
Definition at line 247 of file InstVisitor.h.
|
inline |
Definition at line 193 of file InstVisitor.h.
|
inline |
Definition at line 218 of file InstVisitor.h.
|
inline |
Definition at line 217 of file InstVisitor.h.
|
inline |
Definition at line 216 of file InstVisitor.h.
|
inline |
Definition at line 180 of file InstVisitor.h.