[llvm] 550d425 - [RegAlloc] Add printer and dump for VNInfo [nfc] (#160758)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Sep 26 07:37:39 PDT 2025
    
    
  
Author: Philip Reames
Date: 2025-09-26T14:37:35Z
New Revision: 550d425a719cb8296dd8df4484a1b6a2c6b5b140
URL: https://github.com/llvm/llvm-project/commit/550d425a719cb8296dd8df4484a1b6a2c6b5b140
DIFF: https://github.com/llvm/llvm-project/commit/550d425a719cb8296dd8df4484a1b6a2c6b5b140.diff
LOG: [RegAlloc] Add printer and dump for VNInfo [nfc] (#160758)
Uses the existing format of the LiveRange printer, and just factors it
out so that you can do vni->dump() when debugging, or log a vni in a
debug print statement.
Added: 
    
Modified: 
    llvm/include/llvm/CodeGen/LiveInterval.h
    llvm/lib/CodeGen/LiveInterval.cpp
Removed: 
    
################################################################################
diff  --git a/llvm/include/llvm/CodeGen/LiveInterval.h b/llvm/include/llvm/CodeGen/LiveInterval.h
index e1c5717f5face..f18c177b1c35b 100644
--- a/llvm/include/llvm/CodeGen/LiveInterval.h
+++ b/llvm/include/llvm/CodeGen/LiveInterval.h
@@ -83,8 +83,16 @@ namespace llvm {
 
     /// Mark this value as unused.
     void markUnused() { def = SlotIndex(); }
+
+    LLVM_ABI void print(raw_ostream &OS) const;
+    LLVM_ABI void dump() const;
   };
 
+  inline raw_ostream &operator<<(raw_ostream &OS, const VNInfo &VNI) {
+    VNI.print(OS);
+    return OS;
+  }
+
   /// Result of a LiveRange query. This class hides the implementation details
   /// of live ranges, and it should be used as the primary interface for
   /// examining live ranges around instructions.
diff  --git a/llvm/lib/CodeGen/LiveInterval.cpp b/llvm/lib/CodeGen/LiveInterval.cpp
index b682998c329bc..299db85233c2d 100644
--- a/llvm/lib/CodeGen/LiveInterval.cpp
+++ b/llvm/lib/CodeGen/LiveInterval.cpp
@@ -996,6 +996,17 @@ LLVM_DUMP_METHOD void LiveRange::Segment::dump() const {
 }
 #endif
 
+void VNInfo::print(raw_ostream &OS) const {
+  OS << id << '@';
+  if (isUnused()) {
+    OS << 'x';
+  } else {
+    OS << def;
+    if (isPHIDef())
+      OS << "-phi";
+  }
+}
+
 void LiveRange::print(raw_ostream &OS) const {
   if (empty())
     OS << "EMPTY";
@@ -1013,15 +1024,10 @@ void LiveRange::print(raw_ostream &OS) const {
     for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
          ++i, ++vnum) {
       const VNInfo *vni = *i;
-      if (vnum) OS << ' ';
-      OS << vnum << '@';
-      if (vni->isUnused()) {
-        OS << 'x';
-      } else {
-        OS << vni->def;
-        if (vni->isPHIDef())
-          OS << "-phi";
-      }
+      if (vnum)
+        OS << ' ';
+      OS << *vni;
+      assert(vnum == vni->id && "Bad VNInfo");
     }
   }
 }
@@ -1041,9 +1047,9 @@ void LiveInterval::print(raw_ostream &OS) const {
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-LLVM_DUMP_METHOD void LiveRange::dump() const {
-  dbgs() << *this << '\n';
-}
+LLVM_DUMP_METHOD void VNInfo::dump() const { dbgs() << *this << '\n'; }
+
+LLVM_DUMP_METHOD void LiveRange::dump() const { dbgs() << *this << '\n'; }
 
 LLVM_DUMP_METHOD void LiveInterval::SubRange::dump() const {
   dbgs() << *this << '\n';
        
    
    
More information about the llvm-commits
mailing list