[llvm] [NFC][AMDGPU] Do not hardcode minimum instruction alignment (PR #147785)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 9 10:07:34 PDT 2025
https://github.com/LU-JOHN created https://github.com/llvm/llvm-project/pull/147785
Use symbolic value for minimum instruction alignment.
>From 4815dcf6a4de3ce1acd207c9c4590209993182c8 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Wed, 9 Jul 2025 12:06:28 -0500
Subject: [PATCH] Do not hardcode minimum instruction alignment
Signed-off-by: John Lu <John.Lu at amd.com>
---
.../AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
index 8f89168754180..e7d0e1838fa63 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
@@ -13,6 +13,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCAsmBackend.h"
+#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectWriter.h"
@@ -194,18 +195,21 @@ unsigned AMDGPUAsmBackend::getMinimumNopSize() const {
bool AMDGPUAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const {
- // If the count is not 4-byte aligned, we must be writing data into the text
- // section (otherwise we have unaligned instructions, and thus have far
- // bigger problems), so just write zeros instead.
- OS.write_zeros(Count % 4);
+ // If the count is not aligned to the minimum instruction alignment, we must
+ // be writing data into the text section (otherwise we have unaligned
+ // instructions, and thus have far bigger problems), so just write zeros
+ // instead.
+ unsigned MinInstAlignment = getContext().getAsmInfo()->getMinInstAlignment();
+ OS.write_zeros(Count % MinInstAlignment);
// We are properly aligned, so write NOPs as requested.
- Count /= 4;
+ Count /= MinInstAlignment;
// FIXME: R600 support.
// s_nop 0
const uint32_t Encoded_S_NOP_0 = 0xbf800000;
+ assert(MinInstAlignment == sizeof(Encoded_S_NOP_0));
for (uint64_t I = 0; I != Count; ++I)
support::endian::write<uint32_t>(OS, Encoded_S_NOP_0, Endian);
More information about the llvm-commits
mailing list