Move target-specific logic out of generic MCAssembler.
authorJim Grosbach <grosbach@apple.com>
Tue, 6 Dec 2011 00:47:03 +0000 (00:47 +0000)
committerJim Grosbach <grosbach@apple.com>
Tue, 6 Dec 2011 00:47:03 +0000 (00:47 +0000)
Whether a fixup needs relaxation for the associated instruction is a
target-specific function, as the FIXME indicated. Create a hook for that
and use it.

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

include/llvm/MC/MCAsmBackend.h
include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp
lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
lib/Target/MBlaze/MCTargetDesc/MBlazeAsmBackend.cpp
lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

index 4a0cf37a6eb25c5aab1523146ec453e31205cd4f..b841ddb9f5ab499d432fa0785f45fb7fa558fefc 100644 (file)
 #include "llvm/Support/DataTypes.h"
 
 namespace llvm {
 #include "llvm/Support/DataTypes.h"
 
 namespace llvm {
+class MCAsmLayout;
 class MCELFObjectTargetWriter;
 class MCFixup;
 class MCInst;
 class MCELFObjectTargetWriter;
 class MCFixup;
 class MCInst;
+class MCInstFragment;
 class MCObjectWriter;
 class MCSection;
 template<typename T>
 class MCObjectWriter;
 class MCSection;
 template<typename T>
@@ -104,6 +106,13 @@ public:
   /// \param Inst - The instruction to test.
   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
 
   /// \param Inst - The instruction to test.
   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
 
+  /// fixupNeedsRelaxation - Target specific predicate for whether a given
+  /// fixup requires the associated instruction to be relaxed.
+  virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                                    uint64_t Value,
+                                    const MCInstFragment *DF,
+                                    const MCAsmLayout &Layout) const = 0;
+
   /// RelaxInstruction - Relax the instruction in the given fragment to the next
   /// wider instruction.
   ///
   /// RelaxInstruction - Relax the instruction in the given fragment to the next
   /// wider instruction.
   ///
index 7d840923c8da0e70bafb9edf0e25b5cc6f036493..687dd0c140744cb80a1c4d78b521a2e0e1c5e99c 100644 (file)
@@ -717,7 +717,7 @@ private:
 
   /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
   /// (increased in size, in order to hold its value correctly).
 
   /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
   /// (increased in size, in order to hold its value correctly).
-  bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCFragment *DF,
+  bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
                             const MCAsmLayout &Layout) const;
 
   /// Check whether the given fragment needs relaxation.
                             const MCAsmLayout &Layout) const;
 
   /// Check whether the given fragment needs relaxation.
index 2de6d04f8ba48c0e7bc6145b98cd82112a6f8bb4..c5bf6b9f875573235cce7afbd77215a36545a359 100644 (file)
@@ -646,7 +646,7 @@ void MCAssembler::Finish() {
 }
 
 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
 }
 
 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
-                                       const MCFragment *DF,
+                                       const MCInstFragment *DF,
                                        const MCAsmLayout &Layout) const {
   if (getRelaxAll())
     return true;
                                        const MCAsmLayout &Layout) const {
   if (getRelaxAll())
     return true;
@@ -657,10 +657,7 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
   if (!evaluateFixup(Layout, Fixup, DF, Target, Value))
     return true;
 
   if (!evaluateFixup(Layout, Fixup, DF, Target, Value))
     return true;
 
-  // Otherwise, relax if the value is too big for a (signed) i8.
-  //
-  // FIXME: This is target dependent!
-  return int64_t(Value) != int64_t(int8_t(Value));
+  return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout);
 }
 
 bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF,
 }
 
 bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF,
index 0eed821b767e190c98543086146585d66854156d..59fae27a081e79d0a53253b0feafe5848fb79c14 100644 (file)
@@ -102,6 +102,11 @@ public:
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
+  bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                            uint64_t Value,
+                            const MCInstFragment *DF,
+                            const MCAsmLayout &Layout) const;
+
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
@@ -137,6 +142,17 @@ bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
   return false;
 }
 
   return false;
 }
 
