From: Jim Grosbach Date: Fri, 17 Sep 2010 18:25:25 +0000 (+0000) Subject: handle the upper16/lower16 target operand flags on symbol references for MC X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c686e33d12f84e1e1f5c96eadef851d078bab043;p=oota-llvm.git handle the upper16/lower16 target operand flags on symbol references for MC instruction lowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index 1862b052918..51c8012bec4 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -1466,7 +1466,7 @@ void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) { V1 = MCOperand::CreateImm(ImmVal & 65535); V2 = MCOperand::CreateImm(ImmVal >> 16); } else if (MO.isGlobal()) { - MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO); + MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO.getGlobal()); const MCSymbolRefExpr *SymRef1 = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, OutContext); diff --git a/lib/Target/ARM/ARMBaseInfo.h b/lib/Target/ARM/ARMBaseInfo.h index 70b5b0a2d93..a460a5c05ca 100644 --- a/lib/Target/ARM/ARMBaseInfo.h +++ b/lib/Target/ARM/ARMBaseInfo.h @@ -167,6 +167,24 @@ inline static unsigned getARMRegisterNumbering(unsigned Reg) { } } +namespace ARMII { + /// Target Operand Flag enum. + enum TOF { + //===------------------------------------------------------------------===// + // ARM Specific MachineOperand flags. + + MO_NO_FLAG, + + /// MO_LO16 - On a symbol operand, this represents a relocation containing + /// lower 16 bit of the address. Used only via movw instruction. + MO_LO16, + + /// MO_HI16 - On a symbol operand, this represents a relocation containing + /// higher 16 bit of the address. Used only via movt instruction. + MO_HI16 + }; +} // end namespace ARMII + } // end namespace llvm; #endif diff --git a/lib/Target/ARM/ARMBaseInstrInfo.h b/lib/Target/ARM/ARMBaseInstrInfo.h index 207125e2443..75f185963f4 100644 --- a/lib/Target/ARM/ARMBaseInstrInfo.h +++ b/lib/Target/ARM/ARMBaseInstrInfo.h @@ -181,22 +181,6 @@ namespace ARMII { I_BitShift = 25, CondShift = 28 }; - - /// Target Operand Flag enum. - enum TOF { - //===------------------------------------------------------------------===// - // ARM Specific MachineOperand flags. - - MO_NO_FLAG, - - /// MO_LO16 - On a symbol operand, this represents a relocation containing - /// lower 16 bit of the address. Used only via movw instruction. - MO_LO16, - - /// MO_HI16 - On a symbol operand, this represents a relocation containing - /// higher 16 bit of the address. Used only via movt instruction. - MO_HI16 - }; } class ARMBaseInstrInfo : public TargetInstrInfoImpl { diff --git a/lib/Target/ARM/ARMMCInstLower.cpp b/lib/Target/ARM/ARMMCInstLower.cpp index 404a73b95c7..03c382594f6 100644 --- a/lib/Target/ARM/ARMMCInstLower.cpp +++ b/lib/Target/ARM/ARMMCInstLower.cpp @@ -40,20 +40,39 @@ MachineModuleInfoMachO &ARMMCInstLower::getMachOMMI() const { } #endif -MCSymbol *ARMMCInstLower:: -GetGlobalAddressSymbol(const MachineOperand &MO) const { +MCSymbol *ARMMCInstLower::GetGlobalAddressSymbol(const GlobalValue *GV) const { + return Printer.Mang->getSymbol(GV); +} + +const MCSymbolRefExpr *ARMMCInstLower:: +GetSymbolRef(const MachineOperand &MO) const { + assert(MO.isGlobal() && "Isn't a global address reference?"); // FIXME: HANDLE PLT references how?? + + const MCSymbolRefExpr *SymRef; + const MCSymbol *Symbol = GetGlobalAddressSymbol(MO.getGlobal()); + switch (MO.getTargetFlags()) { default: assert(0 && "Unknown target flag on GV operand"); - case 0: break; + case 0: + SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx); + break; + case ARMII::MO_LO16: + SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx); + break; + case ARMII::MO_HI16: + SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx); + break; } - return Printer.Mang->getSymbol(MO.getGlobal()); + return SymRef; } MCSymbol *ARMMCInstLower:: GetExternalSymbolSymbol(const MachineOperand &MO) const { // FIXME: HANDLE PLT references how?? + // FIXME: This probably needs to be merged with the above SymbolRef stuff + // to handle :lower16: and :upper16: (?) switch (MO.getTargetFlags()) { default: assert(0 && "Unknown target flag on GV operand"); case 0: break; @@ -115,6 +134,17 @@ LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const { return MCOperand::CreateExpr(Expr); } +MCOperand ARMMCInstLower:: +LowerSymbolRefOperand(const MachineOperand &MO, + const MCSymbolRefExpr *Sym) const { + const MCExpr *Expr = Sym; + if (!MO.isJTI() && MO.getOffset()) + Expr = MCBinaryExpr::CreateAdd(Expr, + MCConstantExpr::Create(MO.getOffset(), Ctx), + Ctx); + return MCOperand::CreateExpr(Expr); +} + void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const { OutMI.setOpcode(MI->getOpcode()); @@ -141,7 +171,7 @@ void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const { MO.getMBB()->getSymbol(), Ctx)); break; case MachineOperand::MO_GlobalAddress: - MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO)); + MCOp = LowerSymbolRefOperand(MO, GetSymbolRef(MO)); break; case MachineOperand::MO_ExternalSymbol: MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO)); diff --git a/lib/Target/ARM/ARMMCInstLower.h b/lib/Target/ARM/ARMMCInstLower.h index f6a8129e142..79ed2e9c484 100644 --- a/lib/Target/ARM/ARMMCInstLower.h +++ b/lib/Target/ARM/ARMMCInstLower.h @@ -14,11 +14,13 @@ namespace llvm { class AsmPrinter; + class GlobalValue; class MCAsmInfo; class MCContext; class MCInst; class MCOperand; class MCSymbol; + class MCSymbolRefExpr; class MachineInstr; class MachineModuleInfoMachO; class MachineOperand; @@ -39,10 +41,13 @@ public: void Lower(const MachineInstr *MI, MCInst &OutMI) const; //MCSymbol *GetPICBaseSymbol() const; - MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const; + MCSymbol *GetGlobalAddressSymbol(const GlobalValue *GV) const; + const MCSymbolRefExpr *GetSymbolRef(const MachineOperand &MO) const; MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const; MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const; MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const; + MCOperand LowerSymbolRefOperand(const MachineOperand &MO, + const MCSymbolRefExpr *Expr) const; MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const; /*