merge globaladdress symbol processing stuff into other stuff. Now

all global variable operand flag processing stuff is shared between
different operand types.

llvm-svn: 80886
This commit is contained in:
Chris Lattner 2009-09-03 05:06:07 +00:00
parent 155deabbcb
commit 954b9cd41f
2 changed files with 68 additions and 79 deletions

View File

@ -71,7 +71,7 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
// New MCInst printing stuff. // New MCInst printing stuff.
void printInstruction(const MCInst *MI); void printInstruction(const MCInst *MI);
MCSymbol *GetPICBaseSymbol(); MCSymbol *GetPICBaseSymbol();
MCOperand LowerGlobalAddressOperand(const MachineOperand &MO); MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO);
MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO); MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO);
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO); MCSymbol *GetJumpTableSymbol(const MachineOperand &MO);
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO); MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO);

View File

@ -54,7 +54,7 @@ static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an /// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
/// MCOperand. /// MCOperand.
MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){ MCSymbol *X86ATTAsmPrinter::GetGlobalAddressSymbol(const MachineOperand &MO) {
const GlobalValue *GV = MO.getGlobal(); const GlobalValue *GV = MO.getGlobal();
const char *Suffix = ""; const char *Suffix = "";
@ -70,74 +70,40 @@ MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
if (Subtarget->isTargetCygMing()) if (Subtarget->isTargetCygMing())
DecorateCygMingName(Name, GV); 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);
// Handle target operand flags.
// FIXME: This should be common between external symbols, constant pool etc.
MCSymbol *NegatedSymbol = 0;
switch (MO.getTargetFlags()) { switch (MO.getTargetFlags()) {
default: default: llvm_unreachable("Unknown target flag on GV operand");
llvm_unreachable("Unknown target flag on GV operand"); case X86II::MO_NO_FLAG: // No flag.
case X86II::MO_NO_FLAG: // No flag. case X86II::MO_GOT_ABSOLUTE_ADDRESS: // Doesn't modify symbol name.
break; case X86II::MO_PIC_BASE_OFFSET: // Doesn't modify symbol name.
case X86II::MO_DARWIN_NONLAZY: break;
case X86II::MO_DARWIN_HIDDEN_NONLAZY: case X86II::MO_DLLIMPORT:
case X86II::MO_DLLIMPORT: // Handle dllimport linkage.
case X86II::MO_DARWIN_STUB: Name = "__imp_" + Name;
// These affect the name of the symbol, not any suffix. break;
break; case X86II::MO_DARWIN_NONLAZY:
case X86II::MO_GOT_ABSOLUTE_ADDRESS: case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
assert(0 && "Reloc mode unimp!"); GVStubs[Name] = Mang->getMangledName(GV);
//O << " + [.-"; break;
//PrintPICBaseSymbol(); case X86II::MO_DARWIN_HIDDEN_NONLAZY:
//O << ']'; case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
break; HiddenGVStubs[Name] = Mang->getMangledName(GV);
case X86II::MO_PIC_BASE_OFFSET: break;
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: case X86II::MO_DARWIN_STUB:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: FnStubs[Name] = Mang->getMangledName(GV);
// Subtract the pic base. break;
NegatedSymbol = GetPICBaseSymbol(); // FIXME: These probably should be a modifier on the symbol or something??
break; case X86II::MO_TLSGD: Name += "@TLSGD"; break;
case X86II::MO_GOTTPOFF: Name += "@GOTTPOFF"; break;
// FIXME: These probably should be a modifier on the symbol or something?? case X86II::MO_INDNTPOFF: Name += "@INDNTPOFF"; break;
case X86II::MO_TLSGD: Name += "@TLSGD"; break; case X86II::MO_TPOFF: Name += "@TPOFF"; break;
case X86II::MO_GOTTPOFF: Name += "@GOTTPOFF"; break; case X86II::MO_NTPOFF: Name += "@NTPOFF"; break;
case X86II::MO_INDNTPOFF: Name += "@INDNTPOFF"; break; case X86II::MO_GOTPCREL: Name += "@GOTPCREL"; break;
case X86II::MO_TPOFF: Name += "@TPOFF"; break; case X86II::MO_GOT: Name += "@GOT"; break;
case X86II::MO_NTPOFF: Name += "@NTPOFF"; break; case X86II::MO_GOTOFF: Name += "@GOTOFF"; break;
case X86II::MO_GOTPCREL: Name += "@GOTPCREL"; break; case X86II::MO_PLT: Name += "@PLT"; break;
case X86II::MO_GOT: Name += "@GOT"; break;
case X86II::MO_GOTOFF: Name += "@GOTOFF"; break;
case X86II::MO_PLT: Name += "@PLT"; break;
} }
// Create a symbol for the name. return OutContext.GetOrCreateSymbol(Name);
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
// FIXME: We would like an efficient form for this, so we don't have to do a
// lot of extra uniquing.
const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, OutContext);
if (NegatedSymbol)
Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(NegatedSymbol,
OutContext),
OutContext);
if (MO.getOffset())
Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(MO.getOffset(),
OutContext),
OutContext);
return MCOperand::CreateExpr(Expr);
} }
MCSymbol *X86ATTAsmPrinter::GetExternalSymbolSymbol(const MachineOperand &MO) { MCSymbol *X86ATTAsmPrinter::GetExternalSymbolSymbol(const MachineOperand &MO) {
@ -198,16 +164,36 @@ MCOperand X86ATTAsmPrinter::LowerSymbolOperand(const MachineOperand &MO,
MCSymbol *Sym) { MCSymbol *Sym) {
MCSymbol *NegatedSymbol = 0; MCSymbol *NegatedSymbol = 0;
switch (MO.getTargetFlags()) { switch (MO.getTargetFlags()) {
default: default: llvm_unreachable("Unknown target flag on GV operand");
llvm_unreachable("Unknown target flag on GV operand"); case X86II::MO_NO_FLAG: // No flag.
case X86II::MO_NO_FLAG: // No flag.
break; // These affect the name of the symbol, not any suffix.
case X86II::MO_PIC_BASE_OFFSET: case X86II::MO_DARWIN_NONLAZY:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: case X86II::MO_DARWIN_HIDDEN_NONLAZY:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: case X86II::MO_DLLIMPORT:
// Subtract the pic base. case X86II::MO_DARWIN_STUB:
NegatedSymbol = GetPICBaseSymbol(); case X86II::MO_TLSGD:
break; case X86II::MO_GOTTPOFF:
case X86II::MO_INDNTPOFF:
case X86II::MO_TPOFF:
case X86II::MO_NTPOFF:
case X86II::MO_GOTPCREL:
case X86II::MO_GOT:
case X86II::MO_GOTOFF:
case X86II::MO_PLT:
break;
case X86II::MO_PIC_BASE_OFFSET:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
// Subtract the pic base.
NegatedSymbol = GetPICBaseSymbol();
break;
case X86II::MO_GOT_ABSOLUTE_ADDRESS:
assert(0 && "Reloc mode unimp!");
//O << " + [.-";
//PrintPICBaseSymbol();
//O << ']';
break;
} }
// FIXME: We would like an efficient form for this, so we don't have to do a // FIXME: We would like an efficient form for this, so we don't have to do a
@ -217,10 +203,13 @@ MCOperand X86ATTAsmPrinter::LowerSymbolOperand(const MachineOperand &MO,
Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(NegatedSymbol, Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(NegatedSymbol,
OutContext), OutContext),
OutContext); OutContext);
if (!MO.isSymbol() && MO.getOffset())
Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(MO.getOffset(),
OutContext),
OutContext);
return MCOperand::CreateExpr(Expr); return MCOperand::CreateExpr(Expr);
} }
void X86ATTAsmPrinter:: void X86ATTAsmPrinter::
printInstructionThroughMCStreamer(const MachineInstr *MI) { printInstructionThroughMCStreamer(const MachineInstr *MI) {
@ -288,7 +277,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
MO.getMBB()->getNumber()); MO.getMBB()->getNumber());
break; break;
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress:
MCOp = LowerGlobalAddressOperand(MO); MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
break; break;
case MachineOperand::MO_ExternalSymbol: case MachineOperand::MO_ExternalSymbol:
MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO)); MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));