Skip to content

Commit e4f1c52

Browse files
authored
[AArch64] Assembly support for the Armv9.5-A Memory System Extensions (#76237)
This implements assembly support for the Memory Systems Extensions introduced as part of the Armv9.5-A architecture version. The changes include: * New subtarget feature for FEAT_TLBIW. * New system registers for FEAT_HDBSS: * HDBSSBR_EL2 and HDBSSPROD_EL2. * New system registers for FEAT_HACDBS: * HACDBSBR_EL2 and HACDBSCONS_EL2. * New TLBI instructions for FEAT_TLBIW: * VMALLWS2E1(nXS), VMALLWS2E1IS(nXS) and VMALLWS2E1OS(nXS). * New system register for FEAT_FGWTE3: * FGWTE3_EL3.
1 parent 3736e1d commit e4f1c52

File tree

14 files changed

+153
-0
lines changed

14 files changed

+153
-0
lines changed

clang/test/Driver/aarch64-v95a.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@
2525
// RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | FileCheck -check-prefix=V95A-PAUTHLR %s
2626
// RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | FileCheck -check-prefix=V95A-PAUTHLR %s
2727
// V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+pauth-lr"
28+
29+
// RUN: %clang -target aarch64 -march=armv9.5a+tlbiw -### -c %s 2>&1 | FileCheck -check-prefix=V95A-TLBIW %s
30+
// RUN: %clang -target aarch64 -march=armv9.5-a+tlbiw -### -c %s 2>&1 | FileCheck -check-prefix=V95A-TLBIW %s
31+
// V95A-TLBIW: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+tlbiw"

llvm/include/llvm/TargetParser/AArch64TargetParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ enum ArchExtKind : unsigned {
175175
AEK_SMEFA64 = 71, // FEAT_SME_FA64
176176
AEK_CPA = 72, // FEAT_CPA
177177
AEK_PAUTHLR = 73, // FEAT_PAuth_LR
178+
AEK_TLBIW = 74, // FEAT_TLBIW
178179
AEK_NUM_EXTENSIONS
179180
};
180181
using ExtensionBitset = Bitset<AEK_NUM_EXTENSIONS>;
@@ -299,6 +300,7 @@ inline constexpr ExtensionInfo Extensions[] = {
299300
{"sme-fa64", AArch64::AEK_SMEFA64, "+sme-fa64", "-sme-fa64", FEAT_INIT, "", 0},
300301
{"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
301302
{"pauth-lr", AArch64::AEK_PAUTHLR, "+pauth-lr", "-pauth-lr", FEAT_INIT, "", 0},
303+
{"tlbiw", AArch64::AEK_TLBIW, "+tlbiw", "-tlbiw", FEAT_INIT, "", 0},
302304
// Special cases
303305
{"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", ExtensionInfo::MaxFMVPriority},
304306
};

llvm/lib/Target/AArch64/AArch64.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ def FeatureCPA : SubtargetFeature<"cpa", "HasCPA", "true",
630630
def FeaturePAuthLR : SubtargetFeature<"pauth-lr", "HasPAuthLR",
631631
"true", "Enable Armv9.5-A PAC enhancements (FEAT_PAuth_LR)">;
632632

633+
def FeatureTLBIW : SubtargetFeature<"tlbiw", "HasTLBIW", "true",
634+
"Enable ARMv9.5-A TLBI VMALL for Dirty State (FEAT_TLBIW)">;
635+
633636
//===----------------------------------------------------------------------===//
634637
// Architectures.
635638
//

llvm/lib/Target/AArch64/AArch64SystemOperands.td

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ defm : TLBI<"PAALLOS", 0b110, 0b1000, 0b0001, 0b100, 0>;
643643
defm : TLBI<"PAALL", 0b110, 0b1000, 0b0111, 0b100, 0>;
644644
}
645645

646+
// Armv9.5-A TLBI VMALL for Dirty State
647+
let Requires = ["AArch64::FeatureTLBIW"] in {
648+
// op1, CRn, CRm, op2, needsreg
649+
defm : TLBI<"VMALLWS2E1", 0b100, 0b1000, 0b0110, 0b010, 0>;
650+
defm : TLBI<"VMALLWS2E1IS", 0b100, 0b1000, 0b0010, 0b010, 0>;
651+
defm : TLBI<"VMALLWS2E1OS", 0b100, 0b1000, 0b0101, 0b010, 0>;
652+
}
653+
646654
//===----------------------------------------------------------------------===//
647655
// MRS/MSR (system register read/write) instruction options.
648656
//===----------------------------------------------------------------------===//
@@ -1951,3 +1959,17 @@ def : WOSysReg<"SPMZR_EL0", 0b10, 0b011, 0b1001, 0b1100, 0b100>;
19511959
// Op0 Op1 CRn CRm Op2
19521960
def : RWSysReg<"VDISR_EL3", 0b11, 0b110, 0b1100, 0b0001, 0b001>;
19531961
def : RWSysReg<"VSESR_EL3", 0b11, 0b110, 0b0101, 0b0010, 0b011>;
1962+
1963+
// v9.5a Hardware Dirty State Tracking Structure (FEAT_HDBSS)
1964+
// Op0 Op1 CRn CRm Op2
1965+
def : RWSysReg<"HDBSSBR_EL2", 0b11, 0b100, 0b0010, 0b0011, 0b010>;
1966+
def : RWSysReg<"HDBSSPROD_EL2", 0b11, 0b100, 0b0010, 0b0011, 0b011>;
1967+
1968+
// v9.5a Hardware Accelerator for Cleaning Dirty State (FEAT_HACDBS)
1969+
// Op0 Op1 CRn CRm Op2
1970+
def : RWSysReg<"HACDBSBR_EL2", 0b11, 0b100, 0b0010, 0b0011, 0b100>;
1971+
def : RWSysReg<"HACDBSCONS_EL2", 0b11, 0b100, 0b0010, 0b0011, 0b101>;
1972+
1973+
// v9.5a Fine Grained Write Trap EL3 (FEAT_FGWTE3)
1974+
// Op0 Op1 CRn CRm Op2
1975+
def : RWSysReg<"FGWTE3_EL3", 0b11, 0b110, 0b0001, 0b0001, 0b101>;

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,6 +3706,7 @@ static const struct Extension {
37063706
{"sme-f8f32", {AArch64::FeatureSMEF8F32}},
37073707
{"sme-fa64", {AArch64::FeatureSMEFA64}},
37083708
{"cpa", {AArch64::FeatureCPA}},
3709+
{"tlbiw", {AArch64::FeatureTLBIW}},
37093710
};
37103711

37113712
static void setRequiredFeatureString(FeatureBitset FBS, std::string &Str) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: llvm-mc -triple aarch64 -show-encoding < %s | FileCheck %s
2+
3+
mrs x0, FGWTE3_EL3
4+
// CHECK: mrs x0, FGWTE3_EL3 // encoding: [0xa0,0x11,0x3e,0xd5]
5+
msr FGWTE3_EL3, x0
6+
// CHECK: msr FGWTE3_EL3, x0 // encoding: [0xa0,0x11,0x1e,0xd5]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: llvm-mc -triple aarch64 -show-encoding < %s | FileCheck %s
2+
3+
mrs x0, HACDBSBR_EL2
4+
// CHECK: mrs x0, HACDBSBR_EL2 // encoding: [0x80,0x23,0x3c,0xd5]
5+
msr HACDBSBR_EL2, x0
6+
// CHECK: msr HACDBSBR_EL2, x0 // encoding: [0x80,0x23,0x1c,0xd5]
7+
8+
mrs x0, HACDBSCONS_EL2
9+
// CHECK: mrs x0, HACDBSCONS_EL2 // encoding: [0xa0,0x23,0x3c,0xd5]
10+
msr HACDBSCONS_EL2, x0
11+
// CHECK: msr HACDBSCONS_EL2, x0 // encoding: [0xa0,0x23,0x1c,0xd5]
12+

llvm/test/MC/AArch64/armv9.5a-hdbss.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: llvm-mc -triple aarch64 -show-encoding < %s | FileCheck %s
2+
3+
mrs x0, HDBSSBR_EL2
4+
// CHECK: mrs x0, HDBSSBR_EL2 // encoding: [0x40,0x23,0x3c,0xd5]
5+
msr HDBSSBR_EL2, x0
6+
// CHECK: msr HDBSSBR_EL2, x0 // encoding: [0x40,0x23,0x1c,0xd5]
7+
8+
mrs x0, HDBSSPROD_EL2
9+
// CHECK: mrs x0, HDBSSPROD_EL2 // encoding: [0x60,0x23,0x3c,0xd5]
10+
msr HDBSSPROD_EL2, x0
11+
// CHECK: msr HDBSSPROD_EL2, x0 // encoding: [0x60,0x23,0x1c,0xd5]
12+

llvm/test/MC/AArch64/armv9.5a-tlbiw.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: llvm-mc -triple aarch64 -show-encoding -mattr=+tlbiw -mattr=+xs < %s | FileCheck --check-prefix=CHECK-TLBIW --check-prefix=CHECK-XS %s
2+
// RUN: not llvm-mc -triple aarch64 -show-encoding -mattr=+tlbiw < %s 2> %t | FileCheck --check-prefix=CHECK-TLBIW %s && FileCheck --check-prefix=ERROR-NO-XS-TLBIW %s < %t
3+
// RUN: not llvm-mc -triple aarch64 < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-TLBIW --check-prefix=ERROR-NO-XS-TLBIW %s
4+
5+
tlbi VMALLWS2E1
6+
// CHECK-TLBIW: tlbi vmallws2e1 // encoding: [0x5f,0x86,0x0c,0xd5]
7+
// ERROR-NO-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1 requires: tlbiw
8+
9+
tlbi VMALLWS2E1IS
10+
// CHECK-TLBIW: tlbi vmallws2e1is // encoding: [0x5f,0x82,0x0c,0xd5]
11+
// ERROR-NO-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1IS requires: tlbiw
12+
13+
tlbi VMALLWS2E1OS
14+
// CHECK-TLBIW: tlbi vmallws2e1os // encoding: [0x5f,0x85,0x0c,0xd5]
15+
// ERROR-NO-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1OS requires: tlbiw
16+
17+
tlbi VMALLWS2E1nXS
18+
// CHECK-XS: tlbi vmallws2e1nxs // encoding: [0x5f,0x96,0x0c,0xd5]
19+
// ERROR-NO-XS-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1nXS requires: xs, tlbiw
20+
21+
tlbi VMALLWS2E1ISnXS
22+
// CHECK-XS: tlbi vmallws2e1isnxs // encoding: [0x5f,0x92,0x0c,0xd5]
23+
// ERROR-NO-XS-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1ISnXS requires: xs, tlbiw
24+
25+
tlbi VMALLWS2E1OSnXS
26+
// CHECK-XS: tlbi vmallws2e1osnxs // encoding: [0x5f,0x95,0x0c,0xd5]
27+
// ERROR-NO-XS-TLBIW: [[@LINE-2]]:6: error: TLBI VMALLWS2E1OSnXS requires: xs, tlbiw
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: llvm-mc -triple aarch64 -disassemble < %s | FileCheck %s
2+
3+
[0xa0,0x11,0x3e,0xd5]
4+
# CHECK: mrs x0, FGWTE3_EL3
5+
6+
[0xa0,0x11,0x1e,0xd5]
7+
# CHECK: msr FGWTE3_EL3, x0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: llvm-mc -triple aarch64 -disassemble < %s | FileCheck %s
2+
3+
[0x80,0x23,0x3c,0xd5]
4+
# CHECK: mrs x0, HACDBSBR_EL2
5+
6+
[0x80,0x23,0x1c,0xd5]
7+
# CHECK: msr HACDBSBR_EL2, x0
8+
9+
[0xa0,0x23,0x3c,0xd5]
10+
# CHECK: mrs x0, HACDBSCONS_EL2
11+
12+
[0xa0,0x23,0x1c,0xd5]
13+
# CHECK: msr HACDBSCONS_EL2, x0
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: llvm-mc -triple aarch64 -disassemble < %s | FileCheck %s
2+
3+
[0x40,0x23,0x3c,0xd5]
4+
# CHECK: mrs x0, HDBSSBR_EL2
5+
6+
[0x40,0x23,0x1c,0xd5]
7+
# CHECK: msr HDBSSBR_EL2, x0
8+
9+
[0x60,0x23,0x3c,0xd5]
10+
# CHECK: mrs x0, HDBSSPROD_EL2
11+
12+
[0x60,0x23,0x1c,0xd5]
13+
# CHECK: msr HDBSSPROD_EL2, x0
14+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RUN: llvm-mc -triple aarch64 -disassemble -mattr=+tlbiw -mattr=+xs < %s | FileCheck --check-prefix=CHECK-TLBIW --check-prefix=CHECK-XS %s
2+
# RUN: llvm-mc -triple aarch64 -disassemble -mattr=+tlbiw < %s | FileCheck --check-prefix=CHECK-TLBIW --check-prefix=CHECK-NO-XS-TLBIW %s
3+
# RUN: llvm-mc -triple aarch64 -disassemble < %s | FileCheck --check-prefix=CHECK-NO-TLBIW --check-prefix=CHECK-NO-XS-TLBIW %s
4+
5+
[0x5f,0x86,0x0c,0xd5]
6+
# CHECK-TLBIW: tlbi vmallws2e1
7+
# CHECK-NO-TLBIW: sys #4, c8, c6, #2
8+
9+
[0x5f,0x82,0x0c,0xd5]
10+
# CHECK-TLBIW: tlbi vmallws2e1is
11+
# CHECK-NO-TLBIW: sys #4, c8, c2, #2
12+
13+
[0x5f,0x85,0x0c,0xd5]
14+
# CHECK-TLBIW: tlbi vmallws2e1os
15+
# CHECK-NO-TLBIW: sys #4, c8, c5, #2
16+
17+
[0x5f,0x96,0x0c,0xd5]
18+
# CHECK-XS: tlbi vmallws2e1nxs
19+
# CHECK-NO-XS-TLBIW: sys #4, c9, c6, #2
20+
21+
[0x5f,0x92,0x0c,0xd5]
22+
# CHECK-XS: tlbi vmallws2e1isnxs
23+
# CHECK-NO-XS-TLBIW: sys #4, c9, c2, #2
24+
25+
[0x5f,0x95,0x0c,0xd5]
26+
# CHECK-XS: tlbi vmallws2e1osnxs
27+
# CHECK-NO-XS-TLBIW: sys #4, c9, c5, #2

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,7 @@ TEST(TargetParserTest, AArch64ExtensionFeatures) {
18131813
AArch64::AEK_SME_LUTv2, AArch64::AEK_SMEF8F16,
18141814
AArch64::AEK_SMEF8F32, AArch64::AEK_SMEFA64,
18151815
AArch64::AEK_CPA, AArch64::AEK_PAUTHLR,
1816+
AArch64::AEK_TLBIW,
18161817
};
18171818

18181819
std::vector<StringRef> Features;
@@ -1901,6 +1902,7 @@ TEST(TargetParserTest, AArch64ExtensionFeatures) {
19011902
EXPECT_TRUE(llvm::is_contained(Features, "+sme-fa64"));
19021903
EXPECT_TRUE(llvm::is_contained(Features, "+cpa"));
19031904
EXPECT_TRUE(llvm::is_contained(Features, "+pauth-lr"));
1905+
EXPECT_TRUE(llvm::is_contained(Features, "+tlbiw"));
19041906

19051907
// Assuming we listed every extension above, this should produce the same
19061908
// result. (note that AEK_NONE doesn't have a name so it won't be in the

0 commit comments

Comments
 (0)