FindUsedTypes.h revision 267654
155682Smarkm//===- llvm/Analysis/FindUsedTypes.h - Find all Types in use ----*- C++ -*-===//
2233294Sstas//
3233294Sstas//                     The LLVM Compiler Infrastructure
4233294Sstas//
555682Smarkm// This file is distributed under the University of Illinois Open Source
6233294Sstas// License. See LICENSE.TXT for details.
7233294Sstas//
8233294Sstas//===----------------------------------------------------------------------===//
955682Smarkm//
10233294Sstas// This pass is used to seek out all of the types in use by the program.
11233294Sstas//
1255682Smarkm//===----------------------------------------------------------------------===//
13233294Sstas
14233294Sstas#ifndef LLVM_ANALYSIS_FINDUSEDTYPES_H
15233294Sstas#define LLVM_ANALYSIS_FINDUSEDTYPES_H
1655682Smarkm
17233294Sstas#include "llvm/ADT/SetVector.h"
18233294Sstas#include "llvm/Pass.h"
19233294Sstas
2055682Smarkmnamespace llvm {
21233294Sstas
22233294Sstasclass Type;
23233294Sstasclass Value;
24233294Sstas
25233294Sstasclass FindUsedTypes : public ModulePass {
26233294Sstas  SetVector<Type *> UsedTypes;
27233294Sstaspublic:
28233294Sstas  static char ID; // Pass identification, replacement for typeid
29233294Sstas  FindUsedTypes() : ModulePass(ID) {
30233294Sstas    initializeFindUsedTypesPass(*PassRegistry::getPassRegistry());
31233294Sstas  }
3255682Smarkm
3355682Smarkm  /// getTypes - After the pass has been run, return the set containing all of
3455682Smarkm  /// the types used in the module.
35102644Snectar  ///
3655682Smarkm  const SetVector<Type *> &getTypes() const { return UsedTypes; }
3755682Smarkm
3855682Smarkm  /// Print the types found in the module.  If the optional Module parameter is
3955682Smarkm  /// passed in, then the types are printed symbolically if possible, using the
4055682Smarkm  /// symbol table from the module.
4155682Smarkm  ///
4255682Smarkm  void print(raw_ostream &o, const Module *M) const;
4355682Smarkm
4455682Smarkmprivate:
4555682Smarkm  /// IncorporateType - Incorporate one type and all of its subtypes into the
4655682Smarkm  /// collection of used types.
4755682Smarkm  ///
48233294Sstas  void IncorporateType(Type *Ty);
4955682Smarkm
5055682Smarkm  /// IncorporateValue - Incorporate all of the types used by this value.
5155682Smarkm  ///
5255682Smarkm  void IncorporateValue(const Value *V);
5355682Smarkm
5455682Smarkmpublic:
5555682Smarkm  /// run - This incorporates all types used by the specified module
5672445Sassar  bool runOnModule(Module &M);
5755682Smarkm
5855682Smarkm  /// getAnalysisUsage - We do not modify anything.
59233294Sstas  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
6055682Smarkm    AU.setPreservesAll();
6155682Smarkm  }
6255682Smarkm};
63107207Snectar
64107207Snectar} // End llvm namespace
65107207Snectar
6655682Smarkm#endif
6755682Smarkm