Skip to content

Commit 780c539

Browse files
committed
[RISCV] Implement assembler support for XVentanaCondOps
This change provides an implementation of the XVentanaCondOps vendor extension. This extension is defined in version 1.0.0 of the VTx-family custom instructions specification (https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf) by Ventana Micro Systems. In addition to the technical contribution, this change is intended to be a test case for our vendor extension policy. Once this lands, I plan to use this extension to prototype selection lowering to conditional moves. There's an RVI proposal in flight, and the expectation is that lowering to these and the new RVI instructions is likely to be substantially similar. Differential Revision: https://reviews.llvm.org/D137350
1 parent 4f729d5 commit 780c539

File tree

10 files changed

+98
-3
lines changed

10 files changed

+98
-3
lines changed

clang/test/Preprocessor/riscv-target-features.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
// CHECK-NOT: __riscv_zicboz
4242
// CHECK-NOT: __riscv_svnapot
4343
// CHECK-NOT: __riscv_svinval
44+
// CHECK-NOT: __riscv_xventanacondops
4445

4546
// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
4647
// RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -432,3 +433,7 @@
432433
// RUN: %clang -target riscv64 -march=rv64isvinval -x c -E -dM %s \
433434
// RUN: -o - | FileCheck --check-prefix=CHECK-SVINVAL-EXT %s
434435
// CHECK-SVINVAL-EXT: __riscv_svinval 1000000{{$}}
436+
437+
// RUN: %clang -target riscv64 -march=rv64ixventanacondops -x c -E -dM %s \
438+
// RUN: -o - | FileCheck --check-prefix=CHECK-XVENTANACONDOPS-EXT %s
439+
// CHECK-XVENTANACONDOPS-EXT: __riscv_xventanacondops 1000000{{$}}

llvm/docs/RISCVUsage.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ To use an experimental extension from `clang`, you must add `-menable-experiment
149149
Vendor Extensions
150150
=================
151151

152-
Vendor extensions are extensions which are not standardized by RISC-V International, and are instead defined by a hardware vendor. At the moment, LLVM does not support any vendor extensions for RISC-V, but we expect this to change in the future.
153-
154-
The term vendor extension roughly parallels the definition of a `non-standard` extension from Section 1.3 of the Volume I: RISC-V Unprivileged ISA specification. In particular, we expect to eventually accept both `custom` extensions and `non-conforming` extensions.
152+
Vendor extensions are extensions which are not standardized by RISC-V International, and are instead defined by a hardware vendor. The term vendor extension roughly parallels the definition of a `non-standard` extension from Section 1.3 of the Volume I: RISC-V Unprivileged ISA specification. In particular, we expect to eventually accept both `custom` extensions and `non-conforming` extensions.
155153

156154
Inclusion of a vendor extension will be considered on a case by case basis. All proposals should be brought to the bi-weekly RISCV sync calls for discussion. For a general idea of the factors likely to be considered, please see the `Clang documentation <https://clang.llvm.org/get_involved.html>`_.
157155

158156
It is our intention to follow the naming conventions described in `riscv-non-isa/riscv-toolchain-conventions <https://github.com/riscv-non-isa/riscv-toolchain-conventions#conventions-for-vendor-extensions>`_. Exceptions to this naming will need to be strongly motivated.
159157

158+
The current vendor extensions supported are:
159+
160+
``XVentanaCondOps``
161+
LLVM implements `version 1.0.0 of the VTx-family custom instructions specification <https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf>`_ by Ventana Micro Systems. All instructions are prefixed with `vt.` as described in the specification, and the riscv-toolchai-convention document linked above. These instructions are only available for riscv64 at this time.
162+
160163

161164
Specification Documents
162165
=======================

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
104104

105105
{"svnapot", RISCVExtensionVersion{1, 0}},
106106
{"svinval", RISCVExtensionVersion{1, 0}},
107+
{"xventanacondops", RISCVExtensionVersion{1, 0}},
107108
};
108109

109110
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
465465
return Result;
466466
}
467467
}
468+
if (STI.getFeatureBits()[RISCV::FeatureVendorXVentanaCondOps]) {
469+
LLVM_DEBUG(dbgs() << "Trying Ventana custom opcode table:\n");
470+
Result = decodeInstruction(DecoderTableVentana32, MI, Insn, Address, this,
471+
STI);
472+
if (Result != MCDisassembler::Fail) {
473+
Size = 4;
474+
return Result;
475+
}
476+
}
477+
468478
LLVM_DEBUG(dbgs() << "Trying RISCV32 table :\n");
469479
Result = decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI);
470480
Size = 4;

llvm/lib/Target/RISCV/RISCV.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,21 @@ def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
413413
AssemblerPredicate<(all_of FeatureStdExtZawrs),
414414
"'Zawrs' (Wait on Reservation Set)">;
415415

