Skip to content

Commit 1fbfa33

Browse files
committed
MCAlignFragment: Rename fields and use uint8_t FillLen
* Rename the vague `Value` to `Fill`. * FillLen is at most 8. Making the field smaller to facilitate encoding MCAlignFragment as a MCFragment union member. * Replace an unreachable report_fatal_error with assert.
1 parent b56aeba commit 1fbfa33

File tree

17 files changed

+58
-71
lines changed

17 files changed

+58
-71
lines changed

llvm/include/llvm/MC/MCELFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class MCELFStreamer : public MCObjectStreamer {
7070

7171
void emitIdent(StringRef IdentString) override;
7272

73-
void emitValueToAlignment(Align, int64_t, unsigned, unsigned) override;
73+
void emitValueToAlignment(Align, int64_t, uint8_t, unsigned) override;
7474

7575
void emitCGProfileEntry(const MCSymbolRefExpr *From,
7676
const MCSymbolRefExpr *To, uint64_t Count) override;

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class MCObjectStreamer : public MCStreamer {
131131
void emitBundleLock(bool AlignToEnd) override;
132132
void emitBundleUnlock() override;
133133
void emitBytes(StringRef Data) override;
134-
void emitValueToAlignment(Align Alignment, int64_t Value = 0,
135-
unsigned ValueSize = 1,
134+
void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
135+
uint8_t FillLen = 1,
136136
unsigned MaxBytesToEmit = 0) override;
137137
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI,
138138
unsigned MaxBytesToEmit = 0) override;

llvm/include/llvm/MC/MCSection.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,39 +469,36 @@ class MCRelaxableFragment : public MCEncodedFragment {
469469
};
470470

471471
class MCAlignFragment : public MCFragment {
472-
/// The alignment to ensure, in bytes.
473-
Align Alignment;
474-
475472
/// Flag to indicate that (optimal) NOPs should be emitted instead
476473
/// of using the provided value. The exact interpretation of this flag is
477474
/// target dependent.
478475
bool EmitNops : 1;
479476

480-
/// Value to use for filling padding bytes.
481-
int64_t Value;
477+
/// The alignment to ensure, in bytes.
478+
Align Alignment;
482479

483480
/// The size of the integer (in bytes) of \p Value.
484-
unsigned ValueSize;
481+
uint8_t FillLen;
485482

486483
/// The maximum number of bytes to emit; if the alignment
487484
/// cannot be satisfied in this width then this fragment is ignored.
488485
unsigned MaxBytesToEmit;
489486

487+
/// Value to use for filling padding bytes.
488+
int64_t Fill;
489+
490490
/// When emitting Nops some subtargets have specific nop encodings.
491491
const MCSubtargetInfo *STI = nullptr;
492492

493493
public:
494-
MCAlignFragment(Align Alignment, int64_t Value, unsigned ValueSize,
494+
MCAlignFragment(Align Alignment, int64_t Fill, uint8_t FillLen,
495495
unsigned MaxBytesToEmit)
496-
: MCFragment(FT_Align, false), Alignment(Alignment), EmitNops(false),
497-
Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}
496+
: MCFragment(FT_Align, false), EmitNops(false), Alignment(Alignment),
497+
FillLen(FillLen), MaxBytesToEmit(MaxBytesToEmit), Fill(Fill) {}
498498

499499
Align getAlignment() const { return Alignment; }
500-
501-
int64_t getValue() const { return Value; }
502-
503-
unsigned getValueSize() const { return ValueSize; }
504-
500+
int64_t getFill() const { return Fill; }
501+
uint8_t getFillLen() const { return FillLen; }
505502
unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
506503

507504
bool hasEmitNops() const { return EmitNops; }

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,14 +807,14 @@ class LLVM_ABI MCStreamer {
807807
/// This used to implement the .align assembler directive.
808808
///
809809
/// \param Alignment - The alignment to reach.
810-
/// \param Value - The value to use when filling bytes.
811-
/// \param ValueSize - The size of the integer (in bytes) to emit for
810+
/// \param Fill - The value to use when filling bytes.
811+
/// \param FillLen - The size of the integer (in bytes) to emit for
812812
/// \p Value. This must match a native machine width.
813813
/// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
814814
/// the alignment cannot be reached in this many bytes, no bytes are
815815
/// emitted.
816-
virtual void emitValueToAlignment(Align Alignment, int64_t Value = 0,
817-
unsigned ValueSize = 1,
816+
virtual void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
817+
uint8_t FillLen = 1,
818818
unsigned MaxBytesToEmit = 0);
819819

820820
/// Emit nops until the byte alignment \p ByteAlignment is reached.

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ class MCAsmStreamer final : public MCStreamer {
269269
std::optional<int64_t> Value, unsigned ValueSize,
270270
unsigned MaxBytesToEmit);
271271

272-
void emitValueToAlignment(Align Alignment, int64_t Value = 0,
273-
unsigned ValueSize = 1,
272+
void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
273+
uint8_t FillLen = 1,
274274
unsigned MaxBytesToEmit = 0) override;
275275

276276
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
@@ -1528,10 +1528,10 @@ void MCAsmStreamer::emitAlignmentDirective(uint64_t ByteAlignment,
15281528
EmitEOL();
15291529
}
15301530

1531-
void MCAsmStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
1532-
unsigned ValueSize,
1531+
void MCAsmStreamer::emitValueToAlignment(Align Alignment, int64_t Fill,
1532+
uint8_t FillLen,
15331533
unsigned MaxBytesToEmit) {
1534-
emitAlignmentDirective(Alignment.value(), Value, ValueSize, MaxBytesToEmit);
1534+
emitAlignmentDirective(Alignment.value(), Fill, FillLen, MaxBytesToEmit);
15351535
}
15361536

15371537
void MCAsmStreamer::emitCodeAlignment(Align Alignment,

llvm/lib/MC/MCAssembler.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -553,18 +553,11 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
553553
case MCFragment::FT_Align: {
554554
++stats::EmittedAlignFragments;
555555
const MCAlignFragment &AF = cast<MCAlignFragment>(F);
556-
assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
556+
assert(AF.getFillLen() && "Invalid virtual align in concrete fragment!");
557557

558-
uint64_t Count = FragmentSize / AF.getValueSize();
559-
560-
// FIXME: This error shouldn't actually occur (the front end should emit
561-
// multiple .align directives to enforce the semantics it wants), but is
562-
// severe enough that we want to report it. How to handle this?
563-
if (Count * AF.getValueSize() != FragmentSize)
564-
report_fatal_error("undefined .align directive, value size '" +
565-
Twine(AF.getValueSize()) +
566-
"' is not a divisor of padding size '" +
567-
Twine(FragmentSize) + "'");
558+
uint64_t Count = FragmentSize / AF.getFillLen();
559+
assert(FragmentSize % AF.getFillLen() == 0 &&
560+
"computeFragmentSize computed size is incorrect");
568561

569562
// See if we are aligning with nops, and if so do that first to try to fill
570563
// the Count bytes. Then if that did not fill any bytes or there are any
@@ -579,17 +572,19 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
579572

580573
// Otherwise, write out in multiples of the value size.
581574
for (uint64_t i = 0; i != Count; ++i) {
582-
switch (AF.getValueSize()) {
575+
switch (AF.getFillLen()) {
583576
default: llvm_unreachable("Invalid size!");
584-
case 1: OS << char(AF.getValue()); break;
577+
case 1:
578+
OS << char(AF.getFill());
579+
break;
585580
case 2:
586-
support::endian::write<uint16_t>(OS, AF.getValue(), Endian);
581+
support::endian::write<uint16_t>(OS, AF.getFill(), Endian);
587582
break;
588583
case 4:
589-
support::endian::write<uint32_t>(OS, AF.getValue(), Endian);
584+
support::endian::write<uint32_t>(OS, AF.getFill(), Endian);
590585
break;
591586
case 8:
592-
support::endian::write<uint64_t>(OS, AF.getValue(), Endian);
587+
support::endian::write<uint64_t>(OS, AF.getFill(), Endian);
593588
break;
594589
}
595590
}
@@ -733,8 +728,8 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
733728
case MCFragment::FT_Align:
734729
// Check that we aren't trying to write a non-zero value into a virtual
735730
// section.
736-
assert((cast<MCAlignFragment>(F).getValueSize() == 0 ||
737-
cast<MCAlignFragment>(F).getValue() == 0) &&
731+
assert((cast<MCAlignFragment>(F).getFillLen() == 0 ||
732+
cast<MCAlignFragment>(F).getFill() == 0) &&
738733
"Invalid align in virtual section!");
739734
break;
740735
case MCFragment::FT_Fill:

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void MCELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
321321
}
322322

323323
void MCELFStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
324-
unsigned ValueSize,
324+
uint8_t ValueSize,
325325
unsigned MaxBytesToEmit) {
326326
if (isBundleLocked())
327327
report_fatal_error("Emitting values inside a locked bundle is forbidden");

llvm/lib/MC/MCFragment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ LLVM_DUMP_METHOD void MCFragment::dump() const {
7676
switch (getKind()) {
7777
case MCFragment::FT_Align: {
7878
const auto *AF = cast<MCAlignFragment>(this);
79-
OS << " Align:" << AF->getAlignment().value() << " Value:" << AF->getValue()
80-
<< " ValueSize:" << AF->getValueSize()
79+
OS << " Align:" << AF->getAlignment().value() << " Fill:" << AF->getFill()
80+
<< " FillLen:" << unsigned(AF->getFillLen())
8181
<< " MaxBytesToEmit:" << AF->getMaxBytesToEmit();
8282
if (AF->hasEmitNops())
8383
OS << " Nops";

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,13 @@ void MCObjectStreamer::emitBytes(StringRef Data) {
580580
DF->appendContents(ArrayRef(Data.data(), Data.size()));
581581
}
582582

583-
void MCObjectStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
584-
unsigned ValueSize,
583+
void MCObjectStreamer::emitValueToAlignment(Align Alignment, int64_t Fill,
584+
uint8_t FillLen,
585585
unsigned MaxBytesToEmit) {
586586
if (MaxBytesToEmit == 0)
587587
MaxBytesToEmit = Alignment.value();
588-
insert(getContext().allocFragment<MCAlignFragment>(
589-
Alignment, Value, ValueSize, MaxBytesToEmit));
588+
insert(getContext().allocFragment<MCAlignFragment>(Alignment, Fill, FillLen,
589+
MaxBytesToEmit));
590590

591591
// Update the maximum alignment on the current section if necessary.
592592
MCSection *CurSec = getCurrentSectionOnly();

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ class AsmParser : public MCAsmParser {
567567
bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
568568
bool parseDirectiveOrg(); // ".org"
569569
// ".align{,32}", ".p2align{,w,l}"
570-
bool parseDirectiveAlign(bool IsPow2, unsigned ValueSize);
570+
bool parseDirectiveAlign(bool IsPow2, uint8_t ValueSize);
571571

572572
// ".file", ".line", ".loc", ".loc_label", ".stabs"
573573
bool parseDirectiveFile(SMLoc DirectiveLoc);
@@ -3340,7 +3340,7 @@ bool AsmParser::parseDirectiveOrg() {
33403340

33413341
/// parseDirectiveAlign
33423342
/// ::= {.align, ...} expression [ , expression [ , expression ]]
3343-
bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
3343+
bool AsmParser::parseDirectiveAlign(bool IsPow2, uint8_t ValueSize) {
33443344
SMLoc AlignmentLoc = getLexer().getLoc();
33453345
int64_t Alignment;
33463346
SMLoc MaxBytesLoc;

0 commit comments

Comments
 (0)