aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/CodeGen/AsmPrinter.h13
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinter.cpp77
-rw-r--r--lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp22
-rw-r--r--lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp2
-rw-r--r--lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp2
-rw-r--r--lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp2
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp2
-rw-r--r--lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp2
-rw-r--r--lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp13
-rw-r--r--lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp2
-rw-r--r--lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp62
-rw-r--r--lib/Target/X86/AsmPrinter/X86AsmPrinter.h5
-rw-r--r--lib/Target/X86/AsmPrinter/X86MCInstLower.cpp2
-rw-r--r--lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp2
14 files changed, 105 insertions, 103 deletions
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h
index 31cc868f05..1970e63efe 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 ed410a9614..68fd77c0bd 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 <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;
diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
index 348c455472..72a2c3765a 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 a4c3a49a3f..5095705df8 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 5a1b4921ad..7298ff5e1e 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 5c9dbd598c..81c8e2b090 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 3064f77e5c..95f20399a0 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 1f828e7017..8285a41270 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 7fd17690f4..9e886ee6bb 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 0edf5203c6..532a40db8e 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 16432341e1..8037247fef 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 e7dc939e20..ce47b54483 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 9fb6ca4c46..350b1fa422 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 e2e0b2befc..39344959b6 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);