[llvm] [GlobalISel] Dump the machine function after each legalization iteration. NFC (PR #83401)

David Green via llvm-commits llvm-commits at lists.llvm.org
Mon May 26 00:44:20 PDT 2025


https://github.com/davemgreen updated https://github.com/llvm/llvm-project/pull/83401

>From 0fb3a326109b008956a7c7d949ee9522d6f2c4d1 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Mon, 26 May 2025 08:44:09 +0100
Subject: [PATCH] [GlobalISel] Dump the machine function after each
 legalization iteration. NFC

I find this useful to see the current state of the machine function as
legalization continues. Otherwise it is difficult to view the whole status
as individual combines/legalizations are occuring.
---
 llvm/lib/CodeGen/GlobalISel/Legalizer.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
index aef16b5f33af4..d733a41d57ee8 100644
--- a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -220,8 +220,14 @@ Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
   LegalizationArtifactCombiner ArtCombiner(MIRBuilder, MRI, LI, VT);
   bool Changed = false;
   SmallVector<MachineInstr *, 128> RetryList;
+  unsigned Iteration = 0;
   do {
-    LLVM_DEBUG(dbgs() << "=== New Iteration ===\n");
+    LLVM_DEBUG({
+      if (Iteration > 0) {
+        dbgs() << "=== New Iteration: " << Iteration << " ===\n";
+        MF.dump();
+      }
+    });
     assert(RetryList.empty() && "Expected no instructions in RetryList");
     unsigned NumArtifacts = ArtifactList.size();
     while (!InstList.empty()) {
@@ -301,6 +307,8 @@ Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
         InstList.insert(&MI);
       }
     }
+
+    ++Iteration;
   } while (!InstList.empty());
 
   return {Changed, /*FailedOn*/ nullptr};



More information about the llvm-commits mailing list