[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jul 19 17:26:02 PDT 2025
================
@@ -433,42 +434,44 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
const auto &EF = cast<MCFragment>(F);
OS << StringRef(EF.getContents().data(), EF.getContents().size());
OS << StringRef(EF.getVarContents().data(), EF.getVarContents().size());
- if (F.getKind() == MCFragment::FT_Align) {
- ++stats::EmittedAlignFragments;
- assert(F.getAlignFillLen() &&
- "Invalid virtual align in concrete fragment!");
-
- uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen();
- assert((FragmentSize - F.getFixedSize()) % F.getAlignFillLen() == 0 &&
- "computeFragmentSize computed size is incorrect");
-
- // See if we are aligning with nops, and if so do that first to try to
- // fill the Count bytes. Then if that did not fill any bytes or there are
- // any bytes left to fill use the Value and ValueSize to fill the rest. If
- // we are aligning with nops, ask that target to emit the right data.
- if (F.hasAlignEmitNops()) {
- if (!Asm.getBackend().writeNopData(OS, Count, F.getSubtargetInfo()))
- report_fatal_error("unable to write nop sequence of " + Twine(Count) +
- " bytes");
- } else {
- // Otherwise, write out in multiples of the value size.
- for (uint64_t i = 0; i != Count; ++i) {
- switch (F.getAlignFillLen()) {
- default:
- llvm_unreachable("Invalid size!");
- case 1:
- OS << char(F.getAlignFill());
- break;
- case 2:
- support::endian::write<uint16_t>(OS, F.getAlignFill(), Endian);
- break;
- case 4:
- support::endian::write<uint32_t>(OS, F.getAlignFill(), Endian);
- break;
- case 8:
- support::endian::write<uint64_t>(OS, F.getAlignFill(), Endian);
- break;
- }
+ } break;
+
+ case MCFragment::FT_Align: {
+ ++stats::EmittedAlignFragments;
+ OS << StringRef(F.getContents().data(), F.getContents().size());
+ assert(F.getAlignFillLen() &&
+ "Invalid virtual align in concrete fragment!");
+
+ uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen();
+ assert((FragmentSize - F.getFixedSize()) % F.getAlignFillLen() == 0 &&
+ "computeFragmentSize computed size is incorrect");
+
+ // See if we are aligning with nops, and if so do that first to try to
+ // fill the Count bytes. Then if that did not fill any bytes or there are
+ // any bytes left to fill use the Value and ValueSize to fill the rest. If
+ // we are aligning with nops, ask that target to emit the right data.
----------------
MaskRay wrote:
I think we can simplify the comment. Updated it to "// In the nops mode, call the backend hook to write `Count` nops."
https://github.com/llvm/llvm-project/pull/149465
More information about the llvm-branch-commits
mailing list