LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ValueEnumerator.h
Go to the documentation of this file.
1 //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- 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 class gives values and types Unique ID's.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef VALUE_ENUMERATOR_H
15 #define VALUE_ENUMERATOR_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/IR/Attributes.h"
20 #include <vector>
21 
22 namespace llvm {
23 
24 class Type;
25 class Value;
26 class Instruction;
27 class BasicBlock;
28 class Function;
29 class Module;
30 class MDNode;
31 class NamedMDNode;
32 class AttributeSet;
33 class ValueSymbolTable;
34 class MDSymbolTable;
35 class raw_ostream;
36 
38 public:
39  typedef std::vector<Type*> TypeList;
40 
41  // For each value, we remember its Value* and occurrence frequency.
42  typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
43 private:
45  TypeMapType TypeMap;
46  TypeList Types;
47 
50  ValueList Values;
51  ValueList MDValues;
52  SmallVector<const MDNode *, 8> FunctionLocalMDs;
53  ValueMapType MDValueMap;
54 
56  AttributeGroupMapType AttributeGroupMap;
57  std::vector<AttributeSet> AttributeGroups;
58 
60  AttributeMapType AttributeMap;
61  std::vector<AttributeSet> Attribute;
62 
63  /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
64  /// the "getGlobalBasicBlockID" method.
65  mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
66 
68  InstructionMapType InstructionMap;
69  unsigned InstructionCount;
70 
71  /// BasicBlocks - This contains all the basic blocks for the currently
72  /// incorporated function. Their reverse mapping is stored in ValueMap.
73  std::vector<const BasicBlock*> BasicBlocks;
74 
75  /// When a function is incorporated, this is the size of the Values list
76  /// before incorporation.
77  unsigned NumModuleValues;
78 
79  /// When a function is incorporated, this is the size of the MDValues list
80  /// before incorporation.
81  unsigned NumModuleMDValues;
82 
83  unsigned FirstFuncConstantID;
84  unsigned FirstInstID;
85 
87  void operator=(const ValueEnumerator &) LLVM_DELETED_FUNCTION;
88 public:
89  ValueEnumerator(const Module *M);
90 
91  void dump() const;
92  void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
93 
94  unsigned getValueID(const Value *V) const;
95 
96  unsigned getTypeID(Type *T) const {
97  TypeMapType::const_iterator I = TypeMap.find(T);
98  assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
99  return I->second-1;
100  }
101 
102  unsigned getInstructionID(const Instruction *I) const;
103  void setInstructionID(const Instruction *I);
104 
105  unsigned getAttributeID(AttributeSet PAL) const {
106  if (PAL.isEmpty()) return 0; // Null maps to zero.
107  AttributeMapType::const_iterator I = AttributeMap.find(PAL);
108  assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
109  return I->second;
110  }
111 
112  unsigned getAttributeGroupID(AttributeSet PAL) const {
113  if (PAL.isEmpty()) return 0; // Null maps to zero.
114  AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(PAL);
115  assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");
116  return I->second;
117  }
118 
119  /// getFunctionConstantRange - Return the range of values that corresponds to
120  /// function-local constants.
121  void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
122  Start = FirstFuncConstantID;
123  End = FirstInstID;
124  }
125 
126  const ValueList &getValues() const { return Values; }
127  const ValueList &getMDValues() const { return MDValues; }
129  return FunctionLocalMDs;
130  }
131  const TypeList &getTypes() const { return Types; }
132  const std::vector<const BasicBlock*> &getBasicBlocks() const {
133  return BasicBlocks;
134  }
135  const std::vector<AttributeSet> &getAttributes() const {
136  return Attribute;
137  }
138  const std::vector<AttributeSet> &getAttributeGroups() const {
139  return AttributeGroups;
140  }
141 
142  /// getGlobalBasicBlockID - This returns the function-specific ID for the
143  /// specified basic block. This is relatively expensive information, so it
144  /// should only be used by rare constructs such as address-of-label.
145  unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
146 
147  /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
148  /// use these two methods to get its data into the ValueEnumerator!
149  ///
150  void incorporateFunction(const Function &F);
151  void purgeFunction();
152 
153 private:
154  void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
155 
156  void EnumerateMDNodeOperands(const MDNode *N);
157  void EnumerateMetadata(const Value *MD);
158  void EnumerateFunctionLocalMetadata(const MDNode *N);
159  void EnumerateNamedMDNode(const NamedMDNode *NMD);
160  void EnumerateValue(const Value *V);
161  void EnumerateType(Type *T);
162  void EnumerateOperandType(const Value *V);
163  void EnumerateAttributes(AttributeSet PAL);
164 
165  void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
166  void EnumerateNamedMetadata(const Module *M);
167 };
168 
169 } // End llvm namespace
170 
171 #endif
COFF::RelocationTypeX86 Type
Definition: COFFYAML.cpp:227
Various leaf nodes.
Definition: ISDOpcodes.h:60
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
void setInstructionID(const Instruction *I)
MDNode - a tuple of other values.
Definition: Metadata.h:69
F(f)
std::vector< std::pair< const Value *, unsigned > > ValueList
void incorporateFunction(const Function &F)
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getAttributeID(AttributeSet PAL) const
const TypeList & getTypes() const
unsigned getInstructionID(const Instruction *I) const
unsigned getValueID(const Value *V) const
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
const ValueList & getMDValues() const
const ValueList & getValues() const
const std::vector< AttributeSet > & getAttributes() const
unsigned getTypeID(Type *T) const
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
unsigned getAttributeGroupID(AttributeSet PAL) const
iterator end()
Definition: DenseMap.h:57
See the file comment.
Definition: ValueMap.h:75
const std::vector< AttributeSet > & getAttributeGroups() const
const std::vector< const BasicBlock * > & getBasicBlocks() const
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
const SmallVectorImpl< const MDNode * > & getFunctionLocalMDValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
LLVM Value Representation.
Definition: Value.h:66
std::vector< Type * > TypeList
iterator find(const KeyT &Val)
Definition: DenseMap.h:108
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:345