diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst --- a/llvm/docs/RISCVUsage.rst +++ b/llvm/docs/RISCVUsage.rst @@ -271,5 +271,8 @@ ``XCVmac`` LLVM implements `version 1.0.0 of the CORE-V Multiply-Accumulate (MAC) custom instructions specification `_ by OpenHW Group. All instructions are prefixed with `cv.mac` as described in the specification. These instructions are only available for riscv32 at this time. +``XCVbi`` + LLVM implements `version 1.0.0 of the CORE-V immediate branching custom instructions specification `_ by OpenHW Group. All instructions are prefixed with `cv.` as described in the specification. These instructions are only available for riscv32 at this time. + ``XSfcie`` LLVM implements `version 1.0.0 of the SiFive Custom Instruction Extension (CIE) Software Specification `_ by SiFive. All custom instruction are added as described in the specification, and the riscv-toolchain-convention document linked above. These instructions are only available for S76 processor at this time. diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -66,6 +66,7 @@ {"v", RISCVExtensionVersion{1, 0}}, // vendor-defined ('X') extensions + {"xcvbi", RISCVExtensionVersion{1, 0}}, {"xcvbitmanip", RISCVExtensionVersion{1, 0}}, {"xcvmac", RISCVExtensionVersion{1, 0}}, {"xsfcie", RISCVExtensionVersion{1, 0}}, diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp --- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -565,6 +565,8 @@ "CORE-V Bit Manipulation custom opcode table"); TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVmac, DecoderTableXCVmac32, "CORE-V MAC custom opcode table"); + TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32, + "CORE-V Immediate Branching custom opcode table"); TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table"); return MCDisassembler::Fail; diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -790,6 +790,13 @@ AssemblerPredicate<(all_of FeatureVendorXCVmac), "'XCVmac' (CORE-V Multiply-Accumulate)">; +def FeatureVendorXCVbi + : SubtargetFeature<"xcvbi", "HasVendorXCVbi", "true", + "'XCVbi' (CORE-V Immediate Branching)">; +def HasVendorXCVbi : Predicate<"Subtarget->hasVendorXCVbi()">, + AssemblerPredicate<(all_of FeatureVendorXCVbi), + "'XCVbi' (CORE-V Immediate Branching)">; + //===----------------------------------------------------------------------===// // LLVM specific features and extensions //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td @@ -203,3 +203,22 @@ def : InstAlias<"cv.mulhhu $rd1, $rs1, $rs2", (CV_MULHHUN GPR:$rd1, GPR:$rs1, GPR:$rs2, 0)>; } // Predicates = [HasVendorXCVmac, IsRV32] + +class CVInstImmBranch funct3, dag outs, dag ins, + string opcodestr, string argstr> + : RVInstB { + bits<5> imm5; + let rs2 = imm5; + let DecoderNamespace = "XCVbi"; +} + +let Predicates = [HasVendorXCVbi, IsRV32], hasSideEffects = 0, mayLoad = 0, + mayStore = 0, isBranch = 1, isTerminator = 1 in { + // Immediate branching operations + def CV_BEQIMM : CVInstImmBranch<0b110, (outs), + (ins GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12), + "cv.beqimm", "$rs1, $imm5, $imm12">, Sched<[]>; + def CV_BNEIMM : CVInstImmBranch<0b111, (outs), + (ins GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12), + "cv.bneimm", "$rs1, $imm5, $imm12">, Sched<[]>; +} diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -43,6 +43,7 @@ ; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefixes=CHECK,RV32SVINVAL %s ; RUN: llc -mtriple=riscv32 -mattr=+xcvbitmanip %s -o - | FileCheck --check-prefix=RV32XCVBITMANIP %s ; RUN: llc -mtriple=riscv32 -mattr=+xcvmac %s -o - | FileCheck --check-prefix=RV32XCVMAC %s +; RUN: llc -mtriple=riscv32 -mattr=+xcvbi %s -o - | FileCheck --check-prefix=RV32XCVBI %s ; RUN: llc -mtriple=riscv32 -mattr=+xtheadcmo %s -o - | FileCheck --check-prefix=RV32XTHEADCMO %s ; RUN: llc -mtriple=riscv32 -mattr=+xtheadcondmov %s -o - | FileCheck --check-prefix=RV32XTHEADCONDMOV %s ; RUN: llc -mtriple=riscv32 -mattr=+xtheadfmemidx %s -o - | FileCheck --check-prefix=RV32XTHEADFMEMIDX %s @@ -216,6 +217,7 @@ ; RV32SVINVAL: .attribute 5, "rv32i2p1_svinval1p0" ; RV32XCVBITMANIP: .attribute 5, "rv32i2p1_xcvbitmanip1p0" ; RV32XCVMAC: .attribute 5, "rv32i2p1_xcvmac1p0" +; RV32XCVBI: .attribute 5, "rv32i2p1_xcvbi1p0" ; RV32XTHEADCMO: .attribute 5, "rv32i2p1_xtheadcmo1p0" ; RV32XTHEADCONDMOV: .attribute 5, "rv32i2p1_xtheadcondmov1p0" ; RV32XTHEADFMEMIDX: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_xtheadfmemidx1p0" diff --git a/llvm/test/MC/RISCV/attribute-arch.s b/llvm/test/MC/RISCV/attribute-arch.s --- a/llvm/test/MC/RISCV/attribute-arch.s +++ b/llvm/test/MC/RISCV/attribute-arch.s @@ -290,3 +290,6 @@ .attribute arch, "rv32i_xcvmac" # CHECK: attribute 5, "rv32i2p1_xcvmac1p0" + +.attribute arch, "rv32i_xcvbi" +# CHECK: attribute 5, "rv32i2p1_xcvbi1p0" diff --git a/llvm/test/MC/RISCV/corev/XCVbi-invalid.s b/llvm/test/MC/RISCV/corev/XCVbi-invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/corev/XCVbi-invalid.s @@ -0,0 +1,58 @@ +# RUN: not llvm-mc -triple=riscv32 --mattr=+xcvbi %s 2>&1 \ +# RUN: | FileCheck %s --check-prefixes=CHECK-ERROR + +//===----------------------------------------------------------------------===// +// cv.beqimm +//===----------------------------------------------------------------------===// + +cv.beqimm 0, 0, 0 +# CHECK-ERROR: invalid operand for instruction + +cv.beqimm t0, t1, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.beqimm t0, 0, t1 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.beqimm t0, 16, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.beqimm t0, -17, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.beqimm t0, 0, 1 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.beqimm t0, 0, 4096 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.beqimm t0, 0, -4098 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +//===----------------------------------------------------------------------===// +// cv.bneimm +//===----------------------------------------------------------------------===// + +cv.bneimm 0, 0, 0 +# CHECK-ERROR: invalid operand for instruction + +cv.bneimm t0, t1, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.bneimm t0, 0, t1 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.bneimm t0, 16, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.bneimm t0, -17, 0 +# CHECK-ERROR: immediate must be an integer in the range [-16, 15] + +cv.bneimm t0, 0, 1 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.bneimm t0, 0, 4096 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] + +cv.bneimm t0, 0, -4098 +# CHECK-ERROR: immediate must be a multiple of 2 bytes in the range [-4096, 4094] \ No newline at end of file diff --git a/llvm/test/MC/RISCV/corev/XCVbi.s b/llvm/test/MC/RISCV/corev/XCVbi.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/corev/XCVbi.s @@ -0,0 +1,57 @@ +# RUN: llvm-mc -triple=riscv32 --mattr=+xcvbi -show-encoding %s \ +# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INSTR +# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+xcvbi < %s \ +# RUN: | llvm-objdump --mattr=+xcvbi -M no-aliases -d -r - \ +# RUN: | FileCheck --check-prefix=CHECK-OBJDUMP %s +# RUN: not llvm-mc -triple riscv32 %s 2>&1 \ +# RUN: | FileCheck -check-prefix=CHECK-NO-EXT %s + +//===----------------------------------------------------------------------===// +// cv.beqimm +//===----------------------------------------------------------------------===// + +label1: + +cv.beqimm t0, 0, 0 +# CHECK-INSTR: cv.beqimm t0, 0, 0 +# CHECK-OBJDUMP: cv.beqimm t0, 0, 0x0 +# CHECK-ENCODING: [0x0b,0xe0,0x02,0x00] +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}} + +cv.beqimm a0, 5, 42 +# CHECK-INSTR: cv.beqimm a0, 5, 42 +# CHECK-OBJDUMP: cv.beqimm a0, 5, 0x2e +# CHECK-ENCODING: [0x0b,0x65,0x55,0x02] +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}} + +cv.beqimm a0, -5, label1 +# CHECK-INSTR: cv.beqimm a0, -5, label1 +# CHECK-OBJDUMP: cv.beqimm a0, -5, 0x0 +# CHECK-ENCODING: [0x0b'A',0x60'A',0xb5'A',0x01'A'] +# CHECK-ENCODING: fixup A - offset: 0, value: label1, kind: fixup_riscv_branch +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}} + +//===----------------------------------------------------------------------===// +// cv.bneimm +//===----------------------------------------------------------------------===// + +label2: + +cv.bneimm t0, 0, 0 +# CHECK-INSTR: cv.bneimm t0, 0, 0 +# CHECK-OBJDUMP: cv.bneimm t0, 0, 0xc +# CHECK-ENCODING: [0x0b,0xf0,0x02,0x00] +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}} + +cv.bneimm a0, 5, 42 +# CHECK-INSTR: cv.bneimm a0, 5, 42 +# CHECK-OBJDUMP: cv.bneimm a0, 5, 0x3a +# CHECK-ENCODING: [0x0b,0x75,0x55,0x02] +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}} + +cv.bneimm a0, -5, label2 +# CHECK-INSTR: cv.bneimm a0, -5, label2 +# CHECK-OBJDUMP: cv.bneimm a0, -5, 0xc +# CHECK-ENCODING: [0x0b'A',0x70'A',0xb5'A',0x01'A'] +# CHECK-ENCODING: fixup A - offset: 0, value: label2, kind: fixup_riscv_branch +# CHECK-NO-EXT: instruction requires the following: 'XCVbi' (CORE-V Immediate Branching){{$}}