OLD | NEW |
---|---|
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
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 file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // KeyTypeHasFP indicates whether KeyType is a floating-point type | 27 // KeyTypeHasFP indicates whether KeyType is a floating-point type |
28 // whose values need to be compared using memcmp() for NaN | 28 // whose values need to be compared using memcmp() for NaN |
29 // correctness. TODO: use std::is_floating_point<KeyType> instead of | 29 // correctness. TODO: use std::is_floating_point<KeyType> instead of |
30 // KeyTypeHasFP with C++11. | 30 // KeyTypeHasFP with C++11. |
31 template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false> | 31 template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false> |
32 class TypePool { | 32 class TypePool { |
33 TypePool(const TypePool &) LLVM_DELETED_FUNCTION; | 33 TypePool(const TypePool &) LLVM_DELETED_FUNCTION; |
34 TypePool &operator=(const TypePool &) LLVM_DELETED_FUNCTION; | 34 TypePool &operator=(const TypePool &) LLVM_DELETED_FUNCTION; |
35 | 35 |
36 public: | 36 public: |
37 TypePool() {} | 37 TypePool() : NextPoolID(0) {} |
38 ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { | 38 ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { |
39 TupleType TupleKey = std::make_pair(Ty, Key); | 39 TupleType TupleKey = std::make_pair(Ty, Key); |
40 typename ContainerType::const_iterator Iter = Pool.find(TupleKey); | 40 typename ContainerType::const_iterator Iter = Pool.find(TupleKey); |
41 if (Iter != Pool.end()) | 41 if (Iter != Pool.end()) |
42 return Iter->second; | 42 return Iter->second; |
43 ValueType *Result = ValueType::create(Ctx, Ty, Key); | 43 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); |
44 Pool[TupleKey] = Result; | 44 Pool[TupleKey] = Result; |
45 return Result; | 45 return Result; |
46 } | 46 } |
47 ConstantList getConstantPool() const { | |
48 ConstantList Constants; | |
49 Constants.reserve(Pool.size()); | |
50 for (typename ContainerType::const_iterator I = Pool.begin(), | |
51 E = Pool.end(); | |
52 I != E; ++I) { | |
53 Constants.push_back((*I).second); | |
JF
2014/05/22 21:39:47
I->second ?
Also, C++11 lambdas would be nice her
Jim Stichnoth
2014/05/22 23:48:28
Done.
| |
54 } | |
55 return Constants; | |
56 } | |
47 | 57 |
48 private: | 58 private: |
49 typedef std::pair<Type, KeyType> TupleType; | 59 typedef std::pair<Type, KeyType> TupleType; |
50 struct TupleCompare { | 60 struct TupleCompare { |
51 bool operator()(const TupleType &A, const TupleType &B) { | 61 bool operator()(const TupleType &A, const TupleType &B) { |
52 if (A.first != B.first) | 62 if (A.first != B.first) |
53 return A.first < B.first; | 63 return A.first < B.first; |
54 if (KeyTypeHasFP) | 64 if (KeyTypeHasFP) |
55 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; | 65 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; |
56 return A.second < B.second; | 66 return A.second < B.second; |
57 } | 67 } |
58 }; | 68 }; |
59 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; | 69 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; |
60 ContainerType Pool; | 70 ContainerType Pool; |
71 uint32_t NextPoolID; | |
61 }; | 72 }; |
62 | 73 |
63 // The global constant pool bundles individual pools of each type of | 74 // The global constant pool bundles individual pools of each type of |
64 // interest. | 75 // interest. |
65 class ConstantPool { | 76 class ConstantPool { |
66 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; | 77 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; |
67 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; | 78 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; |
68 | 79 |
69 public: | 80 public: |
70 ConstantPool() {} | 81 ConstantPool() {} |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); | 175 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |
165 } | 176 } |
166 | 177 |
167 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, | 178 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |
168 const IceString &Name, | 179 const IceString &Name, |
169 bool SuppressMangling) { | 180 bool SuppressMangling) { |
170 return ConstPool->Relocatables.getOrAdd( | 181 return ConstPool->Relocatables.getOrAdd( |
171 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); | 182 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |
172 } | 183 } |
173 | 184 |
185 ConstantList GlobalContext::getConstantPool(Type Ty) const { | |
186 if (Ty == IceType_f32) | |
187 return ConstPool->Floats.getConstantPool(); | |
188 if (Ty == IceType_f64) | |
189 return ConstPool->Doubles.getConstantPool(); | |
190 return ConstPool->Integers.getConstantPool(); | |
JF
2014/05/22 21:39:47
A switch would be nice, so that if you add types y
Jim Stichnoth
2014/05/22 23:48:28
Done.
| |
191 } | |
192 | |
174 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 193 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
175 if (Ctx->isVerbose(IceV_Timing)) { | 194 if (Ctx->isVerbose(IceV_Timing)) { |
176 // Prefixing with '#' allows timing strings to be included | 195 // Prefixing with '#' allows timing strings to be included |
177 // without error in textual assembly output. | 196 // without error in textual assembly output. |
178 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 197 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
179 } | 198 } |
180 } | 199 } |
181 | 200 |
182 } // end of namespace Ice | 201 } // end of namespace Ice |
OLD | NEW |