Add fixups for Thumb LDR/STR instructions.
authorBill Wendling <isanbard@gmail.com>
Wed, 15 Dec 2010 08:51:02 +0000 (08:51 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 15 Dec 2010 08:51:02 +0000 (08:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121858 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMAsmBackend.cpp
lib/Target/ARM/ARMFixupKinds.h
lib/Target/ARM/ARMMCCodeEmitter.cpp

index e4acd6673074079f4f72fba2b0526904c62174bd..67f2c7105719808264364007d9ed9ab9241c2dde 100644 (file)
@@ -237,6 +237,9 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
     // 'off by 4' is implicitly handled by the half-word ordering of the
     // Thumb encoding, so we only need to adjust by 2 here.
     return ((Value - 2) >> 2) & 0xff;
+  case ARM::fixup_arm_thumb_ldst:
+    // Offset by 4.
+    return ((Value - 4) & 0x1f) << 6;
   case ARM::fixup_arm_thumb_cb: {
     // Offset by 4 and don't encode the lower bit, which is always 0.
     uint32_t Binary = (Value - 4) >> 1;
@@ -365,6 +368,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
 
   case ARM::fixup_arm_thumb_br:
   case ARM::fixup_arm_thumb_cb:
+  case ARM::fixup_arm_thumb_ldst:
     return 2;
 
   case ARM::fixup_arm_ldst_pcrel_12:
index 3e0bd0e7b7a0d391566277cf8094565a9875768d..f1683732b2854520552635d9fc4b9b16bcbb909e 100644 (file)
@@ -65,6 +65,9 @@ enum Fixups {
   // fixup_arm_thumb_cp - Fixup for Thumb load/store from constant pool instrs.
   fixup_arm_thumb_cp,
 
+  // fixup_arm_thumb_ldst - Fixup for Thumb load/store instrs.
+  fixup_arm_thumb_ldst,
+
   // fixup_arm_thumb_bcc - Fixup for Thumb conditional branching instructions.
   fixup_arm_thumb_bcc,
 
index c633825adfee362f409a1348e7a44361d4efea20..db68f359a2c713f36d1d7f36da9313e830d8812c 100644 (file)
@@ -68,6 +68,7 @@ public:
 { "fixup_arm_thumb_blx",     7,            21,  MCFixupKindInfo::FKF_IsPCRel },
 { "fixup_arm_thumb_cb",      0,            16,  MCFixupKindInfo::FKF_IsPCRel },
 { "fixup_arm_thumb_cp",      1,             8,  MCFixupKindInfo::FKF_IsPCRel },
+{ "fixup_arm_thumb_ldst",    1,             8,  MCFixupKindInfo::FKF_IsPCRel },
 { "fixup_arm_thumb_bcc",     1,             8,  MCFixupKindInfo::FKF_IsPCRel },
 { "fixup_arm_movt_hi16",     0,            16,  0 },
 { "fixup_arm_movw_lo16",     0,            16,  0 },
@@ -213,7 +214,7 @@ public:
 
   /// getAddrModeISOpValue - Encode the t_addrmode_is# operands.
   uint32_t getAddrModeISOpValue(const MCInst &MI, unsigned OpIdx,
-                                SmallVectorImpl<MCFixup> &) const;
+                                SmallVectorImpl<MCFixup> &Fixups) const;
 
   /// getAddrModePCOpValue - Return encoding for t_addrmode_pc operands.
   uint32_t getAddrModePCOpValue(const MCInst &MI, unsigned OpIdx,
@@ -817,14 +818,23 @@ getAddrModeThumbSPOpValue(const MCInst &MI, unsigned OpIdx,
 /// getAddrModeISOpValue - Encode the t_addrmode_is# operands.
 uint32_t ARMMCCodeEmitter::
 getAddrModeISOpValue(const MCInst &MI, unsigned OpIdx,
-                     SmallVectorImpl<MCFixup> &) const {
+                     SmallVectorImpl<MCFixup> &Fixups) const {
   // [Rn, #imm]
   //   {7-3} = imm5
   //   {2-0} = Rn
   const MCOperand &MO = MI.getOperand(OpIdx);
   const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
   unsigned Rn = getARMRegisterNumbering(MO.getReg());
-  unsigned Imm5 = MO1.getImm();
+  unsigned Imm5 = 0;
+
+  if (MO1.isExpr()) {
+    const MCExpr *Expr = MO.getExpr();
+    MCFixupKind Kind = MCFixupKind(ARM::fixup_arm_thumb_ldst);
+    Fixups.push_back(MCFixup::Create(0, Expr, Kind));
+  } else {
+    Imm5 = MO1.getImm();
+  }
+
   return ((Imm5 & 0x1f) << 3) | Rn;
 }