3abdd49afe3ae436f6400b9c026581f2a66eae2c
[oota-llvm.git] / include / llvm / Analysis / ModuleAnalyzer.h
1 //===-- llvm/Analysis/ModuleAnalyzer.h - Module analysis driver --*- C++ -*-==//
2 //
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.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ANALYSIS_MODULEANALYZER_H
10 #define LLVM_ANALYSIS_MODULEANALYZER_H
11
12 #include "llvm/ConstantPool.h"
13 #include <set>
14
15 class Module;
16 class Method;
17 class BasicBlock;
18 class Instruction;
19 class ConstPoolVal;
20 class MethodType;
21 class MethodArgument;
22
23 class ModuleAnalyzer {
24   ModuleAnalyzer(const ModuleAnalyzer &);                   // do not impl
25   const ModuleAnalyzer &operator=(const ModuleAnalyzer &);  // do not impl
26 public:
27   ModuleAnalyzer() {}
28   virtual ~ModuleAnalyzer() {}
29   
30 protected:
31   // processModule - Driver function to call all of my subclasses virtual 
32   // methods.  Commonly called by derived type's constructor.
33   //
34   bool processModule(const Module *M);
35
36   //===--------------------------------------------------------------------===//
37   //  Stages of processing Module level information
38   //
39   virtual bool processConstPool(const ConstantPool &CP, bool isMethod);
40
41   // processType - This callback occurs when an derived type is discovered
42   // at the class level. This activity occurs when processing a constant pool.
43   //
44   virtual bool processType(const Type *Ty) { return false; }
45
46   // processMethods - The default implementation of this method loops through 
47   // all of the methods in the module and processModule's them.
48   //
49   virtual bool processMethods(const Module *M);
50
51   //===--------------------------------------------------------------------===//
52   //  Stages of processing a constant pool
53   //
54
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.
58   //
59   virtual bool processConstPoolPlane(const ConstantPool &CP,
60                                      const ConstantPool::PlaneType &Pl, 
61                                      bool isMethod) {
62     return false;
63   }
64
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...
69   //
70   virtual bool processConstant(const ConstPoolVal *CPV) { return false; }
71
72   // visitMethod - This member is called after the constant pool has been 
73   // processed.  The default implementation of this is a noop.
74   //
75   virtual bool visitMethod(const Method *M) { return false; }
76
77   //===--------------------------------------------------------------------===//
78   //  Stages of processing Method level information
79   //
80   // (processConstPool is also used above, with the isMethod flag set to true)
81   //
82
83   // processMethod - Process all aspects of a method.
84   //
85   virtual bool processMethod(const Method *M);
86
87   // processMethodArgument - This member is called for every argument that 
88   // is passed into the method.
89   //
90   virtual bool processMethodArgument(const MethodArgument *MA) { return false; }
91
92   // processBasicBlock - This member is called for each basic block in a methd.
93   //
94   virtual bool processBasicBlock(const BasicBlock *BB);
95
96   //===--------------------------------------------------------------------===//
97   //  Stages of processing BasicBlock level information
98   //
99
100   // preProcessInstruction - This member is called for each Instruction in a 
101   // method before processInstruction.
102   //
103   virtual bool preProcessInstruction(const Instruction *I);
104
105   // processInstruction - This member is called for each Instruction in a method
106   //
107   virtual bool processInstruction(const Instruction *I) { return false; }
108
109 private:
110   bool handleType(set<const Type *> &TypeSet, const Type *T);
111 };
112
113 #endif