Define generic 1, 2 and 4 byte pc relative relocations. They are common
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 28 Nov 2010 14:17:56 +0000 (14:17 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 28 Nov 2010 14:17:56 +0000 (14:17 +0000)
and at least the 4 byte one will be needed to implement the .cfi_* directives.

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

15 files changed:
include/llvm/MC/MCFixup.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCCodeEmitter.cpp
lib/MC/MCELFStreamer.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MCPureStreamer.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp
lib/MC/WinCOFFStreamer.cpp
lib/Target/MBlaze/MBlazeAsmBackend.cpp
lib/Target/MBlaze/MBlazeFixupKinds.h [deleted file]
lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp
lib/Target/X86/X86AsmBackend.cpp
lib/Target/X86/X86FixupKinds.h
lib/Target/X86/X86MCCodeEmitter.cpp

index eed4c349e848ee9cfbc49bad46774d6f55c5aa74..5352c642e626401e80971d69f324404ef80c4051 100644 (file)
@@ -22,6 +22,9 @@ enum MCFixupKind {
   FK_Data_2,     ///< A two-byte fixup.
   FK_Data_4,     ///< A four-byte fixup.
   FK_Data_8,     ///< A eight-byte fixup.
+  FK_PCRel_1,    ///< A one-byte pc relative fixup.
+  FK_PCRel_2,    ///< A two-byte pc relative fixup.
+  FK_PCRel_4,    ///< A four-byte pc relative fixup.
 
   FirstTargetFixupKind = 128,
 
@@ -77,13 +80,15 @@ public:
 
   /// getKindForSize - Return the generic fixup kind for a value with the given
   /// size. It is an error to pass an unsupported size.
-  static MCFixupKind getKindForSize(unsigned Size) {
+  static MCFixupKind getKindForSize(unsigned Size, bool isPCRel) {
     switch (Size) {
     default: assert(0 && "Invalid generic fixup size!");
-    case 1: return FK_Data_1;
-    case 2: return FK_Data_2;
-    case 4: return FK_Data_4;
-    case 8: return FK_Data_8;
+    case 1: return isPCRel ? FK_PCRel_1 : FK_Data_1;
+    case 2: return isPCRel ? FK_PCRel_2 : FK_Data_2;
+    case 4: return isPCRel ? FK_PCRel_4 : FK_Data_4;
+    case 8:
+      assert(!isPCRel && "8 byte pc relative fixup is not supported.");
+      return FK_Data_8;
     }
   }
 };
index 3b649dbbd2595c78c299d8fc44a549247659169d..4b978368ecf8e8986496f75e6d74acf196eda56c 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "../Target/X86/X86FixupKinds.h"
 #include "../Target/ARM/ARMFixupKinds.h"
-#include "../Target/MBlaze/MBlazeFixupKinds.h"
 
 #include <vector>
 using namespace llvm;
@@ -371,8 +370,9 @@ namespace {
       switch (Kind) {
       default:
         return false;
-      case X86::reloc_pcrel_1byte:
-      case X86::reloc_pcrel_4byte:
+      case FK_PCRel_1:
+      case FK_PCRel_2:
+      case FK_PCRel_4:
       case X86::reloc_riprel_4byte:
       case X86::reloc_riprel_4byte_movq_load:
         return true;
@@ -401,6 +401,9 @@ namespace {
       switch (Kind) {
       default:
         return false;
+      case FK_PCRel_1:
+      case FK_PCRel_2:
+      case FK_PCRel_4:
       case ARM::fixup_arm_pcrel_12:
       case ARM::fixup_arm_vfp_pcrel_12:
       case ARM::fixup_arm_branch:
@@ -429,8 +432,9 @@ namespace {
       switch (Kind) {
       default:
         return false;
-      case MBlaze::reloc_pcrel_2byte:
-      case MBlaze::reloc_pcrel_4byte:
+      case FK_PCRel_1:
+      case FK_PCRel_2:
+      case FK_PCRel_4:
         return true;
       }
     }
@@ -1509,10 +1513,10 @@ void MBlazeELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
     switch ((unsigned)Fixup.getKind()) {
     default:
       llvm_unreachable("Unimplemented");
-    case MBlaze::reloc_pcrel_4byte:
+    case FK_PCRel_4:
       Type = ELF::R_MICROBLAZE_64_PCREL;
       break;
-    case MBlaze::reloc_pcrel_2byte:
+    case FK_PCRel_2:
       Type = ELF::R_MICROBLAZE_32_PCREL;
       break;
     }
@@ -1644,7 +1648,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
       default: llvm_unreachable("invalid fixup kind!");
       case FK_Data_8: Type = ELF::R_X86_64_64; break;
       case X86::reloc_signed_4byte:
-      case X86::reloc_pcrel_4byte:
+      case FK_PCRel_4:
         assert(isInt<32>(Target.getConstant()));
         switch (Modifier) {
         default:
@@ -1670,7 +1674,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
         Type = ELF::R_X86_64_32;
         break;
       case FK_Data_2: Type = ELF::R_X86_64_16; break;
-      case X86::reloc_pcrel_1byte:
+      case FK_PCRel_1:
       case FK_Data_1: Type = ELF::R_X86_64_8; break;
       }
     }
@@ -1697,7 +1701,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
       // FIXME: Should we avoid selecting reloc_signed_4byte in 32 bit mode
       // instead?
       case X86::reloc_signed_4byte:
-      case X86::reloc_pcrel_4byte:
+      case FK_PCRel_4:
       case FK_Data_4:
         switch (Modifier) {
         default:
@@ -1735,7 +1739,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
         }
         break;
       case FK_Data_2: Type = ELF::R_386_16; break;
-      case X86::reloc_pcrel_1byte:
+      case FK_PCRel_1:
       case FK_Data_1: Type = ELF::R_386_8; break;
       }
     }
index d513237855412b1b7bf842e262a96a8ef5fb054e..b11751c27e8e1ed140949fb4a43eacf49c1a63a8 100644 (file)
@@ -22,9 +22,12 @@ const MCFixupKindInfo &MCCodeEmitter::getFixupKindInfo(MCFixupKind Kind) const {
     { "FK_Data_1", 0, 8, 0 },
     { "FK_Data_2", 0, 16, 0 },
     { "FK_Data_4", 0, 32, 0 },
-    { "FK_Data_8", 0, 64, 0 }
+    { "FK_Data_8", 0, 64, 0 },
+    { "FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel },
+    { "FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
+    { "FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel }
   };
   
-  assert(Kind <= 3 && "Unknown fixup kind");
+  assert(Kind <= 6 && "Unknown fixup kind");
   return Builtins[Kind];
 }
index ec28a902a20f42219c638a7f090b1b542db37907..5b707cb21893c6d1673c67c51e2cc55a615ea54f 100644 (file)
@@ -398,7 +398,7 @@ void MCELFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
       DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
   } else {
     DF->addFixup(MCFixup::Create(DF->getContents().size(), AddValueSymbols(Value),
-                                 MCFixup::getKindForSize(Size)));
+                                 MCFixup::getKindForSize(Size, false)));
     DF->getContents().resize(DF->getContents().size() + Size, 0);
   }
 }
index 88fa23049322f7cc6bffaf2dee71b21134d62feb..39b1d4fd4ae96f3650b5eb1dd468eb1ae379d5a3 100644 (file)
@@ -337,7 +337,7 @@ void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
   } else {
     DF->addFixup(MCFixup::Create(DF->getContents().size(),
                                  AddValueSymbols(Value),
-                                 MCFixup::getKindForSize(Size)));
+                                 MCFixup::getKindForSize(Size, false)));
     DF->getContents().resize(DF->getContents().size() + Size, 0);
   }
 }
