FindUsedTypes.h revision 47b6f84736197b5ece84860e6cb6052ebc60c646
1f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner//===- llvm/Analysis/FindUsedTypes.h - Find all Types in use -----*- C++ -*--=//
2f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner//
3f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner// This pass is used to seek out all of the types in use by the program.
4f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner//
5f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner//===----------------------------------------------------------------------===//
6f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
7f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#ifndef LLVM_ANALYSIS_FINDUSEDTYPES_H
8f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#define LLVM_ANALYSIS_FINDUSEDTYPES_H
9f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
10f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#include "llvm/Pass.h"
11f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#include <set>
12f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerclass SymbolTable;
13facd752d3afaeca7dee46648f2a2ae209a94e5e9Chris Lattnerclass Type;
14f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
15facd752d3afaeca7dee46648f2a2ae209a94e5e9Chris Lattnerclass FindUsedTypes : public Pass {
16697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  std::set<const Type *> UsedTypes;
17f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerpublic:
1847b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// getTypes - After the pass has been run, return the set containing all of
1947b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// the types used in the module.
2047b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  ///
215d549083e2dc55cc1aa035f1069480d052717061Chris Lattner  const std::set<const Type *> &getTypes() const { return UsedTypes; }
22f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
2347b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// Print the types found in the module.  If the optional Module parameter is
2447b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// passed in, then the types are printed symbolically if possible, using the
2547b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// symbol table from the module.
2647b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  ///
2797f51a3024a72ef8500e95b90e6361e6783160fdChris Lattner  void print(std::ostream &o, const Module *M) const;
28f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
29f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerprivate:
3047b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// IncorporateType - Incorporate one type and all of its subtypes into the
3147b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// collection of used types.
3247b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  ///
33f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner  void IncorporateType(const Type *Ty);
34f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
35fe700e7e4240fa88b8d5f44d1e7d6dcc51495c26Chris Lattnerpublic:
3647b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// run - This incorporates all types used by the specified module
377e70829632f82de15db187845666aaca6e04b792Chris Lattner  bool run(Module &M);
38f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
3947b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  /// getAnalysisUsage - We do not modify anything.
40f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner    AU.setPreservesAll();
42f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner  }
4347b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner
4447b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  // stub - dummy function, just ignore it
4547b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner  static void stub();
46f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner};
47f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner
4847b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner// Make sure that any clients of this file link in PostDominators.cpp
4947b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattnerstatic IncludeFile
5047b6f84736197b5ece84860e6cb6052ebc60c646Chris LattnerFIND_USED_TYPES_INCLUDE_FILE((void*)&FindUsedTypes::stub);
5147b6f84736197b5ece84860e6cb6052ebc60c646Chris Lattner
52f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#endif
53