diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86AsmBackend.cpp | 18 |
3 files changed, 30 insertions, 5 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 7672528524b..031820d5286 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -715,7 +715,7 @@ void MCAssembler::FinishLayout(MCAsmLayout &Layout) { // Create a new data fragment for the instruction. // - // FIXME: Reuse previous data fragment if possible. + // FIXME-PERF: Reuse previous data fragment if possible. MCDataFragment *DF = new MCDataFragment(); SD.getFragmentList().insert(it2, DF); diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index a52d962c9a4..2a1aa273014 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -383,12 +383,19 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) { Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups); VecOS.flush(); - // Add the fixups and data. - MCDataFragment *DF = getOrCreateDataFragment(); + // FIXME: Eliminate this copy. + SmallVector<MCAsmFixup, 4> AsmFixups; for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { MCFixup &F = Fixups[i]; - DF->addFixup(MCAsmFixup(DF->getContents().size()+F.getOffset(), - *F.getValue(), F.getKind())); + AsmFixups.push_back(MCAsmFixup(F.getOffset(), *F.getValue(), + F.getKind())); + } + + // Add the fixups and data. + MCDataFragment *DF = getOrCreateDataFragment(); + for (unsigned i = 0, e = AsmFixups.size(); i != e; ++i) { + AsmFixups[i].Offset += DF->getContents().size(); + DF->addFixup(AsmFixups[i]); } DF->getContents().append(Code.begin(), Code.end()); } diff --git a/llvm/lib/Target/X86/X86AsmBackend.cpp b/llvm/lib/Target/X86/X86AsmBackend.cpp index 3e4e2b5ae2f..8e2928c3b71 100644 --- a/llvm/lib/Target/X86/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/X86AsmBackend.cpp @@ -12,6 +12,7 @@ #include "X86FixupKinds.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MachObjectWriter.h" @@ -52,6 +53,9 @@ public: DF.getContents()[Fixup.Offset + i] = uint8_t(Value >> (i * 8)); } + bool MayNeedRelaxation(const MCInst &Inst, + const SmallVectorImpl<MCAsmFixup> &Fixups) const; + void RelaxInstruction(const MCInstFragment *IF, MCInst &Res) const; bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const; @@ -82,6 +86,20 @@ static unsigned getRelaxedOpcode(unsigned Op) { } } +bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst, + const SmallVectorImpl<MCAsmFixup> &Fixups) const { + // Check for a 1byte pcrel fixup, and enforce that we would know how to relax + // this instruction. + for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { + if (unsigned(Fixups[i].Kind) == X86::reloc_pcrel_1byte) { + assert(getRelaxedOpcode(Inst.getOpcode()) != Inst.getOpcode()); + return true; + } + } + + return false; +} + // FIXME: Can tblgen help at all here to verify there aren't other instructions // we can relax? void X86AsmBackend::RelaxInstruction(const MCInstFragment *IF, |