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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 // CodeStats collects rudimentary statistics during translation. | 65 // CodeStats collects rudimentary statistics during translation. |
66 class CodeStats { | 66 class CodeStats { |
67 CodeStats(const CodeStats &) = delete; | 67 CodeStats(const CodeStats &) = delete; |
68 CodeStats &operator=(const CodeStats &) = default; | 68 CodeStats &operator=(const CodeStats &) = default; |
69 #define CODESTATS_TABLE \ | 69 #define CODESTATS_TABLE \ |
70 /* dump string, enum value */ \ | 70 /* dump string, enum value */ \ |
71 X("Inst Count ", InstCount) \ | 71 X("Inst Count ", InstCount) \ |
72 X("Regs Saved ", RegsSaved) \ | 72 X("Regs Saved ", RegsSaved) \ |
73 X("Frame Bytes ", FrameByte) \ | 73 X("Frame Bytes ", FrameByte) \ |
74 X("Spills ", NumSpills) \ | 74 X("Spills ", NumSpills) \ |
75 X("Fills ", NumFills) | 75 X("Fills ", NumFills) \ |
76 X("R/P Imms ", NumRPImms) | |
76 //#define X(str, tag) | 77 //#define X(str, tag) |
77 | 78 |
78 public: | 79 public: |
79 enum CSTag { | 80 enum CSTag { |
80 #define X(str, tag) CS_##tag, | 81 #define X(str, tag) CS_##tag, |
81 CODESTATS_TABLE | 82 CODESTATS_TABLE |
82 #undef X | 83 #undef X |
83 CS_NUM | 84 CS_NUM |
84 }; | 85 }; |
85 CodeStats() { reset(); } | 86 CodeStats() { reset(); } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 Tls->StatsCumulative.update(CodeStats::CS_NumSpills); | 257 Tls->StatsCumulative.update(CodeStats::CS_NumSpills); |
257 } | 258 } |
258 void statsUpdateFills() { | 259 void statsUpdateFills() { |
259 if (!getFlags().getDumpStats()) | 260 if (!getFlags().getDumpStats()) |
260 return; | 261 return; |
261 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS); | 262 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS); |
262 Tls->StatsFunction.update(CodeStats::CS_NumFills); | 263 Tls->StatsFunction.update(CodeStats::CS_NumFills); |
263 Tls->StatsCumulative.update(CodeStats::CS_NumFills); | 264 Tls->StatsCumulative.update(CodeStats::CS_NumFills); |
264 } | 265 } |
265 | 266 |
267 // Number of Randomized or Pooled Immediates | |
268 void statsUpdateRPImms() { | |
269 if (!getFlags().getDumpStats()) | |
270 return; | |
271 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS); | |
272 Tls->StatsFunction.update(CodeStats::CS_NumRPImms); | |
273 Tls->StatsCumulative.update(CodeStats::CS_NumRPImms); | |
274 } | |
275 | |
266 // These are predefined TimerStackIdT values. | 276 // These are predefined TimerStackIdT values. |
267 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; | 277 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; |
268 | 278 |
269 // newTimerStackID() creates a new TimerStack in the global space. | 279 // newTimerStackID() creates a new TimerStack in the global space. |
270 // It does not affect any TimerStack objects in TLS. | 280 // It does not affect any TimerStack objects in TLS. |
271 TimerStackIdT newTimerStackID(const IceString &Name); | 281 TimerStackIdT newTimerStackID(const IceString &Name); |
272 // dumpTimers() dumps the global timer data. As such, one probably | 282 // dumpTimers() dumps the global timer data. As such, one probably |
273 // wants to call mergeTimerStacks() as a prerequisite. | 283 // wants to call mergeTimerStacks() as a prerequisite. |
274 void dumpTimers(TimerStackIdT StackID = TSK_Default, | 284 void dumpTimers(TimerStackIdT StackID = TSK_Default, |
275 bool DumpCumulative = true); | 285 bool DumpCumulative = true); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 // This is used in a few cases where we want to take some action on | 394 // This is used in a few cases where we want to take some action on |
385 // a particular function or symbol based on a command-line argument, | 395 // a particular function or symbol based on a command-line argument, |
386 // such as changing the verbose level for a particular function. An | 396 // such as changing the verbose level for a particular function. An |
387 // empty Match argument means match everything. Returns true if | 397 // empty Match argument means match everything. Returns true if |
388 // there is a match. | 398 // there is a match. |
389 static bool matchSymbolName(const IceString &SymbolName, | 399 static bool matchSymbolName(const IceString &SymbolName, |
390 const IceString &Match) { | 400 const IceString &Match) { |
391 return Match.empty() || Match == SymbolName; | 401 return Match.empty() || Match == SymbolName; |
392 } | 402 } |
393 | 403 |
404 // Return the randomization cookie for diversification. | |
405 // Initialize the cookie if necessary | |
406 uint32_t getRandomizationCookie() { | |
407 if (RandomizationCookie != 0) | |
408 return RandomizationCookie; | |
409 RandomizationCookieLock.lock(); | |
Jim Stichnoth
2015/06/19 16:51:02
You should use the std::unique_lock<> pattern (see
| |
410 while (RandomizationCookie == 0) { | |
411 RandomNumberGenerator &RNG = getRNG(); | |
412 RandomizationCookie = (uint32_t)RNG.next( | |
413 (uint64_t)std::numeric_limits<uint32_t>::max() + 1); | |
414 } | |
415 RandomizationCookieLock.unlock(); | |
416 return RandomizationCookie; | |
417 } | |
418 | |
394 private: | 419 private: |
395 // Try to ensure mutexes are allocated on separate cache lines. | 420 // Try to ensure mutexes are allocated on separate cache lines. |
396 | 421 |
397 ICE_CACHELINE_BOUNDARY; | 422 ICE_CACHELINE_BOUNDARY; |
398 // Managed by getAllocator() | 423 // Managed by getAllocator() |
399 GlobalLockType AllocLock; | 424 GlobalLockType AllocLock; |
400 ArenaAllocator<> Allocator; | 425 ArenaAllocator<> Allocator; |
401 | 426 |
402 ICE_CACHELINE_BOUNDARY; | 427 ICE_CACHELINE_BOUNDARY; |
403 // Managed by getConstantPool() | 428 // Managed by getConstantPool() |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 llvm::SmallVector<std::thread, 128> TranslationThreads; | 478 llvm::SmallVector<std::thread, 128> TranslationThreads; |
454 llvm::SmallVector<std::thread, 128> EmitterThreads; | 479 llvm::SmallVector<std::thread, 128> EmitterThreads; |
455 // Each thread has its own TLS pointer which is also held in | 480 // Each thread has its own TLS pointer which is also held in |
456 // AllThreadContexts. | 481 // AllThreadContexts. |
457 ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS); | 482 ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS); |
458 | 483 |
459 // Private helpers for mangleName() | 484 // Private helpers for mangleName() |
460 typedef llvm::SmallVector<char, 32> ManglerVector; | 485 typedef llvm::SmallVector<char, 32> ManglerVector; |
461 void incrementSubstitutions(ManglerVector &OldName) const; | 486 void incrementSubstitutions(ManglerVector &OldName) const; |
462 | 487 |
488 // Randomization Cookie | |
489 // Managed by getRandomizationCookie() | |
490 GlobalLockType RandomizationCookieLock; | |
491 uint32_t RandomizationCookie; | |
492 | |
463 public: | 493 public: |
464 static void TlsInit() { ICE_TLS_INIT_FIELD(TLS); } | 494 static void TlsInit() { ICE_TLS_INIT_FIELD(TLS); } |
465 }; | 495 }; |
466 | 496 |
467 // Helper class to push and pop a timer marker. The constructor | 497 // Helper class to push and pop a timer marker. The constructor |
468 // pushes a marker, and the destructor pops it. This is for | 498 // pushes a marker, and the destructor pops it. This is for |
469 // convenient timing of regions of code. | 499 // convenient timing of regions of code. |
470 class TimerMarker { | 500 class TimerMarker { |
471 TimerMarker() = delete; | 501 TimerMarker() = delete; |
472 TimerMarker(const TimerMarker &) = delete; | 502 TimerMarker(const TimerMarker &) = delete; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 543 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
514 ~OstreamLocker() { Ctx->unlockStr(); } | 544 ~OstreamLocker() { Ctx->unlockStr(); } |
515 | 545 |
516 private: | 546 private: |
517 GlobalContext *const Ctx; | 547 GlobalContext *const Ctx; |
518 }; | 548 }; |
519 | 549 |
520 } // end of namespace Ice | 550 } // end of namespace Ice |
521 | 551 |
522 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 552 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
OLD | NEW |