Skip to content

Commit 1612df1

Browse files
author
brs
committed
[RISCV][MC] MC layer support for the experimental zalasr extension
1 parent a3bbe62 commit 1612df1

13 files changed

+324
-0
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143

144144
// CHECK-NOT: __riscv_zaamo {{.*$}}
145145
// CHECK-NOT: __riscv_zacas {{.*$}}
146+
// CHECK-NOT: __riscv_zalasr {{.*$}}
146147
// CHECK-NOT: __riscv_zalrsc {{.*$}}
147148
// CHECK-NOT: __riscv_zcmop {{.*$}}
148149
// CHECK-NOT: __riscv_zfbfmin {{.*$}}
@@ -1325,6 +1326,14 @@
13251326
// RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
13261327
// CHECK-ZACAS-EXT: __riscv_zacas 1000000{{$}}
13271328

1329+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1330+
// RUN: -march=rv32i_zalasr0p1 -E -dM %s \
1331+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
1332+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1333+
// RUN: -march=rv64i_zalasr0p1 -E -dM %s \
1334+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
1335+
// CHECK-ZALASR-EXT: __riscv_zalasr 1000{{$}}
1336+
13281337
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
13291338
// RUN: -march=rv32i_zalrsc0p2 -E -dM %s \
13301339
// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s

llvm/docs/RISCVUsage.rst

+3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ The primary goal of experimental support is to assist in the process of ratifica
228228
``experimental-zacas``
229229
LLVM implements the `1.0-rc1 draft specification <https://github.com/riscv/riscv-zacas/releases/tag/v1.0-rc1>`_.
230230

231+
``experimental-zalasr``
232+
LLVM implements the `0.0.5 draft specification <https://github.com/mehnadnerd/riscv-zalasr>`_.
233+
231234
``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
232235
LLVM implements assembler support for the `1.0.0-rc2 specification <https://github.com/riscv/riscv-bfloat16/releases/tag/v59042fc71c31a9bcb2f1957621c960ed36fac401>`_.
233236

llvm/lib/Support/RISCVISAInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
194194
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
195195
{"zaamo", {0, 2}},
196196
{"zacas", {1, 0}},
197+
{"zalasr", {0, 1}},
197198
{"zalrsc", {0, 2}},
198199

199200
{"zcmop", {0, 2}},

llvm/lib/Target/RISCV/RISCVFeatures.td

+7
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,13 @@ def FeatureStdExtSvpbmt
797797
: SubtargetFeature<"svpbmt", "HasStdExtSvpbmt", "true",
798798
"'Svpbmt' (Page-Based Memory Types)">;
799799

800+
def FeatureStdExtZalasr
801+
: SubtargetFeature<"experimental-zalasr", "HasStdExtZalasr", "true",
802+
"'Zalasr' (Load-Acquire and Store-Release Instructions)">;
803+
def HasStdExtZalasr : Predicate<"Subtarget->hasStdExtZalasr()">,
804+
AssemblerPredicate<(all_of FeatureStdExtZalasr),
805+
"'Zalasr' (Load-Acquire and Store-Release Instructions)">;
806+
800807
//===----------------------------------------------------------------------===//
801808
// Vendor extensions
802809
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfo.td

+1
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ include "RISCVInstrInfoM.td"
21442144
// Atomic
21452145
include "RISCVInstrInfoA.td"
21462146
include "RISCVInstrInfoZa.td"
2147+
include "RISCVInstrInfoZalasr.td"
21472148

