1 //===-- llvm/Analysis/ModuleAnalyzer.h - Module analysis driver --*- C++ -*-==//
3 // This class provides a nice interface to traverse a module in a predictable
4 // way. This is used by the AssemblyWriter, BytecodeWriter, and SlotCalculator
5 // to do analysis of a module.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_ANALYSIS_MODULEANALYZER_H
10 #define LLVM_ANALYSIS_MODULEANALYZER_H
12 #include "llvm/ConstantPool.h"
23 class ModuleAnalyzer {
24 ModuleAnalyzer(const ModuleAnalyzer &); // do not impl
25 const ModuleAnalyzer &operator=(const ModuleAnalyzer &); // do not impl
28 virtual ~ModuleAnalyzer() {}
31 // processModule - Driver function to call all of my subclasses virtual
32 // methods. Commonly called by derived type's constructor.
34 bool processModule(const Module *M);
36 //===--------------------------------------------------------------------===//
37 // Stages of processing Module level information
39 virtual bool processConstPool(const ConstantPool &CP, bool isMethod);
41 // processType - This callback occurs when an derived type is discovered
42 // at the class level. This activity occurs when processing a constant pool.
44 virtual bool processType(const Type *Ty) { return false; }
46 // processMethods - The default implementation of this method loops through
47 // all of the methods in the module and processModule's them.
49 virtual bool processMethods(const Module *M);
51 //===--------------------------------------------------------------------===//
52 // Stages of processing a constant pool
55 // processConstPoolPlane - Called once for every populated plane in the
56 // constant pool. The default action is to do nothing. The processConstPool
57 // method does the iteration over constants.
59 virtual bool processConstPoolPlane(const ConstantPool &CP,
60 const ConstantPool::PlaneType &Pl,
65 // processConstant is called once per each constant in the constant pool. It
66 // traverses the constant pool such that it visits each constant in the
67 // order of its type. Thus, all 'int' typed constants shall be visited
68 // sequentially, etc...
70 virtual bool processConstant(const ConstPoolVal *CPV) { return false; }
72 // visitMethod - This member is called after the constant pool has been
73 // processed. The default implementation of this is a noop.
75 virtual bool visitMethod(const Method *M) { return false; }
77 //===--------------------------------------------------------------------===//
78 // Stages of processing Method level information
80 // (processConstPool is also used above, with the isMethod flag set to true)
83 // processMethod - Process all aspects of a method.
85 virtual bool processMethod(const Method *M);
87 // processMethodArgument - This member is called for every argument that
88 // is passed into the method.
90 virtual bool processMethodArgument(const MethodArgument *MA) { return false; }
92 // processBasicBlock - This member is called for each basic block in a methd.
94 virtual bool processBasicBlock(const BasicBlock *BB);
96 //===--------------------------------------------------------------------===//
97 // Stages of processing BasicBlock level information
100 // preProcessInstruction - This member is called for each Instruction in a
101 // method before processInstruction.
103 virtual bool preProcessInstruction(const Instruction *I);
105 // processInstruction - This member is called for each Instruction in a method
107 virtual bool processInstruction(const Instruction *I) { return false; }
110 bool handleType(set<const Type *> &TypeSet, const Type *T);