416+
//===----------------------------------------------------------------------===//
417+
// Vendor extensions
418+
//===----------------------------------------------------------------------===//
419+
420+
def FeatureVendorXVentanaCondOps
421+
: SubtargetFeature<"xventanacondops", "HasVendorXVentanaCondOps", "true",
422+
"'XVentanaCondOps' (Ventana Conditional Ops)">;
423+
def HasVendorXVentanaCondOps : Predicate<"Subtarget->hasVendorXVentanaCondOps()">,
424+
AssemblerPredicate<(all_of FeatureVendorXVentanaCondOps),
425+
"'XVentanaCondOps' (Ventana Conditional Ops)">;
426+
427+
//===----------------------------------------------------------------------===//
428+
// LLVM specific features and extensions
429+
//===----------------------------------------------------------------------===//
430+
416431
// Feature32Bit exists to mark CPUs that support RV32 to distinquish them from
417432
// tuning CPU names.
418433
def Feature32Bit

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,3 +1782,9 @@ include "RISCVInstrInfoZk.td"
17821782
include "RISCVInstrInfoV.td"
17831783
include "RISCVInstrInfoZfh.td"
17841784
include "RISCVInstrInfoZicbo.td"
1785+
1786+
//===----------------------------------------------------------------------===//
1787+
// Vendor extensions
1788+
//===----------------------------------------------------------------------===//
1789+
1790+
include "RISCVInstrInfoXVentana.td"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-- RISCVInstrInfoXVentana.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 Ventana Micro Systems.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
//===----------------------------------------------------------------------===//
14+
// XVentanaCondOps
15+
//===----------------------------------------------------------------------===//
16+
17+
let Predicates = [IsRV64, HasVendorXVentanaCondOps], hasSideEffects = 0,
18+
mayLoad = 0, mayStore = 0, isCodeGenOnly = 0, DecoderNamespace = "Ventana" in
19+
class VTMaskedMove<bits<3> funct3, string opcodestr>
20+
: RVInstR<0b0000000, funct3, OPC_CUSTOM_3, (outs GPR:$rd),
21+
(ins GPR:$rs1, GPR:$rs2), opcodestr,
22+
"$rd, $rs1, $rs2"> {
23+
}
24+
25+
def VT_MASKC : VTMaskedMove<0b110, "vt.maskc">,
26+
Sched<[WriteIALU, ReadIALU, ReadIALU]>;
27+
28+
def VT_MASKCN : VTMaskedMove<0b111, "vt.maskcn">,
29+
Sched<[WriteIALU, ReadIALU, ReadIALU]>;

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
9090
bool HasStdExtZmmul = false;
9191
bool HasStdExtZawrs = false;
9292
bool HasStdExtZtso = false;
93+
bool HasVendorXVentanaCondOps = false;
9394
bool HasRV32 = false;
9495
bool HasRV64 = false;
9596
bool IsRV32E = false;
@@ -190,6 +191,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
190191
bool hasStdExtZawrs() const { return HasStdExtZawrs; }
191192
bool hasStdExtZmmul() const { return HasStdExtZmmul; }
192193
bool hasStdExtZtso() const { return HasStdExtZtso; }
194+
bool hasVendorXVentanaCondOps() const { return HasVendorXVentanaCondOps; }
193195
bool is64Bit() const { return HasRV64; }
194196
bool isRV32E() const { return IsRV32E; }
195197
bool enableLinkerRelax() const { return EnableLinkerRelax; }

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
7777
; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s
7878
; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
79+
; RUN: llc -mtriple=riscv64 -mattr=+xventanacondops %s -o - | FileCheck --check-prefix=RV64XVENTANACONDOPS %s
7980
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
8081
; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
8182

@@ -157,6 +158,7 @@
157158
; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
158159
; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0"
159160
; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
161+
; RV64XVENTANACONDOPS: .attribute 5, "rv64i2p0_xventanacondops1p0"
160162
; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
161163

162164
define i32 @addi(i32 %a) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+xventanacondops -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+xventanacondops < %s \
4+
# RUN: | llvm-objdump --mattr=+xventanacondops -M no-aliases -d -r - \
5+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
6+
7+
# CHECK-ASM-AND-OBJ: vt.maskc zero, zero, zero
8+
# CHECK-ASM: encoding: [0x7b,0x60,0x00,0x00]
9+
vt.maskc x0, x0, x0
10+
11+
# CHECK-ASM-AND-OBJ: vt.maskcn zero, zero, zero
12+
# CHECK-ASM: encoding: [0x7b,0x70,0x00,0x00]
13+
vt.maskcn x0, x0, x0
14+
15+
# CHECK-ASM-AND-OBJ: vt.maskc ra, sp, gp
16+
# CHECK-ASM: encoding: [0xfb,0x60,0x31,0x00]
17+
vt.maskc x1, x2, x3
18+
19+
# CHECK-ASM-AND-OBJ: vt.maskcn ra, sp, gp
20+
# CHECK-ASM: encoding: [0xfb,0x70,0x31,0x00]
21+
vt.maskcn x1, x2, x3
22+

0 commit comments

Comments
 (0)