FindUsedTypes.h revision 697954c15da58bd8b186dbafdedd8b06db770201
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; 13f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 14f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerclass FindUsedTypes : public Pass { 15697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner std::set<const Type *> UsedTypes; 16f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 17f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner bool IncludeSymbolTables; 18f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerpublic: 19f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 20f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // FindUsedTypes ctor - This pass can optionally include types that are 21f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // referenced only in symbol tables, but the default is not to. 22f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 23f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner FindUsedTypes(bool IST = false) : IncludeSymbolTables(IST) {} 24f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 25f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // getTypes - After the pass has been run, return the set containing all of 26f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // the types used in the module. 27f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 28697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner inline const std::set<const Type *> &getTypes() const { return UsedTypes; } 29f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 30f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // Print the types found in the module. If the optional Module parameter is 31f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // passed in, then the types are printed symbolically if possible, using the 32f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // symbol table from the module. 33f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 34697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner void printTypes(std::ostream &o, const Module *M = 0) const; 35f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 36f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerprivate: 37f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // IncorporateType - Incorporate one type and all of its subtypes into the 38f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // collection of used types. 39f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 40f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner void IncorporateType(const Type *Ty); 41f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 42f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // IncorporateSymbolTable - Add all types referenced by the specified symtab 43f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // into the collection of used types. 44f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 45f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner void IncorporateSymbolTable(const SymbolTable *ST); 46f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 47fe700e7e4240fa88b8d5f44d1e7d6dcc51495c26Chris Lattnerpublic: 48f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // doPassInitialization - This loops over global constants defined in the 49f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // module, converting them to their new type. 50f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 51f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner bool doPassInitialization(Module *M); 52f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 53f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // doPerMethodWork - This incorporates all types used by the specified method 54f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 55f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner bool doPerMethodWork(Method *M); 56f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner}; 57f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 58f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#endif 59