| 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     // TODO: replace the loop with std::transform + lambdas. | 
 |   51     for (typename ContainerType::const_iterator I = Pool.begin(), | 
 |   52                                                 E = Pool.end(); | 
 |   53          I != E; ++I) { | 
 |   54       Constants.push_back(I->second); | 
 |   55     } | 
 |   56     return Constants; | 
 |   57   } | 
|   47  |   58  | 
|   48 private: |   59 private: | 
|   49   typedef std::pair<Type, KeyType> TupleType; |   60   typedef std::pair<Type, KeyType> TupleType; | 
|   50   struct TupleCompare { |   61   struct TupleCompare { | 
|   51     bool operator()(const TupleType &A, const TupleType &B) { |   62     bool operator()(const TupleType &A, const TupleType &B) { | 
|   52       if (A.first != B.first) |   63       if (A.first != B.first) | 
|   53         return A.first < B.first; |   64         return A.first < B.first; | 
|   54       if (KeyTypeHasFP) |   65       if (KeyTypeHasFP) | 
|   55         return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; |   66         return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; | 
|   56       return A.second < B.second; |   67       return A.second < B.second; | 
|   57     } |   68     } | 
|   58   }; |   69   }; | 
|   59   typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; |   70   typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; | 
|   60   ContainerType Pool; |   71   ContainerType Pool; | 
 |   72   uint32_t NextPoolID; | 
|   61 }; |   73 }; | 
|   62  |   74  | 
|   63 // The global constant pool bundles individual pools of each type of |   75 // The global constant pool bundles individual pools of each type of | 
|   64 // interest. |   76 // interest. | 
|   65 class ConstantPool { |   77 class ConstantPool { | 
|   66   ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; |   78   ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; | 
|   67   ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; |   79   ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; | 
|   68  |   80  | 
|   69 public: |   81 public: | 
|   70   ConstantPool() {} |   82   ConstantPool() {} | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  164   return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |  176   return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); | 
|  165 } |  177 } | 
|  166  |  178  | 
|  167 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |  179 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, | 
|  168                                         const IceString &Name, |  180                                         const IceString &Name, | 
|  169                                         bool SuppressMangling) { |  181                                         bool SuppressMangling) { | 
|  170   return ConstPool->Relocatables.getOrAdd( |  182   return ConstPool->Relocatables.getOrAdd( | 
|  171       this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |  183       this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); | 
|  172 } |  184 } | 
|  173  |  185  | 
 |  186 ConstantList GlobalContext::getConstantPool(Type Ty) const { | 
 |  187   switch (Ty) { | 
 |  188   case IceType_i1: | 
 |  189   case IceType_i8: | 
 |  190   case IceType_i16: | 
 |  191   case IceType_i32: | 
 |  192   case IceType_i64: | 
 |  193     return ConstPool->Integers.getConstantPool(); | 
 |  194   case IceType_f32: | 
 |  195     return ConstPool->Floats.getConstantPool(); | 
 |  196   case IceType_f64: | 
 |  197     return ConstPool->Doubles.getConstantPool(); | 
 |  198   case IceType_void: | 
 |  199   case IceType_NUM: | 
 |  200     break; | 
 |  201   } | 
 |  202   llvm_unreachable("Unknown type"); | 
 |  203 } | 
 |  204  | 
|  174 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |  205 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 
|  175   if (Ctx->isVerbose(IceV_Timing)) { |  206   if (Ctx->isVerbose(IceV_Timing)) { | 
|  176     // Prefixing with '#' allows timing strings to be included |  207     // Prefixing with '#' allows timing strings to be included | 
|  177     // without error in textual assembly output. |  208     // without error in textual assembly output. | 
|  178     Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |  209     Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 
|  179   } |  210   } | 
|  180 } |  211 } | 
|  181  |  212  | 
|  182 } // end of namespace Ice |  213 } // end of namespace Ice | 
| OLD | NEW |