[llvm-commits] [llvm] r114191 - in /llvm/trunk/lib/Target/ARM: ARMAsmPrinter.cpp ARMBaseInfo.h ARMBaseInstrInfo.h ARMMCInstLower.cpp ARMMCInstLower.h

Jim Grosbach grosbach at apple.com
Fri Sep 17 11:25:25 PDT 2010


Author: grosbach
Date: Fri Sep 17 13:25:25 2010
New Revision: 114191

URL: http://llvm.org/viewvc/llvm-project?rev=114191&view=rev
Log:
handle the upper16/lower16 target operand flags on symbol references for MC
instruction lowering.

Modified:
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseInfo.h
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h
    llvm/trunk/lib/Target/ARM/ARMMCInstLower.cpp
    llvm/trunk/lib/Target/ARM/ARMMCInstLower.h

Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=114191&r1=114190&r2=114191&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Fri Sep 17 13:25:25 2010
@@ -1466,7 +1466,7 @@
       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);

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInfo.h?rev=114191&r1=114190&r2=114191&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInfo.h Fri Sep 17 13:25:25 2010
@@ -167,6 +167,24 @@
   }
 }
 
+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

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h?rev=114191&r1=114190&r2=114191&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h Fri Sep 17 13:25:25 2010
@@ -181,22 +181,6 @@
     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 {

Modified: llvm/trunk/lib/Target/ARM/ARMMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMMCInstLower.cpp?rev=114191&r1=114190&r2=114191&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMMCInstLower.cpp Fri Sep 17 13:25:25 2010
@@ -40,20 +40,39 @@
 }
 #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 @@
   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 @@
                        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));

Modified: llvm/trunk/lib/Target/ARM/ARMMCInstLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMMCInstLower.h?rev=114191&r1=114190&r2=114191&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMMCInstLower.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMMCInstLower.h Fri Sep 17 13:25:25 2010
@@ -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 @@
   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;
 
 /*





More information about the llvm-commits mailing list