Skip to content

Commit

Permalink
[RISCV] Add H extension
Browse files Browse the repository at this point in the history
`h` was the prefix of multi-letter extension name, but it become a
extension name in later RISC-V isa spec.

Fortunately we don't have any extension really defined is prefixed
with `h`, so we can just change that.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D136817
  • Loading branch information
kito-cheng committed Jan 10, 2023
1 parent 915f2f1 commit f4c887c
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 148 deletions.
7 changes: 7 additions & 0 deletions clang/test/Preprocessor/riscv-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
// CHECK-NOT: __riscv_xventanacondops
// CHECK-NOT: __riscv_zcd
// CHECK-NOT: __riscv_zcf
// CHECK-NOT: __riscv_h

// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
Expand Down Expand Up @@ -449,6 +450,12 @@
// RUN: -o - | FileCheck --check-prefix=CHECK-SVINVAL-EXT %s
// CHECK-SVINVAL-EXT: __riscv_svinval 1000000{{$}}

// RUN: %clang -target riscv32 -march=rv32ih -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-H-EXT %s
// RUN: %clang -target riscv64 -march=rv64ih -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-H-EXT %s
// CHECK-H-EXT: __riscv_h 1000000{{$}}

// RUN: %clang -target riscv64 -march=rv64ixventanacondops -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-XVENTANACONDOPS-EXT %s
// CHECK-XVENTANACONDOPS-EXT: __riscv_xventanacondops 1000000{{$}}
Expand Down
1 change: 1 addition & 0 deletions llvm/docs/RISCVUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ on support follow.
``C`` Supported
``D`` Supported
``F`` Supported
``H`` Assembly Support
``M`` Supported
``Svinval`` Assembly Support
``Svnapot`` Assembly Support
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/Support/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct RISCVSupportedExtension {

} // end anonymous namespace

static constexpr StringLiteral AllStdExts = "mafdqlcbkjtpvn";
static constexpr StringLiteral AllStdExts = "mafdqlcbkjtpvnh";

