| OLD | NEW |
| 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// |
| 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 /// \file | 10 /// \file |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 template <Type Ty, typename KeyType, typename ValueType> class TypePool { | 123 template <Type Ty, typename KeyType, typename ValueType> class TypePool { |
| 124 TypePool(const TypePool &) = delete; | 124 TypePool(const TypePool &) = delete; |
| 125 TypePool &operator=(const TypePool &) = delete; | 125 TypePool &operator=(const TypePool &) = delete; |
| 126 | 126 |
| 127 public: | 127 public: |
| 128 TypePool() = default; | 128 TypePool() = default; |
| 129 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { | 129 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { |
| 130 auto Iter = Pool.find(Key); | 130 auto Iter = Pool.find(Key); |
| 131 if (Iter != Pool.end()) | 131 if (Iter != Pool.end()) |
| 132 return Iter->second; | 132 return Iter->second; |
| 133 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); | 133 ValueType *Result = ValueType::create(Ctx, Ty, Key); |
| 134 Pool[Key] = Result; | 134 Pool[Key] = Result; |
| 135 return Result; | 135 return Result; |
| 136 } | 136 } |
| 137 ConstantList getConstantPool() const { | 137 ConstantList getConstantPool() const { |
| 138 ConstantList Constants; | 138 ConstantList Constants; |
| 139 Constants.reserve(Pool.size()); | 139 Constants.reserve(Pool.size()); |
| 140 for (auto &I : Pool) | 140 for (auto &I : Pool) |
| 141 Constants.push_back(I.second); | 141 Constants.push_back(I.second); |
| 142 // The sort (and its KeyCompareLess machinery) is not strictly necessary, | 142 // The sort (and its KeyCompareLess machinery) is not strictly necessary, |
| 143 // but is desirable for producing output that is deterministic across | 143 // but is desirable for producing output that is deterministic across |
| 144 // unordered_map::iterator implementations. | 144 // unordered_map::iterator implementations. |
| 145 std::sort(Constants.begin(), Constants.end(), KeyCompareLess<ValueType>()); | 145 std::sort(Constants.begin(), Constants.end(), KeyCompareLess<ValueType>()); |
| 146 return Constants; | 146 return Constants; |
| 147 } | 147 } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 // Use the default hash function, and a custom key comparison function. The | 150 // Use the default hash function, and a custom key comparison function. The |
| 151 // key comparison function for floating point variables can't use the default | 151 // key comparison function for floating point variables can't use the default |
| 152 // == based implementation because of special C++ semantics regarding +0.0, | 152 // == based implementation because of special C++ semantics regarding +0.0, |
| 153 // -0.0, and NaN comparison. However, it's OK to use the default hash for | 153 // -0.0, and NaN comparison. However, it's OK to use the default hash for |
| 154 // floating point values because KeyCompare is the final source of truth - in | 154 // floating point values because KeyCompare is the final source of truth - in |
| 155 // the worst case a "false" collision must be resolved. | 155 // the worst case a "false" collision must be resolved. |
| 156 using ContainerType = | 156 using ContainerType = |
| 157 std::unordered_map<KeyType, ValueType *, std::hash<KeyType>, | 157 std::unordered_map<KeyType, ValueType *, std::hash<KeyType>, |
| 158 KeyCompare<KeyType>>; | 158 KeyCompare<KeyType>>; |
| 159 ContainerType Pool; | 159 ContainerType Pool; |
| 160 uint32_t NextPoolID = 0; | |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 // UndefPool maps ICE types to the corresponding ConstantUndef values. | 162 // UndefPool maps ICE types to the corresponding ConstantUndef values. |
| 164 class UndefPool { | 163 class UndefPool { |
| 165 UndefPool(const UndefPool &) = delete; | 164 UndefPool(const UndefPool &) = delete; |
| 166 UndefPool &operator=(const UndefPool &) = delete; | 165 UndefPool &operator=(const UndefPool &) = delete; |
| 167 | 166 |
| 168 public: | 167 public: |
| 169 UndefPool() : Pool(IceType_NUM) {} | 168 UndefPool() : Pool(IceType_NUM) {} |
| 170 | 169 |
| 171 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { | 170 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { |
| 172 if (Pool[Ty] == nullptr) | 171 if (Pool[Ty] == nullptr) |
| 173 Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++); | 172 Pool[Ty] = ConstantUndef::create(Ctx, Ty); |
| 174 return Pool[Ty]; | 173 return Pool[Ty]; |
| 175 } | 174 } |
| 176 | 175 |
| 177 private: | 176 private: |
| 178 uint32_t NextPoolID = 0; | |
| 179 std::vector<ConstantUndef *> Pool; | 177 std::vector<ConstantUndef *> Pool; |
| 180 }; | 178 }; |
| 181 | 179 |
| 182 } // end of anonymous namespace | 180 } // end of anonymous namespace |
| 183 | 181 |
| 184 // The global constant pool bundles individual pools of each type of | 182 // The global constant pool bundles individual pools of each type of |
| 185 // interest. | 183 // interest. |
| 186 class ConstantPool { | 184 class ConstantPool { |
| 187 ConstantPool(const ConstantPool &) = delete; | 185 ConstantPool(const ConstantPool &) = delete; |
| 188 ConstantPool &operator=(const ConstantPool &) = delete; | 186 ConstantPool &operator=(const ConstantPool &) = delete; |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 Ctx = Func->getContext(); | 1005 Ctx = Func->getContext(); |
| 1008 Active = | 1006 Active = |
| 1009 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 1007 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
| 1010 if (Active) | 1008 if (Active) |
| 1011 Ctx->pushTimer(ID, StackID); | 1009 Ctx->pushTimer(ID, StackID); |
| 1012 } | 1010 } |
| 1013 | 1011 |
| 1014 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 1012 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 1015 | 1013 |
| 1016 } // end of namespace Ice | 1014 } // end of namespace Ice |
| OLD | NEW |