Skip to content

Commit 70498da

Browse files
committed
[RISCV][NFC] DiagnosticString TableGen Crimes
I should be more sorry about this than I really am.
1 parent 9998ba6 commit 70498da

File tree

3 files changed

+20
-47
lines changed

3 files changed

+20
-47
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,45 +1532,15 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15321532
if (isRV64())
15331533
return generateImmOutOfRangeError(Operands, ErrorInfo, 1, (1 << 6) - 1);
15341534
return generateImmOutOfRangeError(Operands, ErrorInfo, 1, (1 << 5) - 1);
1535-
case Match_InvalidUImm1:
1536-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 1) - 1);
1537-
case Match_InvalidUImm2:
1538-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 2) - 1);
15391535
case Match_InvalidUImm2Lsb0:
15401536
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 2,
15411537
"immediate must be one of");
1542-
case Match_InvalidUImm3:
1543-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 3) - 1);
1544-
case Match_InvalidUImm4:
1545-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 4) - 1);
1546-
case Match_InvalidUImm5:
1547-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1);
15481538
case Match_InvalidUImm5NonZero:
15491539
return generateImmOutOfRangeError(Operands, ErrorInfo, 1, (1 << 5) - 1);
15501540
case Match_InvalidUImm5GT3:
15511541
return generateImmOutOfRangeError(Operands, ErrorInfo, 4, (1 << 5) - 1);
1552-
case Match_InvalidUImm6:
1553-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 6) - 1);
1554-
case Match_InvalidUImm7:
1555-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 7) - 1);
1556-
case Match_InvalidUImm8:
1557-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 8) - 1);
15581542
case Match_InvalidUImm8GE32:
15591543
return generateImmOutOfRangeError(Operands, ErrorInfo, 32, (1 << 8) - 1);
1560-
case Match_InvalidSImm5:
1561-
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 4),
1562-
(1 << 4) - 1);
1563-
case Match_InvalidSImm6:
1564-
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 5),
1565-
(1 << 5) - 1);
1566-
case Match_InvalidSImm6NonZero:
1567-
return generateImmOutOfRangeError(
1568-
Operands, ErrorInfo, -(1 << 5), (1 << 5) - 1,
1569-
"immediate must be non-zero in the range");
1570-
case Match_InvalidCLUIImm:
1571-
return generateImmOutOfRangeError(
1572-
Operands, ErrorInfo, 1, (1 << 5) - 1,
1573-
"immediate must be in [0xfffe0, 0xfffff] or");
15741544
case Match_InvalidUImm5Lsb0:
15751545
return generateImmOutOfRangeError(
15761546
Operands, ErrorInfo, 0, (1 << 5) - 2,
@@ -1607,10 +1577,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16071577
return generateImmOutOfRangeError(
16081578
Operands, ErrorInfo, -(1 << 9), (1 << 9) - 16,
16091579
"immediate must be a multiple of 16 bytes and non-zero in the range");
1610-
case Match_InvalidUImm10:
1611-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 10) - 1);
1612-
case Match_InvalidUImm11:
1613-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 11) - 1);
16141580
case Match_InvalidSImm12:
16151581
return generateImmOutOfRangeError(
16161582
Operands, ErrorInfo, -(1 << 11), (1 << 11) - 1,
@@ -1633,8 +1599,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16331599
"operand must be a symbol with "
16341600
"%hi/%tprel_hi modifier or an integer in "
16351601
"the range");
1636-
case Match_InvalidUImm20:
1637-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 20) - 1);
16381602
case Match_InvalidUImm20AUIPC:
16391603
return generateImmOutOfRangeError(
16401604
Operands, ErrorInfo, 0, (1 << 20) - 1,
@@ -1645,11 +1609,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16451609
return generateImmOutOfRangeError(
16461610
Operands, ErrorInfo, -(1 << 20), (1 << 20) - 2,
16471611
"immediate must be a multiple of 2 bytes in the range");
1648-
case Match_InvalidCSRSystemRegister: {
1649-
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 12) - 1,
1650-
"operand must be a valid system register "
1651-
"name or an integer in the range");
1652-
}
16531612
case Match_InvalidVTypeI: {
16541613
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
16551614
return generateVTypeError(ErrorLoc);
@@ -1659,9 +1618,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16591618
(1 << 4),
16601619
"immediate must be in the range");
16611620
}
1662-
case Match_InvalidSImm26:
1663-
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 25),
1664-
(1 << 25) - 1);
16651621
case Match_InvalidRnumArg: {
16661622
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 10);
16671623
}

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,26 @@ def SPMem : MemOperand<SP>;
151151

