Skip to content

Commit 85cc4af

Browse files
authored
[NFC][AMDGPU] Do not hardcode minimum instruction alignment (#147785)
Use symbolic value for minimum instruction alignment. Signed-off-by: John Lu <John.Lu@amd.com>
1 parent bdc0119 commit 85cc4af

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/StringSwitch.h"
1414
#include "llvm/BinaryFormat/ELF.h"
1515
#include "llvm/MC/MCAsmBackend.h"
16+
#include "llvm/MC/MCAsmInfo.h"
1617
#include "llvm/MC/MCAssembler.h"
1718
#include "llvm/MC/MCContext.h"
1819
#include "llvm/MC/MCObjectWriter.h"
@@ -194,18 +195,21 @@ unsigned AMDGPUAsmBackend::getMinimumNopSize() const {
194195

195196
bool AMDGPUAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
196197
const MCSubtargetInfo *STI) const {
197-
// If the count is not 4-byte aligned, we must be writing data into the text
198-
// section (otherwise we have unaligned instructions, and thus have far
199-
// bigger problems), so just write zeros instead.
200-
OS.write_zeros(Count % 4);
198+
// If the count is not aligned to the minimum instruction alignment, we must
199+
// be writing data into the text section (otherwise we have unaligned
200+
// instructions, and thus have far bigger problems), so just write zeros
201+
// instead.
202+
unsigned MinInstAlignment = getContext().getAsmInfo()->getMinInstAlignment();
203+
OS.write_zeros(Count % MinInstAlignment);
201204

202205
// We are properly aligned, so write NOPs as requested.
203-
Count /= 4;
206+
Count /= MinInstAlignment;
204207

205208
// FIXME: R600 support.
206209
// s_nop 0
207210
const uint32_t Encoded_S_NOP_0 = 0xbf800000;
208211

212+
assert(MinInstAlignment == sizeof(Encoded_S_NOP_0));
209213
for (uint64_t I = 0; I != Count; ++I)
210214
support::endian::write<uint32_t>(OS, Encoded_S_NOP_0, Endian);
211215

0 commit comments

Comments
 (0)