Skip to content

Commit

Permalink
[AMDGPU][MC] Corrected parsing of NAME:VALUE modifiers
Browse files Browse the repository at this point in the history
See bug 41298: https://bugs.llvm.org/show_bug.cgi?id=41298

Reviewers: artem.tamazov, arsenm

Differential Revision: https://reviews.llvm.org/D61009

llvm-svn: 361045
  • Loading branch information
dpreobra authored and MrSidims committed May 24, 2019
1 parent f14395c commit 4b3a2f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
50 changes: 17 additions & 33 deletions llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Expand Up @@ -1157,6 +1157,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool isId(const AsmToken &Token, const StringRef Id) const;
bool isToken(const AsmToken::TokenKind Kind) const;
bool trySkipId(const StringRef Id);
bool trySkipId(const StringRef Id, const AsmToken::TokenKind Kind);
bool trySkipToken(const AsmToken::TokenKind Kind);
bool skipToken(const AsmToken::TokenKind Kind, const StringRef ErrMsg);
bool parseString(StringRef &Val, const StringRef ErrMsg = "expected a string");
Expand Down Expand Up @@ -4039,54 +4040,27 @@ bool AMDGPUAsmParser::ParseInstruction(ParseInstructionInfo &Info,
//===----------------------------------------------------------------------===//

OperandMatchResultTy
AMDGPUAsmParser::parseIntWithPrefix(const char *Prefix, int64_t &Int) {
switch(getLexer().getKind()) {
default: return MatchOperand_NoMatch;
case AsmToken::Identifier: {
StringRef Name = Parser.getTok().getString();
if (!Name.equals(Prefix)) {
return MatchOperand_NoMatch;
}
AMDGPUAsmParser::parseIntWithPrefix(const char *Prefix, int64_t &IntVal) {

Parser.Lex();
if (getLexer().isNot(AsmToken::Colon))
return MatchOperand_ParseFail;

Parser.Lex();

bool IsMinus = false;
if (getLexer().getKind() == AsmToken::Minus) {
Parser.Lex();
IsMinus = true;
}

if (getLexer().isNot(AsmToken::Integer))
return MatchOperand_ParseFail;

if (getParser().parseAbsoluteExpression(Int))
return MatchOperand_ParseFail;
if (!trySkipId(Prefix, AsmToken::Colon))
return MatchOperand_NoMatch;

if (IsMinus)
Int = -Int;
break;
}
}
return MatchOperand_Success;
return parseExpr(IntVal) ? MatchOperand_Success : MatchOperand_ParseFail;
}

OperandMatchResultTy
AMDGPUAsmParser::parseIntWithPrefix(const char *Prefix, OperandVector &Operands,
AMDGPUOperand::ImmTy ImmTy,
bool (*ConvertResult)(int64_t&)) {
SMLoc S = Parser.getTok().getLoc();
SMLoc S = getLoc();
int64_t Value = 0;

OperandMatchResultTy Res = parseIntWithPrefix(Prefix, Value);
if (Res != MatchOperand_Success)
return Res;

if (ConvertResult && !ConvertResult(Value)) {
return MatchOperand_ParseFail;
Error(S, "invalid " + StringRef(Prefix) + " value.");
}

Operands.push_back(AMDGPUOperand::CreateImm(this, Value, S, ImmTy));
Expand Down Expand Up @@ -4968,6 +4942,16 @@ AMDGPUAsmParser::trySkipId(const StringRef Id) {
return false;
}

bool
AMDGPUAsmParser::trySkipId(const StringRef Id, const AsmToken::TokenKind Kind) {
if (isId(Id) && peekToken().is(Kind)) {
lex();
lex();
return true;
}
return false;
}

bool
AMDGPUAsmParser::trySkipToken(const AsmToken::TokenKind Kind) {
if (isToken(Kind)) {
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/MC/AMDGPU/expressions.s
Expand Up @@ -162,6 +162,22 @@ v_and_b32 v0, -i1+102, v0
v_add_u16 v0, (i1+100)*2, v0
// VI: v_add_u16_e32 v0, 0xca, v0 ; encoding: [0xff,0x00,0x00,0x4c,0xca,0x00,0x00,0x00]

//===----------------------------------------------------------------------===//
// Constant expressions may be used with Name:Value modifiers.
//===----------------------------------------------------------------------===//

buffer_load_dword v1, off, s[4:7], s1 offset:-1+1
// VI: buffer_load_dword v1, off, s[4:7], s1 ; encoding: [0x00,0x00,0x50,0xe0,0x00,0x01,0x01,0x01]

buffer_load_dword v1, off, s[4:7], s1 offset:i1+4
// VI: buffer_load_dword v1, off, s[4:7], s1 offset:5 ; encoding: [0x05,0x00,0x50,0xe0,0x00,0x01,0x01,0x01]

buffer_load_dword v1, off, s[4:7], s1 offset:4+i1
// VI: buffer_load_dword v1, off, s[4:7], s1 offset:5 ; encoding: [0x05,0x00,0x50,0xe0,0x00,0x01,0x01,0x01]

buffer_load_dword v1, off, s[4:7], s1 offset:-i1+4
// VI: buffer_load_dword v1, off, s[4:7], s1 offset:3 ; encoding: [0x03,0x00,0x50,0xe0,0x00,0x01,0x01,0x01]

//===----------------------------------------------------------------------===//
// Relocatable expressions can be used with 32-bit instructions.
//===----------------------------------------------------------------------===//
Expand Down
7 changes: 7 additions & 0 deletions llvm/test/MC/AMDGPU/vop3-errs.s
Expand Up @@ -46,6 +46,13 @@ v_cmp_le_f64_e64 vcc, v0, v1 mul:4
v_cvt_u32_f32_e64 v0, v1 div:2
// GCN: error: invalid operand for instruction

//
// mul
//

v_cvt_f64_i32 v[5:6], s1 mul:3
// GCN: error: invalid mul value.

//
// v_interp*
//
Expand Down

0 comments on commit 4b3a2f5

Please sign in to comment.