aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp179
-rw-r--r--lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h3
2 files changed, 123 insertions, 59 deletions
diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
index 97d1dd15de..9dffbe831f 100644
--- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
@@ -52,12 +52,28 @@ static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
//===----------------------------------------------------------------------===//
void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
+ // FIXME: the actual label generated doesn't matter here! Just mangle in
+ // something unique (the function number) with Private prefix.
if (Subtarget->isTargetDarwin())
O << "\"L" << getFunctionNumber() << "$pb\"";
- else if (Subtarget->isTargetELF())
+ else {
+ assert(Subtarget->isTargetELF() && "Don't know how to print PIC label!");
O << ".Lllvm$" << getFunctionNumber() << ".$piclabel";
- else
- llvm_unreachable("Don't know how to print PIC label!");
+ }
+}
+
+MCSymbol *X86ATTAsmPrinter::GetPICBaseSymbol() {
+ // FIXME: the actual label generated doesn't matter here! Just mangle in
+ // something unique (the function number) with Private prefix.
+ std::string Name;
+
+ if (Subtarget->isTargetDarwin()) {
+ Name = "L" + utostr(getFunctionNumber())+"$pb";
+ } else {
+ assert(Subtarget->isTargetELF() && "Don't know how to print PIC label!");
+ Name = ".Lllvm$" + utostr(getFunctionNumber())+".$piclabel";
+ }
+ return OutContext.GetOrCreateSymbol(Name);
}
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
@@ -690,7 +706,6 @@ static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
/// MCOperand.
MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
- //OutContext
const GlobalValue *GV = MO.getGlobal();
const char *Suffix = "";
@@ -724,72 +739,121 @@ MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
return MCOperand::CreateMCValue(MCValue::get(Sym, 0, MO.getOffset()));
}
+MCOperand X86ATTAsmPrinter::
+LowerExternalSymbolOperand(const MachineOperand &MO){
+ std::string Name = Mang->makeNameProper(MO.getSymbolName());
+ if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
+ FnStubs[Name+"$stub"] = Name;
+ Name += "$stub";
+ }
+
+ MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
+ return MCOperand::CreateMCValue(MCValue::get(Sym, 0, MO.getOffset()));
+}
+
+
/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
/// AT&T syntax to the current output stream.
///
void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts;
- if (NewAsmPrinter) {
- if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {
- O << "\t";
- printInlineAsm(MI);
- return;
- } else if (MI->isLabel()) {
- printLabel(MI);
- return;
- } else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {
- printDeclare(MI);
- return;
- } else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
- printImplicitDef(MI);
- return;
- }
-
- O << "NEW: ";
- MCInst TmpInst;
+ if (!NewAsmPrinter) {
+ // Call the autogenerated instruction printer routines.
+ printInstruction(MI);
+ return;
+ }
+
+ MCInst TmpInst;
+
+ switch (MI->getOpcode()) {
+ case TargetInstrInfo::DBG_LABEL:
+ case TargetInstrInfo::EH_LABEL:
+ case TargetInstrInfo::GC_LABEL:
+ printLabel(MI);
+ return;
+ case TargetInstrInfo::INLINEASM:
+ O << '\t';
+ printInlineAsm(MI);
+ return;
+ case TargetInstrInfo::DECLARE:
+ printDeclare(MI);
+ return;
+ case TargetInstrInfo::IMPLICIT_DEF:
+ printImplicitDef(MI);
+ return;
+ case X86::MOVPC32r: {
+ // This is a pseudo op for a two instruction sequence with a label, which
+ // looks like:
+ // call "L1$pb"
+ // "L1$pb":
+ // popl %esi
- TmpInst.setOpcode(MI->getOpcode());
+ // Emit the call.
+ MCSymbol *PICBase = GetPICBaseSymbol();
+ TmpInst.setOpcode(X86::CALLpcrel32);
+ TmpInst.addOperand(MCOperand::CreateMCValue(MCValue::get(PICBase)));
+ printInstruction(&TmpInst);
+
+ // Emit the label.
+ OutStreamer.EmitLabel(PICBase);
- for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
- const MachineOperand &MO = MI->getOperand(i);
-
- MCOperand MCOp;
- switch (MO.getType()) {
- default:
- O.flush();
- errs() << "Cannot lower operand #" << i << " of :" << *MI;
- llvm_unreachable("Unimp");
- case MachineOperand::MO_Register:
- MCOp = MCOperand::CreateReg(MO.getReg());
- break;
- case MachineOperand::MO_Immediate:
- MCOp = MCOperand::CreateImm(MO.getImm());
- break;
- case MachineOperand::MO_MachineBasicBlock:
- MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
- MO.getMBB()->getNumber());
- break;
- case MachineOperand::MO_GlobalAddress:
- MCOp = LowerGlobalAddressOperand(MO);
- break;
- }
-
- TmpInst.addOperand(MCOp);
- }
+ // popl $reg
+ TmpInst.setOpcode(X86::POP32r);
+ TmpInst.getOperand(0) = MCOperand::CreateReg(MI->getOperand(0).getReg());
+ printInstruction(&TmpInst);
+ O << "OLD: ";
+ // Call the autogenerated instruction printer routines.
+ printInstruction(MI);
+ return;
+ }
+ }
+
+ O << "NEW: ";
+
+ TmpInst.setOpcode(MI->getOpcode());
+
+ for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
+ const MachineOperand &MO = MI->getOperand(i);
- switch (TmpInst.getOpcode()) {
- case X86::LEA64_32r:
- // Handle the 'subreg rewriting' for the lea64_32mem operand.
- lower_lea64_32mem(&TmpInst, 1);
+ MCOperand MCOp;
+ switch (MO.getType()) {
+ default:
+ O.flush();
+ errs() << "Cannot lower operand #" << i << " of :" << *MI;
+ llvm_unreachable("Unimp");
+ case MachineOperand::MO_Register:
+ MCOp = MCOperand::CreateReg(MO.getReg());
+ break;
+ case MachineOperand::MO_Immediate:
+ MCOp = MCOperand::CreateImm(MO.getImm());
+ break;
+ case MachineOperand::MO_MachineBasicBlock:
+ MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
+ MO.getMBB()->getNumber());
+ break;
+ case MachineOperand::MO_GlobalAddress:
+ MCOp = LowerGlobalAddressOperand(MO);
+ break;
+ case MachineOperand::MO_ExternalSymbol:
+ MCOp = LowerExternalSymbolOperand(MO);
break;
}
- // FIXME: Convert TmpInst.
- printInstruction(&TmpInst);
- O << "OLD: ";
+ TmpInst.addOperand(MCOp);
}
+ switch (TmpInst.getOpcode()) {
+ case X86::LEA64_32r:
+ // Handle the 'subreg rewriting' for the lea64_32mem operand.
+ lower_lea64_32mem(&TmpInst, 1);
+ break;
+ }
+
+ // FIXME: Convert TmpInst.
+ printInstruction(&TmpInst);
+ O << "OLD: ";
+
// Call the autogenerated instruction printer routines.
printInstruction(MI);
}
@@ -825,9 +889,6 @@ void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
-
-
-
const MCSection *TheSection =
getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
SwitchToSection(TheSection);
diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
index fda35b0f6b..a4c8f13958 100644
--- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
+++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
@@ -31,6 +31,7 @@ class MCContext;
class MCInst;
class MCOperand;
class MCStreamer;
+class MCSymbol;
class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
const X86Subtarget *Subtarget;
@@ -67,7 +68,9 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
// New MCInst printing stuff.
void printInstruction(const MCInst *MI);
+ MCSymbol *GetPICBaseSymbol();
MCOperand LowerGlobalAddressOperand(const MachineOperand &MO);
+ MCOperand LowerExternalSymbolOperand(const MachineOperand &MO);
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }