Skip to content

Commit 23457ee

Browse files
committed
[AMDGPU][MC] GFX9 - Support NV bit in FLAT instructions in pre-GFX90A
targets This patch enables support of the NV (non-volatile) bit in FLAT instructions in GFX9 (pre-GFX90A) targets.
1 parent 4a9fdda commit 23457ee

File tree

6 files changed

+1758
-2
lines changed

6 files changed

+1758
-2
lines changed

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5295,7 +5295,8 @@ bool AMDGPUAsmParser::validateCoherencyBits(const MCInst &Inst,
52955295
S = SMLoc::getFromPointer(&CStr.data()[CStr.find("scale_offset")]);
52965296
Error(S, "scale_offset is not supported on this GPU");
52975297
}
5298-
if (CPol & CPol::NV) {
5298+
if ((CPol & CPol::NV) && (!isGFX9() || isGFX90A())) {
5299+
// nv not supported on GFX90A+
52995300
SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol, Operands);
53005301
StringRef CStr(S.getPointer());
53015302
S = SMLoc::getFromPointer(&CStr.data()[CStr.find("nv")]);
@@ -7089,6 +7090,13 @@ ParseStatus AMDGPUAsmParser::parseCPol(OperandVector &Operands) {
70897090
unsigned Enabled = 0, Seen = 0;
70907091
for (;;) {
70917092
SMLoc S = getLoc();
7093+
7094+
if (isGFX9() && trySkipId("nv")) {
7095+
Enabled |= CPol::NV;
7096+
Seen |= CPol::NV;
7097+
continue;
7098+
}
7099+
70927100
bool Disabling;
70937101
unsigned CPol = getCPolKind(getId(), Mnemo, Disabling);
70947102
if (!CPol)

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,19 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
788788
}
789789
}
790790

791+
if (MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::FLAT) {
792+
if (isGFX9() && !isGFX90A()) {
793+
// Pre-GFX90A GFX9's use bit 55 as NV.
794+
assert(Bytes_.size() >= 8);
795+
if (Bytes_[6] & 0x80) { // check bit 55
796+
int CPolIdx =
797+
AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::cpol);
798+
MI.getOperand(CPolIdx).setImm(MI.getOperand(CPolIdx).getImm() |
799+
AMDGPU::CPol::NV);
800+
}
801+
}
802+
}
803+
791804
if ((MCII->get(MI.getOpcode()).TSFlags &
792805
(SIInstrFlags::MTBUF | SIInstrFlags::MUBUF)) &&
793806
(STI.hasFeature(AMDGPU::FeatureGFX90AInsts))) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ void AMDGPUInstPrinter::printCPol(const MCInst *MI, unsigned OpNo,
177177
if ((Imm & CPol::SCC) && AMDGPU::isGFX90A(STI))
178178
O << (AMDGPU::isGFX940(STI) ? " sc1" : " scc");
179179
if (Imm & ~CPol::ALL_pregfx12)
180-
O << " /* unexpected cache policy bit */";
180+
if ((Imm & CPol::NV) && AMDGPU::isGFX9(STI) && !AMDGPU::isGFX90A(STI))
181+
O << " nv";
182+
else
183+
O << " /* unexpected cache policy bit */";
181184
}
182185

183186
void AMDGPUInstPrinter::printTH(const MCInst *MI, int64_t TH, int64_t Scope,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,16 @@ void AMDGPUMCCodeEmitter::encodeInstruction(const MCInst &MI,
394394
Encoding |= getImplicitOpSelHiEncoding(Opcode);
395395
}
396396

397+
// For GFX90A+ targets, bit 55 of the FLAT instructions is the ACC bit
398+
// indicating the use of AGPRs. However, pre-GFX90A, the same bit is for NV.
399+
if ((Desc.TSFlags & SIInstrFlags::FLAT) && AMDGPU::isGFX9(STI) &&
400+
!AMDGPU::isGFX90A(STI)) {
401+
int Idx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::cpol);
402+
unsigned Cpol = MI.getOperand(Idx).getImm();
403+
if (Cpol & AMDGPU::CPol::NV)
404+
Encoding |= (UINT64_C(1) << 55);
405+
}
406+
397407
// GFX10+ v_cmpx opcodes promoted to VOP3 have implied dst=EXEC.
398408
// Documentation requires dst to be encoded as EXEC (0x7E),
399409
// but it looks like the actual value encoded for dst operand

0 commit comments

Comments
 (0)