[llvm] 1db2879 - MCAssembler: Split evaluateFixup to Number of fixups and Number of fixup evaluations for relaxation

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 20:47:58 PDT 2025


Author: Fangrui Song
Date: 2025-08-01T20:47:53-07:00
New Revision: 1db2879a36d11b2e54826b2fc97174e61ad68474

URL: https://github.com/llvm/llvm-project/commit/1db2879a36d11b2e54826b2fc97174e61ad68474
DIFF: https://github.com/llvm/llvm-project/commit/1db2879a36d11b2e54826b2fc97174e61ad68474.diff

LOG: MCAssembler: Split evaluateFixup to Number of fixups and Number of fixup evaluations for relaxation

The number of fixups is a more important metric, guiding the data
structure optimization.

Added: 
    

Modified: 
    llvm/lib/MC/MCAssembler.cpp
    llvm/test/MC/ELF/mc-dump.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 8500fd1fef520..39998aad48e35 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -59,7 +59,8 @@ STATISTIC(EmittedFillFragments,
           "Number of emitted assembler fragments - fill");
 STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
 STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
-STATISTIC(evaluateFixup, "Number of evaluated fixups");
+STATISTIC(Fixups, "Number of fixups");
+STATISTIC(FixupEvalForRelax, "Number of fixup evaluations for relaxation");
 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
@@ -142,7 +143,8 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
                                 MCValue &Target, uint64_t &Value,
                                 bool RecordReloc,
                                 MutableArrayRef<char> Contents) const {
-  ++stats::evaluateFixup;
+  if (RecordReloc)
+    ++stats::Fixups;
 
   // FIXME: This code has some duplication with recordRelocation. We should
   // probably merge the two into a single callback that tries to evaluate a
@@ -735,7 +737,7 @@ void MCAssembler::Finish() {
 
 bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
                                        const MCFixup &Fixup) const {
-  assert(getBackendPtr() && "Expected assembler backend");
+  ++stats::FixupEvalForRelax;
   MCValue Target;
   uint64_t Value;
   bool Resolved = evaluateFixup(F, const_cast<MCFixup &>(Fixup), Target, Value,

diff  --git a/llvm/test/MC/ELF/mc-dump.s b/llvm/test/MC/ELF/mc-dump.s
index fd6cf95f4af44..51b3ff4774cf3 100644
--- a/llvm/test/MC/ELF/mc-dump.s
+++ b/llvm/test/MC/ELF/mc-dump.s
@@ -1,5 +1,5 @@
 # REQUIRES: asserts
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t -debug-only=mc-dump-pre,mc-dump 2>&1 | FileCheck %s --match-full-lines --strict-whitespace
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t -debug-only=mc-dump-pre,mc-dump -stats 2>&1 | FileCheck %s --match-full-lines --strict-whitespace
 
 #CHECK-LABEL:assembler backend - pre-layout
 #      CHECK:MCSection Name:.text
@@ -30,6 +30,9 @@
 # CHECK-NEXT:5 LEB Size:0+1 [15] Value:.Ltmp0-_start Signed:0
 #      CHECK:]
 
+# CHECK:  2 assembler         - Number of fixup evaluations for relaxation
+# CHECK:  8 assembler         - Number of fixups
+
 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t -debug-only=mc-dump -save-temp-labels -g 2>&1 | FileCheck %s --check-prefix=CHECK2
 
 #      CHECK2:5 Data Size:16 [48,8b,04,25,00,00,00,00,48,8b,04,25,00,00,00,00]


        


More information about the llvm-commits mailing list