LLVM API Documentation
00001 //===-- llvm/IR/TypeFinder.h - Class to find used struct types --*- 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 file contains the declaration of the TypeFinder class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_IR_TYPEFINDER_H 00015 #define LLVM_IR_TYPEFINDER_H 00016 00017 #include "llvm/ADT/DenseSet.h" 00018 #include <vector> 00019 00020 namespace llvm { 00021 00022 class MDNode; 00023 class Module; 00024 class StructType; 00025 class Type; 00026 class Value; 00027 00028 /// TypeFinder - Walk over a module, identifying all of the types that are 00029 /// used by the module. 00030 class TypeFinder { 00031 // To avoid walking constant expressions multiple times and other IR 00032 // objects, we keep several helper maps. 00033 DenseSet<const Value*> VisitedConstants; 00034 DenseSet<Type*> VisitedTypes; 00035 00036 std::vector<StructType*> StructTypes; 00037 bool OnlyNamed; 00038 00039 public: 00040 TypeFinder() : OnlyNamed(false) {} 00041 00042 void run(const Module &M, bool onlyNamed); 00043 void clear(); 00044 00045 typedef std::vector<StructType*>::iterator iterator; 00046 typedef std::vector<StructType*>::const_iterator const_iterator; 00047 00048 iterator begin() { return StructTypes.begin(); } 00049 iterator end() { return StructTypes.end(); } 00050 00051 const_iterator begin() const { return StructTypes.begin(); } 00052 const_iterator end() const { return StructTypes.end(); } 00053 00054 bool empty() const { return StructTypes.empty(); } 00055 size_t size() const { return StructTypes.size(); } 00056 iterator erase(iterator I, iterator E) { return StructTypes.erase(I, E); } 00057 00058 StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; } 00059 00060 private: 00061 /// incorporateType - This method adds the type to the list of used 00062 /// structures if it's not in there already. 00063 void incorporateType(Type *Ty); 00064 00065 /// incorporateValue - This method is used to walk operand lists finding types 00066 /// hiding in constant expressions and other operands that won't be walked in 00067 /// other ways. GlobalValues, basic blocks, instructions, and inst operands 00068 /// are all explicitly enumerated. 00069 void incorporateValue(const Value *V); 00070 00071 /// incorporateMDNode - This method is used to walk the operands of an MDNode 00072 /// to find types hiding within. 00073 void incorporateMDNode(const MDNode *V); 00074 }; 00075 00076 } // end llvm namespace 00077 00078 #endif