21482149
// Scalar FP
21492150
include "RISCVInstrInfoF.td"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===-- RISCVInstrInfoZalasr.td - RISC-V 'Zalasr' instructions -------*- 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 RISC-V instructions from the Zalasr (Load-Acquire
10+
// and Store-Release) extension
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
//===----------------------------------------------------------------------===//
15+
// Instruction class templates
16+
//===----------------------------------------------------------------------===//
17+
18+
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
19+
class LAQ_r<bit aq, bit rl, bits<3> funct3, string opcodestr>
20+
: RVInstRAtomic<0b00110, aq, rl, funct3, OPC_AMO,
21+
(outs GPR:$rd), (ins GPRMemZeroOffset:$rs1),
22+
opcodestr, "$rd, $rs1"> {
23+
let rs2 = 0;
24+
}
25+
26+
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
27+
class SRL_r<bit aq, bit rl, bits<3> funct3, string opcodestr>
28+
: RVInstRAtomic<0b00111, aq, rl, funct3, OPC_AMO,
29+
(outs ), (ins GPRMemZeroOffset:$rs1, GPR:$rs2),
30+
opcodestr, "$rs2, $rs1"> {
31+
let rd = 0;
32+
}
33+
multiclass LAQ_r_aq_rl<bits<3> funct3, string opcodestr> {
34+
def _AQ : LAQ_r<1, 0, funct3, opcodestr # ".aq">;
35+
def _AQ_RL : LAQ_r<1, 1, funct3, opcodestr # ".aqrl">;
36+
}
37+
38+
multiclass SRL_r_aq_rl<bits<3> funct3, string opcodestr> {
39+
def _RL : SRL_r<0, 1, funct3, opcodestr # ".rl">;
40+
def _AQ_RL : SRL_r<1, 1, funct3, opcodestr # ".aqrl">;
41+
}
42+
43+
//===----------------------------------------------------------------------===//
44+
// Instructions
45+
//===----------------------------------------------------------------------===//
46+
47+
48+
let Predicates = [HasStdExtZalasr] in {
49+
defm LB : LAQ_r_aq_rl<0b000, "lb">;
50+
defm LH : LAQ_r_aq_rl<0b001, "lh">;
51+
defm LW : LAQ_r_aq_rl<0b010, "lw">;
52+
defm SB : SRL_r_aq_rl<0b000, "sb">;
53+
defm SH : SRL_r_aq_rl<0b001, "sh">;
54+
defm SW : SRL_r_aq_rl<0b010, "sw">;
55+
} // Predicates = [HasStdExtZalasr]
56+
57+
let Predicates = [HasStdExtZalasr, IsRV64] in {
58+
defm LD : LAQ_r_aq_rl<0b011, "ld">;
59+
defm SD : SRL_r_aq_rl<0b011, "sd">;
60+
} // Predicates = [HasStdExtZalasr, IsRV64]
61+
62+
//===----------------------------------------------------------------------===//
63+
// Pseudo-instructions and codegen patterns
64+
//===----------------------------------------------------------------------===//
65+
66+
// Future work: Work out mapping with leading/trailing fences, &c

llvm/test/CodeGen/RISCV/attributes.ll

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s
9898
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
9999
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s
100+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s
100101

101102
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
102103
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -201,6 +202,7 @@
201202
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV64ZACAS %s
202203
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV64ZALRSC %s
203204
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV64ZICFILP %s
205+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV64ZALASR %s
204206

205207
; CHECK: .attribute 4, 16
206208

@@ -298,6 +300,7 @@
298300
; RV32ZVFBFWMA: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin1p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvfbfwma1p0_zvl32b1p0"
299301
; RV32ZAAMO: .attribute 5, "rv32i2p1_zaamo0p2"
300302
; RV32ZACAS: .attribute 5, "rv32i2p1_a2p1_zacas1p0"
303+
; RV32ZALASR: .attribute 5, "rv32i2p1_zalasr0p1"
301304
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc0p2"
302305
; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p4"
303306

@@ -401,6 +404,7 @@
401404
; RV64ZVFBFWMA: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvfbfwma1p0_zvl32b1p0"
402405
; RV64ZAAMO: .attribute 5, "rv64i2p1_zaamo0p2"
403406
; RV64ZACAS: .attribute 5, "rv64i2p1_a2p1_zacas1p0"
407+
; RV64ZALASR: .attribute 5, "rv64i2p1_zalasr0p1"
404408
; RV64ZALRSC: .attribute 5, "rv64i2p1_zalrsc0p2"
405409
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p4"
406410

llvm/test/MC/RISCV/attribute-arch.s

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@
309309
.attribute arch, "rv32izacas1p0"
310310
# CHECK: attribute 5, "rv32i2p1_a2p1_zacas1p0"
311311

312+
.attribute arch, "rv32izalasr0p1"
313+
# CHECK: attribute 5, "rv32i2p1_zalasr0p1"
314+
312315
.attribute arch, "rv32i_xcvalu"
313316
# CHECK: attribute 5, "rv32i2p1_xcvalu1p0"
314317

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zalasr < %s 2>&1 | FileCheck -check-prefixes=CHECK %s
2+
3+
# CHECK: error: instruction requires the following: RV64I Base Instruction Set{{$}}
4+
ld.aq a1, (t0)
5+
6+
# CHECK: error: instruction requires the following: RV64I Base Instruction Set{{$}}
7+
ld.aqrl a1, (t0)
8+
9+
# CHECK: error: instruction requires the following: RV64I Base Instruction Set{{$}}
10+
sd.rl a1, (t0)
11+
12+
# CHECK: error: instruction requires the following: RV64I Base Instruction Set{{$}}
13+
sd.aqrl a1, (t0)
14+
15+
# CHECK: error: unrecognized instruction mnemonic
16+
lw. a1, (t0)
17+
18+
# CHECK: error: unrecognized instruction mnemonic
19+
lw.rl t3, 0(t5)
20+
21+
# CHECK: error: unrecognized instruction mnemonic
22+
lh.rlaq t4, (t6)
23+
24+
# CHECK: error: unrecognized instruction mnemonic
25+
sb. a1, (t0)
26+
27+
# CHECK: error: unrecognized instruction mnemonic
28+
sh.aq t3, 0(t5)
29+
30+
# CHECK: error: unrecognized instruction mnemonic
31+
sh.rlaq t4, (t6)
32+
33+
# CHECK: error: optional integer offset must be 0
34+
lw.aq zero, 1(a0)
35+
36+
# CHECK: error: optional integer offset must be 0
37+
sw.rl t1, 2(s0)
38+
39+
# CHECK: error: optional integer offset must be 0
40+
sb.aqrl sp, 3(s2)

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

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zalasr -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zalasr < %s \
4+
# RUN: | llvm-objdump --mattr=+experimental-zalasr -M no-aliases -d -r - \
5+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
6+
#
7+
# RUN: not llvm-mc -triple riscv32 \
8+
# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
9+
# RUN: | FileCheck --check-prefixes=CHECK-NO-EXT %s
10+
11+
# CHECK-ASM-AND-OBJ: lb.aq t1, (a0)
12+
# CHECK-ASM: encoding: [0x2f,0x03,0x05,0x34]
13+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
14+
lb.aq t1, 0(a0)
15+
16+
# CHECK-ASM-AND-OBJ: lh.aq t1, (a0)
17+
# CHECK-ASM: encoding: [0x2f,0x13,0x05,0x34]
18+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
19+
lh.aq t1, 0(a0)
20+
21+
# CHECK-ASM-AND-OBJ: lw.aq t1, (a0)
22+
# CHECK-ASM: encoding: [0x2f,0x23,0x05,0x34]
23+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
24+
lw.aq t1, (a0)
25+
26+
# CHECK-ASM-AND-OBJ: lb.aqrl t1, (a0)
27+
# CHECK-ASM: encoding: [0x2f,0x03,0x05,0x36]
28+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
29+
lb.aqrl t1, 0(a0)
30+
31+
# CHECK-ASM-AND-OBJ: lh.aqrl t1, (a0)
32+
# CHECK-ASM: encoding: [0x2f,0x13,0x05,0x36]
33+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
34+
lh.aqrl t1, (a0)
35+
36+
# CHECK-ASM-AND-OBJ: lw.aqrl t1, (a0)
37+
# CHECK-ASM: encoding: [0x2f,0x23,0x05,0x36]
38+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
39+
lw.aqrl t1, (a0)
40+
41+
42+
# CHECK-ASM-AND-OBJ: sb.rl t1, (a0)
43+
# CHECK-ASM: encoding: [0x2f,0x00,0x65,0x3a]
44+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
45+
sb.rl t1, (a0)
46+
47+
# CHECK-ASM-AND-OBJ: sh.rl t1, (a0)
48+
# CHECK-ASM: encoding: [0x2f,0x10,0x65,0x3a]
49+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
50+
sh.rl t1, 0(a0)
51+
52+
# CHECK-ASM-AND-OBJ: sw.rl t1, (a0)
53+
# CHECK-ASM: encoding: [0x2f,0x20,0x65,0x3a]
54+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
55+
sw.rl t1, (a0)
56+
57+
# CHECK-ASM-AND-OBJ: sb.aqrl t1, (a0)
58+
# CHECK-ASM: encoding: [0x2f,0x00,0x65,0x3e]
59+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
60+
sb.aqrl t1, (a0)
61+
62+
# CHECK-ASM-AND-OBJ: sh.aqrl t1, (a0)
63+
# CHECK-ASM: encoding: [0x2f,0x10,0x65,0x3e]
64+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
65+
sh.aqrl t1, 0(a0)
66+
67+
# CHECK-ASM-AND-OBJ: sw.aqrl t1, (a0)
68+
# CHECK-ASM: encoding: [0x2f,0x20,0x65,0x3e]
69+
# CHECK-NO-EXT: error: instruction requires the following: 'Zalasr' (Load-Acquire and Store-Release Instructions){{$}}
70+
sw.aqrl t1, 0(a0)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zalasr < %s 2>&1 | FileCheck -check-prefixes=CHECK %s
2+
3+
# CHECK: error: unrecognized instruction mnemonic
4+
lw. a1, (t0)
5+
6+
# CHECK: error: unrecognized instruction mnemonic
7+
lw.rl t3, 0(t5)
8+
9+
# CHECK: error: unrecognized instruction mnemonic
10+
lh.rlaq t4, (t6)
11+
12+
# CHECK: error: unrecognized instruction mnemonic
13+
sb. a1, (t0)
14+
15+
# CHECK: error: unrecognized instruction mnemonic
16+
sh.aq t3, 0(t5)
17+
18+
# CHECK: error: unrecognized instruction mnemonic
19+
sh.rlaq t4, (t6)
20+
21+
# CHECK: error: optional integer offset must be 0
22+
lw.aq zero, 1(a0)
23+
24+
# CHECK: error: optional integer offset must be 0
25+
sw.rl t1, 2(s0)
26+
27+
# CHECK: error: optional integer offset must be 0
28+
sb.aqrl sp, 3(s2)

0 commit comments

Comments
 (0)