remove DebugLoc from MCInst and eliminate "Comment printing" from
authorChris Lattner <sabre@nondot.org>
Wed, 9 Sep 2009 23:14:36 +0000 (23:14 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 9 Sep 2009 23:14:36 +0000 (23:14 +0000)
the MCInst path of the asmprinter.  Instead, pull comment printing
out of the autogenerated asmprinter into each target that uses the
autogenerated asmprinter.  This causes code duplication into each
target, but in a way that will be easier to clean up later when more
asmprinter stuff is commonized into the base AsmPrinter class.

This also fixes an xcore strangeness where it inserted two tabs
before every instruction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81396 91177308-0d34-0410-b5e6-96231b3b80d8

19 files changed:
include/llvm/CodeGen/AsmPrinter.h
include/llvm/MC/MCInst.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp
lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp
utils/TableGen/AsmWriterEmitter.cpp

index c7d2f54e854a31ec1979defe49c7eb77284ce5f7..88534a54d54ec104bfc65940a0079bef0c8a4a08 100644 (file)
@@ -336,8 +336,6 @@ namespace llvm {
 
     /// EmitComments - Pretty-print comments for instructions
     void EmitComments(const MachineInstr &MI) const;
-    /// EmitComments - Pretty-print comments for instructions
-    void EmitComments(const MCInst &MI) const;
     /// EmitComments - Pretty-print comments for basic blocks
     void EmitComments(const MachineBasicBlock &MBB) const;
 
index 9facf3bb5b54d40f46d94a736b911a9e50ab07ef..b204a9b74da640469f2c8d1ad103474d3bcd6e15 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/DataTypes.h"
-#include "llvm/Support/DebugLoc.h"
 
 namespace llvm {
 class raw_ostream;
@@ -132,9 +131,6 @@ public:
 class MCInst {
   unsigned Opcode;
   SmallVector<MCOperand, 8> Operands;
-  
-  // FIXME: This is a hack!
-  DebugLoc Loc;
 public:
   MCInst() : Opcode(~0U) {}
   
@@ -142,9 +138,6 @@ public:
   
   unsigned getOpcode() const { return Opcode; }
 
-  void setDebugLoc(DebugLoc L) { Loc = L; }
-  DebugLoc getDebugLoc() const { return Loc; }
-  
   const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
   MCOperand &getOperand(unsigned i) { return Operands[i]; }
   unsigned getNumOperands() const { return Operands.size(); }
index e4d8ef06f1ba5cd19d52ef224278b9b79b6a5b95..3e8c9131e01017b31d9fadb98b744a4165c22702 100644 (file)
@@ -1390,9 +1390,11 @@ void AsmPrinter::processDebugLoc(DebugLoc DL) {
     if (!DL.isUnknown()) {
       DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
 
-      if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT)
+      if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) {
         printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
                                         DICompileUnit(CurDLT.CompileUnit)));
+        O << '\n';
+      }
 
       PrevDLT = CurDLT;
     }
@@ -1594,17 +1596,16 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
     }
     }
   }
-  O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
+  O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd();
 }
 
 /// printImplicitDef - This method prints the specified machine instruction
 /// that is an implicit def.
 void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
-  if (VerboseAsm) {
-    O.PadToColumn(MAI->getCommentColumn());
-    O << MAI->getCommentString() << " implicit-def: "
-      << TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
-  }
+  if (!VerboseAsm) return;
+  O.PadToColumn(MAI->getCommentColumn());
+  O << MAI->getCommentString() << " implicit-def: "
+    << TRI->getAsmName(MI->getOperand(0).getReg());
 }
 
 /// printLabel - This method prints a local label used by debug and
@@ -1614,7 +1615,7 @@ void AsmPrinter::printLabel(const MachineInstr *MI) const {
 }
 
 void AsmPrinter::printLabel(unsigned Id) const {
-  O << MAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
+  O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':';
 }
 
 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
