OLD | NEW |
1 //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===// | 1 //===-- Bitcode/NaCl/Writer/NaClValueEnumerator.h - ----------*- C++ -*-===// |
| 2 // Number values. |
2 // | 3 // |
3 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
4 // | 5 // |
5 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
7 // | 8 // |
8 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
9 // | 10 // |
10 // This class gives values and types Unique ID's. | 11 // This class gives values and types Unique ID's. |
11 // | 12 // |
12 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
13 | 14 |
14 #ifndef VALUE_ENUMERATOR_H | 15 #ifndef NACL_VALUE_ENUMERATOR_H |
15 #define VALUE_ENUMERATOR_H | 16 #define NACL_VALUE_ENUMERATOR_H |
16 | 17 |
17 #include "llvm/ADT/DenseMap.h" | 18 #include "llvm/ADT/DenseMap.h" |
18 #include "llvm/ADT/SmallVector.h" | 19 #include "llvm/ADT/SmallVector.h" |
19 #include "llvm/IR/Attributes.h" | 20 #include "llvm/IR/Attributes.h" |
20 #include <vector> | 21 #include <vector> |
21 | 22 |
22 namespace llvm { | 23 namespace llvm { |
23 | 24 |
24 class Type; | 25 class Type; |
25 class Value; | 26 class Value; |
26 class Instruction; | 27 class Instruction; |
27 class BasicBlock; | 28 class BasicBlock; |
28 class Function; | 29 class Function; |
29 class Module; | 30 class Module; |
30 class MDNode; | 31 class MDNode; |
31 class NamedMDNode; | 32 class NamedMDNode; |
32 class AttributeSet; | 33 class AttributeSet; |
33 class ValueSymbolTable; | 34 class ValueSymbolTable; |
34 class MDSymbolTable; | 35 class MDSymbolTable; |
35 class raw_ostream; | 36 class raw_ostream; |
36 | 37 |
37 class ValueEnumerator { | 38 class NaClValueEnumerator { |
38 public: | 39 public: |
39 typedef std::vector<Type*> TypeList; | 40 typedef std::vector<Type*> TypeList; |
40 | 41 |
41 // For each value, we remember its Value* and occurrence frequency. | 42 // For each value, we remember its Value* and occurrence frequency. |
42 typedef std::vector<std::pair<const Value*, unsigned> > ValueList; | 43 typedef std::vector<std::pair<const Value*, unsigned> > ValueList; |
43 private: | 44 private: |
44 typedef DenseMap<Type*, unsigned> TypeMapType; | 45 typedef DenseMap<Type*, unsigned> TypeMapType; |
45 TypeMapType TypeMap; | 46 TypeMapType TypeMap; |
46 TypeList Types; | 47 TypeList Types; |
47 | 48 |
(...skipping 28 matching lines...) Expand all Loading... |
76 /// before incorporation. | 77 /// before incorporation. |
77 unsigned NumModuleValues; | 78 unsigned NumModuleValues; |
78 | 79 |
79 /// When a function is incorporated, this is the size of the MDValues list | 80 /// When a function is incorporated, this is the size of the MDValues list |
80 /// before incorporation. | 81 /// before incorporation. |
81 unsigned NumModuleMDValues; | 82 unsigned NumModuleMDValues; |
82 | 83 |
83 unsigned FirstFuncConstantID; | 84 unsigned FirstFuncConstantID; |
84 unsigned FirstInstID; | 85 unsigned FirstInstID; |
85 | 86 |
86 ValueEnumerator(const ValueEnumerator &) LLVM_DELETED_FUNCTION; | 87 NaClValueEnumerator(const NaClValueEnumerator &) LLVM_DELETED_FUNCTION; |
87 void operator=(const ValueEnumerator &) LLVM_DELETED_FUNCTION; | 88 void operator=(const NaClValueEnumerator &) LLVM_DELETED_FUNCTION; |
88 public: | 89 public: |
89 ValueEnumerator(const Module *M); | 90 NaClValueEnumerator(const Module *M); |
90 | 91 |
91 void dump() const; | 92 void dump() const; |
92 void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const; | 93 void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const; |
93 | 94 |
94 unsigned getValueID(const Value *V) const; | 95 unsigned getValueID(const Value *V) const; |
95 | 96 |
96 unsigned getTypeID(Type *T) const { | 97 unsigned getTypeID(Type *T) const { |
97 TypeMapType::const_iterator I = TypeMap.find(T); | 98 TypeMapType::const_iterator I = TypeMap.find(T); |
98 assert(I != TypeMap.end() && "Type not in ValueEnumerator!"); | 99 assert(I != TypeMap.end() && "Type not in NaClValueEnumerator!"); |
99 return I->second-1; | 100 return I->second-1; |
100 } | 101 } |
101 | 102 |
102 unsigned getInstructionID(const Instruction *I) const; | 103 unsigned getInstructionID(const Instruction *I) const; |
103 void setInstructionID(const Instruction *I); | 104 void setInstructionID(const Instruction *I); |
104 | 105 |
105 unsigned getAttributeID(AttributeSet PAL) const { | 106 unsigned getAttributeID(AttributeSet PAL) const { |
106 if (PAL.isEmpty()) return 0; // Null maps to zero. | 107 if (PAL.isEmpty()) return 0; // Null maps to zero. |
107 AttributeMapType::const_iterator I = AttributeMap.find(PAL); | 108 AttributeMapType::const_iterator I = AttributeMap.find(PAL); |
108 assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!"); | 109 assert(I != AttributeMap.end() && "Attribute not in NaClValueEnumerator!"); |
109 return I->second; | 110 return I->second; |
110 } | 111 } |
111 | 112 |
112 unsigned getAttributeGroupID(AttributeSet PAL) const { | 113 unsigned getAttributeGroupID(AttributeSet PAL) const { |
113 if (PAL.isEmpty()) return 0; // Null maps to zero. | 114 if (PAL.isEmpty()) return 0; // Null maps to zero. |
114 AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(PAL); | 115 AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(PAL); |
115 assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!"); | 116 assert(I != AttributeGroupMap.end() && "Attribute not in NaClValueEnumerator
!"); |
116 return I->second; | 117 return I->second; |
117 } | 118 } |
118 | 119 |
119 /// getFunctionConstantRange - Return the range of values that corresponds to | 120 /// getFunctionConstantRange - Return the range of values that corresponds to |
120 /// function-local constants. | 121 /// function-local constants. |
121 void getFunctionConstantRange(unsigned &Start, unsigned &End) const { | 122 void getFunctionConstantRange(unsigned &Start, unsigned &End) const { |
122 Start = FirstFuncConstantID; | 123 Start = FirstFuncConstantID; |
123 End = FirstInstID; | 124 End = FirstInstID; |
124 } | 125 } |
125 | 126 |
(...skipping 12 matching lines...) Expand all Loading... |
138 const std::vector<AttributeSet> &getAttributeGroups() const { | 139 const std::vector<AttributeSet> &getAttributeGroups() const { |
139 return AttributeGroups; | 140 return AttributeGroups; |
140 } | 141 } |
141 | 142 |
142 /// getGlobalBasicBlockID - This returns the function-specific ID for the | 143 /// getGlobalBasicBlockID - This returns the function-specific ID for the |
143 /// specified basic block. This is relatively expensive information, so it | 144 /// specified basic block. This is relatively expensive information, so it |
144 /// should only be used by rare constructs such as address-of-label. | 145 /// should only be used by rare constructs such as address-of-label. |
145 unsigned getGlobalBasicBlockID(const BasicBlock *BB) const; | 146 unsigned getGlobalBasicBlockID(const BasicBlock *BB) const; |
146 | 147 |
147 /// incorporateFunction/purgeFunction - If you'd like to deal with a function, | 148 /// incorporateFunction/purgeFunction - If you'd like to deal with a function, |
148 /// use these two methods to get its data into the ValueEnumerator! | 149 /// use these two methods to get its data into the NaClValueEnumerator! |
149 /// | 150 /// |
150 void incorporateFunction(const Function &F); | 151 void incorporateFunction(const Function &F); |
151 void purgeFunction(); | 152 void purgeFunction(); |
152 | 153 |
153 private: | 154 private: |
154 void OptimizeConstants(unsigned CstStart, unsigned CstEnd); | 155 void OptimizeConstants(unsigned CstStart, unsigned CstEnd); |
155 | 156 |
156 void EnumerateMDNodeOperands(const MDNode *N); | 157 void EnumerateMDNodeOperands(const MDNode *N); |
157 void EnumerateMetadata(const Value *MD); | 158 void EnumerateMetadata(const Value *MD); |
158 void EnumerateFunctionLocalMetadata(const MDNode *N); | 159 void EnumerateFunctionLocalMetadata(const MDNode *N); |
159 void EnumerateNamedMDNode(const NamedMDNode *NMD); | 160 void EnumerateNamedMDNode(const NamedMDNode *NMD); |
160 void EnumerateValue(const Value *V); | 161 void EnumerateValue(const Value *V); |
161 void EnumerateType(Type *T); | 162 void EnumerateType(Type *T); |
162 void EnumerateOperandType(const Value *V); | 163 void EnumerateOperandType(const Value *V); |
163 void EnumerateAttributes(AttributeSet PAL); | 164 void EnumerateAttributes(AttributeSet PAL); |
164 | 165 |
165 void EnumerateValueSymbolTable(const ValueSymbolTable &ST); | 166 void EnumerateValueSymbolTable(const ValueSymbolTable &ST); |
166 void EnumerateNamedMetadata(const Module *M); | 167 void EnumerateNamedMetadata(const Module *M); |
167 }; | 168 }; |
168 | 169 |
169 } // End llvm namespace | 170 } // End llvm namespace |
170 | 171 |
171 #endif | 172 #endif |
OLD | NEW |