[llvm-branch-commits] [llvm-branch] r104774 - in /llvm/branches/Apple/whitney/lib/MC: MCAssembler.cpp MCMachOStreamer.cpp

Daniel Dunbar daniel at zuster.org
Wed May 26 15:29:20 PDT 2010


Author: ddunbar
Date: Wed May 26 17:29:20 2010
New Revision: 104774

URL: http://llvm.org/viewvc/llvm-project?rev=104774&view=rev
Log:
MC: When running with -mc-relax-all, we can eagerly relax instructions and avoid creating unnecessary MCInstFragments.

Modified:
    llvm/branches/Apple/whitney/lib/MC/MCAssembler.cpp
    llvm/branches/Apple/whitney/lib/MC/MCMachOStreamer.cpp

Modified: llvm/branches/Apple/whitney/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/MC/MCAssembler.cpp?rev=104774&r1=104773&r2=104774&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/MC/MCAssembler.cpp (original)
+++ llvm/branches/Apple/whitney/lib/MC/MCAssembler.cpp Wed May 26 17:29:20 2010
@@ -845,11 +845,8 @@
       for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
         IF->getFixups().push_back(Fixups[i]);
 
-      // Update the layout, and remember that we relaxed. If we are relaxing
-      // everything, we can skip this step since nothing will depend on updating
-      // the values.
-      if (!getRelaxAll())
-        Layout.UpdateForSlide(IF, SlideAmount);
+      // Update the layout, and remember that we relaxed.
+      Layout.UpdateForSlide(IF, SlideAmount);
       WasRelaxed = true;
     }
   }

Modified: llvm/branches/Apple/whitney/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/MC/MCMachOStreamer.cpp?rev=104774&r1=104773&r2=104774&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/branches/Apple/whitney/lib/MC/MCMachOStreamer.cpp Wed May 26 17:29:20 2010
@@ -462,23 +462,25 @@
 
   CurSectionData->setHasInstructions(true);
 
-  // See if we might need to relax this instruction, if so it needs its own
-  // fragment.
-  //
-  // FIXME-PERF: Support target hook to do a fast path that avoids the encoder,
-  // when we can immediately tell that we will get something which might need
-  // relaxation (and compute its size).
-  //
-  // FIXME-PERF: We should also be smart about immediately relaxing instructions
-  // which we can already show will never possibly fit (we can also do a very
-  // good job of this before we do the first relaxation pass, because we have
-  // total knowledge about undefined symbols at that point). Even now, though,
-  // we can do a decent job, especially on Darwin where scattering means that we
-  // are going to often know that we can never fully resolve a fixup.
-  if (Assembler.getBackend().MayNeedRelaxation(Inst))
-    EmitInstToFragment(Inst);
-  else
+  // If this instruction doesn't need relaxation, just emit it as data.
+  if (!Assembler.getBackend().MayNeedRelaxation(Inst)) {
     EmitInstToData(Inst);
+    return;
+  }
+
+  // Otherwise, if we are relaxing everything, relax the instruction as much as
+  // possible and emit it as data.
+  if (Assembler.getRelaxAll()) {
+    MCInst Relaxed;
+    Assembler.getBackend().RelaxInstruction(Inst, Relaxed);
+    while (Assembler.getBackend().MayNeedRelaxation(Relaxed))
+      Assembler.getBackend().RelaxInstruction(Relaxed, Relaxed);
+    EmitInstToData(Relaxed);
+    return;
+  }
+
+  // Otherwise emit to a separate fragment.
+  EmitInstToFragment(Inst);
 }
 
 void MCMachOStreamer::Finish() {





More information about the llvm-branch-commits mailing list