[PATCH] D73639: [LLVM] Wrap extern TLS variable in getter Function
Markus Böck via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 09:21:45 PST 2020
zero9178 created this revision.
zero9178 added reviewers: ruiu, mstorsjo, ruscur.
zero9178 added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
zero9178 edited reviewers, added: russell.gallop; removed: ruscur.
This patch wraps an external thread local storage variable inside of a getter function and makes it have internal linkage. This allows LLVM to be built with BUILD_SHARED_LIBS on windows with MinGW. Additionally it allows Clang versions prior to 10 to compile current trunk.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73639
Files:
llvm/include/llvm/Support/TimeProfiler.h
llvm/lib/Support/TimeProfiler.cpp
Index: llvm/lib/Support/TimeProfiler.cpp
===================================================================
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -27,13 +27,18 @@
namespace {
std::mutex Mu;
+// List of all instances
std::vector<llvm::TimeTraceProfiler *>
ThreadTimeTraceProfilerInstances; // guarded by Mu
+// Per Thread instance
+LLVM_THREAD_LOCAL llvm::TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
} // namespace
namespace llvm {
-LLVM_THREAD_LOCAL TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
+TimeTraceProfiler *GetTimeTraceProfilerInstance() {
+ return TimeTraceProfilerInstance;
+}
typedef duration<steady_clock::rep, steady_clock::period> DurationType;
typedef time_point<steady_clock> TimePointType;
Index: llvm/include/llvm/Support/TimeProfiler.h
===================================================================
--- llvm/include/llvm/Support/TimeProfiler.h
+++ llvm/include/llvm/Support/TimeProfiler.h
@@ -14,7 +14,7 @@
namespace llvm {
struct TimeTraceProfiler;
-extern LLVM_THREAD_LOCAL TimeTraceProfiler *TimeTraceProfilerInstance;
+TimeTraceProfiler *GetTimeTraceProfilerInstance();
/// Initialize the time trace profiler.
/// This sets up the global \p TimeTraceProfilerInstance
@@ -30,7 +30,7 @@
/// Is the time trace profiler enabled, i.e. initialized?
inline bool timeTraceProfilerEnabled() {
- return TimeTraceProfilerInstance != nullptr;
+ return GetTimeTraceProfilerInstance() != nullptr;
}
/// Write profiling data to output file.
@@ -62,19 +62,19 @@
TimeTraceScope &operator=(TimeTraceScope &&) = delete;
TimeTraceScope(StringRef Name) {
- if (TimeTraceProfilerInstance != nullptr)
+ if (GetTimeTraceProfilerInstance() != nullptr)
timeTraceProfilerBegin(Name, StringRef(""));
}
TimeTraceScope(StringRef Name, StringRef Detail) {
- if (TimeTraceProfilerInstance != nullptr)
+ if (GetTimeTraceProfilerInstance() != nullptr)
timeTraceProfilerBegin(Name, Detail);
}
TimeTraceScope(StringRef Name, llvm::function_ref<std::string()> Detail) {
- if (TimeTraceProfilerInstance != nullptr)
+ if (GetTimeTraceProfilerInstance() != nullptr)
timeTraceProfilerBegin(Name, Detail);
}
~TimeTraceScope() {
- if (TimeTraceProfilerInstance != nullptr)
+ if (GetTimeTraceProfilerInstance() != nullptr)
timeTraceProfilerEnd();
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73639.241189.patch
Type: text/x-patch
Size: 2422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200129/7da8e2fc/attachment.bin>
More information about the llvm-commits
mailing list