Skip to content

Commit 0a6dc9a

Browse files
committed
[AMDGPU][AsmParser] Refine parsing cache policy modifiers.
Reviewed By: dp, arsenm Differential Revision: https://reviews.llvm.org/D140108
1 parent 35c7e45 commit 0a6dc9a

File tree

2 files changed

+54
-62
lines changed

2 files changed

+54
-62
lines changed

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

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,6 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
12531253
bool ForcedDPP = false;
12541254
bool ForcedSDWA = false;
12551255
KernelScopeInfo KernelScope;
1256-
unsigned CPolSeen;
12571256

12581257
/// @name Auto-generated Match Functions
12591258
/// {
@@ -1554,6 +1553,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
15541553
OperandMatchResultTy
15551554
parseNamedBit(StringRef Name, OperandVector &Operands,
15561555
AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
1556+
unsigned getCPolKind(StringRef Id, StringRef Mnemo, bool &Disabling) const;
15571557
OperandMatchResultTy parseCPol(OperandVector &Operands);
15581558
OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
15591559
StringRef &Value,
@@ -1684,6 +1684,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
16841684
bool isId(const StringRef Id) const;
16851685
bool isId(const AsmToken &Token, const StringRef Id) const;
16861686
bool isToken(const AsmToken::TokenKind Kind) const;
1687+
StringRef getId() const;
16871688
bool trySkipId(const StringRef Id);
16881689
bool trySkipId(const StringRef Pref, const StringRef Id);
16891690
bool trySkipId(const StringRef Id, const AsmToken::TokenKind Kind);
@@ -5868,7 +5869,6 @@ bool AMDGPUAsmParser::ParseInstruction(ParseInstructionInfo &Info,
58685869
OperandMode Mode = OperandMode_Default;
58695870
if (IsMIMG && isGFX10Plus() && Operands.size() == 2)
58705871
Mode = OperandMode_NSA;
5871-
CPolSeen = 0;
58725872
OperandMatchResultTy Res = parseOperand(Operands, Name, Mode);
58735873

58745874
if (Res != MatchOperand_Success) {
@@ -6011,86 +6011,74 @@ AMDGPUAsmParser::parseNamedBit(StringRef Name, OperandVector &Operands,
60116011
return MatchOperand_Success;
60126012
}
60136013

6014+
unsigned AMDGPUAsmParser::getCPolKind(StringRef Id, StringRef Mnemo,
6015+
bool &Disabling) const {
6016+
Disabling = Id.startswith("no");
6017+
6018+
if (isGFX940() && !Mnemo.startswith("s_")) {
6019+
return StringSwitch<unsigned>(Id)
6020+
.Case("nt", AMDGPU::CPol::NT)
6021+
.Case("nont", AMDGPU::CPol::NT)
6022+
.Case("sc0", AMDGPU::CPol::SC0)
6023+
.Case("nosc0", AMDGPU::CPol::SC0)
6024+
.Case("sc1", AMDGPU::CPol::SC1)
6025+
.Case("nosc1", AMDGPU::CPol::SC1)
6026+
.Default(0);
6027+
}
6028+
6029+
return StringSwitch<unsigned>(Id)
6030+
.Case("dlc", AMDGPU::CPol::DLC)
6031+
.Case("nodlc", AMDGPU::CPol::DLC)
6032+
.Case("glc", AMDGPU::CPol::GLC)
6033+
.Case("noglc", AMDGPU::CPol::GLC)
6034+
.Case("scc", AMDGPU::CPol::SCC)
6035+
.Case("noscc", AMDGPU::CPol::SCC)
6036+
.Case("slc", AMDGPU::CPol::SLC)
6037+
.Case("noslc", AMDGPU::CPol::SLC)
6038+
.Default(0);
6039+
}
6040+
60146041
OperandMatchResultTy
60156042
AMDGPUAsmParser::parseCPol(OperandVector &Operands) {
6016-
OperandMatchResultTy Res = MatchOperand_NoMatch;
6017-
6043+
StringRef Mnemo = ((AMDGPUOperand &)*Operands[0]).getToken();
6044+
SMLoc OpLoc = getLoc();
6045+
unsigned Enabled = 0, Seen = 0;
60186046
for (;;) {
6019-
unsigned CPolOn = 0;
6020-
unsigned CPolOff = 0;
60216047
SMLoc S = getLoc();
6022-
6023-
StringRef Mnemo = ((AMDGPUOperand &)*Operands[0]).getToken();
6024-
if (isGFX940() && !Mnemo.startswith("s_")) {
6025-
if (trySkipId("sc0"))
6026-
CPolOn = AMDGPU::CPol::SC0;
6027-
else if (trySkipId("nosc0"))
6028-
CPolOff = AMDGPU::CPol::SC0;
6029-
else if (trySkipId("nt"))
6030-
CPolOn = AMDGPU::CPol::NT;
6031-
else if (trySkipId("nont"))
6032-
CPolOff = AMDGPU::CPol::NT;
6033-
else if (trySkipId("sc1"))
6034-
CPolOn = AMDGPU::CPol::SC1;
6035-
else if (trySkipId("nosc1"))
6036-
CPolOff = AMDGPU::CPol::SC1;
6037-
else
6038-
break;
6039-
} else if (trySkipId("glc"))
6040-
CPolOn = AMDGPU::CPol::GLC;
6041-
else if (trySkipId("noglc"))
6042-
CPolOff = AMDGPU::CPol::GLC;
6043-
else if (trySkipId("slc"))
6044-
CPolOn = AMDGPU::CPol::SLC;
6045-
else if (trySkipId("noslc"))
6046-
CPolOff = AMDGPU::CPol::SLC;
6047-
else if (trySkipId("dlc"))
6048-
CPolOn = AMDGPU::CPol::DLC;
6049-
else if (trySkipId("nodlc"))
6050-
CPolOff = AMDGPU::CPol::DLC;
6051-
else if (trySkipId("scc"))
6052-
CPolOn = AMDGPU::CPol::SCC;
6053-
else if (trySkipId("noscc"))
6054-
CPolOff = AMDGPU::CPol::SCC;
6055-
else
6048+
bool Disabling;
6049+
unsigned CPol = getCPolKind(getId(), Mnemo, Disabling);
6050+
if (!CPol)
60566051
break;
60576052

6058-
if (!isGFX10Plus() && ((CPolOn | CPolOff) & AMDGPU::CPol::DLC)) {
6053+
lex();
6054+
6055+
if (!isGFX10Plus() && CPol == AMDGPU::CPol::DLC) {
60596056
Error(S, "dlc modifier is not supported on this GPU");
60606057
return MatchOperand_ParseFail;
60616058
}
60626059

6063-
if (!isGFX90A() && ((CPolOn | CPolOff) & AMDGPU::CPol::SCC)) {
6060+
if (!isGFX90A() && CPol == AMDGPU::CPol::SCC) {
60646061
Error(S, "scc modifier is not supported on this GPU");
60656062
return MatchOperand_ParseFail;
60666063
}
60676064

6068-
if (CPolSeen & (CPolOn | CPolOff)) {
6065+
if (Seen & CPol) {
60696066
Error(S, "duplicate cache policy modifier");
60706067
return MatchOperand_ParseFail;
60716068
}
60726069

6073-
CPolSeen |= (CPolOn | CPolOff);
6074-
Res = MatchOperand_Success;
6070+
if (!Disabling)
6071+
Enabled |= CPol;
60756072

6076-
AMDGPUOperand *CPolOp = nullptr;
6077-
for (unsigned I = 1; I != Operands.size(); ++I) {
6078-
AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6079-
if (Op.isCPol()) {
6080-
CPolOp = &Op;
6081-
break;
6082-
}
6083-
}
6084-
6085-
if (CPolOp) {
6086-
CPolOp->setImm((CPolOp->getImm() | CPolOn) & ~CPolOff);
6087-
} else {
6088-
Operands.push_back(
6089-
AMDGPUOperand::CreateImm(this, CPolOn, S, AMDGPUOperand::ImmTyCPol));
6090-
}
6073+
Seen |= CPol;
60916074
}
60926075

6093-
return Res;
6076+
if (!Seen)
6077+
return MatchOperand_NoMatch;
6078+
6079+
Operands.push_back(
6080+
AMDGPUOperand::CreateImm(this, Enabled, OpLoc, AMDGPUOperand::ImmTyCPol));
6081+
return MatchOperand_Success;
60946082
}
60956083

60966084
static void addOptionalImmOperand(
@@ -7120,6 +7108,10 @@ AMDGPUAsmParser::isToken(const AsmToken::TokenKind Kind) const {
71207108
return getTokenKind() == Kind;
71217109
}
71227110

7111+
StringRef AMDGPUAsmParser::getId() const {
7112+
return isToken(AsmToken::Identifier) ? getTokenStr() : StringRef();
7113+
}
7114+
71237115
bool
71247116
AMDGPUAsmParser::trySkipId(const StringRef Id) {
71257117
if (isId(Id)) {

llvm/test/MC/AMDGPU/mubuf-gfx10.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
buffer_load_sbyte off, s[8:11], s3 glc slc lds
44
// GFX10: buffer_load_sbyte off, s[8:11], s3 glc slc lds ; encoding: [0x00,0x40,0x25,0xe0,0x00,0x00,0x42,0x03]
55

6-
buffer_load_sbyte off, s[8:11], s3 glc slc lds dlc
6+
buffer_load_sbyte off, s[8:11], s3 glc slc dlc lds
77
// GFX10: buffer_load_sbyte off, s[8:11], s3 glc slc dlc lds ; encoding: [0x00,0xc0,0x25,0xe0,0x00,0x00,0x42,0x03]
88

99
buffer_load_sbyte v5, off, s[8:11], s3 glc slc dlc

0 commit comments

Comments
 (0)