[NFC][Alignment] Use Align in MCAlignFragment

This commit is contained in:
Guillaume Chatelet 2022-06-14 11:31:58 +00:00
parent 3605ebca32
commit 412c788ab0
6 changed files with 11 additions and 9 deletions

View File

@ -293,7 +293,7 @@ public:
class MCAlignFragment : public MCFragment {
/// The alignment to ensure, in bytes.
unsigned Alignment;
Align Alignment;
/// Flag to indicate that (optimal) NOPs should be emitted instead
/// of using the provided value. The exact interpretation of this flag is
@ -314,12 +314,12 @@ class MCAlignFragment : public MCFragment {
const MCSubtargetInfo *STI;
public:
MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
MCAlignFragment(Align Alignment, int64_t Value, unsigned ValueSize,
unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
: MCFragment(FT_Align, false, Sec), Alignment(Alignment), EmitNops(false),
Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}
unsigned getAlignment() const { return Alignment; }
Align getAlignment() const { return Alignment; }
int64_t getValue() const { return Value; }

View File

@ -331,7 +331,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
case MCFragment::FT_Align: {
const MCAlignFragment &AF = cast<MCAlignFragment>(F);
unsigned Offset = Layout.getFragmentOffset(&AF);
unsigned Size = offsetToAlignment(Offset, Align(AF.getAlignment()));
unsigned Size = offsetToAlignment(Offset, AF.getAlignment());
// Insert extra Nops for code alignment if the target define
// shouldInsertExtraNopBytesForCodeAlign target hook.
@ -343,7 +343,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
// minimum nop size.
if (Size > 0 && AF.hasEmitNops()) {
while (Size % getBackend().getMinimumNopSize())
Size += AF.getAlignment();
Size += AF.getAlignment().value();
}
if (Size > AF.getMaxBytesToEmit())
return 0;

View File

@ -376,7 +376,7 @@ LLVM_DUMP_METHOD void MCFragment::dump() const {
if (AF->hasEmitNops())
OS << " (emit nops)";
OS << "\n ";
OS << " Alignment:" << AF->getAlignment()
OS << " Alignment:" << AF->getAlignment().value()
<< " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize()
<< " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">";
break;

View File

@ -647,7 +647,8 @@ void MCObjectStreamer::emitValueToAlignment(unsigned ByteAlignment,
unsigned MaxBytesToEmit) {
if (MaxBytesToEmit == 0)
MaxBytesToEmit = ByteAlignment;
insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
insert(new MCAlignFragment(Align(ByteAlignment), Value, ValueSize,
MaxBytesToEmit));
// Update the maximum alignment on the current section if necessary.
MCSection *CurSec = getCurrentSectionOnly();

View File

@ -1876,7 +1876,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
const MCFragment &AlignFrag = *IT;
if (AlignFrag.getKind() != MCFragment::FT_Align)
report_fatal_error(".init_array section should be aligned");
if (cast<MCAlignFragment>(AlignFrag).getAlignment() != (is64Bit() ? 8 : 4))
if (cast<MCAlignFragment>(AlignFrag).getAlignment() !=
Align(is64Bit() ? 8 : 4))
report_fatal_error(".init_array section should be aligned for pointers");
const MCFragment &Frag = *std::next(IT);

View File

@ -593,7 +593,7 @@ bool RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
if (AF.getAlignment() <= MinNopLen) {
return false;
} else {
Size = AF.getAlignment() - MinNopLen;
Size = AF.getAlignment().value() - MinNopLen;
return true;
}
}