1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

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.

llvm-svn: 94716
This commit is contained in:
Chris Lattner 2010-01-28 01:02:27 +00:00
parent 6a127932c1
commit 8411a9084e
14 changed files with 105 additions and 103 deletions

View File

@ -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);

View File

@ -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 <cerrno>
using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
static cl::opt<cl::boolOrDefault>
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<MachineJumpTableEntry> &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<const MachineBasicBlock*, 16> 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;

View File

@ -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";

View File

@ -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;

View File

@ -97,7 +97,7 @@ bool BlackfinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
}
}
EmitJumpTableInfo(MF);
EmitJumpTableInfo();
O << "\t.size " << *CurrentFnSym << ", .-" << *CurrentFnSym << "\n";

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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);

View File

@ -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:

View File

@ -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);