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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1197223002: Subzero: Use C++11 member initializers where practical. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Rebase Created 5 years, 6 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 | « src/IceGlobalContext.h ('k') | src/IceGlobalInits.h » ('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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 }; 114 };
115 115
116 // TypePool maps constants of type KeyType (e.g. float) to pointers to 116 // TypePool maps constants of type KeyType (e.g. float) to pointers to
117 // type ValueType (e.g. ConstantFloat). 117 // type ValueType (e.g. ConstantFloat).
118 template <Type Ty, typename KeyType, typename ValueType> class TypePool { 118 template <Type Ty, typename KeyType, typename ValueType> class TypePool {
119 TypePool(const TypePool &) = delete; 119 TypePool(const TypePool &) = delete;
120 TypePool &operator=(const TypePool &) = delete; 120 TypePool &operator=(const TypePool &) = delete;
121 121
122 public: 122 public:
123 TypePool() : NextPoolID(0) {} 123 TypePool() = default;
124 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { 124 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) {
125 auto Iter = Pool.find(Key); 125 auto Iter = Pool.find(Key);
126 if (Iter != Pool.end()) 126 if (Iter != Pool.end())
127 return Iter->second; 127 return Iter->second;
128 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); 128 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++);
129 Pool[Key] = Result; 129 Pool[Key] = Result;
130 return Result; 130 return Result;
131 } 131 }
132 ConstantList getConstantPool() const { 132 ConstantList getConstantPool() const {
133 ConstantList Constants; 133 ConstantList Constants;
(...skipping 11 matching lines...) Expand all
145 // Use the default hash function, and a custom key comparison 145 // Use the default hash function, and a custom key comparison
146 // function. The key comparison function for floating point 146 // function. The key comparison function for floating point
147 // variables can't use the default == based implementation because 147 // variables can't use the default == based implementation because
148 // of special C++ semantics regarding +0.0, -0.0, and NaN 148 // of special C++ semantics regarding +0.0, -0.0, and NaN
149 // comparison. However, it's OK to use the default hash for 149 // comparison. However, it's OK to use the default hash for
150 // floating point values because KeyCompare is the final source of 150 // floating point values because KeyCompare is the final source of
151 // truth - in the worst case a "false" collision must be resolved. 151 // truth - in the worst case a "false" collision must be resolved.
152 typedef std::unordered_map<KeyType, ValueType *, std::hash<KeyType>, 152 typedef std::unordered_map<KeyType, ValueType *, std::hash<KeyType>,
153 KeyCompare<KeyType>> ContainerType; 153 KeyCompare<KeyType>> ContainerType;
154 ContainerType Pool; 154 ContainerType Pool;
155 uint32_t NextPoolID; 155 uint32_t NextPoolID = 0;
156 }; 156 };
157 157
158 // UndefPool maps ICE types to the corresponding ConstantUndef values. 158 // UndefPool maps ICE types to the corresponding ConstantUndef values.
159 class UndefPool { 159 class UndefPool {
160 UndefPool(const UndefPool &) = delete; 160 UndefPool(const UndefPool &) = delete;
161 UndefPool &operator=(const UndefPool &) = delete; 161 UndefPool &operator=(const UndefPool &) = delete;
162 162
163 public: 163 public:
164 UndefPool() : NextPoolID(0), Pool(IceType_NUM) {} 164 UndefPool() : Pool(IceType_NUM) {}
165 165
166 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { 166 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
167 if (Pool[Ty] == nullptr) 167 if (Pool[Ty] == nullptr)
168 Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++); 168 Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++);
169 return Pool[Ty]; 169 return Pool[Ty];
170 } 170 }
171 171
172 private: 172 private:
173 uint32_t NextPoolID; 173 uint32_t NextPoolID = 0;
174 std::vector<ConstantUndef *> Pool; 174 std::vector<ConstantUndef *> Pool;
175 }; 175 };
176 176
177 } // end of anonymous namespace 177 } // end of anonymous namespace
178 178
179 // The global constant pool bundles individual pools of each type of 179 // The global constant pool bundles individual pools of each type of
180 // interest. 180 // interest.
181 class ConstantPool { 181 class ConstantPool {
182 ConstantPool(const ConstantPool &) = delete; 182 ConstantPool(const ConstantPool &) = delete;
183 ConstantPool &operator=(const ConstantPool &) = delete; 183 ConstantPool &operator=(const ConstantPool &) = delete;
184 184
185 public: 185 public:
186 ConstantPool() {} 186 ConstantPool() = default;
187 TypePool<IceType_f32, float, ConstantFloat> Floats; 187 TypePool<IceType_f32, float, ConstantFloat> Floats;
188 TypePool<IceType_f64, double, ConstantDouble> Doubles; 188 TypePool<IceType_f64, double, ConstantDouble> Doubles;
189 TypePool<IceType_i1, int8_t, ConstantInteger32> Integers1; 189 TypePool<IceType_i1, int8_t, ConstantInteger32> Integers1;
190 TypePool<IceType_i8, int8_t, ConstantInteger32> Integers8; 190 TypePool<IceType_i8, int8_t, ConstantInteger32> Integers8;
191 TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16; 191 TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16;
192 TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32; 192 TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32;
193 TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64; 193 TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64;
194 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables; 194 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables;
195 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> 195 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable>
196 ExternRelocatables; 196 ExternRelocatables;
(...skipping 20 matching lines...) Expand all
217 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, 217 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
218 ELFStreamer *ELFStr, const ClFlags &Flags) 218 ELFStreamer *ELFStr, const ClFlags &Flags)
219 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), 219 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump),
220 StrEmit(OsEmit), StrError(OsError), Flags(Flags), 220 StrEmit(OsEmit), StrError(OsError), Flags(Flags),
221 RNG(Flags.getRandomSeed()), ObjectWriter(), 221 RNG(Flags.getRandomSeed()), ObjectWriter(),
222 OptQ(/*Sequential=*/Flags.isSequential(), 222 OptQ(/*Sequential=*/Flags.isSequential(),
223 /*MaxSize=*/Flags.getNumTranslationThreads()), 223 /*MaxSize=*/Flags.getNumTranslationThreads()),
224 // EmitQ is allowed unlimited size. 224 // EmitQ is allowed unlimited size.
225 EmitQ(/*Sequential=*/Flags.isSequential()), 225 EmitQ(/*Sequential=*/Flags.isSequential()),
226 DataLowering(TargetDataLowering::createLowering(this)), 226 DataLowering(TargetDataLowering::createLowering(this)),
227 HasSeenCode(false), 227 ProfileBlockInfoVarDecl(VariableDeclaration::create()) {
228 ProfileBlockInfoVarDecl(VariableDeclaration::create()),
229 RandomizationCookie(0) {
230 assert(OsDump && "OsDump is not defined for GlobalContext"); 228 assert(OsDump && "OsDump is not defined for GlobalContext");
231 assert(OsEmit && "OsEmit is not defined for GlobalContext"); 229 assert(OsEmit && "OsEmit is not defined for GlobalContext");
232 assert(OsError && "OsError is not defined for GlobalContext"); 230 assert(OsError && "OsError is not defined for GlobalContext");
233 // Make sure thread_local fields are properly initialized before any 231 // Make sure thread_local fields are properly initialized before any
234 // accesses are made. Do this here instead of at the start of 232 // accesses are made. Do this here instead of at the start of
235 // main() so that all clients (e.g. unit tests) can benefit for 233 // main() so that all clients (e.g. unit tests) can benefit for
236 // free. 234 // free.
237 GlobalContext::TlsInit(); 235 GlobalContext::TlsInit();
238 Cfg::TlsInit(); 236 Cfg::TlsInit();
239 // Create a new ThreadContext for the current thread. No need to 237 // Create a new ThreadContext for the current thread. No need to
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 Ctx = Func->getContext(); 901 Ctx = Func->getContext();
904 Active = 902 Active =
905 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 903 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
906 if (Active) 904 if (Active)
907 Ctx->pushTimer(ID, StackID); 905 Ctx->pushTimer(ID, StackID);
908 } 906 }
909 907
910 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 908 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
911 909
912 } // end of namespace Ice 910 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceGlobalInits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698