LLVM API Documentation

FindUsedTypes.h
Go to the documentation of this file.
00001 //===- llvm/Analysis/FindUsedTypes.h - Find all Types in use ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This pass is used to seek out all of the types in use by the program.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_ANALYSIS_FINDUSEDTYPES_H
00015 #define LLVM_ANALYSIS_FINDUSEDTYPES_H
00016 
00017 #include "llvm/ADT/SetVector.h"
00018 #include "llvm/Pass.h"
00019 
00020 namespace llvm {
00021 
00022 class Type;
00023 class Value;
00024 
00025 class FindUsedTypes : public ModulePass {
00026   SetVector<Type *> UsedTypes;
00027 public:
00028   static char ID; // Pass identification, replacement for typeid
00029   FindUsedTypes() : ModulePass(ID) {
00030     initializeFindUsedTypesPass(*PassRegistry::getPassRegistry());
00031   }
00032 
00033   /// getTypes - After the pass has been run, return the set containing all of
00034   /// the types used in the module.
00035   ///
00036   const SetVector<Type *> &getTypes() const { return UsedTypes; }
00037 
00038   /// Print the types found in the module.  If the optional Module parameter is
00039   /// passed in, then the types are printed symbolically if possible, using the
00040   /// symbol table from the module.
00041   ///
00042   void print(raw_ostream &o, const Module *M) const override;
00043 
00044 private:
00045   /// IncorporateType - Incorporate one type and all of its subtypes into the
00046   /// collection of used types.
00047   ///
00048   void IncorporateType(Type *Ty);
00049 
00050   /// IncorporateValue - Incorporate all of the types used by this value.
00051   ///
00052   void IncorporateValue(const Value *V);
00053 
00054 public:
00055   /// run - This incorporates all types used by the specified module
00056   bool runOnModule(Module &M) override;
00057 
00058   /// getAnalysisUsage - We do not modify anything.
00059   void getAnalysisUsage(AnalysisUsage &AU) const override {
00060     AU.setPreservesAll();
00061   }
00062 };
00063 
00064 } // End llvm namespace
00065 
00066 #endif