Skip to content

Commit 56081a5

Browse files
author
brs
committed
[RISCV][MC] MC layer support for the experimental zalasr extension
1 parent bf2e05c commit 56081a5

File tree

13 files changed

+324
-0
lines changed

13 files changed

+324
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
// CHECK-NOT: __riscv_smaia {{.*$}}
117117
// CHECK-NOT: __riscv_ssaia {{.*$}}
118118
// CHECK-NOT: __riscv_zacas {{.*$}}
119+
// CHECK-NOT: __riscv_zalasr {{.*$}}
119120
// CHECK-NOT: __riscv_zfa {{.*$}}
120121
// CHECK-NOT: __riscv_zfbfmin {{.*$}}
121122
// CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1039,6 +1040,14 @@
10391040
// RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
10401041
// CHECK-ZACAS-EXT: __riscv_zacas 1000000{{$}}
10411042

1043+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1044+
// RUN: -march=rv32i_zalasr1p0 -x c -E -dM %s \
1045+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
1046+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1047+
// RUN: -march=rv64i_zalasr1p0 -x c -E -dM %s \
1048+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
1049+
// CHECK-ZALASR-EXT: __riscv_zalasr 1000000{{$}}
1050+
10421051
// RUN: %clang --target=riscv32-unknown-linux-gnu \
10431052
// RUN: -march=rv32izfa -x c -E -dM %s \
10441053
// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ The primary goal of experimental support is to assist in the process of ratifica
193193
``experimental-zacas``
194194
LLVM implements the `1.0-rc1 draft specification <https://github.com/riscv/riscv-zacas/releases/tag/v1.0-rc1>`_.
195195

196+
``experimental-zalasr``
197+
LLVM implements the `most recent specification <https://github.com/mehnadnerd/riscv-zalasr>`_.
198+
196199
``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
197200
LLVM implements assembler support for the `0.8.0 draft specification <https://github.com/riscv/riscv-bfloat16/releases/tag/20230629>`_.
198201

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
171171
// NOTE: This table should be sorted alphabetically by extension name.
172172
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
173173
{"zacas", RISCVExtensionVersion{1, 0}},
174+
{"zalasr", RISCVExtensionVersion{1, 0}},
174175

175176
{"zfbfmin", RISCVExtensionVersion{0, 8}},
176177

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,13 @@ def HasStdExtZacas : Predicate<"Subtarget->hasStdExtZacas()">,
715715
AssemblerPredicate<(all_of FeatureStdExtZacas),
716716
"'Zacas' (Atomic Compare-And-Swap Instructions)">;
717717

718+
def FeatureStdExtZalasr
719+
: SubtargetFeature<"experimental-zalasr", "HasStdExtZalasr", "true",
720+
"'Zalasr' (Load-Acquire and Store-Release Instructions)">;
721+
def HasStdExtZalasr : Predicate<"Subtarget->hasStdExtZalasr()">,
722+
AssemblerPredicate<(all_of FeatureStdExtZalasr),
723+
"'Zalasr' (Load-Acquire and Store-Release Instructions)">;
724+
718725
//===----------------------------------------------------------------------===//
719726
// Vendor extensions
720727
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,7 @@ include "RISCVInstrInfoM.td"
20952095

20962096
// Atomic
20972097
include "RISCVInstrInfoA.td"
2098+
include "RISCVInstrInfoZalasr.td"
20982099

20992100
// Scalar FP
21002101
include "RISCVInstrInfoF.td"
Lines changed: 66 additions & 0 deletions
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_AQ : LAQ_r_aq_rl<0b000, "lb">;
50+
defm LH_AQ : LAQ_r_aq_rl<0b001, "lh">;
51+
defm LW_AQ : LAQ_r_aq_rl<0b010, "lw">;
52+
defm SB_RL : SRL_r_aq_rl<0b000, "sb">;
53+
defm SH_RL : SRL_r_aq_rl<0b001, "sh">;
54+
defm SW_RL : SRL_r_aq_rl<0b010, "sw">;
55+
} // Predicates = [HasStdExtZalasr]
56+
57+
let Predicates = [HasStdExtZalasr, IsRV64] in {
58+
defm LD_AQ : LAQ_r_aq_rl<0b011, "ld">;
59+
defm SD_RL : 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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFWMA %s
9191
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s
9292
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s
93+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s
9394

9495
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
9596
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -180,6 +181,7 @@
180181
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFWMA %s
181182
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV64ZACAS %s
182183
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV64ZICFILP %s
184+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV64ZALASR %s
183185

184186
; CHECK: .attribute 4, 16
185187

@@ -272,6 +274,7 @@
272274
; RV32ZVFBFWMA: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
273275
; RV32ZACAS: .attribute 5, "rv32i2p1_a2p1_zacas1p0"
274276
; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p2"
277+
; RV32ZALASR: .attribute 5, "rv32i2p1_zalasr1p0"
275278

276279
; RV64M: .attribute 5, "rv64i2p1_m2p0"
277280
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -361,6 +364,7 @@
361364
; RV64ZVFBFWMA: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
362365
; RV64ZACAS: .attribute 5, "rv64i2p1_a2p1_zacas1p0"
363366
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p2"
367+
; RV64ZALASR: .attribute 5, "rv64i2p1_zalasr1p0"
364368

365369
define i32 @addi(i32 %a) {
366370
%1 = add i32 %a, 1

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@
288288
.attribute arch, "rv32izacas1p0"
289289
# CHECK: attribute 5, "rv32i2p1_a2p1_zacas1p0"
290290

291+
.attribute arch, "rv32izalasr1p0"
292+
# CHECK: attribute 5, "rv32i2p1_zalasr1p0"
293+
291294
.attribute arch, "rv32i_xcvalu"
292295
# CHECK: attribute 5, "rv32i2p1_xcvalu1p0"
293296

Lines changed: 40 additions & 0 deletions
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

Lines changed: 70 additions & 0 deletions
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)
Lines changed: 28 additions & 0 deletions
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)