[llvm-commits] [llvm] r120009 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h lib/MC/MCAssembler.cpp

Rafael Espindola rafael.espindola at gmail.com
Tue Nov 23 00:08:33 PST 2010


Author: rafael
Date: Tue Nov 23 02:08:33 2010
New Revision: 120009

URL: http://llvm.org/viewvc/llvm-project?rev=120009&view=rev
Log:
Invalidate the layout on any relaxation, not just Instructions. Bug found by David Meyer.
While here, remove unused argument and rename UpdateForSlide to Invalidate.

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

Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=120009&r1=120008&r2=120009&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Tue Nov 23 02:08:33 2010
@@ -54,10 +54,9 @@
   /// Get the assembler object this is a layout for.
   MCAssembler &getAssembler() const { return Assembler; }
 
-  /// \brief Update the layout because a fragment has been resized. The
-  /// fragments size should have already been updated, the \arg SlideAmount is
-  /// the delta from the old size.
-  void UpdateForSlide(MCFragment *F, int SlideAmount);
+  /// \brief Invalidate all following fragments because a fragment has been resized. The
+  /// fragments size should have already been updated.
+  void Invalidate(MCFragment *F);
 
   /// \brief Update the layout, replacing Src with Dst. The contents
   /// of Src and Dst are not modified, and must be copied by the caller.

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=120009&r1=120008&r2=120009&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Tue Nov 23 02:08:33 2010
@@ -78,7 +78,7 @@
           F->getLayoutOrder() <= LastValidFragment->getLayoutOrder());
 }
 
-void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) {
+void MCAsmLayout::Invalidate(MCFragment *F) {
   // If this fragment wasn't already up-to-date, we don't need to do anything.
   if (!isFragmentUpToDate(F))
     return;
@@ -143,7 +143,7 @@
     Dst->EffectiveSize += Src->EffectiveSize;
   } else {
     // We don't know the effective size of Src, so we have to invalidate Dst.
-    UpdateForSlide(Dst, 0);
+    Invalidate(Dst);
   }
   // Remove Src, but don't delete it yet.
   Src->getParent()->getFragmentList().remove(Src);
@@ -819,7 +819,6 @@
   VecOS.flush();
 
   // Update the instruction fragment.
-  int SlideAmount = Code.size() - IF.getInstSize();
   IF.setInst(Relaxed);
   IF.getCode() = Code;
   IF.getFixups().clear();
@@ -827,8 +826,6 @@
   for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
     IF.getFixups().push_back(Fixups[i]);
 
-  // Update the layout, and remember that we relaxed.
-  Layout.UpdateForSlide(&IF, SlideAmount);
   return true;
 }
 
@@ -894,24 +891,29 @@
     for (MCSectionData::iterator it2 = SD.begin(),
            ie2 = SD.end(); it2 != ie2; ++it2) {
       // Check if this is an fragment that needs relaxation.
+      bool relaxedFrag = false;
       switch(it2->getKind()) {
       default:
         break;
       case MCFragment::FT_Inst:
-        WasRelaxed |= RelaxInstruction(Writer, Layout,
+        relaxedFrag = RelaxInstruction(Writer, Layout,
                                        *cast<MCInstFragment>(it2));
         break;
       case MCFragment::FT_Org:
-        WasRelaxed |= RelaxOrg(Writer, Layout, *cast<MCOrgFragment>(it2));
+        relaxedFrag = RelaxOrg(Writer, Layout, *cast<MCOrgFragment>(it2));
         break;
       case MCFragment::FT_Dwarf:
-        WasRelaxed |= RelaxDwarfLineAddr(Writer, Layout,
+        relaxedFrag = RelaxDwarfLineAddr(Writer, Layout,
 					 *cast<MCDwarfLineAddrFragment>(it2));
 	break;
       case MCFragment::FT_LEB:
-        WasRelaxed |= RelaxLEB(Writer, Layout, *cast<MCLEBFragment>(it2));
+        relaxedFrag = RelaxLEB(Writer, Layout, *cast<MCLEBFragment>(it2));
         break;
       }
+      // Update the layout, and remember that we relaxed.
+      if (relaxedFrag)
+	Layout.Invalidate(it2);
+      WasRelaxed |= relaxedFrag;
     }
   }
 





More information about the llvm-commits mailing list