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; |
| 84 }; | 91 }; |
| 85 | 92 |
| (...skipping 28 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateEmitted(InstCount); |
| 213 getStatsCumulative()->updateEmitted(InstCount); | 221 ICE_TLS_GET_FIELD(TLS)->StatsCumulative.updateEmitted(InstCount); |
| 214 } | 222 } |
| 215 void statsUpdateRegistersSaved(uint32_t Num) { | 223 void statsUpdateRegistersSaved(uint32_t Num) { |
| 216 if (!ALLOW_DUMP || !getFlags().DumpStats) | 224 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 217 return; | 225 return; |
| 218 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateRegistersSaved(Num); | 226 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateRegistersSaved(Num); |
| 219 getStatsCumulative()->updateRegistersSaved(Num); | 227 ICE_TLS_GET_FIELD(TLS)->StatsCumulative.updateRegistersSaved(Num); |
| 220 } | 228 } |
| 221 void statsUpdateFrameBytes(uint32_t Bytes) { | 229 void statsUpdateFrameBytes(uint32_t Bytes) { |
| 222 if (!ALLOW_DUMP || !getFlags().DumpStats) | 230 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 223 return; | 231 return; |
| 224 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFrameBytes(Bytes); | 232 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFrameBytes(Bytes); |
| 225 getStatsCumulative()->updateFrameBytes(Bytes); | 233 ICE_TLS_GET_FIELD(TLS)->StatsCumulative.updateFrameBytes(Bytes); |
| 226 } | 234 } |
| 227 void statsUpdateSpills() { | 235 void statsUpdateSpills() { |
| 228 if (!ALLOW_DUMP || !getFlags().DumpStats) | 236 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 229 return; | 237 return; |
| 230 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateSpills(); | 238 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateSpills(); |
| 231 getStatsCumulative()->updateSpills(); | 239 ICE_TLS_GET_FIELD(TLS)->StatsCumulative.updateSpills(); |
| 232 } | 240 } |
| 233 void statsUpdateFills() { | 241 void statsUpdateFills() { |
| 234 if (!ALLOW_DUMP || !getFlags().DumpStats) | 242 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 235 return; | 243 return; |
| 236 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFills(); | 244 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFills(); |
| 237 getStatsCumulative()->updateFills(); | 245 ICE_TLS_GET_FIELD(TLS)->StatsCumulative.updateFills(); |
|
JF
2015/01/31 05:08:24
Can you get the field only once per function inste
Jim Stichnoth
2015/01/31 05:36:59
Nice, done.
| |
| 238 } | 246 } |
| 239 | 247 |
| 240 // These are predefined TimerStackIdT values. | 248 // These are predefined TimerStackIdT values. |
| 241 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; | 249 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; |
| 242 | 250 |
| 243 // newTimerStackID() creates a new TimerStack in the global space. | 251 // newTimerStackID() creates a new TimerStack in the global space. |
| 244 // It does not affect any TimerStack objects in TLS. | 252 // It does not affect any TimerStack objects in TLS. |
| 245 TimerStackIdT newTimerStackID(const IceString &Name); | 253 TimerStackIdT newTimerStackID(const IceString &Name); |
| 246 // dumpTimers() dumps the global timer data. As such, one probably | 254 // dumpTimers() dumps the global timer data. As such, one probably |
| 247 // wants to call mergeTimerStacks() as a prerequisite. | 255 // 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) { | 297 for (std::thread &Worker : TranslationThreads) { |
| 290 Worker.join(); | 298 Worker.join(); |
| 291 } | 299 } |
| 292 TranslationThreads.clear(); | 300 TranslationThreads.clear(); |
| 293 // TODO(stichnot): join the emitter thread. | 301 // TODO(stichnot): join the emitter thread. |
| 294 if (ALLOW_DUMP) { | 302 if (ALLOW_DUMP) { |
| 295 auto Timers = getTimers(); | 303 auto Timers = getTimers(); |
| 296 for (ThreadContext *TLS : AllThreadContexts) | 304 for (ThreadContext *TLS : AllThreadContexts) |
| 297 Timers->mergeFrom(TLS->Timers); | 305 Timers->mergeFrom(TLS->Timers); |
| 298 } | 306 } |
| 307 if (ALLOW_DUMP) { | |
| 308 // Do a separate loop over AllThreadContexts to avoid holding | |
| 309 // two locks at once. | |
| 310 auto Stats = getStatsCumulative(); | |
| 311 for (ThreadContext *TLS : AllThreadContexts) | |
| 312 Stats->add(TLS->StatsCumulative); | |
| 313 } | |
| 299 } | 314 } |
| 300 | 315 |
| 301 // Translation thread startup routine. | 316 // Translation thread startup routine. |
| 302 void translateFunctionsWrapper(ThreadContext *MyTLS) { | 317 void translateFunctionsWrapper(ThreadContext *MyTLS) { |
| 303 ICE_TLS_SET_FIELD(TLS, MyTLS); | 318 ICE_TLS_SET_FIELD(TLS, MyTLS); |
| 304 translateFunctions(); | 319 translateFunctions(); |
| 305 } | 320 } |
| 306 // Translate functions from the Cfg queue until the queue is empty. | 321 // Translate functions from the Cfg queue until the queue is empty. |
| 307 void translateFunctions(); | 322 void translateFunctions(); |
| 308 | 323 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 454 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
| 440 ~OstreamLocker() { Ctx->unlockStr(); } | 455 ~OstreamLocker() { Ctx->unlockStr(); } |
| 441 | 456 |
| 442 private: | 457 private: |
| 443 GlobalContext *const Ctx; | 458 GlobalContext *const Ctx; |
| 444 }; | 459 }; |
| 445 | 460 |
| 446 } // end of namespace Ice | 461 } // end of namespace Ice |
| 447 | 462 |
| 448 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 463 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| OLD | NEW |