Index: clang/test/Preprocessor/riscv-target-features.c =================================================================== --- clang/test/Preprocessor/riscv-target-features.c +++ clang/test/Preprocessor/riscv-target-features.c @@ -446,6 +446,10 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-XVENTANACONDOPS-EXT %s // CHECK-XVENTANACONDOPS-EXT: __riscv_xventanacondops 1000000{{$}} +// RUN: %clang -target riscv64 -march=rv64ixtheadvdot -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-XTHEADVDOT-EXT %s +// CHECK-XTHEADVDOT-EXT: __riscv_xtheadvdot 1000000{{$}} + // RUN: %clang -target riscv32 -march=rv32izcd0p70 -menable-experimental-extensions \ // RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-ZCD-EXT %s // RUN: %clang -target riscv64 -march=rv64izcd0p70 -menable-experimental-extensions \ Index: llvm/docs/RISCVUsage.rst =================================================================== --- llvm/docs/RISCVUsage.rst +++ llvm/docs/RISCVUsage.rst @@ -160,6 +160,9 @@ ``XVentanaCondOps`` LLVM implements `version 1.0.0 of the VTx-family custom instructions specification `_ 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. +``XTHeadVdot`` + LLVM implements `version 1.0.0 of the THeadV-family custom instructions specification `_ by T-HEAD of Alibaba. All instructions are prefixed with `th.` as described in the specification, and the riscv-toolchai-convention document linked above. + Specification Documents ======================= Index: llvm/lib/Support/RISCVISAInfo.cpp =================================================================== --- llvm/lib/Support/RISCVISAInfo.cpp +++ llvm/lib/Support/RISCVISAInfo.cpp @@ -105,6 +105,7 @@ {"svnapot", RISCVExtensionVersion{1, 0}}, {"svinval", RISCVExtensionVersion{1, 0}}, {"xventanacondops", RISCVExtensionVersion{1, 0}}, + {"xtheadvdot", RISCVExtensionVersion{1, 0}}, }; static const RISCVSupportedExtension SupportedExperimentalExtensions[] = { @@ -784,6 +785,7 @@ static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"}; static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"}; static const char *ImpliedExtsZvfh[] = {"zve32f"}; +static const char *ImpliedExtsXTHeadVdot[] = {"v"}; struct ImpliedExtsEntry { StringLiteral Name; @@ -799,6 +801,7 @@ // Note: The table needs to be sorted by name. static constexpr ImpliedExtsEntry ImpliedExts[] = { {{"v"}, {ImpliedExtsV}}, + {{"xtheadvdot"}, {ImpliedExtsXTHeadVdot}}, {{"zdinx"}, {ImpliedExtsZdinx}}, {{"zfh"}, {ImpliedExtsZfh}}, {{"zfhmin"}, {ImpliedExtsZfhmin}}, Index: llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp =================================================================== --- llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -474,6 +474,15 @@ return Result; } } + if (STI.getFeatureBits()[RISCV::FeatureVendorXTHeadVdot]) { + LLVM_DEBUG(dbgs() << "Trying T-Head custom opcode table:\n"); + Result = + decodeInstruction(DecoderTableTHeadV32, MI, Insn, Address, this, STI); + if (Result != MCDisassembler::Fail) { + Size = 4; + return Result; + } + } LLVM_DEBUG(dbgs() << "Trying RISCV32 table :\n"); Result = decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI); Index: llvm/lib/Target/RISCV/RISCV.td =================================================================== --- llvm/lib/Target/RISCV/RISCV.td +++ llvm/lib/Target/RISCV/RISCV.td @@ -445,6 +445,14 @@ AssemblerPredicate<(all_of FeatureVendorXVentanaCondOps), "'XVentanaCondOps' (Ventana Conditional Ops)">; +def FeatureVendorXTHeadVdot + : SubtargetFeature<"xtheadvdot", "HasVendorXTHeadVdot", "true", + "'xtheadvdot' (T-Head Vector Extensions for Dot)", + [FeatureStdExtV]>; +def HasVendorXTHeadVdot : Predicate<"Subtarget->hasVendorXTHeadVdot()">, + AssemblerPredicate<(all_of FeatureVendorXTHeadVdot), + "'xtheadvdot' (T-Head Vector Extensions for Dot)">; + //===----------------------------------------------------------------------===// // LLVM specific features and extensions //===----------------------------------------------------------------------===// Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td =================================================================== --- llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -1845,3 +1845,4 @@ //===----------------------------------------------------------------------===// include "RISCVInstrInfoXVentana.td" +include "RISCVInstrInfoXTHead.td" Index: llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td =================================================================== --- /dev/null +++ llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td @@ -0,0 +1,69 @@ +//===-- RISCVInstrInfoXTHead.td ----------------------------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file describes the vendor extensions defined by T-Head of Alibaba. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// Instruction class templates +//===----------------------------------------------------------------------===// +class THInstVdotVV funct6, RISCVVFormat opv, dag outs, dag ins, + string opcodestr, string argstr> + : RVInstVV { + let Inst{26} = 0; + let Opcode = OPC_CUSTOM_0.Value; + let DecoderNamespace = "THeadV"; +} + +class THInstVdotVX funct6, RISCVVFormat opv, dag outs, dag ins, + string opcodestr, string argstr> + : RVInstVX { + let Inst{26} = 1; + let Opcode = OPC_CUSTOM_0.Value; + let DecoderNamespace = "THeadV"; +} + +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { +// op vd, vs1, vs2, vm (reverse the order of vs1 and vs2) +class THVdotALUrVV funct6, RISCVVFormat opv, string opcodestr> + : THInstVdotVV; + +// op vd, rs1, vs2, vm (reverse the order of rs1 and vs2) +class THVdotALUrVX funct6, RISCVVFormat opv, string opcodestr> + : THInstVdotVX; +} // hasSideEffects = 0, mayLoad = 0, mayStore = 0 + +//===----------------------------------------------------------------------===// +// Combination of instruction classes. +// Use these multiclasses to define instructions more easily. +//===----------------------------------------------------------------------===// +multiclass THVdotVMAQA_VX funct6> { + def _VX : THVdotALUrVX; +} + +multiclass THVdotVMAQA funct6> { + def _VV : THVdotALUrVV; + defm "" : THVdotVMAQA_VX; +} + +//===----------------------------------------------------------------------===// +// Instructions +//===----------------------------------------------------------------------===// +let Predicates = [HasVendorXTHeadVdot], + Constraints = "@earlyclobber $vd", + RVVConstraint = WidenV in { +defm THVdotVMAQA : THVdotVMAQA<"th.vmaqa", 0b100000>; +defm THVdotVMAQAU : THVdotVMAQA<"th.vmaqau", 0b100010>; +defm THVdotVMAQASU : THVdotVMAQA<"th.vmaqasu", 0b100100>; +defm THVdotVMAQAUS : THVdotVMAQA_VX<"th.vmaqaus",0b100110>; +} Index: llvm/test/CodeGen/RISCV/attributes.ll =================================================================== --- llvm/test/CodeGen/RISCV/attributes.ll +++ llvm/test/CodeGen/RISCV/attributes.ll @@ -79,6 +79,7 @@ ; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s ; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s ; RUN: llc -mtriple=riscv64 -mattr=+xventanacondops %s -o - | FileCheck --check-prefix=RV64XVENTANACONDOPS %s +; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefix=RV64XTHEADVDOT %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zca %s -o - | FileCheck --check-prefix=RV64ZCA %s @@ -163,6 +164,7 @@ ; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0" ; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0" ; RV64XVENTANACONDOPS: .attribute 5, "rv64i2p0_xventanacondops1p0" +; RV64XTHEADVDOT: .attribute 5, "rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0" ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1" ; RV64ZCA: .attribute 5, "rv64i2p0_zca0p70" Index: llvm/test/MC/RISCV/XTHeadVdot-valid.s =================================================================== --- /dev/null +++ llvm/test/MC/RISCV/XTHeadVdot-valid.s @@ -0,0 +1,93 @@ +# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+xtheadvdot %s \ +# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST +# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CHECK-ERROR +# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+xtheadvdot %s \ +# RUN: | llvm-objdump -d --mattr=+xtheadvdot - \ +# RUN: | FileCheck %s --check-prefix=CHECK-INST +# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+xtheadvdot %s \ +# RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN + +th.vmaqau.vv v8, v20, v4, v0.t +# CHECK-INST: th.vmaqau.vv v8, v20, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x88] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 88 + +th.vmaqau.vv v8, v20, v4 +# CHECK-INST: th.vmaqau.vv v8, v20, v4 +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x8a] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 8a + +th.vmaqau.vx v8, a0, v4, v0.t +# CHECK-INST: th.vmaqau.vx v8, a0, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x45,0x8c] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 8c + +th.vmaqau.vx v8, a0, v4 +# CHECK-INST: th.vmaqau.vx v8, a0, v4 +# CHECK-ENCODING: [0x0b,0x64,0x45,0x8e] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 8e + +th.vmaqa.vv v8, v20, v4, v0.t +# CHECK-INST: th.vmaqa.vv v8, v20, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x80] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 80 + +th.vmaqa.vv v8, v20, v4 +# CHECK-INST: th.vmaqa.vv v8, v20, v4 +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x82] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 82 + +th.vmaqa.vx v8, a0, v4, v0.t +# CHECK-INST: th.vmaqa.vx v8, a0, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x45,0x84] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 84 + +th.vmaqa.vx v8, a0, v4 +# CHECK-INST: th.vmaqa.vx v8, a0, v4 +# CHECK-ENCODING: [0x0b,0x64,0x45,0x86] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 86 + +th.vmaqasu.vv v8, v20, v4, v0.t +# CHECK-INST: th.vmaqasu.vv v8, v20, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x90] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 90 + +th.vmaqasu.vv v8, v20, v4 +# CHECK-INST: th.vmaqasu.vv v8, v20, v4 +# CHECK-ENCODING: [0x0b,0x64,0x4a,0x92] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 4a 92 + +th.vmaqasu.vx v8, a0, v4, v0.t +# CHECK-INST: th.vmaqasu.vx v8, a0, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x45,0x94] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 94 + +th.vmaqasu.vx v8, a0, v4 +# CHECK-INST: th.vmaqasu.vx v8, a0, v4 +# CHECK-ENCODING: [0x0b,0x64,0x45,0x96] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 96 + +th.vmaqaus.vx v8, a0, v4, v0.t +# CHECK-INST: th.vmaqaus.vx v8, a0, v4, v0.t +# CHECK-ENCODING: [0x0b,0x64,0x45,0x9c] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 9c + +th.vmaqaus.vx v8, a0, v4 +# CHECK-INST: th.vmaqaus.vx v8, a0, v4 +# CHECK-ENCODING: [0x0b,0x64,0x45,0x9e] +# CHECK-ERROR: instruction requires the following: 'xtheadvdot' (T-Head Vector Extensions for Dot){{$}} +# CHECK-UNKNOWN: 0b 64 45 9e