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