index 6af1659b935e5c7bfbd6c1ed3eb02fe2e348c03e..2dfb389f092fe6daa2a7f427bb488e95d93531b2 100644 (file)
@@ -173,7 +173,7 @@ void MCPureStreamer::EmitValue(const MCExpr *Value, unsigned Size,
   } else {
     DF->addFixup(MCFixup::Create(DF->getContents().size(),
                                  AddValueSymbols(Value),
-                                 MCFixup::getKindForSize(Size)));
+                                 MCFixup::getKindForSize(Size, false)));
     DF->getContents().resize(DF->getContents().size() + Size, 0);
   }
 }
index a70f1c3d2247b7a74ec051a3d6b573651b9c13de..45d2ff7491219c911e2dab1d27818f896459061f 100644 (file)
@@ -32,11 +32,11 @@ using namespace llvm::object;
 static unsigned getFixupKindLog2Size(unsigned Kind) {
   switch (Kind) {
   default: llvm_unreachable("invalid fixup kind!");
-  case X86::reloc_pcrel_1byte:
+  case FK_PCRel_1:
   case FK_Data_1: return 0;
-  case X86::reloc_pcrel_2byte:
+  case FK_PCRel_2:
   case FK_Data_2: return 1;
-  case X86::reloc_pcrel_4byte:
+  case FK_PCRel_4:
   case X86::reloc_riprel_4byte:
   case X86::reloc_riprel_4byte_movq_load:
   case X86::reloc_signed_4byte:
@@ -49,9 +49,9 @@ static bool isFixupKindPCRel(unsigned Kind) {
   switch (Kind) {
   default:
     return false;
-  case X86::reloc_pcrel_1byte:
-  case X86::reloc_pcrel_2byte:
-  case X86::reloc_pcrel_4byte:
+  case FK_PCRel_1:
+  case FK_PCRel_2:
+  case FK_PCRel_4:
   case X86::reloc_riprel_4byte:
   case X86::reloc_riprel_4byte_movq_load:
     return true;
index fd79203fdacb87a29169d3d61a378ed3680b0aa5..b330bddce6f679e40ccf0f2bd34a5f7767407306 100644 (file)
@@ -689,7 +689,7 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
   Reloc.Data.VirtualAddress += Fixup.getOffset();
 
   switch ((unsigned)Fixup.getKind()) {
-  case X86::reloc_pcrel_4byte:
+  case FK_PCRel_4:
   case X86::reloc_riprel_4byte:
   case X86::reloc_riprel_4byte_movq_load:
     Reloc.Data.Type = Is64Bit ? COFF::IMAGE_REL_AMD64_REL32
index 376751be515e5a12b0d21665de0a6f8a5525c307..0f0224891d595350ea8ec1d65db0ea39c5d68c97 100644 (file)
@@ -363,7 +363,7 @@ void WinCOFFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
   } else {
     DF->addFixup(MCFixup::Create(DF->getContents().size(),
                                  AddValueSymbols(Value),
-                                 MCFixup::getKindForSize(Size)));
+                                 MCFixup::getKindForSize(Size, false)));
     DF->getContents().resize(DF->getContents().size() + Size, 0);
   }
 }
index 7de3cf8424ae8f4726b327a1db7c1456f8fee05a..56c04199cff223889b43f2f6894a8ad378291b3f 100644 (file)
@@ -10,7 +10,6 @@
 #include "llvm/Target/TargetAsmBackend.h"
 #include "MBlaze.h"
 #include "MBlazeELFWriterInfo.h"
-#include "MBlazeFixupKinds.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCAsmLayout.h"
@@ -32,9 +31,9 @@ static unsigned getFixupKindSize(unsigned Kind) {
   switch (Kind) {
   default: assert(0 && "invalid fixup kind!");
   case FK_Data_1: return 1;
-  case MBlaze::reloc_pcrel_2byte:
+  case FK_PCRel_2:
   case FK_Data_2: return 2;
-  case MBlaze::reloc_pcrel_4byte:
+  case FK_PCRel_4:
   case FK_Data_4: return 4;
   case FK_Data_8: return 8;
   }
diff --git a/lib/Target/MBlaze/MBlazeFixupKinds.h b/lib/Target/MBlaze/MBlazeFixupKinds.h
deleted file mode 100644 (file)
index 72466ca..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-//===-- MBlaze/MBlazeFixupKinds.h - MBlaze Fixup Entries --------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_MBLAZE_MBLAZEFIXUPKINDS_H
-#define LLVM_MBLAZE_MBLAZEFIXUPKINDS_H
-
-#include "llvm/MC/MCFixup.h"
-
-namespace llvm {
-namespace MBlaze {
-enum Fixups {
-  reloc_pcrel_4byte = FirstTargetFixupKind,  // 32-bit pcrel, e.g. a brlid
-  reloc_pcrel_2byte                          // 16-bit pcrel, e.g. beqid
-};
-}
-}
-
-#endif
index 625c73f0f9bf22525dad2624dd45737154c3582f..e7fb788b3c71347fb560c1b4895d16a7b2a8da08 100644 (file)
@@ -14,7 +14,6 @@
 #define DEBUG_TYPE "mccodeemitter"
 #include "MBlaze.h"
 #include "MBlazeInstrInfo.h"
-#include "MBlazeFixupKinds.h"
 #include "llvm/MC/MCCodeEmitter.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
@@ -56,22 +55,6 @@ public:
     return 2;
   }
 
-  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
-    const static MCFixupKindInfo Infos[] = {
-      // name                offset  bits    flags
-      { "reloc_pcrel_4byte", 2,      4 * 8,  MCFixupKindInfo::FKF_IsPCRel },
-      { "reloc_pcrel_2byte", 2,      2 * 8,  MCFixupKindInfo::FKF_IsPCRel } };
-
-    if (Kind < FirstTargetFixupKind)
-      return MCCodeEmitter::getFixupKindInfo(Kind);
-
-    if (unsigned(Kind-FirstTargetFixupKind) < getNumFixupKinds())
-      return Infos[Kind - FirstTargetFixupKind];
-
-    assert(0 && "Invalid fixup kind.");
-    return Infos[0];
-  }
-
   static unsigned GetMBlazeRegNum(const MCOperand &MO) {
     // FIXME: getMBlazeRegisterNumbering() is sufficient?
     assert(0 && "MBlazeMCCodeEmitter::GetMBlazeRegNum() not yet implemented.");
@@ -181,13 +164,13 @@ EmitImmediate(const MCInst &MI, unsigned opNo, bool pcrel, unsigned &CurByte,
     MCFixupKind FixupKind;
     switch (MI.getOpcode()) {
     default:
-      FixupKind = pcrel ? MCFixupKind(MBlaze::reloc_pcrel_2byte) : FK_Data_2;
+      FixupKind = pcrel ? FK_PCRel_2 : FK_Data_2;
       Fixups.push_back(MCFixup::Create(0,oper.getExpr(),FixupKind));
       break;
     case MBlaze::ORI32:
     case MBlaze::ADDI32:
     case MBlaze::BRLID32:
-      FixupKind = pcrel ? MCFixupKind(MBlaze::reloc_pcrel_4byte) : FK_Data_4;
+      FixupKind = pcrel ? FK_PCRel_4 : FK_Data_4;
       Fixups.push_back(MCFixup::Create(0,oper.getExpr(),FixupKind));
       break;
     }
index f27cd03943006e6653a707dddcc07a3ca3eadf2f..48467c89e5b9fec71c9568a274087f9e561bf42f 100644 (file)
@@ -29,11 +29,11 @@ using namespace llvm;
 static unsigned getFixupKindLog2Size(unsigned Kind) {
   switch (Kind) {
   default: assert(0 && "invalid fixup kind!");
-  case X86::reloc_pcrel_1byte:
+  case FK_PCRel_1:
   case FK_Data_1: return 0;
-  case X86::reloc_pcrel_2byte:
+  case FK_PCRel_2:
   case FK_Data_2: return 1;
-  case X86::reloc_pcrel_4byte:
+  case FK_PCRel_4:
   case X86::reloc_riprel_4byte:
   case X86::reloc_riprel_4byte_movq_load:
   case X86::reloc_signed_4byte:
index 64ee3eb33047337c494433a4466bd84525204495..95077591d539b8b05b9b8a71fbf079688b42881e 100644 (file)
 namespace llvm {
 namespace X86 {
 enum Fixups {
-  reloc_pcrel_4byte = FirstTargetFixupKind,  // 32-bit pcrel, e.g. a branch.
-  reloc_pcrel_1byte,                         // 8-bit pcrel, e.g. branch_1
-  reloc_pcrel_2byte,                         // 16-bit pcrel, e.g. callw
-  reloc_riprel_4byte,                        // 32-bit rip-relative
+  reloc_riprel_4byte = FirstTargetFixupKind, // 32-bit rip-relative
   reloc_riprel_4byte_movq_load,              // 32-bit rip-relative in movq
   reloc_signed_4byte,                        // 32-bit signed. Unlike FK_Data_4
                                              // this will be sign extended at
index 586216d774b191f019f455450d28f26037aedbdf..bd37999620b7d25c4267936183043de472d05376 100644 (file)
@@ -44,9 +44,6 @@ public:
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
     const static MCFixupKindInfo Infos[] = {
-      { "reloc_pcrel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
-      { "reloc_pcrel_1byte", 0, 1 * 8, MCFixupKindInfo::FKF_IsPCRel },
-      { "reloc_pcrel_2byte", 0, 2 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_signed_4byte", 0, 4 * 8, 0},
@@ -173,13 +170,7 @@ static MCFixupKind getImmFixupKind(uint64_t TSFlags) {
   unsigned Size = X86II::getSizeOfImm(TSFlags);
   bool isPCRel = X86II::isImmPCRel(TSFlags);
 
-  switch (Size) {
-  default: assert(0 && "Unknown immediate size");
-  case 1: return isPCRel ? MCFixupKind(X86::reloc_pcrel_1byte) : FK_Data_1;
-  case 2: return isPCRel ? MCFixupKind(X86::reloc_pcrel_2byte) : FK_Data_2;
-  case 4: return isPCRel ? MCFixupKind(X86::reloc_pcrel_4byte) : FK_Data_4;
-  case 8: assert(!isPCRel); return FK_Data_8;
-  }
+  return MCFixup::getKindForSize(Size, isPCRel);
 }
 
 /// Is32BitMemOperand - Return true if the specified instruction with a memory
@@ -222,9 +213,9 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
   if (DispOp.isImm()) {
     // If this is a simple integer displacement that doesn't require a relocation,
     // emit it now.
-    if (FixupKind != MCFixupKind(X86::reloc_pcrel_1byte) &&
-       FixupKind != MCFixupKind(X86::reloc_pcrel_2byte) &&
-       FixupKind != MCFixupKind(X86::reloc_pcrel_4byte)) {
+    if (FixupKind != FK_PCRel_1 &&
+       FixupKind != FK_PCRel_2 &&
+       FixupKind != FK_PCRel_4) {
       EmitConstant(DispOp.getImm()+ImmOffset, Size, CurByte, OS);
       return;
     }
@@ -243,13 +234,13 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
 
   // If the fixup is pc-relative, we need to bias the value to be relative to
   // the start of the field, not the end of the field.
-  if (FixupKind == MCFixupKind(X86::reloc_pcrel_4byte) ||
+  if (FixupKind == FK_PCRel_4 ||
       FixupKind == MCFixupKind(X86::reloc_riprel_4byte) ||
       FixupKind == MCFixupKind(X86::reloc_riprel_4byte_movq_load))
     ImmOffset -= 4;
-  if (FixupKind == MCFixupKind(X86::reloc_pcrel_2byte))
+  if (FixupKind == FK_PCRel_2)
     ImmOffset -= 2;
-  if (FixupKind == MCFixupKind(X86::reloc_pcrel_1byte))
+  if (FixupKind == FK_PCRel_1)
     ImmOffset -= 1;
 
   if (ImmOffset)