[lld] 10b9847 - [ELF] Simplify --print-icf-sections

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 18:26:34 PST 2024


Author: Fangrui Song
Date: 2024-11-29T18:26:29-08:00
New Revision: 10b98473e8f9e3886bd4a51966c755d760de14ed

URL: https://github.com/llvm/llvm-project/commit/10b98473e8f9e3886bd4a51966c755d760de14ed
DIFF: https://github.com/llvm/llvm-project/commit/10b98473e8f9e3886bd4a51966c755d760de14ed.diff

LOG: [ELF] Simplify --print-icf-sections

Added: 
    

Modified: 
    lld/ELF/ICF.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 606953e94bbadd..80ddc3c32cf5d1 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -459,11 +459,6 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec,
   isec->eqClass[(cnt + 1) % 2] = hash | (1U << 31);
 }
 
-static void print(Ctx &ctx, const Twine &s) {
-  if (ctx.arg.printIcfSections)
-    Msg(ctx) << s;
-}
-
 // The main function of ICF.
 template <class ELFT> void ICF<ELFT>::run() {
   // Compute isPreemptible early. We may add more symbols later, so this loop
@@ -544,13 +539,16 @@ template <class ELFT> void ICF<ELFT>::run() {
 
   Log(ctx) << "ICF needed " << cnt << " iterations";
 
+  auto print = [&ctx = ctx]() -> ELFSyncStream {
+    return {ctx, ctx.arg.printIcfSections ? DiagLevel::Msg : DiagLevel::None};
+  };
   // Merge sections by the equivalence class.
   forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) {
     if (end - begin == 1)
       return;
-    print(ctx, "selected section " + toStr(ctx, sections[begin]));
+    print() << "selected section " << sections[begin];
     for (size_t i = begin + 1; i < end; ++i) {
-      print(ctx, "  removing identical section " + toStr(ctx, sections[i]));
+      print() << "  removing identical section " << sections[i];
       sections[begin]->replace(sections[i]);
 
       // At this point we know sections merged are fully identical and hence


        


More information about the llvm-commits mailing list