diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td index abbeff78b6e28..54efe67f600a9 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -149,18 +149,40 @@ class UImmAsmOperand : ImmAsmOperand<"U", width, suffix> { } +class RISCVOp : Operand { + let OperandNamespace = "RISCVOp"; +} + +class RISCVUImmOp : RISCVOp { + let ParserMatchClass = UImmAsmOperand; + let DecoderMethod = "decodeUImmOperand<" # bitsNum # ">"; + let OperandType = "OPERAND_UIMM" # bitsNum; +} + +class RISCVUImmLeafOp : + RISCVUImmOp, ImmLeaf(Imm);">; + +class RISCVSImmOp : RISCVOp { + let ParserMatchClass = SImmAsmOperand; + let EncoderMethod = "getImmOpValue"; + let DecoderMethod = "decodeSImmOperand<" # bitsNum # ">"; + let OperandType = "OPERAND_SIMM" # bitsNum; +} + +class RISCVSImmLeafOp : + RISCVSImmOp, ImmLeaf(Imm);">; + def FenceArg : AsmOperandClass { let Name = "FenceArg"; let RenderMethod = "addFenceArgOperands"; let ParserMethod = "parseFenceArg"; } -def fencearg : Operand { +def fencearg : RISCVOp { let ParserMatchClass = FenceArg; let PrintMethod = "printFenceArg"; let DecoderMethod = "decodeUImmOperand<4>"; let OperandType = "OPERAND_UIMM4"; - let OperandNamespace = "RISCVOp"; } def UImmLog2XLenAsmOperand : AsmOperandClass { @@ -169,7 +191,7 @@ def UImmLog2XLenAsmOperand : AsmOperandClass { let DiagnosticType = "InvalidUImmLog2XLen"; } -def uimmlog2xlen : Operand, ImmLeafis64Bit()) return isUInt<6>(Imm); return isUInt<5>(Imm); @@ -186,21 +208,17 @@ def uimmlog2xlen : Operand, ImmLeaf(Imm); }]; let OperandType = "OPERAND_UIMMLOG2XLEN"; - let OperandNamespace = "RISCVOp"; } -def uimm1 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<1>; - let DecoderMethod = "decodeUImmOperand<1>"; - let OperandType = "OPERAND_UIMM1"; - let OperandNamespace = "RISCVOp"; +def InsnDirectiveOpcode : AsmOperandClass { + let Name = "InsnDirectiveOpcode"; + let ParserMethod = "parseInsnDirectiveOpcode"; + let RenderMethod = "addImmOperands"; + let PredicateMethod = "isImm"; } -def uimm2 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<2>; - let DecoderMethod = "decodeUImmOperand<2>"; - let OperandType = "OPERAND_UIMM2"; - let OperandNamespace = "RISCVOp"; +def uimm1 : RISCVUImmLeafOp<1>; +def uimm2 : RISCVUImmLeafOp<2> { let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -208,75 +226,22 @@ def uimm2 : Operand, ImmLeaf(Imm);}]> { return isUInt<2>(Imm); }]; } - -def uimm3 : Operand { - let ParserMatchClass = UImmAsmOperand<3>; - let DecoderMethod = "decodeUImmOperand<3>"; - let OperandType = "OPERAND_UIMM3"; - let OperandNamespace = "RISCVOp"; -} - -def uimm4 : Operand { - let ParserMatchClass = UImmAsmOperand<4>; - let DecoderMethod = "decodeUImmOperand<4>"; - let OperandType = "OPERAND_UIMM4"; - let OperandNamespace = "RISCVOp"; -} - -def uimm5 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<5>; - let DecoderMethod = "decodeUImmOperand<5>"; - let OperandType = "OPERAND_UIMM5"; - let OperandNamespace = "RISCVOp"; -} - -def InsnDirectiveOpcode : AsmOperandClass { - let Name = "InsnDirectiveOpcode"; - let ParserMethod = "parseInsnDirectiveOpcode"; - let RenderMethod = "addImmOperands"; - let PredicateMethod = "isImm"; -} - -def uimm6 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<6>; - let DecoderMethod = "decodeUImmOperand<6>"; - let OperandType = "OPERAND_UIMM6"; - let OperandNamespace = "RISCVOp"; -} - -def uimm7_opcode : Operand { +def uimm3 : RISCVUImmOp<3>; +def uimm4 : RISCVUImmOp<4>; +def uimm5 : RISCVUImmLeafOp<5>; +def uimm6 : RISCVUImmLeafOp<6>; +def uimm7_opcode : RISCVUImmOp<7> { let ParserMatchClass = InsnDirectiveOpcode; - let DecoderMethod = "decodeUImmOperand<7>"; - let OperandType = "OPERAND_UIMM7"; - let OperandNamespace = "RISCVOp"; } - -def uimm7 : Operand { - let ParserMatchClass = UImmAsmOperand<7>; - let DecoderMethod = "decodeUImmOperand<7>"; - let OperandType = "OPERAND_UIMM7"; - let OperandNamespace = "RISCVOp"; -} - -def uimm8 : Operand { - let ParserMatchClass = UImmAsmOperand<8>; - let DecoderMethod = "decodeUImmOperand<8>"; - let OperandType = "OPERAND_UIMM8"; - let OperandNamespace = "RISCVOp"; -} - -def simm12 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = SImmAsmOperand<12>; - let EncoderMethod = "getImmOpValue"; - let DecoderMethod = "decodeSImmOperand<12>"; +def uimm7 : RISCVUImmOp<7>; +def uimm8 : RISCVUImmOp<8>; +def simm12 : RISCVSImmLeafOp<12> { let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) return isInt<12>(Imm); return MCOp.isBareSymbolRef(); }]; - let OperandType = "OPERAND_SIMM12"; - let OperandNamespace = "RISCVOp"; } // A 12-bit signed immediate which cannot fit in 6-bit signed immediate, @@ -299,11 +264,10 @@ def simm13_lsb0 : Operand { let OperandType = "OPERAND_PCREL"; } -class UImm20Operand : Operand { +class UImm20Operand : RISCVOp { let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<20>"; let OperandType = "OPERAND_UIMM20"; - let OperandNamespace = "RISCVOp"; } class UImm20OperandMaybeSym : UImm20Operand { @@ -405,12 +369,11 @@ def CSRSystemRegister : AsmOperandClass { let DiagnosticType = "InvalidCSRSystemRegister"; } -def csr_sysreg : Operand { +def csr_sysreg : RISCVOp { let ParserMatchClass = CSRSystemRegister; let PrintMethod = "printCSRSystemRegister"; let DecoderMethod = "decodeUImmOperand<12>"; let OperandType = "OPERAND_UIMM12"; - let OperandNamespace = "RISCVOp"; } // A parameterized register class alternative to i32imm/i64imm from Target.td. diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td index 74439bb67c616..aff6e77e0cfc4 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td @@ -18,7 +18,7 @@ def UImmLog2XLenNonZeroAsmOperand : AsmOperandClass { let DiagnosticType = "InvalidUImmLog2XLenNonZero"; } -def uimmlog2xlennonzero : Operand, ImmLeafis64Bit()) return isUInt<6>(Imm) && (Imm != 0); return isUInt<5>(Imm) && (Imm != 0); @@ -27,7 +27,6 @@ def uimmlog2xlennonzero : Operand, ImmLeaf, ImmLeaf, ImmLeaf(Imm);}]> { - let ParserMatchClass = SImmAsmOperand<6>; - let EncoderMethod = "getImmOpValue"; - let DecoderMethod = "decodeSImmOperand<6>"; - let OperandType = "OPERAND_SIMM6"; - let OperandNamespace = "RISCVOp"; +def simm6 : RISCVSImmLeafOp<6> { let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) @@ -52,13 +46,12 @@ def simm6 : Operand, ImmLeaf(Imm);}]> { }]; } -def simm6nonzero : Operand, +def simm6nonzero : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = SImmAsmOperand<6, "NonZero">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeSImmNonZeroOperand<6>"; let OperandType = "OPERAND_SIMM6_NONZERO"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) @@ -67,11 +60,10 @@ def simm6nonzero : Operand, }]; } -def immzero : Operand, +def immzero : RISCVOp, ImmLeaf { let ParserMatchClass = ImmZeroAsmOperand; let OperandType = "OPERAND_ZERO"; - let OperandNamespace = "RISCVOp"; } def CLUIImmAsmOperand : AsmOperandClass { @@ -86,7 +78,7 @@ def CLUIImmAsmOperand : AsmOperandClass { // loaded in to bits 17-12 of the destination register and sign extended from // bit 17. Therefore, this 6-bit immediate can represent values in the ranges // [1, 31] and [0xfffe0, 0xfffff]. -def c_lui_imm : Operand, +def c_lui_imm : RISCVOp, ImmLeaf(Imm) || (Imm >= 0xfffe0 && Imm <= 0xfffff));}]> { @@ -94,7 +86,6 @@ def c_lui_imm : Operand, let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeCLUIImmOperand"; let OperandType = "OPERAND_CLUI_IMM"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) @@ -105,13 +96,12 @@ def c_lui_imm : Operand, } // A 7-bit unsigned immediate where the least significant two bits are zero. -def uimm7_lsb00 : Operand, +def uimm7_lsb00 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<7, "Lsb00">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<7>"; let OperandType = "OPERAND_UIMM7_LSB00"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -121,13 +111,12 @@ def uimm7_lsb00 : Operand, } // A 8-bit unsigned immediate where the least significant two bits are zero. -def uimm8_lsb00 : Operand, +def uimm8_lsb00 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<8, "Lsb00">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<8>"; let OperandType = "OPERAND_UIMM8_LSB00"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -137,13 +126,12 @@ def uimm8_lsb00 : Operand, } // A 8-bit unsigned immediate where the least significant three bits are zero. -def uimm8_lsb000 : Operand, +def uimm8_lsb000 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<8, "Lsb000">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<8>"; let OperandType = "OPERAND_UIMM8_LSB000"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -170,13 +158,12 @@ def simm9_lsb0 : Operand, } // A 9-bit unsigned immediate where the least significant three bits are zero. -def uimm9_lsb000 : Operand, +def uimm9_lsb000 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<9, "Lsb000">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<9>"; let OperandType = "OPERAND_UIMM9_LSB000"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -187,14 +174,13 @@ def uimm9_lsb000 : Operand, // A 10-bit unsigned immediate where the least significant two bits are zero // and the immediate can't be zero. -def uimm10_lsb00nonzero : Operand, +def uimm10_lsb00nonzero : RISCVOp, ImmLeaf(Imm) && (Imm != 0);}]> { let ParserMatchClass = UImmAsmOperand<10, "Lsb00NonZero">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmNonZeroOperand<10>"; let OperandType = "OPERAND_UIMM10_LSB00_NONZERO"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -204,14 +190,13 @@ def uimm10_lsb00nonzero : Operand, } // A 10-bit signed immediate where the least significant four bits are zero. -def simm10_lsb0000nonzero : Operand, +def simm10_lsb0000nonzero : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = SImmAsmOperand<10, "Lsb0000NonZero">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeSImmNonZeroOperand<10>"; let OperandType = "OPERAND_SIMM10_LSB0000_NONZERO"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -243,11 +228,10 @@ def InsnCDirectiveOpcode : AsmOperandClass { let PredicateMethod = "isImm"; } -def uimm2_opcode : Operand { +def uimm2_opcode : RISCVOp { let ParserMatchClass = InsnCDirectiveOpcode; let DecoderMethod = "decodeUImmOperand<2>"; let OperandType = "OPERAND_UIMM2"; - let OperandNamespace = "RISCVOp"; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td index 45d5255e0244b..9fc9a29c210df 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td @@ -24,12 +24,11 @@ class VTypeIAsmOperand : AsmOperandClass { let RenderMethod = "addVTypeIOperands"; } -class VTypeIOp : Operand { +class VTypeIOp : RISCVOp { let ParserMatchClass = VTypeIAsmOperand; let PrintMethod = "printVTypeI"; let DecoderMethod = "decodeUImmOperand<"#VTypeINum#">"; let OperandType = "OPERAND_VTYPEI" # VTypeINum; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) @@ -58,12 +57,7 @@ def VMaskOp : RegisterOperand { let DecoderMethod = "decodeVMaskReg"; } -def simm5 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = SImmAsmOperand<5>; - let EncoderMethod = "getImmOpValue"; - let DecoderMethod = "decodeSImmOperand<5>"; - let OperandType = "OPERAND_SIMM5"; - let OperandNamespace = "RISCVOp"; +def simm5 : RISCVSImmLeafOp<5> { let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) @@ -78,11 +72,10 @@ def SImm5Plus1AsmOperand : AsmOperandClass { let DiagnosticType = "InvalidSImm5Plus1"; } -def simm5_plus1 : Operand, ImmLeaf(Imm) && Imm != -16) || Imm == 16;}]> { let ParserMatchClass = SImm5Plus1AsmOperand; let OperandType = "OPERAND_SIMM5_PLUS1"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (MCOp.evaluateAsConstantImm(Imm)) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td index 3975b8426256a..fa6a1af6a05e9 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td @@ -29,26 +29,15 @@ def VCIX_XVW : VCIXType<0b1111>; // The payload and tsimm5 operands are all marked as ImmArg in the IR // intrinsic and will be target constant, so use TImmLeaf rather than ImmLeaf. -def payload1 : Operand, TImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<1>; - let DecoderMethod = "decodeUImmOperand<1>"; - let OperandType = "OPERAND_UIMM1"; - let OperandNamespace = "RISCVOp"; +class PayloadOp : RISCVOp, TImmLeaf(Imm);"> { + let ParserMatchClass = UImmAsmOperand; + let DecoderMethod = "decodeUImmOperand<"# bitsNum # ">"; + let OperandType = "OPERAND_UIMM" # bitsNum; } -def payload2 : Operand, TImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<2>; - let DecoderMethod = "decodeUImmOperand<2>"; - let OperandType = "OPERAND_UIMM2"; - let OperandNamespace = "RISCVOp"; -} - -def payload5 : Operand, TImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<5>; - let DecoderMethod = "decodeUImmOperand<5>"; - let OperandType = "OPERAND_UIMM5"; - let OperandNamespace = "RISCVOp"; -} +def payload1 : PayloadOp<1>; +def payload2 : PayloadOp<2>; +def payload5 : PayloadOp<5>; def tsimm5 : Operand, TImmLeaf(Imm);}]> { let ParserMatchClass = SImmAsmOperand<5>; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td index a21c3d132636b..9809010d02103 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -48,7 +48,7 @@ def UImmLog2XLenHalfAsmOperand : AsmOperandClass { let DiagnosticType = "InvalidUImmLog2XLenHalf"; } -def shfl_uimm : Operand, ImmLeafis64Bit()) return isUInt<5>(Imm); return isUInt<4>(Imm); @@ -56,7 +56,6 @@ def shfl_uimm : Operand, ImmLeaf, +def uimm2_lsb0 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<2, "Lsb0">; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<2>"; let OperandType = "OPERAND_UIMM2_LSB0"; - let OperandNamespace = "RISCVOp"; let MCOperandPredicate = [{ int64_t Imm; if (!MCOp.evaluateAsConstantImm(Imm)) @@ -32,11 +31,10 @@ def uimm2_lsb0 : Operand, }]; } -def uimm8ge32 : Operand { +def uimm8ge32 : RISCVOp { let ParserMatchClass = UImmAsmOperand<8, "GE32">; let DecoderMethod = "decodeUImmOperand<8>"; let OperandType = "OPERAND_UIMM8_GE32"; - let OperandNamespace = "RISCVOp"; } def RlistAsmOperand : AsmOperandClass { diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td index 6c0fb29bac214..537f8c0326681 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td @@ -16,7 +16,7 @@ //===----------------------------------------------------------------------===// // A 12-bit signed immediate where the least significant five bits are zero. -def simm12_lsb00000 : Operand, +def simm12_lsb00000 : RISCVOp, ImmLeaf(Imm);}]> { let ParserMatchClass = SImmAsmOperand<12, "Lsb00000">; let EncoderMethod = "getImmOpValue"; @@ -28,7 +28,6 @@ def simm12_lsb00000 : Operand, return MCOp.isBareSymbolRef(); }]; let OperandType = "OPERAND_SIMM12_LSB00000"; - let OperandNamespace = "RISCVOp"; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td index 9e98434756b20..3ec63b1b6adb3 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td @@ -36,19 +36,17 @@ def RnumArg : AsmOperandClass { let DiagnosticType = "InvalidRnumArg"; } -def rnum : Operand, TImmLeaf= 0 && Imm <= 10);}]> { +def rnum : RISCVOp, TImmLeaf= 0 && Imm <= 10);}]> { let ParserMatchClass = RnumArg; let EncoderMethod = "getImmOpValue"; let DecoderMethod = "decodeUImmOperand<4>"; let OperandType = "OPERAND_RVKRNUM"; - let OperandNamespace = "RISCVOp"; } -def byteselect : Operand, TImmLeaf(Imm);}]> { +def byteselect : RISCVOp, TImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<2>; let DecoderMethod = "decodeUImmOperand<2>"; let OperandType = "OPERAND_UIMM2"; - let OperandNamespace = "RISCVOp"; } //===----------------------------------------------------------------------===//