mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #12137 from davidungar/fixing-radar-34475709
Moves formerly statically-allocated RecursiveSharedTimer(s) effectively into ASTContext
This commit is contained in:
@@ -66,6 +66,15 @@ public:
|
||||
#undef FRONTEND_STATISTIC
|
||||
};
|
||||
|
||||
struct AlwaysOnFrontendRecursiveSharedTimers {
|
||||
AlwaysOnFrontendRecursiveSharedTimers();
|
||||
#define FRONTEND_RECURSIVE_SHARED_TIMER(ID) RecursiveSharedTimer ID;
|
||||
#include "Statistics.def"
|
||||
#undef FRONTEND_RECURSIVE_SHARED_TIMER
|
||||
|
||||
int dummyInstanceVariableToGetConstructorToParse;
|
||||
};
|
||||
|
||||
struct FrontendStatsTracer
|
||||
{
|
||||
UnifiedStatsReporter *Reporter;
|
||||
@@ -105,6 +114,8 @@ private:
|
||||
std::unique_ptr<AlwaysOnFrontendCounters> FrontendCounters;
|
||||
std::unique_ptr<AlwaysOnFrontendCounters> LastTracedFrontendCounters;
|
||||
std::vector<FrontendStatsEvent> FrontendStatsEvents;
|
||||
std::unique_ptr<AlwaysOnFrontendRecursiveSharedTimers>
|
||||
FrontendRecursiveSharedTimers;
|
||||
|
||||
void publishAlwaysOnStatsToLLVM();
|
||||
void printAlwaysOnStatsAndTimers(llvm::raw_ostream &OS);
|
||||
@@ -128,6 +139,7 @@ public:
|
||||
|
||||
AlwaysOnDriverCounters &getDriverCounters();
|
||||
AlwaysOnFrontendCounters &getFrontendCounters();
|
||||
AlwaysOnFrontendRecursiveSharedTimers &getFrontendRecursiveSharedTimers();
|
||||
FrontendStatsTracer getStatsTracer(StringRef N,
|
||||
SourceRange const &R);
|
||||
void saveAnyFrontendStatsEvents(FrontendStatsTracer const& T,
|
||||
|
||||
@@ -101,3 +101,9 @@ FRONTEND_STATISTIC(IRModule, NumIRInsts)
|
||||
|
||||
FRONTEND_STATISTIC(LLVM, NumLLVMBytesOutput)
|
||||
#endif
|
||||
|
||||
/// Frontend timers for recursive routines
|
||||
#ifdef FRONTEND_RECURSIVE_SHARED_TIMER
|
||||
FRONTEND_RECURSIVE_SHARED_TIMER(NominalTypeDecl__lookupDirect)
|
||||
FRONTEND_RECURSIVE_SHARED_TIMER(ClangImporter__Implementation__loadAllMembers)
|
||||
#endif
|
||||
|
||||
@@ -47,11 +47,12 @@ namespace swift {
|
||||
};
|
||||
|
||||
/// A SharedTimer for recursive routines.
|
||||
/// Declare as a static, and use as below:
|
||||
/// void example() {
|
||||
/// static RecursiveSharedTimer timer("lookupDirect");
|
||||
/// auto guard = RecursiveSharedTimer::Guard(timer);
|
||||
/// (void)guard;
|
||||
/// RecursiveSharedTimer::Guard guard; // MUST BE AT TOP SCOPE of function to
|
||||
/// work right! if (auto s = getASTContext().Stats) {
|
||||
/// guard =
|
||||
/// ctx.Stats->getFrontendRecursiveSharedTimers().NominalTypeDecl__lookupDirect.getGuard();
|
||||
// }
|
||||
/// ...
|
||||
/// }
|
||||
|
||||
@@ -76,13 +77,33 @@ namespace swift {
|
||||
RecursiveSharedTimer(StringRef name) : name(name) {}
|
||||
|
||||
struct Guard {
|
||||
RecursiveSharedTimer &recursiveTimer;
|
||||
Guard &operator=(Guard &) = delete;
|
||||
Guard(RecursiveSharedTimer &rst) : recursiveTimer(rst) {
|
||||
recursiveTimer.enterRecursiveFunction();
|
||||
RecursiveSharedTimer *recursiveTimerOrNull;
|
||||
|
||||
Guard(RecursiveSharedTimer *rst) : recursiveTimerOrNull(rst) {
|
||||
if (recursiveTimerOrNull)
|
||||
recursiveTimerOrNull->enterRecursiveFunction();
|
||||
}
|
||||
~Guard() { recursiveTimer.exitRecursiveFunction(); }
|
||||
~Guard() {
|
||||
if (recursiveTimerOrNull)
|
||||
recursiveTimerOrNull->exitRecursiveFunction();
|
||||
}
|
||||
|
||||
// All this stuff is to do an RAII object that be moved.
|
||||
Guard() : recursiveTimerOrNull(nullptr) {}
|
||||
Guard(Guard &&other) {
|
||||
recursiveTimerOrNull = other.recursiveTimerOrNull;
|
||||
other.recursiveTimerOrNull = nullptr;
|
||||
}
|
||||
Guard &operator=(Guard &&other) {
|
||||
recursiveTimerOrNull = other.recursiveTimerOrNull;
|
||||
other.recursiveTimerOrNull = nullptr;
|
||||
return *this;
|
||||
}
|
||||
Guard(const Guard &) = delete;
|
||||
Guard &operator=(const Guard &) = delete;
|
||||
};
|
||||
|
||||
Guard getGuard() { return Guard(this); }
|
||||
};
|
||||
} // end namespace swift
|
||||
|
||||
|
||||
Reference in New Issue
Block a user