[llvm-commits] CVS: llvm/lib/CodeGen/MachineInstr.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Feb 19 10:20:01 PST 2004


Changes in directory llvm/lib/CodeGen:

MachineInstr.cpp updated: 1.90 -> 1.91

---
Log message:

Fix a __LONG__ term annoyance of mine: symbolic registers weren't being printed
by operator<< on MachineInstr's, and looking up what register "24" is all of the
time was greatly annoying.


---
Diffs of the changes:  (+16 -6)

Index: llvm/lib/CodeGen/MachineInstr.cpp
diff -u llvm/lib/CodeGen/MachineInstr.cpp:1.90 llvm/lib/CodeGen/MachineInstr.cpp:1.91
--- llvm/lib/CodeGen/MachineInstr.cpp:1.90	Mon Feb 16 01:17:42 2004
+++ llvm/lib/CodeGen/MachineInstr.cpp	Thu Feb 19 10:17:08 2004
@@ -15,7 +15,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Value.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetInstrInfo.h"
@@ -198,13 +198,13 @@
 
 static inline void OutputReg(std::ostream &os, unsigned RegNo,
                              const MRegisterInfo *MRI = 0) {
-  if (MRI) {
-    if (MRegisterInfo::isPhysicalRegister(RegNo))
+  if (MRegisterInfo::isPhysicalRegister(RegNo)) {
+    if (MRI)
       os << "%" << MRI->get(RegNo).Name;
     else
-      os << "%reg" << RegNo;
+      os << "%mreg(" << RegNo << ")";
   } else
-    os << "%mreg(" << RegNo << ")";
+    os << "%reg" << RegNo;
 }
 
 static void print(const MachineOperand &MO, std::ostream &OS,
@@ -328,7 +328,17 @@
   OS << "\n";
 }
 
-std::ostream &operator<<(std::ostream& os, const MachineInstr& MI) {
+std::ostream &operator<<(std::ostream &os, const MachineInstr &MI) {
+  // If the instruction is embedded into a basic block, we can find the target
+  // info for the instruction.
+  if (const MachineBasicBlock *MBB = MI.getParent()) {
+    const MachineFunction *MF = MBB->getParent();
+    MI.print(os, MF->getTarget());
+    return os;
+  }
+
+  // Otherwise, print it out in the "raw" format without symbolic register names
+  // and such.
   os << TargetInstrDescriptors[MI.getOpcode()].Name;
   
   for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {





More information about the llvm-commits mailing list