Add new optional getPassName() virtual function that a Pass can override
[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 class Type;
14
15 class FindUsedTypes : public Pass {
16   std::set<const Type *> UsedTypes;
17
18   bool IncludeSymbolTables;
19 public:
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   static AnalysisID ID;
24   static AnalysisID IncludeSymbolTableID;
25
26   FindUsedTypes(AnalysisID id) : IncludeSymbolTables(id != ID) {}
27   virtual const char *getPassName() const { return "Find Used Types"; }
28
29   // getTypes - After the pass has been run, return the set containing all of
30   // the types used in the module.
31   //
32   inline const std::set<const Type *> &getTypes() const { return UsedTypes; }
33
34   // Print the types found in the module.  If the optional Module parameter is
35   // passed in, then the types are printed symbolically if possible, using the
36   // symbol table from the module.
37   //
38   void printTypes(std::ostream &o, const Module *M = 0) const;
39
40 private:
41   // IncorporateType - Incorporate one type and all of its subtypes into the
42   // collection of used types.
43   //
44   void IncorporateType(const Type *Ty);
45
46   // IncorporateSymbolTable - Add all types referenced by the specified symtab
47   // into the collection of used types.
48   //
49   void IncorporateSymbolTable(const SymbolTable *ST);
50
51 public:
52   // run - This incorporates all types used by the specified module
53   //
54   bool run(Module *M);
55
56   // getAnalysisUsage - Of course, we provide ourself...
57   //
58   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
59     AU.setPreservesAll();
60     AU.addProvided(ID);
61   }
62 };
63
64 #endif