MC: Switch to using MCInst fragments to do relaxation.
Also, both MCMachOStreamer and MCAssembler are now target independent!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99256 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp
index 2a1aa27..9141a90 100644
--- a/lib/MC/MCMachOStreamer.cpp
+++ b/lib/MC/MCMachOStreamer.cpp
@@ -18,6 +18,8 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetAsmBackend.h"
+
using namespace llvm;
namespace {
@@ -391,6 +393,32 @@
F.getKind()));
}
+ // 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, AsmFixups)) {
+ MCInstFragment *IF = new MCInstFragment(Inst, CurSectionData);
+
+ // Add the fixups and data.
+ //
+ // FIXME: Revisit this design decision when relaxation is done, we may be
+ // able to get away with not storing any extra data in the MCInst.
+ IF->getCode() = Code;
+ IF->getFixups() = AsmFixups;
+
+ return;
+ }
+
// Add the fixups and data.
MCDataFragment *DF = getOrCreateDataFragment();
for (unsigned i = 0, e = AsmFixups.size(); i != e; ++i) {