Skip to content

Commit 21e1bf2

Browse files
Add more ZA modes (#77361)
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 c2fd5b7 commit 21e1bf2

File tree

7 files changed

+87
-2
lines changed

7 files changed

+87
-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
@@ -1420,6 +1420,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14201420
OptionalAttr<UnitAttr>:$arm_locally_streaming,
14211421
OptionalAttr<UnitAttr>:$arm_streaming_compatible,
14221422
OptionalAttr<UnitAttr>:$arm_new_za,
1423+
OptionalAttr<UnitAttr>:$arm_preserves_za,
1424+
OptionalAttr<UnitAttr>:$arm_shared_za,
14231425
OptionalAttr<StrAttr>:$section,
14241426
OptionalAttr<UnnamedAddr>:$unnamed_addr,
14251427
OptionalAttr<I64Attr>:$alignment,

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,8 @@ static constexpr std::array ExplicitAttributes{
16411641
StringLiteral("aarch64_pstate_sm_body"),
16421642
StringLiteral("aarch64_pstate_sm_compatible"),
16431643
StringLiteral("aarch64_pstate_za_new"),
1644+
StringLiteral("aarch64_pstate_za_preserved"),
1645+
StringLiteral("aarch64_pstate_za_shared"),
16441646
StringLiteral("vscale_range"),
16451647
StringLiteral("frame-pointer"),
16461648
StringLiteral("target-features"),
@@ -1717,6 +1719,11 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
17171719

17181720
if (func->hasFnAttribute("aarch64_pstate_za_new"))
17191721
funcOp.setArmNewZa(true);
1722+
else if (func->hasFnAttribute("aarch64_pstate_za_shared"))
1723+
funcOp.setArmSharedZa(true);
1724+
// PreservedZA can be used with either NewZA or SharedZA.
1725+
if (func->hasFnAttribute("aarch64_pstate_za_preserved"))
1726+
funcOp.setArmPreservesZa(true);
17201727

17211728
llvm::Attribute attr = func->getFnAttribute(llvm::Attribute::VScaleRange);
17221729
if (attr.isValid()) {

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,10 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
11021102

11031103
if (func.getArmNewZa())
11041104
llvmFunc->addFnAttr("aarch64_pstate_za_new");
1105+
else if (func.getArmSharedZa())
1106+
llvmFunc->addFnAttr("aarch64_pstate_za_shared");
1107+
if (func.getArmPreservesZa())
1108+
llvmFunc->addFnAttr("aarch64_pstate_za_preserved");
11051109

11061110
if (auto targetFeatures = func.getTargetFeatures())
11071111
llvmFunc->addFnAttr("target-features", targetFeatures->getFeaturesString());
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" {

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,29 @@ llvm.func @streaming_compatible_func() attributes {arm_streaming_compatible} {
23302330

23312331
// -----
23322332

2333+
// CHECK-LABEL: @new_za_func
2334+
// CHECK: #[[ATTR:[0-9]*]]
2335+
llvm.func @new_za_func() attributes {arm_new_za} {
2336+
llvm.return
2337+
}
2338+
// CHECK #[[ATTR]] = { "aarch64_pstate_za_new" }
2339+
2340+
// CHECK-LABEL: @shared_za_func
2341+
// CHECK: #[[ATTR:[0-9]*]]
2342+
llvm.func @shared_za_func() attributes {arm_shared_za } {
2343+
llvm.return
2344+
}
2345+
// CHECK #[[ATTR]] = { "aarch64_pstate_za_shared" }
2346+
2347+
// CHECK-LABEL: @preserves_za_func
2348+
// CHECK: #[[ATTR:[0-9]*]]
2349+
llvm.func @preserves_za_func() attributes {arm_preserves_za} {
2350+
llvm.return
2351+
}
2352+
// CHECK #[[ATTR]] = { "aarch64_pstate_za_preserved" }
2353+
2354+
// -----
2355+
23332356
//
23342357
// Zero-initialize operation.
23352358
//

0 commit comments

Comments
 (0)