diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp --- a/lld/MachO/MarkLive.cpp +++ b/lld/MachO/MarkLive.cpp @@ -57,7 +57,6 @@ 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 @@ } } -template -void MarkLiveImpl::addSym( - Symbol *s, - const typename MarkLiveImpl::WorklistEntry *prev) { - if (s->used) - return; - s->used = true; - printWhyLive(s, prev); - if (auto *d = dyn_cast(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 @@ message(out); } -// NOTE: if/when `constexpr if` becomes available, we can simplify a lot of -// the partial template specializations below. - -template <> -void MarkLiveImpl::printWhyLive(Symbol *s, const WhyLiveEntry *prev) { - if (!config->whyLive.empty() && config->whyLive.match(s->getName())) - printWhyLiveImpl(s, prev); -} - -template <> -void MarkLiveImpl::printWhyLive(Symbol *s, const InputSection *prev) {} - -template <> -const InputSection * -MarkLiveImpl::getInputSection(const WhyLiveEntry *entry) const { - return entry->isec; +template +void MarkLiveImpl::addSym( + Symbol *s, + const typename MarkLiveImpl::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(s)) { + if (d->isec) + enqueue(d->isec, d->value, prev); + if (d->unwindEntry) + enqueue(d->unwindEntry, 0, prev); + } } -template <> -const InputSection * -MarkLiveImpl::getInputSection(const InputSection *isec) const { - return isec; +template +const InputSection *MarkLiveImpl::getInputSection( + const MarkLiveImpl::WorklistEntry *entry) const { + if constexpr (RecordWhyLive) + return entry->isec; + else + return entry; } -template <> -typename MarkLiveImpl::WorklistEntry *MarkLiveImpl::makeEntry( - InputSection *isec, const MarkLiveImpl::WorklistEntry *prev) const { - if (!isec) { - assert(!prev); - return nullptr; +template +typename MarkLiveImpl::WorklistEntry * +MarkLiveImpl::makeEntry( + InputSection *isec, + const MarkLiveImpl::WorklistEntry *prev) const { + if constexpr (RecordWhyLive) { + if (!isec) { + assert(!prev); + return nullptr; + } + return make(isec, prev); + } else { + return isec; } - return make(isec, prev); -} - -template <> -typename MarkLiveImpl::WorklistEntry *MarkLiveImpl::makeEntry( - InputSection *isec, const MarkLiveImpl::WorklistEntry *prev) const { - return isec; } template