@@ -1780,9 +1781,7 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
 
 /// EmitComments - Pretty-print comments for instructions
 void AsmPrinter::EmitComments(const MachineInstr &MI) const {
-  if (!VerboseAsm ||
-      MI.getDebugLoc().isUnknown())
-    return;
+  assert(VerboseAsm && !MI.getDebugLoc().isUnknown());
   
   DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
 
@@ -1799,27 +1798,6 @@ void AsmPrinter::EmitComments(const MachineInstr &MI) const {
     O << ":" << DLT.Col;
 }
 
-/// EmitComments - Pretty-print comments for instructions
-void AsmPrinter::EmitComments(const MCInst &MI) const {
-  if (!VerboseAsm ||
-      MI.getDebugLoc().isUnknown())
-    return;
-  
-  DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
-
-  // Print source line info
-  O.PadToColumn(MAI->getCommentColumn());
-  O << MAI->getCommentString() << " SrcLine ";
-  if (DLT.CompileUnit) {
-    std::string Str;
-    DICompileUnit CU(DLT.CompileUnit);
-    O << CU.getFilename(Str) << " ";
-  }
-  O << DLT.Line;
-  if (DLT.Col != 0) 
-    O << ":" << DLT.Col;
-}
-
 /// PrintChildLoopComment - Print comments about child loops within
 /// the loop for this basic block, with nesting.
 ///
index bc4333d9c1bb032e71e1c99cc75a5aef3945227f..29446a427cec18ef7cb1dd0e1159262f96a17f4e 100644 (file)
@@ -1709,6 +1709,7 @@ void DwarfDebug::BeginFunction(MachineFunction *MF) {
     unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col,
                                         DICompileUnit(DLT.CompileUnit));
     Asm->printLabel(LabelID);
+    O << '\n';
   }
 
   if (TimePassesIsEnabled)
index 59c2174020a111855443dc15bb00541304463184..7d1bb789c9f1aae580df7c666dccf7121d0ae7bd 100644 (file)
@@ -1031,6 +1031,9 @@ void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   // Call the autogenerated instruction printer routines.
   processDebugLoc(MI->getDebugLoc());
   printInstruction(MI);
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 bool ARMAsmPrinter::doInitialization(Module &M) {
index e22ebec49419f58a3a11475bad28737f926aeaa3..0d6ee122b4fdf33c063bc4d96498c1b4dfb54dfd 100644 (file)
@@ -176,7 +176,13 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
          II != E; ++II) {
       // Print the assembly for the instruction.
       ++EmittedInsts;
+      processDebugLoc(II->getDebugLoc());
+      
       printInstruction(II);
+      
+      if (VerboseAsm && !II->getDebugLoc().isUnknown())
+        EmitComments(*II);
+      O << '\n';
     }
   }
 
index 759726f5d6d54b684de839a488793a6f43557d1c..b37e62533919d9b9c228eac4ab4d561bc69aadff 100644 (file)
@@ -143,7 +143,13 @@ bool BlackfinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
+      processDebugLoc(II->getDebugLoc());
+
       printInstruction(II);
+      if (VerboseAsm && !II->getDebugLoc().isUnknown())
+        EmitComments(*II);
+      O << '\n';
+      
       ++EmittedInsts;
     }
   }
index 230f0f5280369f4f3783ed045df6d73515f4aa0b..011128031d30e4e6976d2fac4c12f932b452fcc7 100644 (file)
@@ -410,6 +410,10 @@ void SPUAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
   processDebugLoc(MI->getDebugLoc());
   printInstruction(MI);
+
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
index 6e2e9599dfea921ebf10968b2e10406a7c53ca6d..dc2f31a2bb56437bfe6883048133e4e14a1a05a9 100644 (file)
@@ -145,8 +145,14 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
 
+  processDebugLoc(MI->getDebugLoc());
+
   // Call the autogenerated instruction printer routines.
   printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
index e56b38b5e550aa74c29312ce74675c9d3c18cb12..5c41ce90f0c04b45352c71753c6202a8596904ba 100644 (file)
@@ -275,8 +275,15 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
+      processDebugLoc(II->getDebugLoc());
+
       // Print the assembly for the instruction.
       printInstruction(II);
+      
+      if (VerboseAsm && !II->getDebugLoc().isUnknown())
+        EmitComments(*II);
+      O << '\n';
+      
       ++EmittedInsts;
     }
 
