[lld] 40bcbe4 - [lld-macho][nfc] InputSections don't need to track their total # of callsites

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 10 22:02:08 PST 2021


Author: Jez Ng
Date: 2021-12-11T01:01:57-05:00
New Revision: 40bcbe48e8ecefc6f873acef10f3265401008655

URL: https://github.com/llvm/llvm-project/commit/40bcbe48e8ecefc6f873acef10f3265401008655
DIFF: https://github.com/llvm/llvm-project/commit/40bcbe48e8ecefc6f873acef10f3265401008655.diff

LOG: [lld-macho][nfc] InputSections don't need to track their total # of callsites

... only whether they have more than zero. This simplifies the code slightly.

I've also moved the field into the ConcatInputSection subclass since it doesn't
actually get used by the other InputSections.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D115539

Added: 
    

Modified: 
    lld/MachO/ConcatOutputSection.cpp
    lld/MachO/InputSection.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
index 46cd15a40025d..9f71e81b073a8 100644
--- a/lld/MachO/ConcatOutputSection.cpp
+++ b/lld/MachO/ConcatOutputSection.cpp
@@ -124,13 +124,13 @@ bool ConcatOutputSection::needsThunks() const {
   if (!target->usesThunks())
     return false;
   uint64_t isecAddr = addr;
-  for (InputSection *isec : inputs)
+  for (ConcatInputSection *isec : inputs)
     isecAddr = alignTo(isecAddr, isec->align) + isec->getSize();
   if (isecAddr - addr + in.stubs->getSize() <=
       std::min(target->backwardBranchRange, target->forwardBranchRange))
     return false;
   // Yes, this program is large enough to need thunks.
-  for (InputSection *isec : inputs) {
+  for (ConcatInputSection *isec : inputs) {
     for (Reloc &r : isec->relocs) {
       if (!target->hasAttr(r.type, RelocAttrBits::BRANCH))
         continue;
@@ -143,9 +143,8 @@ bool ConcatOutputSection::needsThunks() const {
       // might need to create more for this referent at the time we are
       // estimating distance to __stubs in estimateStubsInRangeVA().
       ++thunkInfo.callSiteCount;
-      // Knowing InputSection call site count will help us avoid work on those
-      // that have no BRANCH relocs.
-      ++isec->callSiteCount;
+      // We can avoid work on InputSections that have no BRANCH relocs.
+      isec->hasCallSites = true;
     }
   }
   return true;
@@ -250,7 +249,7 @@ void ConcatOutputSection::finalize() {
                                     isecVA + forwardBranchRange - slop)
       finalizeOne(inputs[finalIdx++]);
 
-    if (isec->callSiteCount == 0)
+    if (!isec->hasCallSites)
       continue;
 
     if (finalIdx == endIdx && stubsInRangeVA == TargetInfo::outOfRangeVA) {

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 1183e32fbabf9..fa137223c426f 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -57,9 +57,8 @@ class InputSection {
   OutputSection *parent = nullptr;
 
   uint32_t align = 1;
-  uint32_t callSiteCount : 31;
   // is address assigned?
-  uint32_t isFinal : 1;
+  bool isFinal = false;
 
   ArrayRef<uint8_t> data;
   std::vector<Reloc> relocs;
@@ -86,12 +85,11 @@ class InputSection {
 
   InputSection(Kind kind, StringRef segname, StringRef name, InputFile *file,
                ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
-      : align(align), callSiteCount(0), isFinal(false), data(data),
+      : align(align), data(data),
         shared(make<Shared>(file, name, segname, flags, kind)) {}
 
   InputSection(const InputSection &rhs)
-      : align(rhs.align), callSiteCount(0), isFinal(false), data(rhs.data),
-        shared(rhs.shared) {}
+      : align(rhs.align), data(rhs.data), shared(rhs.shared) {}
 
   const Shared *const shared;
 };
@@ -143,6 +141,7 @@ class ConcatInputSection final : public InputSection {
   // first and not copied to the output.
   bool wasCoalesced = false;
   bool live = !config->deadStrip;
+  bool hasCallSites = false;
   // This variable has two usages. Initially, it represents the input order.
   // After assignAddresses is called, it represents the offset from the
   // beginning of the output section this section was assigned to.


        


More information about the llvm-commits mailing list