[PATCH] D97410: [llvm] Check availability for os_signpost
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 12:36:49 PST 2021
JDevlieghere created this revision.
JDevlieghere added a reviewer: dsanders.
Herald added subscribers: dexonsmith, hiraditya.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.
Add availability checks to the os_signpost code so this can be enabled with an older deployment target.
https://reviews.llvm.org/D97410
Files:
llvm/lib/Support/Signposts.cpp
Index: llvm/lib/Support/Signposts.cpp
===================================================================
--- llvm/lib/Support/Signposts.cpp
+++ llvm/lib/Support/Signposts.cpp
@@ -14,6 +14,7 @@
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Mutex.h"
+#include <Availability.h>
#include <os/signpost.h>
#endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS
@@ -47,30 +48,40 @@
const auto &I = Signposts.find(O);
if (I != Signposts.end())
return I->second;
-
- const auto &Inserted = Signposts.insert(
- std::make_pair(O, os_signpost_id_make_with_pointer(getLogger(), O)));
+ os_signpost_id_t ID = {};
+ if (__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *)) {
+ ID = os_signpost_id_make_with_pointer(getLogger(), O);
+ }
+ const auto &Inserted = Signposts.insert(std::make_pair(O, ID));
return Inserted.first->second;
}
public:
SignpostEmitterImpl() : SignpostLog(LogCreator(), LogDeleter), Signposts() {}
- bool isEnabled() const { return os_signpost_enabled(*SignpostLog); }
+ bool isEnabled() const {
+ if (__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *))
+ return os_signpost_enabled(*SignpostLog);
+ return false;
+ }
void startInterval(const void *O, llvm::StringRef Name) {
if (isEnabled()) {
- // Both strings used here are required to be constant literal strings.
- os_signpost_interval_begin(getLogger(), getSignpostForObject(O),
- "LLVM Timers", "Begin %s", Name.data());
+ if (__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *)) {
+ // Both strings used here are required to be constant literal strings.
+ os_signpost_interval_begin(getLogger(), getSignpostForObject(O),
+ "LLVM Timers", "Begin %s", Name.data());
+ }
}
}
void endInterval(const void *O, llvm::StringRef Name) {
if (isEnabled()) {
- // Both strings used here are required to be constant literal strings.
- os_signpost_interval_end(getLogger(), getSignpostForObject(O),
- "LLVM Timers", "End %s", Name.data());
+ if (__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *)) {
+ // Both strings used here are required to be constant literal strings.
+ os_signpost_interval_end(getLogger(), getSignpostForObject(O),
+ "LLVM Timers", "End %s", Name.data());
+ }
}
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97410.326182.patch
Type: text/x-patch
Size: 2535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210224/b959904c/attachment.bin>
More information about the llvm-commits
mailing list