index 5c33bed035f6173cd608fa1281eadffc939908f6..f9b8044c4a013a612e48566259ffb3dde3001ba0 100644 (file)
@@ -42,7 +42,13 @@ PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
 }
 
 bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
+  processDebugLoc(MI->getDebugLoc());
+  
   printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
   return true;
 }
 
index a92aa4850efd936507c5c84c055bd22d8d157114..fecd2ea33a92bae579793fb9ccc7fae2e6852aad 100644 (file)
@@ -603,6 +603,10 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   }
 
   printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
index 168034641b89d478fa1a8fee6f070508d0b82251..e4c5b5531774b15c4355b9892dc8431a0f4e63e1 100644 (file)
@@ -129,6 +129,11 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
       // Print the assembly for the instruction.
       processDebugLoc(II->getDebugLoc());
       printInstruction(II);
+      
+      if (VerboseAsm && !II->getDebugLoc().isUnknown())
+        EmitComments(*II);
+      O << '\n';
+      
       ++EmittedInsts;
     }
   }
index 8586782a8b7e0b4fc0a55d1f7cc3630c76691e0a..b93bdfe2ac9ebd4087a45471d71cccc94dfb0816 100644 (file)
@@ -153,8 +153,14 @@ bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
 
+  processDebugLoc(MI->getDebugLoc());
+
   // Call the autogenerated instruction printer routines.
   printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum) {
index 7b91819f9798c478abfe37db36cbf43e7a00f814..c8e9efd468b3ea019b8827b6ca31e87e9845d057 100644 (file)
@@ -702,6 +702,10 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
     printInstructionThroughMCStreamer(MI);
   else
     printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
index cc8c74b7a484616f8bd419ffb7e1be4c2a9d6de9..9fd504d3f44b8ac948337fe7bd207ddb2b138b3f 100644 (file)
@@ -437,6 +437,10 @@ void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
 
   // Call the autogenerated instruction printer routines.
   printInstruction(MI);
+  
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 bool X86IntelAsmPrinter::doInitialization(Module &M) {
index fcab086644f568158e25d38b691547fce38bbaa3..e27c83b5ddbfbec40679f074c63b0e4ec22e23bf 100644 (file)
@@ -267,7 +267,6 @@ MCOperand X86ATTAsmPrinter::LowerSymbolOperand(const MachineOperand &MO,
 void X86ATTAsmPrinter::
 printInstructionThroughMCStreamer(const MachineInstr *MI) {
   MCInst TmpInst;
-  TmpInst.setDebugLoc(MI->getDebugLoc());
   switch (MI->getOpcode()) {
   case TargetInstrInfo::DBG_LABEL:
   case TargetInstrInfo::EH_LABEL:
index 801a1b33c8563d3b1675f45aea67d04a87a9d5d7..40856a3713ff8e5b1a071c3882fcaf5110f0837f 100644 (file)
@@ -279,7 +279,6 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF)
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
-      O << "\t";
       printMachineInstruction(II);
     }
 
@@ -313,10 +312,7 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
   const MachineOperand &MO = MI->getOperand(opNum);
   switch (MO.getType()) {
   case MachineOperand::MO_Register:
-    if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
-      O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
-    else
-      llvm_unreachable("not implemented");
+    O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
     break;
   case MachineOperand::MO_Immediate:
     O << MO.getImm();
@@ -368,6 +364,9 @@ void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
     return;
   }
   printInstruction(MI);
+  if (VerboseAsm && !MI->getDebugLoc().isUnknown())
+    EmitComments(*MI);
+  O << '\n';
 }
 
 bool XCoreAsmPrinter::doInitialization(Module &M) {
index d6aa8bf04660245275745bd7f4ccc91c5066867f..db959ad7c490500a0fb978b0d1684f712f3659de 100644 (file)
@@ -323,10 +323,6 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, Record *AsmWriter) {
     }
   }
   
-  Operands.push_back(
-    AsmWriterOperand("EmitComments(*MI);\n",
-                     AsmWriterOperand::isLiteralStatementOperand));
-  AddLiteralString("\\n");
   Operands.push_back(AsmWriterOperand("return;",
                                   AsmWriterOperand::isLiteralStatementOperand));
 }