+bool ARMAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
+                                         uint64_t Value,
+                                         const MCInstFragment *DF,
+                                         const MCAsmLayout &Layout) const {
+  // FIXME:  This isn't correct for ARM. Just moving the "generic" logic
+  // into the targets for now.
+  //
+  // Relax if the value is too big for a (signed) i8.
+  return int64_t(Value) != int64_t(int8_t(Value));
+}
+
 void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
   unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
 
 void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
   unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
 
index 08f7d46a58f93d8aa840cee6d8776ac965b1b1cc..d5acbe97493ba12f965b7509d03570be579a1358 100644 (file)
@@ -58,6 +58,11 @@ public:
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
+  bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                            uint64_t Value,
+                            const MCInstFragment *DF,
+                            const MCAsmLayout &Layout) const;
+
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
@@ -87,6 +92,18 @@ bool MBlazeAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
   return hasExprOrImm;
 }
 
   return hasExprOrImm;
 }
 
+bool MBlazeAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
+                                            uint64_t Value,
+                                            const MCInstFragment *DF,
+                                            const MCAsmLayout &Layout) const {
+  // FIXME: Is this right? It's what the "generic" code was doing before,
+  // but is X86 specific. Is it actually true for MBlaze also, or was it
+  // just close enough to not be a big deal?
+  //
+  // Relax if the value is too big for a (signed) i8.
+  return int64_t(Value) != int64_t(int8_t(Value));
+}
+
 void MBlazeAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
   Res = Inst;
   Res.setOpcode(getRelaxedOpcode(Inst.getOpcode()));
 void MBlazeAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
   Res = Inst;
   Res.setOpcode(getRelaxedOpcode(Inst.getOpcode()));
index 7bc5fe4a6e4e2fb54e51d1a09f1c9296396cf71b..20e16368f87f6ab6bfcc8bb9055a8171ca07a6bc 100644 (file)
@@ -173,6 +173,16 @@ public:
     return false;
   }
 
     return false;
   }
 
+  /// fixupNeedsRelaxation - Target specific predicate for whether a given
+  /// fixup requires the associated instruction to be relaxed.
+  bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                            uint64_t Value,
+                            const MCInstFragment *DF,
+                            const MCAsmLayout &Layout) const {
+    // FIXME.
+    assert(0 && "RelaxInstruction() unimplemented");
+  }
+
   /// RelaxInstruction - Relax the instruction in the given fragment
   /// to the next wider instruction.
   ///
   /// RelaxInstruction - Relax the instruction in the given fragment
   /// to the next wider instruction.
   ///
index 9f2fd6d01b8e44d79651a8ae90778e9b954be0b7..12e0b3d436d1fff7cca16907895635910071cea6 100644 (file)
@@ -93,6 +93,15 @@ public:
     // FIXME.
     return false;
   }
     // FIXME.
     return false;
   }
+
+  bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                            uint64_t Value,
+                            const MCInstFragment *DF,
+                            const MCAsmLayout &Layout) const {
+    // FIXME.
+    assert(0 && "RelaxInstruction() unimplemented");
+  }
+
   
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
     // FIXME.
   
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
     // FIXME.
index 69ad7d7b6b3278171ad5b31ad6fd9bed18337f46..87b2b055ab27d18fbb8988a3a79982ae70484397 100644 (file)
@@ -107,6 +107,11 @@ public:
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
 
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
+  bool fixupNeedsRelaxation(const MCFixup &Fixup,
+                            uint64_t Value,
+                            const MCInstFragment *DF,
+                            const MCAsmLayout &Layout) const;
+
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
 
   bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
@@ -244,6 +249,14 @@ bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
   return hasExp && !hasRIP;
 }
 
   return hasExp && !hasRIP;
 }
 
+bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
+                                         uint64_t Value,
+                                         const MCInstFragment *DF,
+                                         const MCAsmLayout &Layout) const {
+  // Relax if the value is too big for a (signed) i8.
+  return int64_t(Value) != int64_t(int8_t(Value));
+}
+
 // FIXME: Can tblgen help at all here to verify there aren't other instructions
 // we can relax?
 void X86AsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
 // FIXME: Can tblgen help at all here to verify there aren't other instructions
 // we can relax?
 void X86AsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {