[lld] 824a288 - [lld-macho][nfc] Simplify MarkLive.cpp using `if constexpr`
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 07:41:04 PDT 2022
Author: Jez Ng
Date: 2022-08-31T10:40:04-04:00
New Revision: 824a28819e2bb82ca0086da2d4c3bed8761590c0
URL: https://github.com/llvm/llvm-project/commit/824a28819e2bb82ca0086da2d4c3bed8761590c0
DIFF: https://github.com/llvm/llvm-project/commit/824a28819e2bb82ca0086da2d4c3bed8761590c0.diff
LOG: [lld-macho][nfc] Simplify MarkLive.cpp using `if constexpr`
No significant perf diff, as expected.
base diff difference (95% CI)
sys_time 1.722 ± 0.030 1.727 ± 0.027 [ -0.6% .. +1.2%]
user_time 5.081 ± 0.032 5.087 ± 0.030 [ -0.2% .. +0.4%]
wall_time 6.008 ± 0.056 6.029 ± 0.053 [ -0.1% .. +0.8%]
samples 25 37
Reviewed By: #lld-macho, oontvoo, thakis, BertalanD
Differential Revision: https://reviews.llvm.org/D133014
Added:
Modified:
lld/MachO/MarkLive.cpp
Removed:
################################################################################
diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp
index ba7d215d9f0a4..d407599ee8109 100644
--- a/lld/MachO/MarkLive.cpp
+++ b/lld/MachO/MarkLive.cpp
@@ -57,7 +57,6 @@ template <bool RecordWhyLive> class MarkLiveImpl : public MarkLive {
private:
void enqueue(InputSection *isec, uint64_t off, const WorklistEntry *prev);
void addSym(Symbol *s, const WorklistEntry *prev);
- void printWhyLive(Symbol *s, const WorklistEntry *prev);
const InputSection *getInputSection(const WorklistEntry *) const;
WorklistEntry *makeEntry(InputSection *, const WorklistEntry *prev) const;
@@ -82,23 +81,7 @@ void MarkLiveImpl<RecordWhyLive>::enqueue(
}
}
-template <bool RecordWhyLive>
-void MarkLiveImpl<RecordWhyLive>::addSym(
- Symbol *s,
- const typename MarkLiveImpl<RecordWhyLive>::WorklistEntry *prev) {
- if (s->used)
- return;
- s->used = true;
- printWhyLive(s, prev);
- if (auto *d = dyn_cast<Defined>(s)) {
- if (d->isec)
- enqueue(d->isec, d->value, prev);
- if (d->unwindEntry)
- enqueue(d->unwindEntry, 0, prev);
- }
-}
-
-static void printWhyLiveImpl(const Symbol *s, const WhyLiveEntry *prev) {
+static void printWhyLive(const Symbol *s, const WhyLiveEntry *prev) {
std::string out = toString(*s) + " from " + toString(s->getFile());
int indent = 2;
for (const WhyLiveEntry *entry = prev; entry;
@@ -113,44 +96,47 @@ static void printWhyLiveImpl(const Symbol *s, const WhyLiveEntry *prev) {
message(out);
}
-// NOTE: if/when `constexpr if` becomes available, we can simplify a lot of
-// the partial template specializations below.
-
-template <>
-void MarkLiveImpl<true>::printWhyLive(Symbol *s, const WhyLiveEntry *prev) {
- if (!config->whyLive.empty() && config->whyLive.match(s->getName()))
- printWhyLiveImpl(s, prev);
-}
-
-template <>
-void MarkLiveImpl<false>::printWhyLive(Symbol *s, const InputSection *prev) {}
-
-template <>
-const InputSection *
-MarkLiveImpl<true>::getInputSection(const WhyLiveEntry *entry) const {
- return entry->isec;
+template <bool RecordWhyLive>
+void MarkLiveImpl<RecordWhyLive>::addSym(
+ Symbol *s,
+ const typename MarkLiveImpl<RecordWhyLive>::WorklistEntry *prev) {
+ if (s->used)
+ return;
+ s->used = true;
+ if constexpr (RecordWhyLive)
+ if (!config->whyLive.empty() && config->whyLive.match(s->getName()))
+ printWhyLive(s, prev);
+ if (auto *d = dyn_cast<Defined>(s)) {
+ if (d->isec)
+ enqueue(d->isec, d->value, prev);
+ if (d->unwindEntry)
+ enqueue(d->unwindEntry, 0, prev);
+ }
}
-template <>
-const InputSection *
-MarkLiveImpl<false>::getInputSection(const InputSection *isec) const {
- return isec;
+template <bool RecordWhyLive>
+const InputSection *MarkLiveImpl<RecordWhyLive>::getInputSection(
+ const MarkLiveImpl<RecordWhyLive>::WorklistEntry *entry) const {
+ if constexpr (RecordWhyLive)
+ return entry->isec;
+ else
+ return entry;
}
-template <>
-typename MarkLiveImpl<true>::WorklistEntry *MarkLiveImpl<true>::makeEntry(
- InputSection *isec, const MarkLiveImpl<true>::WorklistEntry *prev) const {
- if (!isec) {
- assert(!prev);
- return nullptr;
+template <bool RecordWhyLive>
+typename MarkLiveImpl<RecordWhyLive>::WorklistEntry *
+MarkLiveImpl<RecordWhyLive>::makeEntry(
+ InputSection *isec,
+ const MarkLiveImpl<RecordWhyLive>::WorklistEntry *prev) const {
+ if constexpr (RecordWhyLive) {
+ if (!isec) {
+ assert(!prev);
+ return nullptr;
+ }
+ return make<WhyLiveEntry>(isec, prev);
+ } else {
+ return isec;
}
- return make<WhyLiveEntry>(isec, prev);
-}
-
-template <>
-typename MarkLiveImpl<false>::WorklistEntry *MarkLiveImpl<false>::makeEntry(
- InputSection *isec, const MarkLiveImpl<false>::WorklistEntry *prev) const {
- return isec;
}
template <bool RecordWhyLive>
More information about the llvm-commits
mailing list