diff options
Diffstat (limited to 'lib/MC/MCObjectStreamer.cpp')
-rw-r--r-- | lib/MC/MCObjectStreamer.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 774632306d..37a445fae0 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCSection.h" // @LOCALMOD #include "llvm/MC/MCSymbol.h" #include "llvm/Support/ErrorHandling.h" using namespace llvm; @@ -54,6 +55,11 @@ MCFragment *MCObjectStreamer::getCurrentFragment() const { } MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() const { + // @LOCALMOD-BEGIN + if (getCurrentSectionData()->isBundlingEnabled()) { + return new MCDataFragment(getCurrentSectionData()); + } + // @LOCALMOD-END MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); if (!F) F = new MCDataFragment(getCurrentSectionData()); @@ -153,6 +159,54 @@ void MCObjectStreamer::EmitWeakReference(MCSymbol *Alias, report_fatal_error("This file format doesn't support weak aliases."); } +// @LOCALMOD-BEGIN ======================================================== + +void MCObjectStreamer::EmitBundleAlignStart() { + MCSectionData *SD = getCurrentSectionData(); + assert(SD->isBundlingEnabled() && + ".bundle_align_start called, but bundling disabled!"); + assert(!SD->isBundleLocked() && + ".bundle_align_start while bundle locked"); + SD->setBundleAlignNext(MCFragment::BundleAlignStart); +} + +void MCObjectStreamer::EmitBundleAlignEnd() { + MCSectionData *SD = getCurrentSectionData(); + assert(SD->isBundlingEnabled() && + ".bundle_align_end called, but bundling disabled!"); + assert(!SD->isBundleLocked() && + ".bundle_align_end while bundle locked"); + SD->setBundleAlignNext(MCFragment::BundleAlignEnd); +} + +void MCObjectStreamer::EmitBundleLock() { + MCSectionData *SD = getCurrentSectionData(); + assert(SD->isBundlingEnabled() && + ".bundle_lock called, but bundling disabled!"); + assert(!SD->isBundleLocked() && + ".bundle_lock issued when bundle already locked"); + SD->setBundleLocked(true); + SD->setBundleGroupFirstFrag(true); +} + +void MCObjectStreamer::EmitBundleUnlock() { + MCSectionData *SD = getCurrentSectionData(); + assert(SD->isBundlingEnabled() && + ".bundle_unlock called, but bundling disabled!"); + assert(SD->isBundleLocked() && + ".bundle_unlock called when bundle not locked"); + // If there has been at least one fragment emitted inside + // this bundle lock, then we need to mark the last emitted + // fragment as the group end. + if (!SD->isBundleGroupFirstFrag()) { + assert(getCurrentFragment() != NULL); + getCurrentFragment()->setBundleGroupEnd(true); + } + SD->setBundleLocked(false); + SD->setBundleGroupFirstFrag(false); +} +// @LOCALMOD-END ========================================================== + void MCObjectStreamer::ChangeSection(const MCSection *Section) { assert(Section && "Cannot switch to a null section!"); @@ -160,6 +214,13 @@ void MCObjectStreamer::ChangeSection(const MCSection *Section) { } void MCObjectStreamer::EmitInstruction(const MCInst &Inst) { + + // @LOCALMOD-BEGIN + if (getAssembler().getBackend().CustomExpandInst(Inst, *this)) { + return; + } + // @LOCALMOD-END + // Scan for values. for (unsigned i = Inst.getNumOperands(); i--; ) if (Inst.getOperand(i).isExpr()) @@ -235,6 +296,7 @@ void MCObjectStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, void MCObjectStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) { assert(AddrSpace == 0 && "Address space must be 0!"); getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end()); + getCurrentSectionData()->MarkBundleOffsetUnknown(); // @LOCALMOD } void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment, @@ -246,6 +308,10 @@ void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment, new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit, getCurrentSectionData()); + // @LOCALMOD-BEGIN + // Bump the bundle offset to account for alignment. + getCurrentSectionData()->AlignBundleOffsetTo(ByteAlignment); + // @LOCALMOD-END // Update the maximum alignment on the current section if necessary. if (ByteAlignment > getCurrentSectionData()->getAlignment()) getCurrentSectionData()->setAlignment(ByteAlignment); @@ -301,6 +367,7 @@ void MCObjectStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue, // FIXME: A MCFillFragment would be more memory efficient but MCExpr has // problems evaluating expressions across multiple fragments. getOrCreateDataFragment()->getContents().append(NumBytes, FillValue); + getCurrentSectionData()->MarkBundleOffsetUnknown(); } void MCObjectStreamer::FinishImpl() { |