diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index c51c4201ebd18..db73b38f0ef88 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -280,7 +280,7 @@ class RISCVAsmParser : public MCTargetAsmParser { std::unique_ptr defaultFRMArgLegacyOp() const; public: - enum RISCVMatchResultTy { + enum RISCVMatchResultTy : unsigned { Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY, #define GET_OPERAND_DIAGNOSTIC_TYPES #include "RISCVGenAsmMatcher.inc" @@ -1524,10 +1524,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, std::numeric_limits::max(), "operand either must be a bare symbol name or an immediate integer in " "the range"); - case Match_InvalidImmZero: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "immediate must be zero"); - } case Match_InvalidUImmLog2XLen: if (isRV64()) return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 6) - 1); @@ -1654,47 +1650,10 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, "operand must be a valid system register " "name or an integer in the range"); } - case Match_InvalidLoadFPImm: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be a valid floating-point constant"); - } - case Match_InvalidBareSymbol: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be a bare symbol name"); - } - case Match_InvalidPseudoJumpSymbol: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be a valid jump target"); - } - case Match_InvalidCallSymbol: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be a bare symbol name"); - } - case Match_InvalidTPRelAddSymbol: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be a symbol with %tprel_add modifier"); - } - case Match_InvalidTLSDESCCallSymbol: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, - "operand must be a symbol with %tlsdesc_call modifier"); - } - case Match_InvalidRTZArg: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be 'rtz' floating-point rounding mode"); - } case Match_InvalidVTypeI: { SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); return generateVTypeError(ErrorLoc); } - case Match_InvalidVMaskRegister: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be v0.t"); - } - case Match_InvalidVMaskCarryInRegister: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operand must be v0"); - } case Match_InvalidSImm5Plus1: { return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 4) + 1, (1 << 4), @@ -1703,26 +1662,14 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, case Match_InvalidSImm26: return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 25), (1 << 25) - 1); - case Match_InvalidRlist: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error( - ErrorLoc, - "operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}"); - } - case Match_InvalidStackAdj: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error( - ErrorLoc, - "stack adjustment is invalid for this instruction and register list; " - "refer to Zc spec for a detailed range of stack adjustment"); - } case Match_InvalidRnumArg: { return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 10); } - case Match_InvalidRegReg: { - SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); - return Error(ErrorLoc, "operands must be register and register"); } + + if (const char *MatchDiag = getMatchKindDiag((RISCVMatchResultTy)Result)) { + SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); + return Error(ErrorLoc, MatchDiag); } llvm_unreachable("Unknown match type detected!"); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td index 54fee1ac3130e..fde7dc89dd693 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -125,6 +125,7 @@ def ImmZeroAsmOperand : AsmOperandClass { let Name = "ImmZero"; let RenderMethod = "addImmOperands"; let DiagnosticType = !strconcat("Invalid", Name); + let DiagnosticString = "immediate must be zero"; } // A parse method for (${gpr}) or 0(${gpr}), where the 0 is be silently ignored. @@ -323,6 +324,7 @@ def BareSymbol : AsmOperandClass { let Name = "BareSymbol"; let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidBareSymbol"; + let DiagnosticString = "operand must be a bare symbol name"; let ParserMethod = "parseBareSymbol"; } @@ -335,6 +337,7 @@ def CallSymbol : AsmOperandClass { let Name = "CallSymbol"; let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidCallSymbol"; + let DiagnosticString = "operand must be a bare symbol name"; let ParserMethod = "parseCallSymbol"; } @@ -347,6 +350,7 @@ def PseudoJumpSymbol : AsmOperandClass { let Name = "PseudoJumpSymbol"; let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidPseudoJumpSymbol"; + let DiagnosticString = "operand must be a valid jump target"; let ParserMethod = "parsePseudoJumpSymbol"; } @@ -359,6 +363,7 @@ def TPRelAddSymbol : AsmOperandClass { let Name = "TPRelAddSymbol"; let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidTPRelAddSymbol"; + let DiagnosticString = "operand must be a symbol with %tprel_add modifier"; let ParserMethod = "parseOperandWithModifier"; } @@ -1779,6 +1784,7 @@ def TLSDESCCallSymbol : AsmOperandClass { let Name = "TLSDESCCallSymbol"; let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidTLSDESCCallSymbol"; + let DiagnosticString = "operand must be a symbol with %tlsdesc_call modifier"; let ParserMethod = "parseOperandWithModifier"; } diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td index 671e493fb3763..fdb2334b131da 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td @@ -48,6 +48,7 @@ def VMaskAsmOperand : AsmOperandClass { let IsOptional = 1; let DefaultMethod = "defaultMaskRegOp"; let DiagnosticType = "InvalidVMaskRegister"; + let DiagnosticString = "operand must be v0.t"; } def VMaskCarryInAsmOperand : AsmOperandClass { @@ -55,6 +56,7 @@ def VMaskCarryInAsmOperand : AsmOperandClass { let RenderMethod = "addRegOperands"; let PredicateMethod = "isV0Reg"; let DiagnosticType = "InvalidVMaskCarryInRegister"; + let DiagnosticString = "operand must be v0"; } def VMaskOp : RegisterOperand { diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td index b98934d8c6396..bade4863ad348 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td @@ -514,6 +514,7 @@ def CVrrAsmOperand : AsmOperandClass { let Name = "RegReg"; let ParserMethod = "parseRegReg"; let DiagnosticType = "InvalidRegReg"; + let DiagnosticString = "operands must be register and register"; } def CVrr : Operand, diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td index 5cc16765d4ae2..9dfbcf678d6eb 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td @@ -39,12 +39,15 @@ def RlistAsmOperand : AsmOperandClass { let Name = "Rlist"; let ParserMethod = "parseReglist"; let DiagnosticType = "InvalidRlist"; + let DiagnosticString = "operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}"; } def StackAdjAsmOperand : AsmOperandClass { let Name = "StackAdj"; let ParserMethod = "parseZcmpStackAdj"; let DiagnosticType = "InvalidStackAdj"; + let DiagnosticString = "stack adjustment is invalid for this instruction and register list; " + "refer to Zc spec for a detailed range of stack adjustment"; let PredicateMethod = "isSpimm"; let RenderMethod = "addSpimmOperands"; } diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td index ab54b45f4de93..a539ca82b7462 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td @@ -30,6 +30,7 @@ def LoadFPImmOperand : AsmOperandClass { let ParserMethod = "parseFPImm"; let RenderMethod = "addFPImmOperands"; let DiagnosticType = "InvalidLoadFPImm"; + let DiagnosticString = "operand must be a valid floating-point constant"; } def loadfpimm : Operand { @@ -43,6 +44,7 @@ def RTZArg : AsmOperandClass { let Name = "RTZArg"; let RenderMethod = "addFRMArgOperands"; let DiagnosticType = "InvalidRTZArg"; + let DiagnosticString = "operand must be 'rtz' floating-point rounding mode"; let ParserMethod = "parseFRMArg"; }