LLVM  3.7.0
TypeFinder.h
Go to the documentation of this file.
1 //===-- llvm/IR/TypeFinder.h - Class to find used struct types --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the TypeFinder class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_TYPEFINDER_H
15 #define LLVM_IR_TYPEFINDER_H
16 
17 #include "llvm/ADT/DenseSet.h"
18 #include <vector>
19 
20 namespace llvm {
21 
22 class MDNode;
23 class Module;
24 class StructType;
25 class Type;
26 class Value;
27 
28 /// TypeFinder - Walk over a module, identifying all of the types that are
29 /// used by the module.
30 class TypeFinder {
31  // To avoid walking constant expressions multiple times and other IR
32  // objects, we keep several helper maps.
33  DenseSet<const Value*> VisitedConstants;
34  DenseSet<const MDNode *> VisitedMetadata;
35  DenseSet<Type*> VisitedTypes;
36 
37  std::vector<StructType*> StructTypes;
38  bool OnlyNamed;
39 
40 public:
41  TypeFinder() : OnlyNamed(false) {}
42 
43  void run(const Module &M, bool onlyNamed);
44  void clear();
45 
46  typedef std::vector<StructType*>::iterator iterator;
47  typedef std::vector<StructType*>::const_iterator const_iterator;
48 
49  iterator begin() { return StructTypes.begin(); }
50  iterator end() { return StructTypes.end(); }
51 
52  const_iterator begin() const { return StructTypes.begin(); }
53  const_iterator end() const { return StructTypes.end(); }
54 
55  bool empty() const { return StructTypes.empty(); }
56  size_t size() const { return StructTypes.size(); }
57  iterator erase(iterator I, iterator E) { return StructTypes.erase(I, E); }
58 
59  StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; }
60 
61 private:
62  /// incorporateType - This method adds the type to the list of used
63  /// structures if it's not in there already.
64  void incorporateType(Type *Ty);
65 
66  /// incorporateValue - This method is used to walk operand lists finding types
67  /// hiding in constant expressions and other operands that won't be walked in
68  /// other ways. GlobalValues, basic blocks, instructions, and inst operands
69  /// are all explicitly enumerated.
70  void incorporateValue(const Value *V);
71 
72  /// incorporateMDNode - This method is used to walk the operands of an MDNode
73  /// to find types hiding within.
74  void incorporateMDNode(const MDNode *V);
75 };
76 
77 } // end llvm namespace
78 
79 #endif
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
Metadata node.
Definition: Metadata.h:740
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
const_iterator end() const
Definition: TypeFinder.h:53
#define false
Definition: ConvertUTF.c:65
const_iterator begin() const
Definition: TypeFinder.h:52
bool empty() const
Definition: TypeFinder.h:55
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
StructType *& operator[](unsigned Idx)
Definition: TypeFinder.h:59
void run(const Module &M, bool onlyNamed)
Definition: TypeFinder.cpp:23
iterator end()
Definition: TypeFinder.h:50
std::vector< StructType * >::const_iterator const_iterator
Definition: TypeFinder.h:47
#define I(x, y, z)
Definition: MD5.cpp:54
std::vector< StructType * >::iterator iterator
Definition: TypeFinder.h:46
iterator erase(iterator I, iterator E)
Definition: TypeFinder.h:57
size_t size() const
Definition: TypeFinder.h:56
LLVM Value Representation.
Definition: Value.h:69
iterator begin()
Definition: TypeFinder.h:49
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
Definition: TypeFinder.h:30