New pass to figure out what types are in use by a program
[oota-llvm.git] / include / llvm / Analysis / FindUsedTypes.h
1 //===- llvm/Analysis/FindUsedTypes.h - Find all Types in use -----*- C++ -*--=//
2 //
3 // This pass is used to seek out all of the types in use by the program.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_ANALYSIS_FINDUSEDTYPES_H
8 #define LLVM_ANALYSIS_FINDUSEDTYPES_H
9
10 #include "llvm/Pass.h"
11 #include <set>
12 class SymbolTable;
13
14 class FindUsedTypes : public Pass {
15   set<const Type *> UsedTypes;
16
17   bool IncludeSymbolTables;
18 public:
19
20   // FindUsedTypes ctor - This pass can optionally include types that are
21   // referenced only in symbol tables, but the default is not to.
22   //
23   FindUsedTypes(bool IST = false) : IncludeSymbolTables(IST) {}
24
25   // getTypes - After the pass has been run, return the set containing all of
26   // the types used in the module.
27   //
28   inline const set<const Type *> &getTypes() const { return UsedTypes; }
29
30   // Print the types found in the module.  If the optional Module parameter is
31   // passed in, then the types are printed symbolically if possible, using the
32   // symbol table from the module.
33   //
34   void printTypes(ostream &o, const Module *M = 0) const;
35
36 private:
37   // IncorporateType - Incorporate one type and all of its subtypes into the
38   // collection of used types.
39   //
40   void IncorporateType(const Type *Ty);
41
42   // IncorporateSymbolTable - Add all types referenced by the specified symtab
43   // into the collection of used types.
44   //
45   void IncorporateSymbolTable(const SymbolTable *ST);
46
47 protected:
48   // doPassInitialization - This loops over global constants defined in the
49   // module, converting them to their new type.
50   //
51   bool doPassInitialization(Module *M);
52
53   // doPerMethodWork - This incorporates all types used by the specified method
54   //
55   bool doPerMethodWork(Method *M);
56 };
57
58 #endif