handle the upper16/lower16 target operand flags on symbol references for MC

instruction lowering.

llvm-svn: 114191
This commit is contained in:
Jim Grosbach 2010-09-17 18:25:25 +00:00
parent cea0a8d7ae
commit 0d35df1cfe
5 changed files with 60 additions and 23 deletions

View File

@ -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);

View File

@ -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

View File

@ -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 {

View File

@ -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));

View File

@ -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;
/*