FindUsedTypes.h revision 97f51a3024a72ef8500e95b90e6361e6783160fd
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: 18f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // FindUsedTypes ctor - This pass can optionally include types that are 19f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // referenced only in symbol tables, but the default is not to. 20f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 21facd752d3afaeca7dee46648f2a2ae209a94e5e9Chris Lattner static AnalysisID ID; 22facd752d3afaeca7dee46648f2a2ae209a94e5e9Chris Lattner 23f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // getTypes - After the pass has been run, return the set containing all of 24f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // the types used in the module. 25f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 265d549083e2dc55cc1aa035f1069480d052717061Chris Lattner const std::set<const Type *> &getTypes() const { return UsedTypes; } 27f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 28f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // Print the types found in the module. If the optional Module parameter is 29f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // passed in, then the types are printed symbolically if possible, using the 30f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // symbol table from the module. 31f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 3297f51a3024a72ef8500e95b90e6361e6783160fdChris Lattner void print(std::ostream &o, const Module *M) const; 33f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 34f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattnerprivate: 35f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // IncorporateType - Incorporate one type and all of its subtypes into the 36f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // collection of used types. 37f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 38f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner void IncorporateType(const Type *Ty); 39f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 40fe700e7e4240fa88b8d5f44d1e7d6dcc51495c26Chris Lattnerpublic: 41facd752d3afaeca7dee46648f2a2ae209a94e5e9Chris Lattner // run - This incorporates all types used by the specified module 42f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 437e70829632f82de15db187845666aaca6e04b792Chris Lattner bool run(Module &M); 44f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 45f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner // getAnalysisUsage - Of course, we provide ourself... 46f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner // 47f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner virtual void getAnalysisUsage(AnalysisUsage &AU) const { 48f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner AU.setPreservesAll(); 49f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner AU.addProvided(ID); 50f57b845547302d24ecb6a9e79d7bc386f761a6c9Chris Lattner } 51f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner}; 52f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner 53f26e28711bcc10536036e0c10c931a8ca28b778cChris Lattner#endif 54