[llvm] [X86] Reimplement bundle alignment mode (PR #175830)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 18:52:43 PDT 2026


================
@@ -396,6 +396,35 @@ void MCAssembler::addRelocDirective(RelocDirective RD) {
   relocDirectives.push_back(RD);
 }
 
+/// Write NOPs while limiting the maximum NOP size.
+static void writeControlledNops(raw_ostream &OS, const MCAssembler &Asm,
+                                uint64_t NumBytes, uint64_t FragmentOffset,
+                                uint64_t MaxNopSize,
+                                const MCSubtargetInfo *STI) {
+  uint64_t NumBytesEmitted = 0;
+  while (NumBytesEmitted < NumBytes) {
+    uint64_t NumBytesToEmit = std::min(NumBytes - NumBytesEmitted, MaxNopSize);
+
+    if (Asm.isBundlingEnabled()) {
+      unsigned BundleAlignSize = Asm.getBundleAlignSize();
+      uint64_t OffsetInBundle =
+          (FragmentOffset + NumBytesEmitted) & (BundleAlignSize - 1);
+      uint64_t SpaceInBundle = BundleAlignSize - OffsetInBundle;
+      NumBytesToEmit = std::min(NumBytesToEmit, SpaceInBundle);
+    }
+
+    assert(NumBytesToEmit && "try to emit zero-sized NOP");
+
+    if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit, STI)) {
+      report_fatal_error("unable to write NOP sequence of the remaining " +
----------------
MaskRay wrote:

new code use either report{Usage,Internal}FatalError; avoid report_fatal_error

https://github.com/llvm/llvm-project/pull/175830


More information about the llvm-commits mailing list