[lld] 64cc719 - [lld-macho][nfc] Track # of ICF calls to `equals*` methods

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 7 09:36:45 PST 2022


Author: Jez Ng
Date: 2022-03-07T12:36:27-05:00
New Revision: 64cc719766ecc969e930a009f8c14302ba4faee8

URL: https://github.com/llvm/llvm-project/commit/64cc719766ecc969e930a009f8c14302ba4faee8
DIFF: https://github.com/llvm/llvm-project/commit/64cc719766ecc969e930a009f8c14302ba4faee8.diff

LOG: [lld-macho][nfc] Track # of ICF calls to `equals*` methods

This is debug code that is disabled by default. It'll provide a easy way
to figure out the impact (if any) of tweaking ICF's hashing algorithm
(since a poor quality hash will result in many more `equals*` calls).

Reviewed By: #lld-macho, oontvoo

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

Added: 
    

Modified: 
    lld/MachO/ICF.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp
index b90464a771065..70317d422fe40 100644
--- a/lld/MachO/ICF.cpp
+++ b/lld/MachO/ICF.cpp
@@ -23,6 +23,8 @@ using namespace llvm;
 using namespace lld;
 using namespace lld::macho;
 
+static constexpr bool verboseDiagnostics = false;
+
 class ICF {
 public:
   ICF(std::vector<ConcatInputSection *> &inputs);
@@ -47,6 +49,8 @@ class ICF {
 
   unsigned icfPass = 0;
   std::atomic<bool> icfRepeat{false};
+  std::atomic<uint64_t> equalsConstantCount{0};
+  std::atomic<uint64_t> equalsVariableCount{0};
 };
 
 ICF::ICF(std::vector<ConcatInputSection *> &inputs) {
@@ -87,6 +91,8 @@ ICF::ICF(std::vector<ConcatInputSection *> &inputs) {
 // except references to other ConcatInputSections.
 bool ICF::equalsConstant(const ConcatInputSection *ia,
                          const ConcatInputSection *ib) {
+  if (verboseDiagnostics)
+    ++equalsConstantCount;
   // We can only fold within the same OutputSection.
   if (ia->parent != ib->parent)
     return false;
@@ -159,6 +165,8 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
 // handled by equalsConstant().
 bool ICF::equalsVariable(const ConcatInputSection *ia,
                          const ConcatInputSection *ib) {
+  if (verboseDiagnostics)
+    ++equalsVariableCount;
   assert(ia->relocs.size() == ib->relocs.size());
   auto f = [this](const Reloc &ra, const Reloc &rb) {
     // We already filtered out mismatching values/addends in equalsConstant.
@@ -307,6 +315,10 @@ void ICF::run() {
     });
   } while (icfRepeat);
   log("ICF needed " + Twine(icfPass) + " iterations");
+  if (verboseDiagnostics) {
+    log("equalsConstant() called " + Twine(equalsConstantCount) + " times");
+    log("equalsVariable() called " + Twine(equalsVariableCount) + " times");
+  }
 
   // Fold sections within equivalence classes
   forEachClass([&](size_t begin, size_t end) {


        


More information about the llvm-commits mailing list