Index: llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -1438,7 +1438,7 @@ void peekTokens(MutableArrayRef Tokens); AsmToken::TokenKind getTokenKind() const; - bool parseExpr(int64_t &Imm); + bool parseExpr(int64_t &Imm, StringRef Expected = ""); bool parseExpr(OperandVector &Operands); StringRef getTokenStr() const; AsmToken peekToken(); @@ -5673,8 +5673,8 @@ if (isToken(AsmToken::Identifier) && (HwReg.Id = getHwregId(getTokenStr())) >= 0) { HwReg.IsSymbolic = true; - lex(); // skip message name - } else if (!parseExpr(HwReg.Id)) { + lex(); // skip register name + } else if (!parseExpr(HwReg.Id, "a register name")) { return false; } @@ -5743,7 +5743,7 @@ } else { return MatchOperand_ParseFail; } - } else if (parseExpr(ImmVal)) { + } else if (parseExpr(ImmVal, "an hwreg macro")) { if (ImmVal < 0 || !isUInt<16>(ImmVal)) { Error(Loc, "invalid immediate: only 16-bit values are legal"); return MatchOperand_ParseFail; @@ -5774,7 +5774,7 @@ if (isToken(AsmToken::Identifier) && (Msg.Id = getMsgId(getTokenStr())) >= 0) { Msg.IsSymbolic = true; lex(); // skip message name - } else if (!parseExpr(Msg.Id)) { + } else if (!parseExpr(Msg.Id, "a message name")) { return false; } @@ -5784,7 +5784,7 @@ if (isToken(AsmToken::Identifier) && (Op.Id = getMsgOpId(Msg.Id, getTokenStr())) >= 0) { lex(); // skip operation name - } else if (!parseExpr(Op.Id)) { + } else if (!parseExpr(Op.Id, "an operation name")) { return false; } @@ -5854,7 +5854,7 @@ } else { return MatchOperand_ParseFail; } - } else if (parseExpr(ImmVal)) { + } else if (parseExpr(ImmVal, "a sendmsg macro")) { if (ImmVal < 0 || !isUInt<16>(ImmVal)) { Error(Loc, "invalid immediate: only 16-bit values are legal"); return MatchOperand_ParseFail; @@ -6072,8 +6072,23 @@ } bool -AMDGPUAsmParser::parseExpr(int64_t &Imm) { - return !getParser().parseAbsoluteExpression(Imm); +AMDGPUAsmParser::parseExpr(int64_t &Imm, StringRef Expected) { + SMLoc S = getLoc(); + + const MCExpr *Expr; + if (Parser.parseExpression(Expr)) + return false; + + if (Expr->evaluateAsAbsolute(Imm)) + return true; + + if (Expected.empty()) { + Error(S, "expected absolute expression"); + } else { + Error(S, Twine("expected ", Expected) + + Twine(" or an absolute expression")); + } + return false; } bool @@ -6390,7 +6405,7 @@ SMLoc OffsetLoc = Parser.getTok().getLoc(); - if (!parseExpr(Imm)) { + if (!parseExpr(Imm, "a swizzle macro")) { return false; } if (!isUInt<16>(Imm)) { Index: llvm/test/MC/AMDGPU/ds-err.s =================================================================== --- llvm/test/MC/AMDGPU/ds-err.s +++ llvm/test/MC/AMDGPU/ds-err.s @@ -46,7 +46,7 @@ // CHECK: error: expected a colon ds_swizzle_b32 v8, v2 offset- -// CHECK: error: expected absolute expression +// CHECK: error: expected a swizzle macro or an absolute expression ds_swizzle_b32 v8, v2 offset:SWIZZLE(QUAD_PERM, 0, 1, 2, 3) // CHECK: error: expected a swizzle mode Index: llvm/test/MC/AMDGPU/gfx10_err_pos.s =================================================================== --- llvm/test/MC/AMDGPU/gfx10_err_pos.s +++ llvm/test/MC/AMDGPU/gfx10_err_pos.s @@ -331,26 +331,6 @@ //============================================================================== // expected absolute expression -ds_swizzle_b32 v8, v2 offset:SWIZZLE(QUAD_PERM, 0, 1, 2, 3) -// CHECK: error: expected absolute expression -// CHECK-NEXT:{{^}}ds_swizzle_b32 v8, v2 offset:SWIZZLE(QUAD_PERM, 0, 1, 2, 3) -// CHECK-NEXT:{{^}} ^ - -s_sendmsg sendmsg(MSG_GS, GS_OP_CUTX, 0) -// CHECK: error: expected absolute expression -// CHECK-NEXT:{{^}}s_sendmsg sendmsg(MSG_GS, GS_OP_CUTX, 0) -// CHECK-NEXT:{{^}} ^ - -s_sendmsg sendmsg(MSG_GSX, GS_OP_CUT, 0) -// CHECK: error: expected absolute expression -// CHECK-NEXT:{{^}}s_sendmsg sendmsg(MSG_GSX, GS_OP_CUT, 0) -// CHECK-NEXT:{{^}} ^ - -s_setreg_b32 hwreg(HW_REG_WRONG), s2 -// CHECK: error: expected absolute expression -// CHECK-NEXT:{{^}}s_setreg_b32 hwreg(HW_REG_WRONG), s2 -// CHECK-NEXT:{{^}} ^ - s_waitcnt vmcnt(x) // CHECK: error: expected absolute expression // CHECK-NEXT:{{^}}s_waitcnt vmcnt(x) @@ -371,6 +351,38 @@ // CHECK-NEXT:{{^}}tbuffer_store_format_xyzw v[1:4], off, ttmp[4:7], s0 format:BUF_NUM_FORMAT_UINT] // CHECK-NEXT:{{^}} ^ +//============================================================================== +// expected a message name or an absolute expression + +s_sendmsg sendmsg(MSG_GSX, GS_OP_CUT, 0) +// CHECK: error: expected a message name or an absolute expression +// CHECK-NEXT:{{^}}s_sendmsg sendmsg(MSG_GSX, GS_OP_CUT, 0) +// CHECK-NEXT:{{^}} ^ + +//============================================================================== +// expected a register name or an absolute expression + +s_setreg_b32 hwreg(HW_REG_WRONG), s2 +// CHECK: error: expected a register name or an absolute expression +// CHECK-NEXT:{{^}}s_setreg_b32 hwreg(HW_REG_WRONG), s2 +// CHECK-NEXT:{{^}} ^ + +//============================================================================== +// expected a sendmsg macro or an absolute expression + +s_sendmsg undef +// CHECK: error: expected a sendmsg macro or an absolute expression +// CHECK-NEXT:{{^}}s_sendmsg undef +// CHECK-NEXT:{{^}} ^ + +//============================================================================== +// expected a swizzle macro or an absolute expression + +ds_swizzle_b32 v8, v2 offset:SWZ(QUAD_PERM, 0, 1, 2, 3) +// CHECK: error: expected a swizzle macro or an absolute expression +// CHECK-NEXT:{{^}}ds_swizzle_b32 v8, v2 offset:SWZ(QUAD_PERM, 0, 1, 2, 3) +// CHECK-NEXT:{{^}} ^ + //============================================================================== // expected an 11-bit unsigned offset @@ -402,6 +414,22 @@ // CHECK-NEXT:{{^}}v_mov_b32_sdwa v1, sext(u) // CHECK-NEXT:{{^}} ^ +//============================================================================== +// expected an hwreg macro or an absolute expression + +s_setreg_b32 undef, s2 +// CHECK: error: expected an hwreg macro or an absolute expression +// CHECK-NEXT:{{^}}s_setreg_b32 undef, s2 +// CHECK-NEXT:{{^}} ^ + +//============================================================================== +// expected an operation name or an absolute expression + +s_sendmsg sendmsg(MSG_GS, GS_OP_CUTX, 0) +// CHECK: error: expected an operation name or an absolute expression +// CHECK-NEXT:{{^}}s_sendmsg sendmsg(MSG_GS, GS_OP_CUTX, 0) +// CHECK-NEXT:{{^}} ^ + //============================================================================== // failed parsing operand. Index: llvm/test/MC/AMDGPU/sopk-err.s =================================================================== --- llvm/test/MC/AMDGPU/sopk-err.s +++ llvm/test/MC/AMDGPU/sopk-err.s @@ -14,13 +14,13 @@ // GCN: error: invalid immediate: only 16-bit values are legal s_setreg_b32 typo(0x40), s2 -// GCN: error: expected absolute expression +// GCN: error: expected an hwreg macro or an absolute expression s_setreg_b32 hwreg(0x40), s2 // GCN: error: invalid code of hardware register: only 6-bit values are legal s_setreg_b32 hwreg(HW_REG_WRONG), s2 -// GCN: error: expected absolute expression +// GCN: error: expected a register name or an absolute expression s_setreg_b32 hwreg(1 2,3), s2 // GCN: error: expected a comma or a closing parenthesis Index: llvm/test/MC/AMDGPU/sopp-err.s =================================================================== --- llvm/test/MC/AMDGPU/sopp-err.s +++ llvm/test/MC/AMDGPU/sopp-err.s @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// s_sendmsg sendmsg(MSG_INTERRUPTX) -// GCN: error: expected absolute expression +// GCN: error: expected a message name or an absolute expression s_sendmsg sendmsg(1 -) // GCN: error: unknown token in expression @@ -26,7 +26,7 @@ // GCN: error: invalid operation id s_sendmsg sendmsg(MSG_GS, SYSMSG_OP_ECC_ERR_INTERRUPT) -// GCN: error: expected absolute expression +// GCN: error: expected an operation name or an absolute expression s_sendmsg sendmsg(MSG_GS, 0) // GCN: error: invalid operation id @@ -50,10 +50,10 @@ // GCN: error: expected a closing parenthesis s_sendmsg sendmsg(MSG_GSX, GS_OP_CUT, 0) -// GCN: error: expected absolute expression +// GCN: error: expected a message name or an absolute expression s_sendmsg sendmsg(MSG_GS, GS_OP_CUTX, 0) -// GCN: error: expected absolute expression +// GCN: error: expected an operation name or an absolute expression s_sendmsg sendmsg(MSG_GS, 1 -) // GCN: error: unknown token in expression