[llvm] r200347 - Keep the MCSubtargetInfo in the MCRelxableFragment class.

David Woodhouse dwmw2 at infradead.org
Tue Jan 28 15:12:54 PST 2014


Author: dwmw2
Date: Tue Jan 28 17:12:53 2014
New Revision: 200347

URL: http://llvm.org/viewvc/llvm-project?rev=200347&view=rev
Log:
Keep the MCSubtargetInfo in the MCRelxableFragment class.

Needed to fix PR18303 to correctly re-encode the instruction if it
is relaxed.

We keep a copy of the MCSubtargetInfo to make sure that we are not
effected by future changes to the subtarget info coming from the
assembler (e.g. when parsing .code 16 directived).

Modified:
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/lib/MC/MCObjectStreamer.cpp
    llvm/trunk/lib/MC/MCPureStreamer.cpp

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=200347&r1=200346&r2=200347&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Tue Jan 28 17:12:53 2014
@@ -17,6 +17,7 @@
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/MC/MCFixup.h"
 #include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/DataTypes.h"
 #include <algorithm>
@@ -33,6 +34,7 @@ class MCFragment;
 class MCObjectWriter;
 class MCSection;
 class MCSectionData;
+class MCSubtargetInfo;
 class MCSymbol;
 class MCSymbolData;
 class MCValue;
@@ -288,6 +290,11 @@ class MCRelaxableFragment : public MCEnc
   /// Inst - The instruction this is a fragment for.
   MCInst Inst;
 
+  /// STI - The MCSubtargetInfo in effect when the instruction was encoded.
+  /// Keep a copy instead of a reference to make sure that updates to STI
+  /// in the assembler are not seen here.
+  const MCSubtargetInfo STI;
+
   /// Contents - Binary data for the currently encoded instruction.
   SmallVector<char, 8> Contents;
 
@@ -295,8 +302,10 @@ class MCRelaxableFragment : public MCEnc
   SmallVector<MCFixup, 1> Fixups;
 
 public:
-  MCRelaxableFragment(const MCInst &_Inst, MCSectionData *SD = 0)
-    : MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(_Inst) {
+  MCRelaxableFragment(const MCInst &_Inst,
+                      const MCSubtargetInfo &_STI,
+                      MCSectionData *SD = 0)
+    : MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(_Inst), STI(_STI) {
   }
 
   virtual SmallVectorImpl<char> &getContents() { return Contents; }
@@ -305,6 +314,8 @@ public:
   const MCInst &getInst() const { return Inst; }
   void setInst(const MCInst& Value) { Inst = Value; }
 
+  const MCSubtargetInfo &getSubtargetInfo() { return STI; }
+
   SmallVectorImpl<MCFixup> &getFixups() {
     return Fixups;
   }

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=200347&r1=200346&r2=200347&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Tue Jan 28 17:12:53 2014
@@ -230,7 +230,7 @@ void MCObjectStreamer::EmitInstToFragmen
                                           const MCSubtargetInfo &STI) {
   // Always create a new, separate fragment here, because its size can change
   // during relaxation.
-  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst);
+  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
   insert(IF);
 
   SmallString<128> Code;

Modified: llvm/trunk/lib/MC/MCPureStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCPureStreamer.cpp?rev=200347&r1=200346&r2=200347&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCPureStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCPureStreamer.cpp Tue Jan 28 17:12:53 2014
@@ -181,7 +181,7 @@ bool MCPureStreamer::EmitValueToOffset(c
 
 void MCPureStreamer::EmitInstToFragment(const MCInst &Inst,
                                         const MCSubtargetInfo &STI) {
-  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst);
+  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
   insert(IF);
 
   // Add the fixups and data.





More information about the llvm-commits mailing list