Skip to content

Commit c4645ff

Browse files
authored
[RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (#117169)
The Qualcomm uC Xqcicsr extension adds 2 instructions that can read and write CSRs. The current spec can be found at: https://github.com/quic/riscv-unified-db/releases/latest This patch adds assembler only support.
1 parent 9ea5be6 commit c4645ff

File tree

12 files changed

+111
-1
lines changed

12 files changed

+111
-1
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
// CHECK-NEXT: smctr 1.0 'Smctr' (Control Transfer Records Machine Level)
189189
// CHECK-NEXT: ssctr 1.0 'Ssctr' (Control Transfer Records Supervisor Level)
190190
// CHECK-NEXT: svukte 0.3 'Svukte' (Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
191+
// CHECK-NEXT: xqcicsr 0.2 'Xqcicsr' (Qualcomm uC CSR Extension)
191192
// CHECK-EMPTY:
192193
// CHECK-NEXT: Supported Profiles
193194
// CHECK-NEXT: rva20s64

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ The current vendor extensions supported are:
426426
``Xwchc``
427427
LLVM implements `the custom compressed opcodes present in some QingKe cores` by WCH / Nanjing Qinheng Microelectronics. The vendor refers to these opcodes by the name "XW".
428428

429+
``experimental-Xqcicsr``
430+
LLVM implements `version 0.2 of the Qualcomm uC CSR extension specification <https://github.com/quic/riscv-unified-db/releases/latest>`__ by Qualcomm. All instructions are prefixed with `qc.` as described in the specification. These instructions are only available for riscv32.
431+
429432
Experimental C Intrinsics
430433
=========================
431434

llvm/docs/ReleaseNotes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
211211
* `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
212212
will use the relevant GPR rather than FPR. This makes inline assembly portable
213213
between e.g. F and Zfinx code.
214-
214+
* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
215+
extension.
215216

216217
Changes to the WebAssembly Backend
217218
----------------------------------

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
682682
"CORE-V SIMD extensions custom opcode table");
683683
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
684684
"CORE-V Immediate Branching custom opcode table");
685+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
686+
"Qualcomm uC CSR custom opcode table");
685687
TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
686688

687689
return MCDisassembler::Fail;

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,16 @@ def HasVendorXwchc
13411341
AssemblerPredicate<(all_of FeatureVendorXwchc),
13421342
"'Xwchc' (WCH/QingKe additional compressed opcodes)">;
13431343

1344+
// Qualcomm Extension(s)
1345+
1346+
def FeatureVendorXqcicsr
1347+
: RISCVExperimentalExtension<"xqcicsr", 0, 2,
1348+
"'Xqcicsr' (Qualcomm uC CSR Extension)">;
1349+
def HasVendorXqcicsr
1350+
: Predicate<"Subtarget->hasVendorXqcicsr()">,
1351+
AssemblerPredicate<(all_of FeatureVendorXqcicsr),
1352+
"'Xqcicsr' (Qualcomm uC CSR Extension)">;
1353+
13441354
//===----------------------------------------------------------------------===//
13451355
// LLVM specific features and extensions
13461356
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,7 @@ include "RISCVInstrInfoXSf.td"
20642064
include "RISCVInstrInfoSFB.td"
20652065
include "RISCVInstrInfoXCV.td"
20662066
include "RISCVInstrInfoXwch.td"
2067+
include "RISCVInstrInfoXqci.td"
20672068

20682069
//===----------------------------------------------------------------------===//
20692070
// Global ISel
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===---------------- RISCVInstrInfoXQci.td ----------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file describes the vendor extensions defined by QUALCOMM.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
//===----------------------------------------------------------------------===//
14+
// Operand and SDNode transformation definitions.
15+
//===----------------------------------------------------------------------===//
16+
17+
//===----------------------------------------------------------------------===//
18+
// Instruction Formats
19+
//===----------------------------------------------------------------------===//
20+
21+
//===----------------------------------------------------------------------===//
22+
// Instruction Class Templates
23+
//===----------------------------------------------------------------------===//
24+
25+
//===----------------------------------------------------------------------===//
26+
// Instructions
27+
//===----------------------------------------------------------------------===//
28+
29+
let Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr" in {
30+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
31+
def QC_CSRRWR : RVInstR<0b1000110, 0b000, OPC_SYSTEM, (outs GPR:$rd),
32+
(ins GPR:$rs1, GPRNoX0:$rs2), "qc.csrrwr",
33+
"$rd, $rs1, $rs2">;
34+
35+
def QC_CSRRWRI : RVInstR<0b1000111, 0b000, OPC_SYSTEM, (outs GPR:$rd),
36+
(ins uimm5:$rs1, GPRNoX0:$rs2), "qc.csrrwri",
37+
"$rd, $rs1, $rs2">;
38+
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
39+
} // Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr"

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,10 @@ Error RISCVISAInfo::checkDependency() {
771771
return getIncompatibleError("xwchc", "zcb");
772772
}
773773

774+
if (Exts.count("xqcicsr") != 0 && (XLen != 32)) {
775+
return getError("'xqcicsr' is only supported for 'rv32'");
776+
}
777+
774778
return Error::success();
775779
}
776780

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
; RUN: llc -mtriple=riscv32 -mattr=+xtheadmempair %s -o - | FileCheck --check-prefix=RV32XTHEADMEMPAIR %s
8282
; RUN: llc -mtriple=riscv32 -mattr=+xtheadsync %s -o - | FileCheck --check-prefix=RV32XTHEADSYNC %s
8383
; RUN: llc -mtriple=riscv32 -mattr=+xwchc %s -o - | FileCheck --check-prefix=RV32XWCHC %s
84+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicsr %s -o - | FileCheck --check-prefix=RV32XQCICSR %s
8485
; RUN: llc -mtriple=riscv32 -mattr=+zaamo %s -o - | FileCheck --check-prefix=RV32ZAAMO %s
8586
; RUN: llc -mtriple=riscv32 -mattr=+zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
8687
; RUN: llc -mtriple=riscv32 -mattr=+zca %s -o - | FileCheck --check-prefixes=CHECK,RV32ZCA %s
@@ -385,6 +386,7 @@
385386
; RV32XTHEADMEMPAIR: .attribute 5, "rv32i2p1_xtheadmempair1p0"
386387
; RV32XTHEADSYNC: .attribute 5, "rv32i2p1_xtheadsync1p0"
387388
; RV32XWCHC: .attribute 5, "rv32i2p1_xwchc2p2"
389+
; RV32XQCICSR: .attribute 5, "rv32i2p1_xqcicsr0p2"
388390
; RV32ZAAMO: .attribute 5, "rv32i2p1_zaamo1p0"
389391
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc1p0"
390392
; RV32ZCA: .attribute 5, "rv32i2p1_zca1p0"

llvm/test/MC/RISCV/xqcicsr-invalid.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Xqcicsr - Qualcomm uC CSR Extension
2+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-xqcicsr < %s 2>&1 \
3+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-PLUS %s
4+
# RUN: not llvm-mc -triple riscv32 -mattr=-experimental-xqcicsr < %s 2>&1 \
5+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-MINUS %s
6+
7+
# CHECK: :[[@LINE+1]]:20: error: invalid operand for instruction
8+
qc.csrrwr x10, x5, x0
9+
10+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
11+
qc.csrrwr x10, x5
12+
13+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicsr' (Qualcomm uC CSR Extension)
14+
qc.csrrwr x10, x5, x20
15+
16+
17+
# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
18+
qc.csrrwri x20, 31, x0
19+
20+
# CHECK-PLUS: :[[@LINE+1]]:17: error: immediate must be an integer in the range [0, 31]
21+
qc.csrrwri x20, 45, x12
22+
23+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
24+
qc.csrrwri x20, 23
25+
26+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicsr' (Qualcomm uC CSR Extension)
27+
qc.csrrwri x30, 31, x12

llvm/test/MC/RISCV/xqcicsr-valid.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Xqcicsr - Qualcomm uC CSR Extension
2+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcicsr -riscv-no-aliases -show-encoding \
3+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
4+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcicsr < %s \
5+
# RUN: | llvm-objdump --mattr=+experimental-xqcicsr -M no-aliases --no-print-imm-hex -d - \
6+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
7+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcicsr -show-encoding \
8+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
9+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcicsr < %s \
10+
# RUN: | llvm-objdump --mattr=+experimental-xqcicsr --no-print-imm-hex -d - \
11+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
12+
13+
# CHECK-INST: qc.csrrwr a0, t0, s4
14+
# CHECK-ENC: encoding: [0x73,0x85,0x42,0x8d]
15+
qc.csrrwr x10, x5, x20
16+
17+
# CHECK-INST: qc.csrrwri s4, 31, a2
18+
# CHECK-ENC: encoding: [0x73,0x8a,0xcf,0x8e]
19+
qc.csrrwri x20, 31, x12

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ Experimental extensions
11041104
smctr 1.0
11051105
ssctr 1.0
11061106
svukte 0.3
1107+
xqcicsr 0.2
11071108
11081109
Supported Profiles
11091110
rva20s64

0 commit comments

Comments
 (0)