From c5ea263a23f4f15587e35c9cb07cf72a9fba7613 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 9 Sep 2009 23:14:36 +0000 Subject: [PATCH] remove DebugLoc from MCInst and eliminate "Comment printing" from 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 --- include/llvm/CodeGen/AsmPrinter.h | 2 - include/llvm/MC/MCInst.h | 7 ---- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 42 +++++-------------- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 1 + lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 3 ++ .../Alpha/AsmPrinter/AlphaAsmPrinter.cpp | 6 +++ .../AsmPrinter/BlackfinAsmPrinter.cpp | 6 +++ .../CellSPU/AsmPrinter/SPUAsmPrinter.cpp | 4 ++ .../MSP430/AsmPrinter/MSP430AsmPrinter.cpp | 6 +++ lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp | 7 ++++ .../PIC16/AsmPrinter/PIC16AsmPrinter.cpp | 6 +++ .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 4 ++ .../Sparc/AsmPrinter/SparcAsmPrinter.cpp | 5 +++ .../SystemZ/AsmPrinter/SystemZAsmPrinter.cpp | 6 +++ .../X86/AsmPrinter/X86ATTAsmPrinter.cpp | 4 ++ .../X86/AsmPrinter/X86IntelAsmPrinter.cpp | 4 ++ lib/Target/X86/AsmPrinter/X86MCInstLower.cpp | 1 - .../XCore/AsmPrinter/XCoreAsmPrinter.cpp | 9 ++-- utils/TableGen/AsmWriterEmitter.cpp | 4 -- 19 files changed, 76 insertions(+), 51 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index c7d2f54e854..88534a54d54 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -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; diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h index 9facf3bb5b5..b204a9b74da 100644 --- a/include/llvm/MC/MCInst.h +++ b/include/llvm/MC/MCInst.h @@ -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 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(); } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index e4d8ef06f1b..3e8c9131e01 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -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. /// diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index bc4333d9c1b..29446a427ce 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -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) diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 59c2174020a..7d1bb789c9f 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -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) { diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index e22ebec4941..0d6ee122b4f 100644 --- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -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'; } } diff --git a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp index 759726f5d6d..b37e6253391 100644 --- a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp +++ b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp @@ -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; } } diff --git a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index 230f0f52803..011128031d3 100644 --- a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -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() diff --git a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp index 6e2e9599dfe..dc2f31a2bb5 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp +++ b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp @@ -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, diff --git a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp index e56b38b5e55..5c41ce90f0c 100644 --- a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp @@ -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; } diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp index 5c33bed035f..f9b8044c4a0 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp @@ -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; } diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index a92aa4850ef..fecd2ea33a9 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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() diff --git a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp index 168034641b8..e4c5b553177 100644 --- a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp @@ -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; } } diff --git a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp index 8586782a8b7..b93bdfe2ac9 100644 --- a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp +++ b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp @@ -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) { diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 7b91819f979..c8e9efd468b 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -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) { diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp index cc8c74b7a48..9fd504d3f44 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -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) { diff --git a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp index fcab086644f..e27c83b5ddb 100644 --- a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp +++ b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp @@ -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: diff --git a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp index 801a1b33c85..40856a3713f 100644 --- a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp @@ -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) { diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index d6aa8bf0466..db959ad7c49 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -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)); } -- 2.34.1