[llvm] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 05:04:34 PST 2024


================
@@ -174,6 +177,72 @@ void LoongArchAsmBackend::applyFixup(const MCAssembler &Asm,
   }
 }
 
+// Linker relaxation may change code size. We have to insert Nops
+// for .align directive when linker relaxation enabled. So then Linker
+// could satisfy alignment by removing Nops.
+// The function returns the total Nops Size we need to insert.
+bool LoongArchAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
+    const MCAlignFragment &AF, unsigned &Size) {
+  // Calculate Nops Size only when linker relaxation enabled.
+  const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+  if (!STI->hasFeature(LoongArch::FeatureRelax))
+    return false;
+
+  // Ignore alignment if the minimum Nop size is less than the MaxBytesToEmit.
----------------
SixWeining wrote:

Seems the comment should be:
```
// Ignore alignment if MaxBytesToEmit is less than the minimum Nop size.
```

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


More information about the llvm-commits mailing list