diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -44,7 +44,11 @@ InstFormatCB = 15, InstFormatCJ = 16, InstFormatCU = 17, - InstFormatOther = 18, + InstFormatCLB = 18, + InstFormatCLH = 19, + InstFormatCSB = 20, + InstFormatCSH = 21, + InstFormatOther = 22, InstFormatMask = 31, InstFormatShift = 0, diff --git a/llvm/lib/Target/RISCV/RISCVInstrFormats.td b/llvm/lib/Target/RISCV/RISCVInstrFormats.td --- a/llvm/lib/Target/RISCV/RISCVInstrFormats.td +++ b/llvm/lib/Target/RISCV/RISCVInstrFormats.td @@ -48,7 +48,11 @@ def InstFormatCB : InstFormat<15>; def InstFormatCJ : InstFormat<16>; def InstFormatCU : InstFormat<17>; -def InstFormatOther : InstFormat<18>; +def InstFormatCLB : InstFormat<18>; +def InstFormatCLH : InstFormat<19>; +def InstFormatCSB : InstFormat<20>; +def InstFormatCSH : InstFormat<21>; +def InstFormatOther : InstFormat<22>; class RISCVVConstraint val> { bits<3> Value = val; diff --git a/llvm/lib/Target/RISCV/RISCVInstrFormatsC.td b/llvm/lib/Target/RISCV/RISCVInstrFormatsC.td --- a/llvm/lib/Target/RISCV/RISCVInstrFormatsC.td +++ b/llvm/lib/Target/RISCV/RISCVInstrFormatsC.td @@ -168,3 +168,65 @@ let Inst{6-2} = funct5; let Inst{1-0} = opcode; } + +// The immediate value encoding differs for each instruction, so each subclass +// is responsible for setting the appropriate bits in the Inst field. +// The bits Inst{6-5} must be set for each instruction. +class RVInst16CLB funct6, bits<2> opcode, dag outs, dag ins, + string opcodestr, string argstr> + : RVInst16 { + bits<3> rd; + bits<3> rs1; + + let Inst{15-10} = funct6; + let Inst{9-7} = rs1; + let Inst{4-2} = rd; + let Inst{1-0} = opcode; +} + +// The immediate value encoding differs for each instruction, so each subclass +// is responsible for setting the appropriate bits in the Inst field. +// The bits Inst{5} must be set for each instruction. +class RVInst16CLH funct6, bit funct1, bits<2> opcode, dag outs, + dag ins, string opcodestr, string argstr> + : RVInst16 { + bits<3> rd; + bits<3> rs1; + + let Inst{15-10} = funct6; + let Inst{9-7} = rs1; + let Inst{6} = funct1; + let Inst{4-2} = rd; + let Inst{1-0} = opcode; +} + +// The immediate value encoding differs for each instruction, so each subclass +// is responsible for setting the appropriate bits in the Inst field. +// The bits Inst{6-5} must be set for each instruction. +class RVInst16CSB funct6, bits<2> opcode, dag outs, dag ins, + string opcodestr, string argstr> + : RVInst16 { + bits<3> rs2; + bits<3> rs1; + + let Inst{15-10} = funct6; + let Inst{9-7} = rs1; + let Inst{4-2} = rs2; + let Inst{1-0} = opcode; +} + +// The immediate value encoding differs for each instruction, so each subclass +// is responsible for setting the appropriate bits in the Inst field. +// The bits Inst{5} must be set for each instruction. +class RVInst16CSH funct6, bit funct1, bits<2> opcode, dag outs, + dag ins, string opcodestr, string argstr> + : RVInst16 { + bits<3> rs2; + bits<3> rs1; + + let Inst{15-10} = funct6; + let Inst{9-7} = rs1; + let Inst{6} = funct1; + let Inst{4-2} = rs2; + let Inst{1-0} = opcode; +} diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td @@ -36,6 +36,46 @@ // Instruction Class Templates //===----------------------------------------------------------------------===// +let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in +class CLoadB_ri funct6, string OpcodeStr> + : RVInst16CLB { + bits<2> imm; + + let Inst{6-5} = imm{0,1}; +} + +let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in +class CLoadH_ri funct6, bit funct1, string OpcodeStr> + : RVInst16CLH { + bits<2> imm; + + let Inst{5} = imm{1}; +} + +let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in +class CStoreB_rri funct6, string OpcodeStr> + : RVInst16CSB { + bits<2> imm; + + let Inst{6-5} = imm{0,1}; +} + +let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in +class CStoreH_rri funct6, bit funct1, string OpcodeStr> + : RVInst16CSH { + bits<2> imm; + + let Inst{5} = imm{1}; +} + let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in class RVZcArith_r funct5, string OpcodeStr> : RVInst16CU<0b100111, funct5, 0b01, (outs GPRC:$rd_wb), (ins GPRC:$rd), @@ -72,48 +112,17 @@ def C_NOT : RVZcArith_r<0b11101 , "c.not">, Sched<[WriteIALU, ReadIALU]>; -def C_LBU : CLoad_ri<0b100, "c.lbu", GPRC, uimm2>, - Sched<[WriteLDB, ReadMemBase]> { - bits<2> imm; - - let Inst{12-10} = 0b000; - let Inst{6-5} = imm{0,1}; -} - -def C_LHU : CLoad_ri<0b100, "c.lhu", GPRC, uimm2_lsb0>, - Sched<[WriteLDH, ReadMemBase]> { - bits<2> imm; - - let Inst{12-10} = 0b001; - let Inst{6} = 0b0; - let Inst{5} = imm{1}; -} - -def C_LH : CLoad_ri<0b100, "c.lh", GPRC, uimm2_lsb0>, - Sched<[WriteLDH, ReadMemBase]> { - bits<2> imm; - - let Inst{12-10} = 0b001; - let Inst{6} = 0b1; - let Inst{5} = imm{1}; -} - -def C_SB : CStore_rri<0b100, "c.sb", GPRC, uimm2>, - Sched<[WriteSTB, ReadStoreData, ReadMemBase]> { - bits<2> imm; - - let Inst{12-10} = 0b010; - let Inst{6-5} = imm{0,1}; -} - -def C_SH : CStore_rri<0b100, "c.sh", GPRC, uimm2_lsb0>, - Sched<[WriteSTH, ReadStoreData, ReadMemBase]> { - bits<2> imm; - - let Inst{12-10} = 0b011; - let Inst{6} = 0b1; - let Inst{5} = imm{1}; -} +def C_LBU : CLoadB_ri<0b100000, "c.lbu">, + Sched<[WriteLDB, ReadMemBase]>; +def C_LHU : CLoadH_ri<0b100001, 0b0, "c.lhu">, + Sched<[WriteLDH, ReadMemBase]>; +def C_LH : CLoadH_ri<0b100001, 0b1, "c.lh">, + Sched<[WriteLDH, ReadMemBase]>; + +def C_SB : CStoreB_rri<0b100010, "c.sb">, + Sched<[WriteSTB, ReadStoreData, ReadMemBase]>; +def C_SH : CStoreH_rri<0b100011, 0b1, "c.sh">, + Sched<[WriteSTH, ReadStoreData, ReadMemBase]>; } let Predicates = [HasStdExtZcb, HasStdExtMOrZmmul] in{