[llvm-commits] [llvm] r79170 - in /llvm/trunk/lib/Target/X86/AsmPrinter: X86ATTAsmPrinter.cpp X86ATTAsmPrinter.h
Chris Lattner
sabre at nondot.org
Sat Aug 15 20:12:25 PDT 2009
Author: lattner
Date: Sat Aug 15 22:12:25 2009
New Revision: 79170
URL: http://llvm.org/viewvc/llvm-project?rev=79170&view=rev
Log:
implement support for lowering references to global addresses. For example, we now
can asmprint:
NEW: movl "L___stack_chk_guard$non_lazy_ptr", %eax
OLD: movl L___stack_chk_guard$non_lazy_ptr, %eax
where 'new' is coming out of the MCInst version of the printer.
Modified:
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=79170&r1=79169&r2=79170&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Sat Aug 15 22:12:25 2009
@@ -687,6 +687,43 @@
}
}
+/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
+/// MCOperand.
+MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
+ //OutContext
+ const GlobalValue *GV = MO.getGlobal();
+
+ const char *Suffix = "";
+ if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
+ Suffix = "$stub";
+ else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
+ MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
+ MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
+ MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
+ Suffix = "$non_lazy_ptr";
+
+ std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
+ if (Subtarget->isTargetCygMing())
+ DecorateCygMingName(Name, GV);
+
+ // Handle dllimport linkage.
+ if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
+ Name = "__imp_" + Name;
+
+ if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
+ MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
+ GVStubs[Name] = Mang->getMangledName(GV);
+ else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
+ MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
+ HiddenGVStubs[Name] = Mang->getMangledName(GV);
+ else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
+ FnStubs[Name] = Mang->getMangledName(GV);
+
+ // Create a symbol for the name.
+ 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.
///
@@ -718,15 +755,24 @@
const MachineOperand &MO = MI->getOperand(i);
MCOperand MCOp;
- if (MO.isReg()) {
+ 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());
- } else if (MO.isImm()) {
+ break;
+ case MachineOperand::MO_Immediate:
MCOp = MCOperand::CreateImm(MO.getImm());
- } else if (MO.isMBB()) {
+ break;
+ case MachineOperand::MO_MachineBasicBlock:
MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
MO.getMBB()->getNumber());
- } else {
- llvm_unreachable("Unimp");
+ break;
+ case MachineOperand::MO_GlobalAddress:
+ MCOp = LowerGlobalAddressOperand(MO);
+ break;
}
TmpInst.addOperand(MCOp);
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h?rev=79170&r1=79169&r2=79170&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h Sat Aug 15 22:12:25 2009
@@ -29,6 +29,7 @@
class MachineJumpTableInfo;
class MCContext;
class MCInst;
+class MCOperand;
class MCStreamer;
class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
@@ -66,6 +67,7 @@
// New MCInst printing stuff.
void printInstruction(const MCInst *MI);
+ MCOperand LowerGlobalAddressOperand(const MachineOperand &MO);
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
More information about the llvm-commits
mailing list