Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1019233002: Subzero: Fix floating-point constant pooling. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Simplification Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/abi-atomics.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file defines aspects of the compilation that persist across 10 // This file defines aspects of the compilation that persist across
(...skipping 22 matching lines...) Expand all
33 template <> struct hash<Ice::RelocatableTuple> { 33 template <> struct hash<Ice::RelocatableTuple> {
34 size_t operator()(const Ice::RelocatableTuple &Key) const { 34 size_t operator()(const Ice::RelocatableTuple &Key) const {
35 return hash<Ice::IceString>()(Key.Name) + 35 return hash<Ice::IceString>()(Key.Name) +
36 hash<Ice::RelocOffsetT>()(Key.Offset); 36 hash<Ice::RelocOffsetT>()(Key.Offset);
37 } 37 }
38 }; 38 };
39 } // end of namespace std 39 } // end of namespace std
40 40
41 namespace Ice { 41 namespace Ice {
42 42
43 namespace {
44
45 // Define the key comparison function for the constant pool's
46 // unordered_map, but only for key types of interest: integer types,
47 // floating point types, and the special RelocatableTuple.
48 template <typename KeyType, class Enable = void> struct KeyCompare {};
49
50 template <typename KeyType>
51 struct KeyCompare<KeyType,
52 typename std::enable_if<
53 std::is_integral<KeyType>::value ||
54 std::is_same<KeyType, RelocatableTuple>::value>::type> {
55 bool operator()(const KeyType &Value1, const KeyType &Value2) const {
56 return Value1 == Value2;
57 }
58 };
59 template <typename KeyType>
60 struct KeyCompare<KeyType, typename std::enable_if<
61 std::is_floating_point<KeyType>::value>::type> {
62 bool operator()(const KeyType &Value1, const KeyType &Value2) const {
63 return !memcmp(&Value1, &Value2, sizeof(KeyType));
64 }
65 };
66
43 // TypePool maps constants of type KeyType (e.g. float) to pointers to 67 // TypePool maps constants of type KeyType (e.g. float) to pointers to
44 // type ValueType (e.g. ConstantFloat). 68 // type ValueType (e.g. ConstantFloat).
45 template <Type Ty, typename KeyType, typename ValueType> class TypePool { 69 template <Type Ty, typename KeyType, typename ValueType> class TypePool {
46 TypePool(const TypePool &) = delete; 70 TypePool(const TypePool &) = delete;
47 TypePool &operator=(const TypePool &) = delete; 71 TypePool &operator=(const TypePool &) = delete;
48 72
49 public: 73 public:
50 TypePool() : NextPoolID(0) {} 74 TypePool() : NextPoolID(0) {}
51 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { 75 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) {
52 auto Iter = Pool.find(Key); 76 auto Iter = Pool.find(Key);
53 if (Iter != Pool.end()) 77 if (Iter != Pool.end())
54 return Iter->second; 78 return Iter->second;
55 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); 79 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++);
56 Pool[Key] = Result; 80 Pool[Key] = Result;
57 return Result; 81 return Result;
58 } 82 }
59 ConstantList getConstantPool() const { 83 ConstantList getConstantPool() const {
60 ConstantList Constants; 84 ConstantList Constants;
61 Constants.reserve(Pool.size()); 85 Constants.reserve(Pool.size());
62 for (auto &I : Pool) 86 for (auto &I : Pool)
63 Constants.push_back(I.second); 87 Constants.push_back(I.second);
64 return Constants; 88 return Constants;
65 } 89 }
66 90
67 private: 91 private:
68 typedef std::unordered_map<KeyType, ValueType *> ContainerType; 92 typedef std::unordered_map<KeyType, ValueType *, std::hash<KeyType>,
93 KeyCompare<KeyType>> ContainerType;
JF 2015/03/19 20:33:12 Comment on why using std::hash is OK here but the
Jim Stichnoth 2015/03/20 05:29:48 Done.
69 ContainerType Pool; 94 ContainerType Pool;
70 uint32_t NextPoolID; 95 uint32_t NextPoolID;
71 }; 96 };
72 97
73 // UndefPool maps ICE types to the corresponding ConstantUndef values. 98 // UndefPool maps ICE types to the corresponding ConstantUndef values.
74 class UndefPool { 99 class UndefPool {
75 UndefPool(const UndefPool &) = delete; 100 UndefPool(const UndefPool &) = delete;
76 UndefPool &operator=(const UndefPool &) = delete; 101 UndefPool &operator=(const UndefPool &) = delete;
77 102
78 public: 103 public:
79 UndefPool() : NextPoolID(0), Pool(IceType_NUM) {} 104 UndefPool() : NextPoolID(0), Pool(IceType_NUM) {}
80 105
81 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { 106 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
82 if (Pool[Ty] == nullptr) 107 if (Pool[Ty] == nullptr)
83 Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++); 108 Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++);
84 return Pool[Ty]; 109 return Pool[Ty];
85 } 110 }
86 111
87 private: 112 private:
88 uint32_t NextPoolID; 113 uint32_t NextPoolID;
89 std::vector<ConstantUndef *> Pool; 114 std::vector<ConstantUndef *> Pool;
90 }; 115 };
91 116
117 } // end of anonymous namespace
118
92 // The global constant pool bundles individual pools of each type of 119 // The global constant pool bundles individual pools of each type of
93 // interest. 120 // interest.
94 class ConstantPool { 121 class ConstantPool {
95 ConstantPool(const ConstantPool &) = delete; 122 ConstantPool(const ConstantPool &) = delete;
96 ConstantPool &operator=(const ConstantPool &) = delete; 123 ConstantPool &operator=(const ConstantPool &) = delete;
97 124
98 public: 125 public:
99 ConstantPool() {} 126 ConstantPool() {}
100 TypePool<IceType_f32, float, ConstantFloat> Floats; 127 TypePool<IceType_f32, float, ConstantFloat> Floats;
101 TypePool<IceType_f64, double, ConstantDouble> Doubles; 128 TypePool<IceType_f64, double, ConstantDouble> Doubles;
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 Ctx = Func->getContext(); 768 Ctx = Func->getContext();
742 Active = 769 Active =
743 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 770 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
744 if (Active) 771 if (Active)
745 Ctx->pushTimer(ID, StackID); 772 Ctx->pushTimer(ID, StackID);
746 } 773 }
747 774
748 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 775 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
749 776
750 } // end of namespace Ice 777 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/abi-atomics.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698