Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions llvm/include/llvm/MC/MCAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ class MCAssembler {
// refactoring too.
mutable SmallPtrSet<const MCSymbol *, 32> ThumbFuncs;

/// The bundle alignment size currently set in the assembler.
///
/// By default it's 0, which means bundling is disabled.
unsigned BundleAlignSize = 0;

/// Evaluate a fixup to a relocatable expression and the value which should be
/// placed into the fixup.
///
Expand Down Expand Up @@ -143,8 +138,6 @@ class MCAssembler {
/// Compute the effective fragment size.
LLVM_ABI uint64_t computeFragmentSize(const MCFragment &F) const;

LLVM_ABI void layoutBundle(MCFragment *Prev, MCFragment *F) const;

// Get the offset of the given fragment inside its containing section.
uint64_t getFragmentOffset(const MCFragment &F) const { return F.Offset; }

Expand Down Expand Up @@ -203,16 +196,6 @@ class MCAssembler {
bool getRelaxAll() const { return RelaxAll; }
void setRelaxAll(bool Value) { RelaxAll = Value; }

bool isBundlingEnabled() const { return BundleAlignSize != 0; }

unsigned getBundleAlignSize() const { return BundleAlignSize; }

void setBundleAlignSize(unsigned Size) {
assert((Size == 0 || !(Size & (Size - 1))) &&
"Expect a power-of-two bundle align size");
BundleAlignSize = Size;
}

const_iterator begin() const { return Sections.begin(); }
const_iterator end() const { return Sections.end(); }

Expand All @@ -226,12 +209,6 @@ class MCAssembler {
LLVM_ABI bool registerSection(MCSection &Section);
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol);

/// Write the necessary bundle padding to \p OS.
/// Expects a fragment \p F containing instructions and its size \p FSize.
LLVM_ABI void writeFragmentPadding(raw_ostream &OS,
const MCEncodedFragment &F,
uint64_t FSize) const;

LLVM_ABI void reportError(SMLoc L, const Twine &Msg) const;
// Record pending errors during layout iteration, as they may go away once the
// layout is finalized.
Expand Down
5 changes: 0 additions & 5 deletions llvm/include/llvm/MC/MCELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ class MCELFStreamer : public MCObjectStreamer {
// target-specific code.
void finishImpl() final;

void emitBundleAlignMode(Align Alignment) override;
void emitBundleLock(bool AlignToEnd) override;
void emitBundleUnlock() override;

/// ELF object attributes section emission support
struct AttributeItem {
// This structure holds all attributes, accounting for their string /
Expand Down Expand Up @@ -151,7 +147,6 @@ class MCELFStreamer : public MCObjectStreamer {
}

private:
bool isBundleLocked() const;
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;

void finalizeCGProfileEntry(const MCSymbolRefExpr *&S, uint64_t Offset);
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ class MCObjectStreamer : public MCStreamer {
/// can change its size during relaxation.
void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);

void emitBundleAlignMode(Align Alignment) override;
void emitBundleLock(bool AlignToEnd) override;
void emitBundleUnlock() override;
void emitBytes(StringRef Data) override;
void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
uint8_t FillLen = 1,
Expand Down
45 changes: 0 additions & 45 deletions llvm/include/llvm/MC/MCSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ class LLVM_ABI MCSection {
SV_DXContainer,
};

/// Express the state of bundle locked groups while emitting code.
enum BundleLockStateType {
NotBundleLocked,
BundleLocked,
BundleLockedAlignToEnd
};

struct iterator {
MCFragment *F = nullptr;
iterator() = default;
Expand All @@ -94,16 +87,6 @@ class LLVM_ABI MCSection {
/// The section index in the assemblers section list.
unsigned Ordinal = 0;

/// Keeping track of bundle-locked state.
BundleLockStateType BundleLockState = NotBundleLocked;

/// Current nesting depth of bundle_lock directives.
unsigned BundleLockNestingDepth = 0;

/// We've seen a bundle_lock directive but not its first instruction
/// yet.
bool BundleGroupBeforeFirstInst : 1;

/// Whether this section has had instructions emitted into it.
bool HasInstructions : 1;

Expand Down Expand Up @@ -169,17 +152,6 @@ class LLVM_ABI MCSection {
unsigned getOrdinal() const { return Ordinal; }
void setOrdinal(unsigned Value) { Ordinal = Value; }

BundleLockStateType getBundleLockState() const { return BundleLockState; }
void setBundleLockState(BundleLockStateType NewState);
bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }

bool isBundleGroupBeforeFirstInst() const {
return BundleGroupBeforeFirstInst;
}
void setBundleGroupBeforeFirstInst(bool IsFirst) {
BundleGroupBeforeFirstInst = IsFirst;
}

bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }

Expand Down Expand Up @@ -259,7 +231,6 @@ class MCFragment {
///
/// MCEncodedFragment
bool HasInstructions : 1;
bool AlignToBundleEnd : 1;
/// MCDataFragment
bool LinkerRelaxable : 1;
/// MCRelaxableFragment: x86-specific
Expand Down Expand Up @@ -297,7 +268,6 @@ class MCFragment {
/// Interface implemented by fragments that contain encoded instructions and/or
/// data.
class MCEncodedFragment : public MCFragment {
uint8_t BundlePadding = 0;
uint32_t ContentStart = 0;
uint32_t ContentEnd = 0;
uint32_t FixupStart = 0;
Expand Down Expand Up @@ -329,21 +299,6 @@ class MCEncodedFragment : public MCFragment {
}
}

/// Should this fragment be placed at the end of an aligned bundle?
bool alignToBundleEnd() const { return AlignToBundleEnd; }
void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; }

/// Get the padding size that must be inserted before this fragment.
/// Used for bundling. By default, no padding is inserted.
/// Note that padding size is restricted to 8 bits. This is an optimization
/// to reduce the amount of space used for each fragment. In practice, larger
/// padding should never be required.
uint8_t getBundlePadding() const { return BundlePadding; }

/// Set the padding size for this fragment. By default it's a no-op,
/// and only some fragments have a meaningful implementation.
void setBundlePadding(uint8_t N) { BundlePadding = N; }

/// Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
/// Guaranteed to be non-null if hasInstructions() == true
const MCSubtargetInfo *getSubtargetInfo() const { return STI; }
Expand Down
13 changes: 0 additions & 13 deletions llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,19 +1068,6 @@ class LLVM_ABI MCStreamer {
const MCPseudoProbeInlineStack &InlineStack,
MCSymbol *FnSym);

/// Set the bundle alignment mode from now on in the section.
/// The value 1 means turn the bundle alignment off.
virtual void emitBundleAlignMode(Align Alignment);

/// The following instructions are a bundle-locked group.
///
/// \param AlignToEnd - If true, the bundle-locked group will be aligned to
/// the end of a bundle.
virtual void emitBundleLock(bool AlignToEnd);

/// Ends a bundle-locked group.
virtual void emitBundleUnlock();

/// If this file is backed by a assembly streamer, this dumps the
/// specified string in the output .s file. This capability is indicated by
/// the hasRawTextSupport() predicate. By default this aborts.
Expand Down
21 changes: 0 additions & 21 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@ class MCAsmStreamer final : public MCStreamer {
const MCPseudoProbeInlineStack &InlineStack,
MCSymbol *FnSym) override;

void emitBundleAlignMode(Align Alignment) override;
void emitBundleLock(bool AlignToEnd) override;
void emitBundleUnlock() override;

std::optional<std::pair<bool, std::string>>
emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
SMLoc Loc, const MCSubtargetInfo &STI) override;
Expand Down Expand Up @@ -2472,23 +2468,6 @@ void MCAsmStreamer::emitPseudoProbe(uint64_t Guid, uint64_t Index,
EmitEOL();
}

void MCAsmStreamer::emitBundleAlignMode(Align Alignment) {
OS << "\t.bundle_align_mode " << Log2(Alignment);
EmitEOL();
}

void MCAsmStreamer::emitBundleLock(bool AlignToEnd) {
OS << "\t.bundle_lock";
if (AlignToEnd)
OS << " align_to_end";
EmitEOL();
}

void MCAsmStreamer::emitBundleUnlock() {
OS << "\t.bundle_unlock";
EmitEOL();
}

std::optional<std::pair<bool, std::string>>
MCAsmStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
const MCExpr *Expr, SMLoc,
Expand Down
128 changes: 0 additions & 128 deletions llvm/lib/MC/MCAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ void MCAssembler::reset() {
Sections.clear();
Symbols.clear();
ThumbFuncs.clear();
BundleAlignSize = 0;

// reset objects owned by us
if (getBackendPtr())
Expand Down Expand Up @@ -282,87 +281,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
llvm_unreachable("invalid fragment kind");
}

// Compute the amount of padding required before the fragment \p F to
// obey bundling restrictions, where \p FOffset is the fragment's offset in
// its section and \p FSize is the fragment's size.
static uint64_t computeBundlePadding(unsigned BundleSize,
const MCEncodedFragment *F,
uint64_t FOffset, uint64_t FSize) {
uint64_t OffsetInBundle = FOffset & (BundleSize - 1);
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 (OffsetInBundle > 0 && EndOfFragment > BundleSize)
return BundleSize - OffsetInBundle;
else
return 0;
}

void MCAssembler::layoutBundle(MCFragment *Prev, MCFragment *F) const {
// If bundling is enabled and this fragment has instructions in it, it has to
// obey the bundling restrictions. With padding, we'll have:
//
//
// BundlePadding
// |||
// -------------------------------------
// Prev |##########| F |
// -------------------------------------
// ^
// |
// F->Offset
//
// The fragment's offset will point to after the padding, and its computed
// size won't include the padding.
//
// ".align N" is an example of a directive that introduces multiple
// fragments. We could add a special case to handle ".align N" by emitting
// within-fragment padding (which would produce less padding when N is less
// than the bundle size), but for now we don't.
//
assert(isa<MCEncodedFragment>(F) &&
"Only MCEncodedFragment implementations have instructions");
MCEncodedFragment *EF = cast<MCEncodedFragment>(F);
uint64_t FSize = computeFragmentSize(*EF);

if (FSize > getBundleAlignSize())
report_fatal_error("Fragment can't be larger than a bundle size");

uint64_t RequiredBundlePadding =
computeBundlePadding(getBundleAlignSize(), EF, EF->Offset, FSize);
if (RequiredBundlePadding > UINT8_MAX)
report_fatal_error("Padding cannot exceed 255 bytes");
EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
EF->Offset += RequiredBundlePadding;
if (auto *DF = dyn_cast_or_null<MCDataFragment>(Prev))
if (DF->getContents().empty())
DF->Offset = EF->Offset;
}

// Simple getSymbolOffset helper for the non-variable case.
static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S,
bool ReportError, uint64_t &Val) {
Expand Down Expand Up @@ -480,41 +398,6 @@ bool MCAssembler::registerSymbol(const MCSymbol &Symbol) {
return Changed;
}

void MCAssembler::writeFragmentPadding(raw_ostream &OS,
const MCEncodedFragment &EF,
uint64_t FSize) const {
assert(getBackendPtr() && "Expected assembler backend");
// Should NOP padding be written out before this fragment?
unsigned BundlePadding = EF.getBundlePadding();
if (BundlePadding > 0) {
assert(isBundlingEnabled() &&
"Writing bundle padding with disabled bundling");
assert(EF.hasInstructions() &&
"Writing bundle padding for a fragment without instructions");

unsigned TotalLength = BundlePadding + static_cast<unsigned>(FSize);
const MCSubtargetInfo *STI = EF.getSubtargetInfo();
if (EF.alignToBundleEnd() && TotalLength > getBundleAlignSize()) {
// If the padding itself crosses a bundle boundary, it must be emitted
// in 2 pieces, since even nop instructions must not cross boundaries.
// v--------------v <- BundleAlignSize
// v---------v <- BundlePadding
// ----------------------------
// | Prev |####|####| F |
// ----------------------------
// ^-------------------^ <- TotalLength
unsigned DistanceToBoundary = TotalLength - getBundleAlignSize();
if (!getBackend().writeNopData(OS, DistanceToBoundary, STI))
report_fatal_error("unable to write NOP sequence of " +
Twine(DistanceToBoundary) + " bytes");
BundlePadding -= DistanceToBoundary;
}
if (!getBackend().writeNopData(OS, BundlePadding, STI))
report_fatal_error("unable to write NOP sequence of " +
Twine(BundlePadding) + " bytes");
}
}

/// Write the fragment \p F to the output file.
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
const MCFragment &F) {
Expand All @@ -523,9 +406,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,

llvm::endianness Endian = Asm.getBackend().Endian;

if (const MCEncodedFragment *EF = dyn_cast<MCEncodedFragment>(&F))
Asm.writeFragmentPadding(OS, *EF, FragmentSize);

// This variable (and its dummy usage) is to participate in the assert at
// the end of the function.
uint64_t Start = OS.tell();
Expand Down Expand Up @@ -1101,17 +981,9 @@ bool MCAssembler::relaxFragment(MCFragment &F) {
}

void MCAssembler::layoutSection(MCSection &Sec) {
MCFragment *Prev = nullptr;
uint64_t Offset = 0;
for (MCFragment &F : Sec) {
F.Offset = Offset;
if (LLVM_UNLIKELY(isBundlingEnabled())) {
if (F.hasInstructions()) {
layoutBundle(Prev, &F);
Offset = F.Offset;
}
Prev = &F;
}
Offset += computeFragmentSize(F);
}
}
Expand Down
Loading
Loading