152152
def GPRCMem : MemOperand<GPRC>;
153153

154-
class SImmAsmOperand<int width, string suffix = "">
154+
class RISCVRangedImmDiagnosticString<int lo, int hi, string prefix = "immediate must be an integer in the range"> {
155+
string Message = prefix # " [" # lo # ", " # hi # "]";
156+
}
157+
158+
class RISCVSImmDiagnosticString<int bitsNum, string prefix = "immediate must be an integer in the range"> :
159+
RISCVRangedImmDiagnosticString<!sub(0, !shl(1, !sub(bitsNum, 1))), !sub(!shl(1, !sub(bitsNum, 1)), 1), prefix> {
160+
}
161+
162+
class RISCVUImmDiagnosticString<int bitsNum, string prefix = "immediate must be an integer in the range"> :
163+
RISCVRangedImmDiagnosticString<0, !sub(!shl(1, bitsNum), 1), prefix> {
164+
}
165+
166+
class SImmAsmOperand<int width, string suffix = "", string messagePrefix = "immediate must be an integer in the range">
155167
: ImmAsmOperand<"S", width, suffix> {
168+
let DiagnosticString = RISCVSImmDiagnosticString<width, messagePrefix>.Message;
156169
}
157170

158-
class UImmAsmOperand<int width, string suffix = "">
171+
class UImmAsmOperand<int width, string suffix = "", string messagePrefix = "immediate must be an integer in the range">
159172
: ImmAsmOperand<"U", width, suffix> {
173+
let DiagnosticString = RISCVUImmDiagnosticString<width, messagePrefix>.Message;
160174
}
161175

162176
class RISCVOp<ValueType vt = XLenVT> : Operand<vt> {
@@ -376,6 +390,8 @@ def CSRSystemRegister : AsmOperandClass {
376390
let Name = "CSRSystemRegister";
377391
let ParserMethod = "parseCSRSystemRegister";
378392
let DiagnosticType = "InvalidCSRSystemRegister";
393+
let DiagnosticString = RISCVUImmDiagnosticString<12, "operand must be a valid system register "
394+
"name or an integer in the range">.Message;
379395
}
380396

381397
def csr_sysreg : RISCVOp, TImmLeaf<XLenVT, "return isUInt<12>(Imm);"> {

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def simm6 : RISCVSImmLeafOp<6> {
4747

4848
def simm6nonzero : RISCVOp,
4949
ImmLeaf<XLenVT, [{return (Imm != 0) && isInt<6>(Imm);}]> {
50-
let ParserMatchClass = SImmAsmOperand<6, "NonZero">;
50+
let ParserMatchClass = SImmAsmOperand<6, "NonZero", "immediate must be non-zero in the range">;
5151
let EncoderMethod = "getImmOpValue";
5252
let DecoderMethod = "decodeSImmNonZeroOperand<6>";
5353
let OperandType = "OPERAND_SIMM6_NONZERO";
@@ -69,6 +69,7 @@ def CLUIImmAsmOperand : AsmOperandClass {
6969
let Name = "CLUIImm";
7070
let RenderMethod = "addImmOperands";
7171
let DiagnosticType = !strconcat("Invalid", Name);
72+
let DiagnosticString = "immediate must be in [0xfffe0, 0xfffff] or [1, 31]";
7273
}
7374

7475

0 commit comments

Comments
 (0)