diff options
author | Eli Bendersky <eliben@google.com> | 2013-01-07 21:51:08 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2013-01-07 21:51:08 +0000 |
commit | 6c1d4972cf1cd6b6072e31c05f97abb1ed7a8497 (patch) | |
tree | 01a1fc8d4730a3b75657fafa9a5428bd7e4f0057 /lib | |
parent | d3ae2866d105f6da6375544eb41aea0dad75a9f2 (diff) | |
download | external_llvm-6c1d4972cf1cd6b6072e31c05f97abb1ed7a8497.zip external_llvm-6c1d4972cf1cd6b6072e31c05f97abb1ed7a8497.tar.gz external_llvm-6c1d4972cf1cd6b6072e31c05f97abb1ed7a8497.tar.bz2 |
Add the align_to_end option to .bundle_lock in the MC implementation of aligned
bundling. The document describing this feature and the implementation has also
been updated:
https://sites.google.com/a/chromium.org/dev/nativeclient/pnacl/aligned-bundling-support-in-llvm
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171797 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 6 | ||||
-rw-r--r-- | lib/MC/MCAssembler.cpp | 34 | ||||
-rw-r--r-- | lib/MC/MCELFStreamer.cpp | 15 | ||||
-rw-r--r-- | lib/MC/MCNullStreamer.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCObjectStreamer.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 24 |
6 files changed, 66 insertions, 17 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 9b7074d..e234dfe 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -260,7 +260,7 @@ public: virtual void EmitInstruction(const MCInst &Inst); virtual void EmitBundleAlignMode(unsigned AlignPow2); - virtual void EmitBundleLock(); + virtual void EmitBundleLock(bool AlignToEnd); virtual void EmitBundleUnlock(); /// EmitRawText - If this file is backed by an assembly streamer, this dumps @@ -1370,8 +1370,10 @@ void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) { EmitEOL(); } -void MCAsmStreamer::EmitBundleLock() { +void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) { OS << "\t.bundle_lock"; + if (AlignToEnd) + OS << " align_to_end"; EmitEOL(); } diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 20b64e2..d30dc7d 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -167,10 +167,34 @@ uint64_t MCAsmLayout::computeBundlePadding(const MCFragment *F, "computeBundlePadding should only be called if bundling is enabled"); uint64_t BundleMask = BundleSize - 1; uint64_t OffsetInBundle = FOffset & BundleMask; - - // If the fragment would cross a bundle boundary, add enough padding until - // the end of the current bundle. - if (OffsetInBundle + FSize > BundleSize) + uint64_t EndOfFragment = OffsetInBundle + FSize; + + // There are two kinds of bundling restrictions: + // + // 1) For alignToBundleEnd(), add padding to ensure that the fragment will + // *end* on a bundle boundary. + // 2) Otherwise, check if the fragment would cross a bundle boundary. If it + // would, add padding until the end of the bundle so that the fragment + // will start in a new one. + if (F->alignToBundleEnd()) { + // Three possibilities here: + // + // A) The fragment just happens to end at a bundle boundary, so we're good. + // B) The fragment ends before the current bundle boundary: pad it just + // enough to reach the boundary. + // C) The fragment ends after the current bundle boundary: pad it until it + // reaches the end of the next bundle boundary. + // + // Note: this code could be made shorter with some modulo trickery, but it's + // intentionally kept in its more explicit form for simplicity. + if (EndOfFragment == BundleSize) + return 0; + else if (EndOfFragment < BundleSize) + return BundleSize - EndOfFragment; + else { // EndOfFragment > BundleSize + return 2 * BundleSize - EndOfFragment; + } + } else if (EndOfFragment > BundleSize) return BundleSize - OffsetInBundle; else return 0; @@ -204,7 +228,7 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A) : Section(&_Section), Ordinal(~UINT32_C(0)), Alignment(1), - BundleLocked(false), BundleGroupBeforeFirstInst(false), + BundleLockState(NotBundleLocked), BundleGroupBeforeFirstInst(false), HasInstructions(false) { if (A) diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index e3acc44..e9afff6 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -379,8 +379,14 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) { MCSectionData *SD = getCurrentSectionData(); if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst()) DF = getOrCreateDataFragment(); - else + else { DF = new MCDataFragment(SD); + if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) { + // If this is a new fragment created for a bundle-locked group, and the + // group was marked as "align_to_end", set a flag in the fragment. + DF->setAlignToBundleEnd(true); + } + } // We're now emitting an instruction in a bundle group, so this flag has // to be turned off. @@ -407,7 +413,7 @@ void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) { report_fatal_error(".bundle_align_mode should be only set once per file"); } -void MCELFStreamer::EmitBundleLock() { +void MCELFStreamer::EmitBundleLock(bool AlignToEnd) { MCSectionData *SD = getCurrentSectionData(); // Sanity checks @@ -417,7 +423,8 @@ void MCELFStreamer::EmitBundleLock() { else if (SD->isBundleLocked()) report_fatal_error("Nesting of .bundle_lock is forbidden"); - SD->setBundleLocked(true); + SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd : + MCSectionData::BundleLocked); SD->setBundleGroupBeforeFirstInst(true); } @@ -432,7 +439,7 @@ void MCELFStreamer::EmitBundleUnlock() { else if (SD->isBundleGroupBeforeFirstInst()) report_fatal_error("Empty bundle-locked group is forbidden"); - SD->setBundleLocked(false); + SD->setBundleLockState(MCSectionData::NotBundleLocked); } void MCELFStreamer::FinishImpl() { diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp index d1cd006..364c324 100644 --- a/lib/MC/MCNullStreamer.cpp +++ b/lib/MC/MCNullStreamer.cpp @@ -96,7 +96,7 @@ namespace { virtual void EmitInstruction(const MCInst &Inst) {} virtual void EmitBundleAlignMode(unsigned AlignPow2) {} - virtual void EmitBundleLock() {} + virtual void EmitBundleLock(bool AlignToEnd) {} virtual void EmitBundleUnlock() {} virtual void FinishImpl() {} diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 6d5c0a5..a848615 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -233,7 +233,7 @@ void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) { llvm_unreachable(BundlingNotImplementedMsg); } -void MCObjectStreamer::EmitBundleLock() { +void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) { llvm_unreachable(BundlingNotImplementedMsg); } diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 8a22ed5..7c3fea5 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -2473,15 +2473,31 @@ bool AsmParser::ParseDirectiveBundleAlignMode() { } /// ParseDirectiveBundleLock -/// ::= {.bundle_lock} +/// ::= {.bundle_lock} [align_to_end] bool AsmParser::ParseDirectiveBundleLock() { CheckForValidSection(); + bool AlignToEnd = false; + + if (getLexer().isNot(AsmToken::EndOfStatement)) { + StringRef Option; + SMLoc Loc = getTok().getLoc(); + const char *kInvalidOptionError = + "invalid option for '.bundle_lock' directive"; + + if (ParseIdentifier(Option)) + return Error(Loc, kInvalidOptionError); + + if (Option != "align_to_end") + return Error(Loc, kInvalidOptionError); + else if (getLexer().isNot(AsmToken::EndOfStatement)) + return Error(Loc, + "unexpected token after '.bundle_lock' directive option"); + AlignToEnd = true; + } - if (getLexer().isNot(AsmToken::EndOfStatement)) - return TokError("unexpected token in '.bundle_lock' directive"); Lex(); - getStreamer().EmitBundleLock(); + getStreamer().EmitBundleLock(AlignToEnd); return false; } |