diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -189,11 +189,13 @@ let OperandNamespace = "RISCVOp"; } -def uimm1 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<1>; - let DecoderMethod = "decodeUImmOperand<1>"; - let OperandType = "OPERAND_UIMM1"; - let OperandNamespace = "RISCVOp"; +foreach i = [1, 5] in { + def uimm # i : Operand, ImmLeaf(Imm);}], i)> { + let ParserMatchClass = UImmAsmOperand; + let DecoderMethod = !format("decodeUImmOperand<{0}>", i); + let OperandType = "OPERAND_UIMM" # i; + let OperandNamespace = "RISCVOp"; + } } def uimm2 : Operand, ImmLeaf(Imm);}]> { @@ -209,26 +211,6 @@ }]; } -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"; @@ -237,11 +219,13 @@ let PredicateMethod = "isImm"; } -def uimm6 : Operand { - let ParserMatchClass = UImmAsmOperand<6>; - let DecoderMethod = "decodeUImmOperand<6>"; - let OperandType = "OPERAND_UIMM6"; - let OperandNamespace = "RISCVOp"; +foreach i = [3, 4, 6, 7, 8] in { + def uimm # i : Operand { + let ParserMatchClass = UImmAsmOperand; + let DecoderMethod = !format("decodeUImmOperand<{0}>", i); + let OperandType = "OPERAND_UIMM" # i; + let OperandNamespace = "RISCVOp"; + } } def uimm7_opcode : Operand { @@ -251,20 +235,6 @@ 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"; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td @@ -29,25 +29,13 @@ // The payload and timm5 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"; -} - -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"; +foreach i = [1, 2, 5] in { + def payload # i : Operand, TImmLeaf(Imm);}], i)> { + let ParserMatchClass = UImmAsmOperand; + let DecoderMethod = !format("decodeUImmOperand<{0}>", i); + let OperandType = "OPERAND_UIMM" # i; + let OperandNamespace = "RISCVOp"; + } } def timm5 : Operand, TImmLeaf(Imm);}]> { diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -171,41 +171,22 @@ SDLoc(N), N->getValueType(0)); }]>; -def C3LeftShift : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - return C > 3 && (C >> llvm::countr_zero(C)) == 3; -}]>; - -def C5LeftShift : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - return C > 5 && (C >> llvm::countr_zero(C)) == 5; -}]>; - -def C9LeftShift : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - return C > 5 && (C >> llvm::countr_zero(C)) == 9; -}]>; - -// Constant of the form (3 << C) where C is less than 32. -def C3LeftShiftUW : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - unsigned Shift = llvm::countr_zero(C); - return 1 <= Shift && Shift < 32 && (C >> Shift) == 3; -}]>; +foreach i = [3, 5, 9] in { + def C # i # LeftShift : PatLeaf<(imm), !format([{ + uint64_t C = N->getZExtValue(); + return C > {0} && (C >> llvm::countr_zero(C)) == {0}; + }], i)>; +} -// Constant of the form (5 << C) where C is less than 32. -def C5LeftShiftUW : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - unsigned Shift = llvm::countr_zero(C); - return 1 <= Shift && Shift < 32 && (C >> Shift) == 5; -}]>; +// Constant of the form (i << C) where C is less than 32. +foreach i = [3, 5, 9] in { + def C # i # LeftShiftUW : PatLeaf<(imm), !format([{ + uint64_t C = N->getZExtValue(); + unsigned Shift = llvm::countr_zero(C); + return 1 <= Shift && Shift < 32 && (C >> Shift) == {0}; + }], i)>; +} -// Constant of the form (9 << C) where C is less than 32. -def C9LeftShiftUW : PatLeaf<(imm), [{ - uint64_t C = N->getZExtValue(); - unsigned Shift = llvm::countr_zero(C); - return 1 <= Shift && Shift < 32 && (C >> Shift) == 9; -}]>; def CSImm12MulBy4 : PatLeaf<(imm), [{ if (!N->hasOneUse())