static const RISCVSupportedExtension SupportedExtensions[] = {
{"i", RISCVExtensionVersion{2, 0}},
Expand All @@ -48,6 +48,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
{"d", RISCVExtensionVersion{2, 0}},
{"c", RISCVExtensionVersion{2, 0}},

{"h", RISCVExtensionVersion{1, 0}},

{"zihintpause", RISCVExtensionVersion{2, 0}},

{"zfhmin", RISCVExtensionVersion{1, 0}},
Expand Down Expand Up @@ -284,17 +286,14 @@ static int multiLetterExtensionRank(const std::string &ExtName) {
case 's':
HighOrder = 0;
break;
case 'h':
HighOrder = 1;
break;
case 'z':
HighOrder = 2;
HighOrder = 1;
// `z` extension must be sorted by canonical order of second letter.
// e.g. zmx has higher rank than zax.
LowOrder = singleLetterExtensionRank(ExtName[1]);
break;
case 'x':
HighOrder = 3;
HighOrder = 2;
break;
default:
llvm_unreachable("Unknown prefix for multi-char extension");
Expand Down Expand Up @@ -611,8 +610,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,

// The order is OK, then push it into features.
// TODO: Use version number when setting target features
// Currently LLVM supports only "mafdcv".
StringRef SupportedStandardExtension = "mafdcv";
// Currently LLVM supports only "mafdcvh".
StringRef SupportedStandardExtension = "mafdcvh";
if (!SupportedStandardExtension.contains(C))
return createStringError(errc::invalid_argument,
"unsupported standard user-level extension '%c'",
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/RISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def HasStdExtD : Predicate<"Subtarget->hasStdExtD()">,
AssemblerPredicate<(all_of FeatureStdExtD),
"'D' (Double-Precision Floating-Point)">;

def FeatureStdExtH
: SubtargetFeature<"h", "HasStdExtH", "true",
"'H' (Hypervisor)">;

def HasStdExtH : Predicate<"Subtarget->hasStdExtH()">,
AssemblerPredicate<(all_of FeatureStdExtH),
"'H' (Hypervisor)">;

def FeatureStdExtZihintpause
: SubtargetFeature<"zihintpause", "HasStdExtZihintpause", "true",
"'zihintpause' (Pause Hint)">;
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ def HINVAL_GVMA : Priv_rr<"hinval.gvma", 0b0110011>, Sched<[]>;
} // Predicates = [HasStdExtSvinval]

def SFENCE_VMA : Priv_rr<"sfence.vma", 0b0001001>, Sched<[]>;

let Predicates = [HasStdExtH] in {
def HFENCE_VVMA : Priv_rr<"hfence.vvma", 0b0010001>, Sched<[]>;
def HFENCE_GVMA : Priv_rr<"hfence.gvma", 0b0110001>, Sched<[]>;

Expand All @@ -846,8 +848,8 @@ def HLVX_WU : HLoad_r<0b0110100, 0b00011, "hlvx.wu">, Sched<[]>;
def HSV_B : HStore_rr<0b0110001, "hsv.b">, Sched<[]>;
def HSV_H : HStore_rr<0b0110011, "hsv.h">, Sched<[]>;
def HSV_W : HStore_rr<0b0110101, "hsv.w">, Sched<[]>;

let Predicates = [IsRV64] in {
}
let Predicates = [IsRV64, HasStdExtH] in {
def HLV_WU : HLoad_r<0b0110100, 0b00001, "hlv.wu">, Sched<[]>;
def HLV_D : HLoad_r<0b0110110, 0b00000, "hlv.d">, Sched<[]>;
def HSV_D : HStore_rr<0b0110111, "hsv.d">, Sched<[]>;
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/CodeGen/RISCV/attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
; RUN: llc -mtriple=riscv32 -mattr=+zbc %s -o - | FileCheck --check-prefix=RV32ZBC %s
; RUN: llc -mtriple=riscv32 -mattr=+zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
; RUN: llc -mtriple=riscv32 -mattr=+v %s -o - | FileCheck --check-prefix=RV32V %s
; RUN: llc -mtriple=riscv32 -mattr=+h %s -o - | FileCheck --check-prefix=RV32H %s
; RUN: llc -mtriple=riscv32 -mattr=+zbb,+zfh,+v,+f %s -o - | FileCheck --check-prefix=RV32COMBINED %s
; RUN: llc -mtriple=riscv32 -mattr=+zbkb %s -o - | FileCheck --check-prefix=RV32ZBKB %s
; RUN: llc -mtriple=riscv32 -mattr=+zbkc %s -o - | FileCheck --check-prefix=RV32ZBKC %s
Expand Down Expand Up @@ -57,6 +58,7 @@
; RUN: llc -mtriple=riscv64 -mattr=+zbc %s -o - | FileCheck --check-prefix=RV64ZBC %s
; RUN: llc -mtriple=riscv64 -mattr=+zbs %s -o - | FileCheck --check-prefix=RV64ZBS %s
; RUN: llc -mtriple=riscv64 -mattr=+v %s -o - | FileCheck --check-prefix=RV64V %s
; RUN: llc -mtriple=riscv64 -mattr=+h %s -o - | FileCheck --check-prefix=RV64H %s
; RUN: llc -mtriple=riscv64 -mattr=+zbb,+zfh,+v,+f %s -o - | FileCheck --check-prefix=RV64COMBINED %s
; RUN: llc -mtriple=riscv64 -mattr=+zbkb %s -o - | FileCheck --check-prefix=RV64ZBKB %s
; RUN: llc -mtriple=riscv64 -mattr=+zbkc %s -o - | FileCheck --check-prefix=RV64ZBKC %s
Expand Down Expand Up @@ -102,6 +104,7 @@
; RV32ZBC: .attribute 5, "rv32i2p0_zbc1p0"
; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
; RV32V: .attribute 5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
; RV32H: .attribute 5, "rv32i2p0_h1p0"
; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_d2p0_v1p0_zfh1p0_zbb1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
; RV32ZBKB: .attribute 5, "rv32i2p0_zbkb1p0"
; RV32ZBKC: .attribute 5, "rv32i2p0_zbkc1p0"
Expand Down Expand Up @@ -143,6 +146,7 @@
; RV64ZBC: .attribute 5, "rv64i2p0_zbc1p0"
; RV64ZBS: .attribute 5, "rv64i2p0_zbs1p0"
; RV64V: .attribute 5, "rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
; RV64H: .attribute 5, "rv64i2p0_h1p0"
; RV64COMBINED: .attribute 5, "rv64i2p0_f2p0_d2p0_v1p0_zfh1p0_zbb1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
; RV64ZBKB: .attribute 5, "rv64i2p0_zbkb1p0"
; RV64ZBKC: .attribute 5, "rv64i2p0_zbkc1p0"
Expand Down
50 changes: 0 additions & 50 deletions llvm/test/MC/RISCV/priv-aliases-valid.s

This file was deleted.

72 changes: 0 additions & 72 deletions llvm/test/MC/RISCV/priv-valid.s
Original file line number Diff line number Diff line change
Expand Up @@ -48,75 +48,3 @@ sfence.w.inval
# CHECK-INST: sfence.inval.ir
# CHECK: encoding: [0x73,0x00,0x10,0x18]
sfence.inval.ir

# CHECK-INST: hfence.vvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x22]
hfence.vvma zero, zero

# CHECK-INST: hfence.vvma a0, a1
# CHECK: encoding: [0x73,0x00,0xb5,0x22]
hfence.vvma a0, a1

# CHECK-INST: hfence.gvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x62]
hfence.gvma zero, zero

# CHECK-INST: hfence.gvma a0, a1
# CHECK: encoding: [0x73,0x00,0xb5,0x62]
hfence.gvma a0, a1

# CHECK-INST: hinval.vvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x26]
hinval.vvma zero, zero

# CHECK-INST: hinval.vvma a0, a1
# CHECK: encoding: [0x73,0x00,0xb5,0x26]
hinval.vvma a0, a1

# CHECK-INST: hinval.gvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x66]
hinval.gvma zero, zero

# CHECK-INST: hinval.gvma a0, a1
# CHECK: encoding: [0x73,0x00,0xb5,0x66]
hinval.gvma a0, a1

# CHECK-INST: hlv.b a0, (a1)
# CHECK: encoding: [0x73,0xc5,0x05,0x60]
hlv.b a0, (a1)

# CHECK-INST: hlv.bu a0, (a1)
# CHECK: encoding: [0x73,0xc5,0x15,0x60]
hlv.bu a0, (a1)

# CHECK-INST: hlv.h a1, (a2)
# CHECK: encoding: [0xf3,0x45,0x06,0x64]
hlv.h a1, (a2)

# CHECK-INST: hlv.hu a1, (a1)
# CHECK: encoding: [0xf3,0xc5,0x15,0x64]
hlv.hu a1, (a1)

# CHECK-INST: hlvx.hu a1, (a2)
# CHECK: encoding: [0xf3,0x45,0x36,0x64]
hlvx.hu a1, (a2)

# CHECK-INST: hlv.w a2, (a2)
# CHECK: encoding: [0x73,0x46,0x06,0x68]
hlv.w a2, (a2)

# CHECK-INST: hlvx.wu a2, (a3)
# CHECK: encoding: [0x73,0xc6,0x36,0x68]
hlvx.wu a2, (a3)

# CHECK-INST: hsv.b a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x62]
hsv.b a0, (a1)

# CHECK-INST: hsv.h a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x66]
hsv.h a0, (a1)

# CHECK-INST: hsv.w a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x6a]
hsv.w a0, (a1)
12 changes: 12 additions & 0 deletions llvm/test/MC/RISCV/rv32h-invalid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RUN: not llvm-mc -triple riscv32 -mattr=+h < %s 2>&1 \
# RUN: | FileCheck %s -check-prefixes=CHECK-OFFSET
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 \
# RUN: | FileCheck %s -check-prefixes=CHECK,CHECK-OFFSET

hfence.vvma zero, zero # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor)

hlv.h a0, 0(a1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor)

hlv.wu a0, 0(a1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor), RV64I Base Instruction Set

hlv.b a0, 100(a1) # CHECK-OFFSET: :[[@LINE]]:13: error: optional integer offset must be 0
70 changes: 70 additions & 0 deletions llvm/test/MC/RISCV/rv32ih-aliases-valid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# RUN: llvm-mc %s -triple=riscv32 -mattr=+h -riscv-no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST,CHECK-ALIAS-INST %s
# RUN: llvm-mc %s -triple=riscv64 -mattr=+h -riscv-no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST,CHECK-ALIAS-INST %s
# RUN: llvm-mc -filetype=obj -mattr=+h -triple riscv32 < %s \
# RUN: | llvm-objdump --mattr=+h -M no-aliases -d - \
# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-NOALIAS-INST %s
# RUN: llvm-mc -filetype=obj -mattr=+h -triple riscv64 < %s \
# RUN: | llvm-objdump --mattr=+h -M no-aliases -d - \
# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-NOALIAS-INST %s

# CHECK-ALIAS-INST: hfence.gvma
# CHECK-NOALIAS-INST: hfence.gvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x62]
hfence.gvma

# CHECK-ALIAS-INST: hfence.gvma a0
# CHECK-NOALIAS-INST: hfence.gvma a0, zero
# CHECK: encoding: [0x73,0x00,0x05,0x62]
hfence.gvma a0

# CHECK-ALIAS-INST: hfence.vvma
# CHECK-NOALIAS-INST: hfence.vvma zero, zero
# CHECK: encoding: [0x73,0x00,0x00,0x22]
hfence.vvma

# CHECK-ALIAS-INST: hfence.vvma a0
# CHECK-NOALIAS-INST: hfence.vvma a0, zero
# CHECK: encoding: [0x73,0x00,0x05,0x22]
hfence.vvma a0

# CHECK-INST: hlv.b a0, (a1)
# CHECK: encoding: [0x73,0xc5,0x05,0x60]
hlv.b a0, 0(a1)

# CHECK-INST: hlv.bu a0, (a1)
# CHECK: encoding: [0x73,0xc5,0x15,0x60]
hlv.bu a0, 0(a1)

# CHECK-INST: hlv.h a1, (a2)
# CHECK: encoding: [0xf3,0x45,0x06,0x64]
hlv.h a1, 0(a2)

# CHECK-INST: hlv.hu a1, (a1)
# CHECK: encoding: [0xf3,0xc5,0x15,0x64]
hlv.hu a1, 0(a1)

# CHECK-INST: hlvx.hu a1, (a2)
# CHECK: encoding: [0xf3,0x45,0x36,0x64]
hlvx.hu a1, 0(a2)

# CHECK-INST: hlv.w a2, (a2)
# CHECK: encoding: [0x73,0x46,0x06,0x68]
hlv.w a2, 0(a2)

# CHECK-INST: hlvx.wu a2, (a3)
# CHECK: encoding: [0x73,0xc6,0x36,0x68]
hlvx.wu a2, 0(a3)

# CHECK-INST: hsv.b a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x62]
hsv.b a0, 0(a1)

# CHECK-INST: hsv.h a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x66]
hsv.h a0, 0(a1)

# CHECK-INST: hsv.w a0, (a1)
# CHECK: encoding: [0x73,0xc0,0xa5,0x6a]
hsv.w a0, 0(a1)
Loading

0 comments on commit f4c887c

Please sign in to comment.