handle the upper16/lower16 target operand flags on symbol references for MC
authorJim Grosbach <grosbach@apple.com>
Fri, 17 Sep 2010 18:25:25 +0000 (18:25 +0000)
committerJim Grosbach <grosbach@apple.com>
Fri, 17 Sep 2010 18:25:25 +0000 (18:25 +0000)
instruction lowering.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114191 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMBaseInfo.h
lib/Target/ARM/ARMBaseInstrInfo.h
lib/Target/ARM/ARMMCInstLower.cpp
lib/Target/ARM/ARMMCInstLower.h

index 1862b052918b71b26e4702c33683698faf9b4f0d..51c8012bec411cc206afa35fa77b4464156aeac5 100644 (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);
index 70b5b0a2d93da5b319d31dcf7af8bbdf7dda475d..a460a5c05ca7579899b7f2cae6db9af8518846c8 100644 (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
index 207125e2443952cc09d54fa05bc42b9a840ffaef..75f185963f422c30fc4216bb511550ae45d60f23 100644 (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 {
index 404a73b95c77c3f5eec2b0e0bb314ceb92ce86c8..03c382594f69cd36f184daf53a374b33f47175ea 100644 (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));
index f6a8129e142ec0af273cde16158ab809e57aa34f..79ed2e9c484250d66d74734a62a810b1ab1905c1 100644 (file)
 
 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;
 
 /*