aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-16 04:28:14 +0000
committerChris Lattner <sabre@nondot.org>2009-08-16 04:28:14 +0000
commit9b60e04b65b519afa02bb7f9185f8497d38963d0 (patch)
tree72d5420f18888de01549f4a016757aa3812e34f8
parent12bb766ae9458b631e9acd97443345966788b5de (diff)
downloadexternal_llvm-9b60e04b65b519afa02bb7f9185f8497d38963d0.zip
external_llvm-9b60e04b65b519afa02bb7f9185f8497d38963d0.tar.gz
external_llvm-9b60e04b65b519afa02bb7f9185f8497d38963d0.tar.bz2
add support for external symbols + X86::MOVPC32r.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79175 91177308-0d34-0410-b5e6-96231b3b80d8
-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 97d1dd1..9dffbe8 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 fda35b0..a4c8f13 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); }