From 14c38ec2afeaf25c53a50c2c65116aca8c889401 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 28 Jan 2010 01:02:27 +0000 Subject: [PATCH] Remove the argument from EmitJumpTableInfo, because it doesn't need it. Move the X86 implementation of function body emission up to AsmPrinter::EmitFunctionBody, which works by calling the virtual EmitInstruction method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94716 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 13 +++- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 77 ++++++++++++++++--- lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 22 +++--- .../Alpha/AsmPrinter/AlphaAsmPrinter.cpp | 2 +- .../AsmPrinter/BlackfinAsmPrinter.cpp | 2 +- .../CellSPU/AsmPrinter/SPUAsmPrinter.cpp | 2 +- .../MSP430/AsmPrinter/MSP430AsmPrinter.cpp | 2 +- lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp | 2 +- .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 13 +--- .../SystemZ/AsmPrinter/SystemZAsmPrinter.cpp | 2 +- lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp | 62 +-------------- lib/Target/X86/AsmPrinter/X86AsmPrinter.h | 5 +- lib/Target/X86/AsmPrinter/X86MCInstLower.cpp | 2 +- .../XCore/AsmPrinter/XCoreAsmPrinter.cpp | 2 +- 14 files changed, 105 insertions(+), 103 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 31cc868f057..1970e63efef 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -214,18 +214,27 @@ namespace llvm { /// EmitFunctionHeader - This method emits the header for the current /// function. void EmitFunctionHeader(); + + /// EmitFunctionBody - This method emits the body and trailer for a + /// function. + void EmitFunctionBody(); + /// EmitInstruction - Targets should implement this to emit instructions. + virtual void EmitInstruction(const MachineInstr *MI) { + assert(0 && "EmitInstruction not implemented"); + } + /// EmitConstantPool - Print to the current output stream assembly /// representations of the constants in the constant pool MCP. This is /// used to print out constants which have been "spilled to memory" by /// the code generator. /// virtual void EmitConstantPool(); - + /// EmitJumpTableInfo - Print assembly representations of the jump tables /// used by the current function to the current output stream. /// - void EmitJumpTableInfo(MachineFunction &MF); + void EmitJumpTableInfo(); /// EmitGlobalVariable - Emit the specified global variable to the .s file. virtual void EmitGlobalVariable(const GlobalVariable *GV); diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index ed410a9614f..68fd77c0bdb 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "asm-printer" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/Assembly/Writer.h" #include "llvm/DerivedTypes.h" @@ -31,10 +32,6 @@ #include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/FormattedStream.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/Target/Mangler.h" #include "llvm/Target/TargetData.h" @@ -45,9 +42,17 @@ #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/FormattedStream.h" #include using namespace llvm; +STATISTIC(EmittedInsts, "Number of machine instrs printed"); + static cl::opt AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), cl::init(cl::BOU_UNSET)); @@ -336,6 +341,58 @@ void AsmPrinter::EmitFunctionEntryLabel() { } +/// EmitFunctionBody - This method emits the body and trailer for a +/// function. +void AsmPrinter::EmitFunctionBody() { + + // Print out code for the function. + bool HasAnyRealCode = false; + for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); + I != E; ++I) { + // Print a label for the basic block. + EmitBasicBlockStart(I); + for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); + II != IE; ++II) { + // Print the assembly for the instruction. + if (!II->isLabel()) + HasAnyRealCode = true; + + ++EmittedInsts; + + // FIXME: Clean up processDebugLoc. + processDebugLoc(II, true); + + EmitInstruction(II); + + if (VerboseAsm) + EmitComments(*II); + O << '\n'; + + // FIXME: Clean up processDebugLoc. + processDebugLoc(II, false); + } + } + + // If the function is empty and the object file uses .subsections_via_symbols, + // then we need to emit *some* thing to the function body to prevent the + // labels from collapsing together. + if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) { + // FIXME: EmitByte(0). + O << "\tnop\n"; + } + + if (MAI->hasDotTypeDotSizeDirective()) + O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; + + // Emit post-function debug information. + if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling()) + DW->EndFunction(MF); + + // Print out jump tables referenced by the function. + EmitJumpTableInfo(); +} + + bool AsmPrinter::doFinalization(Module &M) { // Emit global variables. for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); @@ -528,15 +585,15 @@ void AsmPrinter::EmitConstantPool() { /// EmitJumpTableInfo - Print assembly representations of the jump tables used /// by the current function to the current output stream. /// -void AsmPrinter::EmitJumpTableInfo(MachineFunction &MF) { - MachineJumpTableInfo *MJTI = MF.getJumpTableInfo(); +void AsmPrinter::EmitJumpTableInfo() { + const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); if (MJTI == 0) return; const std::vector &JT = MJTI->getJumpTables(); if (JT.empty()) return; // Pick the directive to use to print the jump table entries, and switch to // the appropriate section. - const Function *F = MF.getFunction(); + const Function *F = MF->getFunction(); bool JTInDiffSection = false; if (// In PIC mode, we need to emit the jump table to the same section as the // function body itself, otherwise the label differences won't make sense. @@ -547,8 +604,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineFunction &MF) { // FIXME: this isn't the right predicate, should be based on the MCSection // for the function. F->isWeakForLinker()) { - OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, - TM)); + OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F,Mang,TM)); } else { // Otherwise, drop it in the readonly section. const MCSection *ReadOnlySection = @@ -572,8 +628,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineFunction &MF) { MAI->hasSetDirective()) { SmallPtrSet EmittedSets; const TargetLowering *TLI = TM.getTargetLowering(); - const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(&MF, JTI, - OutContext); + const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { const MachineBasicBlock *MBB = JTBBs[ii]; if (!EmittedSets.insert(MBB)) continue; diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 348c455472c..72a2c3765ac 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -266,22 +266,11 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { // instructions. EmitFunctionHeader(); - if (Subtarget->isTargetDarwin()) { - // If the function is empty, then we need to emit *something*. Otherwise, - // the function's label might be associated with something that it wasn't - // meant to be associated with. We emit a noop in this situation. - MachineFunction::iterator I = MF.begin(); - - if (++I == MF.end() && MF.front().empty()) - O << "\tnop\n"; - } - // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { // Print a label for the basic block. - if (I != MF.begin()) - EmitBasicBlockStart(I); + EmitBasicBlockStart(I); // Print the assembly for the instruction. for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); @@ -289,6 +278,15 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { printMachineInstruction(II); } + if (Subtarget->isTargetDarwin()) { + // If the function is empty, then we need to emit *something*. Otherwise, + // the function's label might be associated with something that it wasn't + // meant to be associated with. We emit a noop in this situation. + MachineFunction::iterator I = MF.begin(); + if (++I == MF.end() && MF.front().empty()) + O << "\tnop\n"; + } + if (MAI->hasDotTypeDotSizeDirective()) O << "\t.size " << *CurrentFnSym << ", .-" << *CurrentFnSym << "\n"; diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index a4c3a49a3f0..5095705df8e 100644 --- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -154,7 +154,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.end " << *CurrentFnSym << "\n"; // Print out jump tables referenced by the function - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything. return false; diff --git a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp index 5a1b4921ad3..7298ff5e1e2 100644 --- a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp +++ b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp @@ -97,7 +97,7 @@ bool BlackfinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { } } - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); O << "\t.size " << *CurrentFnSym << ", .-" << *CurrentFnSym << "\n"; diff --git a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index 5c9dbd598ce..81c8e2b0901 100644 --- a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -425,7 +425,7 @@ bool LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.size\t" << *CurrentFnSym << ",.-" << *CurrentFnSym << "\n"; // Print out jump tables referenced by the function. - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // Emit post-function debug information. DW->EndFunction(&MF); diff --git a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp index 3064f77e5c8..95f20399a0d 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp +++ b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp @@ -110,7 +110,7 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; // Print out constants referenced by the function - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything return false; diff --git a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp index 1f828e70178..8285a412703 100644 --- a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp @@ -268,7 +268,7 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) { emitFunctionEnd(MF); // Print out jump tables referenced by the function - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything. return false; diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 7fd17690f4d..9e886ee6bb0 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -319,8 +319,6 @@ namespace { void printPredicateOperand(const MachineInstr *MI, unsigned OpNo, const char *Modifier); - - virtual bool runOnMachineFunction(MachineFunction &F) = 0; }; /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux @@ -624,8 +622,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) { for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { // Print a label for the basic block. - if (I != MF.begin()) - EmitBasicBlockStart(I); + EmitBasicBlockStart(I); // Print the assembly for the instructions. for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); @@ -639,7 +636,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) { DW->EndFunction(&MF); // Print out jump tables referenced by the function. - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything. return false; @@ -686,9 +683,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { // Print a label for the basic block. - if (I != MF.begin()) { - EmitBasicBlockStart(I); - } + EmitBasicBlockStart(I); for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); II != IE; ++II) { // Print the assembly for the instruction. @@ -700,7 +695,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { DW->EndFunction(&MF); // Print out jump tables referenced by the function. - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything. return false; diff --git a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp index 0edf5203c64..532a40db8e4 100644 --- a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp +++ b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp @@ -105,7 +105,7 @@ bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; // Print out jump tables referenced by the function. - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // We didn't modify anything return false; diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index 16432341e19..8037247fefa 100644 --- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -8,12 +8,10 @@ //===----------------------------------------------------------------------===// // // This file contains a printer that converts from our internal representation -// of machine-dependent LLVM code to AT&T format assembly -// language. This printer is the output mechanism used by `llc'. +// of machine-dependent LLVM code to X86 machine code. // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "asm-printer" #include "X86AsmPrinter.h" #include "X86ATTInstPrinter.h" #include "X86IntelInstPrinter.h" @@ -41,11 +39,8 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/Statistic.h" using namespace llvm; -STATISTIC(EmittedInsts, "Number of machine instrs printed"); - //===----------------------------------------------------------------------===// // Primitive Helper Functions. //===----------------------------------------------------------------------===// @@ -63,8 +58,7 @@ void X86AsmPrinter::PrintPICBaseSymbol() const { OutContext); } -/// runOnMachineFunction - This uses the printMachineInstruction() -/// method to print assembly for each instruction. +/// runOnMachineFunction - Emit the function body. /// bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { SetupMachineFunction(MF); @@ -99,38 +93,8 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { // Have common code print out the function header with linkage info etc. EmitFunctionHeader(); - - // Print out code for the function. - bool hasAnyRealCode = false; - for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); - I != E; ++I) { - // Print a label for the basic block. - EmitBasicBlockStart(I); - for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); - II != IE; ++II) { - // Print the assembly for the instruction. - if (!II->isLabel()) - hasAnyRealCode = true; - printMachineInstruction(II); - } - } - - if (Subtarget->isTargetDarwin() && !hasAnyRealCode) { - // If the function is empty, then we need to emit *something*. Otherwise, - // the function's label might be associated with something that it wasn't - // meant to be associated with. We emit a noop in this situation. - O << "\tnop\n"; - } - - if (MAI->hasDotTypeDotSizeDirective()) - O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; - - // Emit post-function debug information. - if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling()) - DW->EndFunction(&MF); - - // Print out jump tables referenced by the function. - EmitJumpTableInfo(MF); + // Emit the rest of the function body. + EmitFunctionBody(); // We didn't modify anything. return false; @@ -523,24 +487,6 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, } - -/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in -/// AT&T syntax to the current output stream. -/// -void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) { - ++EmittedInsts; - - processDebugLoc(MI, true); - - printInstructionThroughMCStreamer(MI); - - if (VerboseAsm) - EmitComments(*MI); - O << '\n'; - - processDebugLoc(MI, false); -} - void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { if (Subtarget->isTargetDarwin()) { // All darwin targets use mach-o. diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.h b/lib/Target/X86/AsmPrinter/X86AsmPrinter.h index e7dc939e205..ce47b544830 100644 --- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.h @@ -57,9 +57,8 @@ class VISIBILITY_HIDDEN X86AsmPrinter : public AsmPrinter { virtual void EmitEndOfAsmFile(Module &M); - void printInstructionThroughMCStreamer(const MachineInstr *MI); - - + virtual void EmitInstruction(const MachineInstr *MI); + void printMCInst(const MCInst *MI); void printSymbolOperand(const MachineOperand &MO); diff --git a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp index 9fb6ca4c460..350b1fa422e 100644 --- a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp +++ b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp @@ -408,7 +408,7 @@ void X86MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const { -void X86AsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) { +void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { X86MCInstLower MCInstLowering(OutContext, Mang, *this); switch (MI->getOpcode()) { case TargetInstrInfo::DBG_LABEL: diff --git a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp index e2e0b2befcf..39344959b6f 100644 --- a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp @@ -264,7 +264,7 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF) { emitFunctionEnd(MF); // Print out jump tables referenced by the function - EmitJumpTableInfo(MF); + EmitJumpTableInfo(); // Emit post-function debug information. DW->EndFunction(&MF);