Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.h - 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 declares aspects of the compilation that persist across | 10 // This file declares aspects of the compilation that persist across |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 public: | 66 public: |
| 67 CodeStats() | 67 CodeStats() |
| 68 : InstructionsEmitted(0), RegistersSaved(0), FrameBytes(0), Spills(0), | 68 : InstructionsEmitted(0), RegistersSaved(0), FrameBytes(0), Spills(0), |
| 69 Fills(0) {} | 69 Fills(0) {} |
| 70 void reset() { *this = CodeStats(); } | 70 void reset() { *this = CodeStats(); } |
| 71 void updateEmitted(uint32_t InstCount) { InstructionsEmitted += InstCount; } | 71 void updateEmitted(uint32_t InstCount) { InstructionsEmitted += InstCount; } |
| 72 void updateRegistersSaved(uint32_t Num) { RegistersSaved += Num; } | 72 void updateRegistersSaved(uint32_t Num) { RegistersSaved += Num; } |
| 73 void updateFrameBytes(uint32_t Bytes) { FrameBytes += Bytes; } | 73 void updateFrameBytes(uint32_t Bytes) { FrameBytes += Bytes; } |
| 74 void updateSpills() { ++Spills; } | 74 void updateSpills() { ++Spills; } |
| 75 void updateFills() { ++Fills; } | 75 void updateFills() { ++Fills; } |
| 76 void add(const CodeStats &Other) { | |
| 77 InstructionsEmitted += Other.InstructionsEmitted; | |
| 78 RegistersSaved += Other.RegistersSaved; | |
| 79 FrameBytes += Other.FrameBytes; | |
| 80 Spills += Other.Spills; | |
| 81 Fills += Other.Fills; | |
| 82 } | |
| 76 void dump(const IceString &Name, Ostream &Str); | 83 void dump(const IceString &Name, Ostream &Str); |
| 77 | 84 |
| 78 private: | 85 private: |
| 79 uint32_t InstructionsEmitted; | 86 uint32_t InstructionsEmitted; |
| 80 uint32_t RegistersSaved; | 87 uint32_t RegistersSaved; |
| 81 uint32_t FrameBytes; | 88 uint32_t FrameBytes; |
| 82 uint32_t Spills; | 89 uint32_t Spills; |
| 83 uint32_t Fills; | 90 uint32_t Fills; |
|
JF
2015/01/31 05:48:38
X-macros for these, and add(), and the update*() m
Jim Stichnoth
2015/01/31 16:42:28
Done.
| |
| 84 }; | 91 }; |
| 85 | 92 |
| 86 // TimerList is a vector of TimerStack objects, with extra methods | 93 // TimerList is a vector of TimerStack objects, with extra methods |
| 87 // to initialize and merge these vectors. | 94 // to initialize and merge these vectors. |
| 88 class TimerList : public std::vector<TimerStack> { | 95 class TimerList : public std::vector<TimerStack> { |
| 89 public: | 96 public: |
| 90 // initInto() initializes a target list of timers based on the | 97 // initInto() initializes a target list of timers based on the |
| 91 // current list. In particular, it creates the same number of | 98 // current list. In particular, it creates the same number of |
| 92 // timers, in the same order, with the same names, but initially | 99 // timers, in the same order, with the same names, but initially |
| 93 // empty of timing data. | 100 // empty of timing data. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 114 | 121 |
| 115 // ThreadContext contains thread-local data. This data can be | 122 // ThreadContext contains thread-local data. This data can be |
| 116 // combined/reduced as needed after all threads complete. | 123 // combined/reduced as needed after all threads complete. |
| 117 class ThreadContext { | 124 class ThreadContext { |
| 118 ThreadContext(const ThreadContext &) = delete; | 125 ThreadContext(const ThreadContext &) = delete; |
| 119 ThreadContext &operator=(const ThreadContext &) = delete; | 126 ThreadContext &operator=(const ThreadContext &) = delete; |
| 120 | 127 |
| 121 public: | 128 public: |
| 122 ThreadContext() {} | 129 ThreadContext() {} |
| 123 CodeStats StatsFunction; | 130 CodeStats StatsFunction; |
| 131 CodeStats StatsCumulative; | |
| 124 TimerList Timers; | 132 TimerList Timers; |
| 125 }; | 133 }; |
| 126 | 134 |
| 127 public: | 135 public: |
| 128 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer, | 136 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer, |
| 129 VerboseMask Mask, TargetArch Arch, OptLevel Opt, | 137 VerboseMask Mask, TargetArch Arch, OptLevel Opt, |
| 130 IceString TestPrefix, const ClFlags &Flags); | 138 IceString TestPrefix, const ClFlags &Flags); |
| 131 ~GlobalContext(); | 139 ~GlobalContext(); |
| 132 | 140 |
| 133 VerboseMask getVerbose() const { return VMask; } | 141 VerboseMask getVerbose() const { return VMask; } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 210 |
| 203 // Reset stats at the beginning of a function. | 211 // Reset stats at the beginning of a function. |
| 204 void resetStats() { | 212 void resetStats() { |
| 205 if (ALLOW_DUMP) | 213 if (ALLOW_DUMP) |
| 206 ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset(); | 214 ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset(); |
| 207 } | 215 } |
| 208 void dumpStats(const IceString &Name, bool Final = false); | 216 void dumpStats(const IceString &Name, bool Final = false); |
| 209 void statsUpdateEmitted(uint32_t InstCount) { | 217 void statsUpdateEmitted(uint32_t InstCount) { |
| 210 if (!ALLOW_DUMP || !getFlags().DumpStats) | 218 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 211 return; | 219 return; |
| 212 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateEmitted(InstCount); | 220 auto TLS = ICE_TLS_GET_FIELD(TLS); |
|
JF
2015/01/31 05:48:38
auto *TLS = ...;
Jim Stichnoth
2015/01/31 16:42:28
Done, took it one step further...
My original ide
| |
| 213 getStatsCumulative()->updateEmitted(InstCount); | 221 TLS->StatsFunction.updateEmitted(InstCount); |
| 222 TLS->StatsCumulative.updateEmitted(InstCount); | |
| 214 } | 223 } |
| 215 void statsUpdateRegistersSaved(uint32_t Num) { | 224 void statsUpdateRegistersSaved(uint32_t Num) { |
| 216 if (!ALLOW_DUMP || !getFlags().DumpStats) | 225 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 217 return; | 226 return; |
| 218 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateRegistersSaved(Num); | 227 auto TLS = ICE_TLS_GET_FIELD(TLS); |
| 219 getStatsCumulative()->updateRegistersSaved(Num); | 228 TLS->StatsFunction.updateRegistersSaved(Num); |
| 229 TLS->StatsCumulative.updateRegistersSaved(Num); | |
| 220 } | 230 } |
| 221 void statsUpdateFrameBytes(uint32_t Bytes) { | 231 void statsUpdateFrameBytes(uint32_t Bytes) { |
| 222 if (!ALLOW_DUMP || !getFlags().DumpStats) | 232 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 223 return; | 233 return; |
| 224 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFrameBytes(Bytes); | 234 auto TLS = ICE_TLS_GET_FIELD(TLS); |
| 225 getStatsCumulative()->updateFrameBytes(Bytes); | 235 TLS->StatsFunction.updateFrameBytes(Bytes); |
| 236 TLS->StatsCumulative.updateFrameBytes(Bytes); | |
| 226 } | 237 } |
| 227 void statsUpdateSpills() { | 238 void statsUpdateSpills() { |
| 228 if (!ALLOW_DUMP || !getFlags().DumpStats) | 239 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 229 return; | 240 return; |
| 230 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateSpills(); | 241 auto TLS = ICE_TLS_GET_FIELD(TLS); |
| 231 getStatsCumulative()->updateSpills(); | 242 TLS->StatsFunction.updateSpills(); |
| 243 TLS->StatsCumulative.updateSpills(); | |
| 232 } | 244 } |
| 233 void statsUpdateFills() { | 245 void statsUpdateFills() { |
| 234 if (!ALLOW_DUMP || !getFlags().DumpStats) | 246 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 235 return; | 247 return; |
| 236 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFills(); | 248 auto TLS = ICE_TLS_GET_FIELD(TLS); |
| 237 getStatsCumulative()->updateFills(); | 249 TLS->StatsFunction.updateFills(); |
| 250 TLS->StatsCumulative.updateFills(); | |
| 238 } | 251 } |
| 239 | 252 |
| 240 // These are predefined TimerStackIdT values. | 253 // These are predefined TimerStackIdT values. |
| 241 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; | 254 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; |
| 242 | 255 |
| 243 // newTimerStackID() creates a new TimerStack in the global space. | 256 // newTimerStackID() creates a new TimerStack in the global space. |
| 244 // It does not affect any TimerStack objects in TLS. | 257 // It does not affect any TimerStack objects in TLS. |
| 245 TimerStackIdT newTimerStackID(const IceString &Name); | 258 TimerStackIdT newTimerStackID(const IceString &Name); |
| 246 // dumpTimers() dumps the global timer data. As such, one probably | 259 // dumpTimers() dumps the global timer data. As such, one probably |
| 247 // wants to call mergeTimerStacks() as a prerequisite. | 260 // wants to call mergeTimerStacks() as a prerequisite. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 for (std::thread &Worker : TranslationThreads) { | 302 for (std::thread &Worker : TranslationThreads) { |
| 290 Worker.join(); | 303 Worker.join(); |
| 291 } | 304 } |
| 292 TranslationThreads.clear(); | 305 TranslationThreads.clear(); |
| 293 // TODO(stichnot): join the emitter thread. | 306 // TODO(stichnot): join the emitter thread. |
| 294 if (ALLOW_DUMP) { | 307 if (ALLOW_DUMP) { |
| 295 auto Timers = getTimers(); | 308 auto Timers = getTimers(); |
| 296 for (ThreadContext *TLS : AllThreadContexts) | 309 for (ThreadContext *TLS : AllThreadContexts) |
| 297 Timers->mergeFrom(TLS->Timers); | 310 Timers->mergeFrom(TLS->Timers); |
| 298 } | 311 } |
| 312 if (ALLOW_DUMP) { | |
| 313 // Do a separate loop over AllThreadContexts to avoid holding | |
| 314 // two locks at once. | |
| 315 auto Stats = getStatsCumulative(); | |
| 316 for (ThreadContext *TLS : AllThreadContexts) | |
| 317 Stats->add(TLS->StatsCumulative); | |
| 318 } | |
| 299 } | 319 } |
| 300 | 320 |
| 301 // Translation thread startup routine. | 321 // Translation thread startup routine. |
| 302 void translateFunctionsWrapper(ThreadContext *MyTLS) { | 322 void translateFunctionsWrapper(ThreadContext *MyTLS) { |
| 303 ICE_TLS_SET_FIELD(TLS, MyTLS); | 323 ICE_TLS_SET_FIELD(TLS, MyTLS); |
| 304 translateFunctions(); | 324 translateFunctions(); |
| 305 } | 325 } |
| 306 // Translate functions from the Cfg queue until the queue is empty. | 326 // Translate functions from the Cfg queue until the queue is empty. |
| 307 void translateFunctions(); | 327 void translateFunctions(); |
| 308 | 328 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 459 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
| 440 ~OstreamLocker() { Ctx->unlockStr(); } | 460 ~OstreamLocker() { Ctx->unlockStr(); } |
| 441 | 461 |
| 442 private: | 462 private: |
| 443 GlobalContext *const Ctx; | 463 GlobalContext *const Ctx; |
| 444 }; | 464 }; |
| 445 | 465 |
| 446 } // end of namespace Ice | 466 } // end of namespace Ice |
| 447 | 467 |
| 448 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 468 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| OLD | NEW |