Skip to content

Commit 89686b4

Browse files
Add more ZA modes
Adds the arm_shared_za and arm_preserves_za attributes to the existing arm_new_za attribute. The functionality already exists in LLVM, so just "linking the pieces together". For more details see: https://arm-software.github.io/acle/main/acle.html#sme-attributes-relating-to-za
1 parent bf31226 commit 89686b4

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

mlir/include/mlir/Dialect/ArmSME/Transforms/Passes.td

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@ def ArmStreamingMode : I32EnumAttr<"ArmStreamingMode", "Armv9 Streaming SVE mode
2828
let genSpecializedAttr = 0;
2929
}
3030

31-
// TODO: Add other ZA modes.
3231
// https://arm-software.github.io/acle/main/acle.html#sme-attributes-relating-to-za
32+
// See also the LLVM definitions: https://llvm.org/docs/AArch64SME.html
33+
//
34+
// Various frontends (e.g. Flang) that build on top of this may restrict or
35+
// enforce how these attributes are used, both individually and in terms of
36+
// combinations that are allowed.
37+
//
38+
// The MLIR interface here does not make any attempt to perform any checking,
39+
// it is up to the higher level to ensure that these attributes are used in a
40+
// way that both makes sense and is legal according to the Arm architecture.
3341
def ArmZaMode : I32EnumAttr<"ArmZaMode", "Armv9 ZA storage mode",
3442
[
3543
I32EnumAttrCase<"Disabled", 0, "disabled">,
3644
// A function's ZA state is created on entry and destroyed on exit.
3745
I32EnumAttrCase<"NewZA", 1, "arm_new_za">,
46+
// A function that preserves ZA state.
47+
I32EnumAttrCase<"PreservesZA", 2, "arm_preserves_za">,
48+
// A function that uses ZA state as input and/or output
49+
I32EnumAttrCase<"SharedZA", 3, "arm_shared_za">,
3850
]>{
3951
let cppNamespace = "mlir::arm_sme";
4052
let genSpecializedAttr = 0;
@@ -79,7 +91,15 @@ def EnableArmStreaming
7991
clEnumValN(mlir::arm_sme::ArmZaMode::NewZA,
8092
"new-za",
8193
"The function has ZA state. The ZA state is "
82-
"created on entry and destroyed on exit.")
94+
"created on entry and destroyed on exit."),
95+
clEnumValN(mlir::arm_sme::ArmZaMode::PreservesZA,
96+
"preserves-za",
97+
"The function preserves ZA state. The ZA state is "
98+
"saved on entry and restored on exit."),
99+
clEnumValN(mlir::arm_sme::ArmZaMode::SharedZA,
100+
"shared-za",
101+
"The function uses ZA state. The ZA state may "
102+
"be used for input and/or output.")
83103
)}]>,
84104
Option<"onlyIfRequiredByOps", "only-if-required-by-ops", "bool",
85105
/*default=*/"false",

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14131413
OptionalAttr<UnitAttr>:$arm_locally_streaming,
14141414
OptionalAttr<UnitAttr>:$arm_streaming_compatible,
14151415
OptionalAttr<UnitAttr>:$arm_new_za,
1416+
OptionalAttr<UnitAttr>:$arm_preserves_za,
1417+
OptionalAttr<UnitAttr>:$arm_shared_za,
14161418
OptionalAttr<StrAttr>:$section,
14171419
OptionalAttr<UnnamedAddr>:$unnamed_addr,
14181420
OptionalAttr<I64Attr>:$alignment,

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,8 @@ static constexpr std::array ExplicitAttributes{
16391639
StringLiteral("aarch64_pstate_sm_body"),
16401640
StringLiteral("aarch64_pstate_sm_compatible"),
16411641
StringLiteral("aarch64_pstate_za_new"),
1642+
StringLiteral("aarch64_pstate_za_preserved"),
1643+
StringLiteral("aarch64_pstate_za_shared"),
16421644
StringLiteral("vscale_range"),
16431645
StringLiteral("frame-pointer"),
16441646
StringLiteral("target-features"),
@@ -1715,6 +1717,11 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
17151717

17161718
if (func->hasFnAttribute("aarch64_pstate_za_new"))
17171719
funcOp.setArmNewZa(true);
1720+
else if (func->hasFnAttribute("aarch64_pstate_za_shared"))
1721+
funcOp.setArmSharedZa(true);
1722+
// PreservedZA can be used with either NewZA or SharedZA.
1723+
if (func->hasFnAttribute("aarch64_pstate_za_preserved"))
1724+
funcOp.setArmPreservesZa(true);
17181725

17191726
llvm::Attribute attr = func->getFnAttribute(llvm::Attribute::VScaleRange);
17201727
if (attr.isValid()) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
// RUN: mlir-opt %s -enable-arm-streaming=za-mode=new-za -convert-arm-sme-to-llvm | FileCheck %s -check-prefix=ENABLE-ZA
22
// RUN: mlir-opt %s -enable-arm-streaming -convert-arm-sme-to-llvm | FileCheck %s -check-prefix=DISABLE-ZA
3+
// RUN: mlir-opt %s -enable-arm-streaming=za-mode=shared-za -convert-arm-sme-to-llvm | FileCheck %s -check-prefix=SHARED-ZA
4+
// RUN: mlir-opt %s -enable-arm-streaming=za-mode=preserves-za -convert-arm-sme-to-llvm | FileCheck %s -check-prefix=PRESERVES-ZA
35
// RUN: mlir-opt %s -convert-arm-sme-to-llvm | FileCheck %s -check-prefix=NO-ARM-STREAMING
46

57
// CHECK-LABEL: @declaration
68
func.func private @declaration()
79

810
// ENABLE-ZA-LABEL: @arm_new_za
911
// ENABLE-ZA-SAME: attributes {arm_new_za, arm_streaming}
12+
// SHARED-ZA-LABEL: @arm_new_za
13+
// SHARED-ZA-SAME: attributes {arm_shared_za, arm_streaming}
14+
// PRESERVES-ZA-LABEL: @arm_new_za
15+
// PRESERVES-ZA-SAME: attributes {arm_preserves_za, arm_streaming}
1016
// DISABLE-ZA-LABEL: @arm_new_za
1117
// DISABLE-ZA-NOT: arm_new_za
1218
// DISABLE-ZA-SAME: attributes {arm_streaming}
1319
// NO-ARM-STREAMING-LABEL: @arm_new_za
1420
// NO-ARM-STREAMING-NOT: arm_new_za
1521
// NO-ARM-STREAMING-NOT: arm_streaming
22+
// NO-ARM-STREAMING-NOT: arm_shared_za
23+
// NO-ARM-STREAMING-NOT: arm_preserves_za
1624
func.func @arm_new_za() { return }

mlir/test/Target/LLVMIR/Import/function-attributes.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ define void @streaming_compatible_func() "aarch64_pstate_sm_compatible" {
220220

221221
// -----
222222

223+
; CHECK-LABEL: @arm_new_za_func
224+
; CHECK-SAME: attributes {arm_new_za}
225+
define void @arm_new_za_func() "aarch64_pstate_za_new" {
226+
ret void
227+
}
228+
229+
230+
; CHECK-LABEL: @arm_preserves_za_func
231+
; CHECK-SAME: attributes {arm_preserves_za}
232+
define void @arm_preserves_za_func() "aarch64_pstate_za_preserved" {
233+
ret void
234+
}
235+
236+
; CHECK-LABEL: @arm_shared_za_func
237+
; CHECK-SAME: attributes {arm_shared_za}
238+
define void @arm_shared_za_func() "aarch64_pstate_za_shared" {
239+
ret void
240+
}
241+
242+
// -----
243+
223244
; CHECK-LABEL: @section_func
224245
; CHECK-SAME: attributes {section = ".section.name"}
225246
define void @section_func() section ".section.name" {

0 commit comments

Comments
 (0)