}
bool AMDGPUAsmParser::parseCnt(int64_t &IntVal) {
- StringRef CntName = Parser.getTok().getString();
- int64_t CntVal;
- Parser.Lex();
- if (getLexer().isNot(AsmToken::LParen))
- return true;
+ SMLoc CntLoc = getLoc();
+ StringRef CntName = getTokenStr();
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
- return true;
+ if (!skipToken(AsmToken::Identifier, "expected a counter name") ||
+ !skipToken(AsmToken::LParen, "expected a left parenthesis"))
+ return false;
- SMLoc ValLoc = Parser.getTok().getLoc();
- if (getParser().parseAbsoluteExpression(CntVal))
- return true;
+ int64_t CntVal;
+ SMLoc ValLoc = getLoc();
+ if (!parseExpr(CntVal))
+ return false;
AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(getSTI().getCPU());
Failed = encodeCnt(ISA, IntVal, CntVal, Sat, encodeExpcnt, decodeExpcnt);
} else if (CntName == "lgkmcnt" || CntName == "lgkmcnt_sat") {
Failed = encodeCnt(ISA, IntVal, CntVal, Sat, encodeLgkmcnt, decodeLgkmcnt);
+ } else {
+ Error(CntLoc, "invalid counter name " + CntName);
+ return false;
}
if (Failed) {
Error(ValLoc, "too large value for " + CntName);
- return true;
+ return false;
}
- if (getLexer().isNot(AsmToken::RParen)) {
- return true;
- }
+ if (!skipToken(AsmToken::RParen, "expected a closing parenthesis"))
+ return false;
- Parser.Lex();
- if (getLexer().is(AsmToken::Amp) || getLexer().is(AsmToken::Comma)) {
- const AsmToken NextToken = getLexer().peekTok();
- if (NextToken.is(AsmToken::Identifier)) {
- Parser.Lex();
+ if (trySkipToken(AsmToken::Amp) || trySkipToken(AsmToken::Comma)) {
+ if (isToken(AsmToken::EndOfStatement)) {
+ Error(getLoc(), "expected a counter name");
+ return false;
}
}
- return false;
+ return true;
}
OperandMatchResultTy
AMDGPUAsmParser::parseSWaitCntOps(OperandVector &Operands) {
AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(getSTI().getCPU());
int64_t Waitcnt = getWaitcntBitMask(ISA);
- SMLoc S = Parser.getTok().getLoc();
-
- switch(getLexer().getKind()) {
- default: return MatchOperand_ParseFail;
- case AsmToken::Integer:
- // The operand can be an integer value.
- if (getParser().parseAbsoluteExpression(Waitcnt))
- return MatchOperand_ParseFail;
- break;
+ SMLoc S = getLoc();
- case AsmToken::Identifier:
- do {
- if (parseCnt(Waitcnt))
- return MatchOperand_ParseFail;
- } while(getLexer().isNot(AsmToken::EndOfStatement));
- break;
+ // If parse failed, do not return error code
+ // to avoid excessive error messages.
+ if (isToken(AsmToken::Identifier) && peekToken().is(AsmToken::LParen)) {
+ while (parseCnt(Waitcnt) && !isToken(AsmToken::EndOfStatement));
+ } else {
+ parseExpr(Waitcnt);
}
+
Operands.push_back(AMDGPUOperand::CreateImm(this, Waitcnt, S));
return MatchOperand_Success;
}
// GCN: error: too large value for vmcnt
s_waitcnt vmcnt(0), expcnt(0), lgkmcnt(0),
-// GCN: error: failed parsing operand
+// GCN: error: expected a counter name
s_waitcnt vmcnt(0) & expcnt(0) & lgkmcnt(0)&
-// GCN: error: failed parsing operand
+// GCN: error: expected a counter name
+
+s_waitcnt vmcnt(0) & expcnt(0) & x
+// GCN: error: expected a left parenthesis
+
+s_waitcnt vmcnt(0) & expcnt(0) x
+// GCN: error: expected a left parenthesis
+
+s_waitcnt vmcnt(0) & expcnt(0) & 1
+// GCN: error: expected a counter name
+
+s_waitcnt vmcnt(0) & expcnt(0) 1
+// GCN: error: expected a counter name
+
+s_waitcnt vmcnt(0) & expcnt(0) x(0)
+// GCN: error: invalid counter name x
+
+s_waitcnt vmcnt(x)
+// GCN: error: expected absolute expression
+
+s_waitcnt x
+// GCN: error: expected absolute expression
+
+s_waitcnt vmcnt(0
+// GCN: error: expected a closing parenthesis
s_waitcnt lgkmcnt_sat(16)
// GCN: s_waitcnt ; encoding: [0x7f,0x0f,0x8c,0xbf]
+x=1
+s_waitcnt lgkmcnt_sat(x+1)
+// GCN: s_waitcnt lgkmcnt(2) ; encoding: [0x7f,0x02,0x8c,0xbf]
+
+s_waitcnt lgkmcnt_sat(1+x)
+// GCN: s_waitcnt lgkmcnt(2) ; encoding: [0x7f,0x02,0x8c,0xbf]
+
+s_waitcnt x+1
+// GCN: s_waitcnt vmcnt(2) expcnt(0) lgkmcnt(0) ; encoding: [0x02,0x00,0x8c,0xbf]
+
+s_waitcnt 1+x
+// GCN: s_waitcnt vmcnt(2) expcnt(0) lgkmcnt(0) ; encoding: [0x02,0x00,0x8c,0xbf]
+
+lgkmcnt_sat=1
+s_waitcnt lgkmcnt_sat
+// GCN: s_waitcnt vmcnt(1) expcnt(0) lgkmcnt(0) ; encoding: [0x01,0x00,0x8c,0xbf]
+
+s_waitcnt lgkmcnt_sat+1
+// GCN: s_waitcnt vmcnt(2) expcnt(0) lgkmcnt(0) ; encoding: [0x02,0x00,0x8c,0xbf]
+
+//===----------------------------------------------------------------------===//
+// misc sopp instructions
+//===----------------------------------------------------------------------===//
+
s_sethalt 9
// GCN: s_sethalt 9 ; encoding: [0x09,0x00,0x8d,0xbf]