[llvm] 4425b51 - X86AsmBackend: Remove some computeFragmentSize calls
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 1 18:37:07 PDT 2025
Author: Fangrui Song
Date: 2025-06-01T18:37:02-07:00
New Revision: 4425b513f3f6d1abb82635309d4eafd2aac6ded5
URL: https://github.com/llvm/llvm-project/commit/4425b513f3f6d1abb82635309d4eafd2aac6ded5
DIFF: https://github.com/llvm/llvm-project/commit/4425b513f3f6d1abb82635309d4eafd2aac6ded5.diff
LOG: X86AsmBackend: Remove some computeFragmentSize calls
The function was brittle as it performed only one iteration, which might
not converge. The reverted be5a845e4c29aadb513ae6e5e2879dccf37efdbb
mentioned that !NDEBUG and NDEBUG builds evaluated fragment offsets at
different times.
* X86AsmBackend::finishLayout performed only one iteration, which might
not converge. In addition, the removed `#ifndef NDEBUG` code (disabled
by default) in X86AsmBackend::finishLayout was problematic, as !NDEBUG
and NDEBUG builds evaluated fragment offsets at different times before
this patch.
Added:
Modified:
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 43d643035fa5c..ac60543e50eff 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -916,9 +916,6 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
continue;
}
-#ifndef NDEBUG
- const uint64_t OrigOffset = Asm.getFragmentOffset(F);
-#endif
const uint64_t OrigSize = Asm.computeFragmentSize(F);
// To keep the effects local, prefer to relax instructions closest to
@@ -949,14 +946,6 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
if (F.getKind() == MCFragment::FT_BoundaryAlign)
cast<MCBoundaryAlignFragment>(F).setSize(RemainingSize);
-#ifndef NDEBUG
- const uint64_t FinalOffset = Asm.getFragmentOffset(F);
- const uint64_t FinalSize = Asm.computeFragmentSize(F);
- assert(OrigOffset + OrigSize == FinalOffset + FinalSize &&
- "can't move start of next fragment!");
- assert(FinalSize == RemainingSize && "inconsistent size computation?");
-#endif
-
// If we're looking at a boundary align, make sure we don't try to pad
// its target instructions for some following directive. Doing so would
// break the alignment of the current boundary align.
@@ -971,10 +960,8 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
}
// The layout is done. Mark every fragment as valid.
- for (MCSection &Section : Asm) {
+ for (MCSection &Section : Asm)
Asm.getFragmentOffset(*Section.curFragList()->Tail);
- Asm.computeFragmentSize(*Section.curFragList()->Tail);
- }
}
unsigned X86AsmBackend::getMaximumNopSize(const MCSubtargetInfo &STI) const {
More information about the llvm-commits
mailing list