Skip to content

Commit 79524ba

Browse files
authored
[mlir][ArmSME] Add sve streaming compatible attribute (#75222)
Following the same path already used for ArmStreaming and ArmLocallyStreaming. This should correspond to clang's __arm_streaming_compatible attribute.
1 parent 9c093cb commit 79524ba

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def ArmStreamingMode : I32EnumAttr<"ArmStreamingMode", "Armv9 Streaming SVE mode
2020
// StreamingLocally: PSTATE.SM is kept internal and the callee manages it
2121
// on entry/exit.
2222
I32EnumAttrCase<"StreamingLocally", 2, "arm_locally_streaming">,
23+
// StreamingCompatible: the function may be entered in either
24+
// non-streaming mode (PSTATE.SM=0) or in streaming mode (PSTATE.SM=1)
25+
I32EnumAttrCase<"StreamingCompatible", 3, "arm_streaming_compatible">,
2326
]>{
2427
let cppNamespace = "mlir::arm_sme";
2528
let genSpecializedAttr = 0;
@@ -61,7 +64,11 @@ def EnableArmStreaming
6164
clEnumValN(mlir::arm_sme::ArmStreamingMode::StreamingLocally,
6265
"streaming-locally",
6366
"Streaming mode is internal to the function, callee "
64-
"manages PSTATE.SM on entry/exit.")
67+
"manages PSTATE.SM on entry/exit."),
68+
clEnumValN(mlir::arm_sme::ArmStreamingMode::StreamingCompatible,
69+
"streaming-compatible",
70+
"Function supports both streaming and non-streaming "
71+
"modes.")
6572
)}]>,
6673
Option<"zaMode", "za-mode", "mlir::arm_sme::ArmZaMode",
6774
/*default=*/"mlir::arm_sme::ArmZaMode::Disabled",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14111411
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_,
14121412
OptionalAttr<UnitAttr>:$arm_streaming,
14131413
OptionalAttr<UnitAttr>:$arm_locally_streaming,
1414+
OptionalAttr<UnitAttr>:$arm_streaming_compatible,
14141415
OptionalAttr<UnitAttr>:$arm_new_za,
14151416
OptionalAttr<StrAttr>:$section,
14161417
OptionalAttr<UnnamedAddr>:$unnamed_addr,

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ static void processMemoryEffects(llvm::Function *func, LLVMFuncOp funcOp) {
16371637
static constexpr std::array ExplicitAttributes{
16381638
StringLiteral("aarch64_pstate_sm_enabled"),
16391639
StringLiteral("aarch64_pstate_sm_body"),
1640+
StringLiteral("aarch64_pstate_sm_compatible"),
16401641
StringLiteral("aarch64_pstate_za_new"),
16411642
StringLiteral("vscale_range"),
16421643
StringLiteral("frame-pointer"),
@@ -1709,6 +1710,8 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
17091710
funcOp.setArmStreaming(true);
17101711
else if (func->hasFnAttribute("aarch64_pstate_sm_body"))
17111712
funcOp.setArmLocallyStreaming(true);
1713+
else if (func->hasFnAttribute("aarch64_pstate_sm_compatible"))
1714+
funcOp.setArmStreamingCompatible(true);
17121715

17131716
if (func->hasFnAttribute("aarch64_pstate_za_new"))
17141717
funcOp.setArmNewZa(true);

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
965965
llvmFunc->addFnAttr("aarch64_pstate_sm_enabled");
966966
else if (func.getArmLocallyStreaming())
967967
llvmFunc->addFnAttr("aarch64_pstate_sm_body");
968+
else if (func.getArmStreamingCompatible())
969+
llvmFunc->addFnAttr("aarch64_pstate_sm_compatible");
968970

969971
if (func.getArmNewZa())
970972
llvmFunc->addFnAttr("aarch64_pstate_za_new");

mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// RUN: mlir-opt %s -enable-arm-streaming -verify-diagnostics | FileCheck %s
22
// RUN: mlir-opt %s -enable-arm-streaming=streaming-mode=streaming-locally -verify-diagnostics | FileCheck %s -check-prefix=CHECK-LOCALLY
3+
// RUN: mlir-opt %s -enable-arm-streaming=streaming-mode=streaming-compatible -verify-diagnostics | FileCheck %s -check-prefix=CHECK-COMPATIBLE
34
// RUN: mlir-opt %s -enable-arm-streaming=za-mode=new-za -verify-diagnostics | FileCheck %s -check-prefix=CHECK-ENABLE-ZA
45
// RUN: mlir-opt %s -enable-arm-streaming=only-if-required-by-ops -verify-diagnostics | FileCheck %s -check-prefix=IF-REQUIRED
56

67
// CHECK-LABEL: @arm_streaming
78
// CHECK-SAME: attributes {arm_streaming}
89
// CHECK-LOCALLY-LABEL: @arm_streaming
910
// CHECK-LOCALLY-SAME: attributes {arm_locally_streaming}
11+
// CHECK-COMPATIBLE-LABEL: @arm_streaming
12+
// CHECK-COMPATIBLE-SAME: attributes {arm_streaming_compatible}
1013
// CHECK-ENABLE-ZA-LABEL: @arm_streaming
1114
// CHECK-ENABLE-ZA-SAME: attributes {arm_new_za, arm_streaming}
1215
func.func @arm_streaming() { return }
@@ -15,6 +18,8 @@ func.func @arm_streaming() { return }
1518
// CHECK-SAME: attributes {enable_arm_streaming_ignore}
1619
// CHECK-LOCALLY-LABEL: @not_arm_streaming
1720
// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
21+
// CHECK-COMPATIBLE-LABEL: @not_arm_streaming
22+
// CHECK-COMPATIBLE-SAME: attributes {enable_arm_streaming_ignore}
1823
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
1924
// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
2025
func.func @not_arm_streaming() attributes {enable_arm_streaming_ignore} { return }

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ define void @locally_streaming_func() "aarch64_pstate_sm_body" {
212212

213213
// -----
214214

215+
; CHECK-LABEL: @streaming_compatible_func
216+
; CHECK-SAME: attributes {arm_streaming_compatible}
217+
define void @streaming_compatible_func() "aarch64_pstate_sm_compatible" {
218+
ret void
219+
}
220+
221+
// -----
222+
215223
; CHECK-LABEL: @section_func
216224
; CHECK-SAME: attributes {section = ".section.name"}
217225
define void @section_func() section ".section.name" {

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,20 @@ llvm.func @locally_streaming_func() attributes {arm_locally_streaming} {
23052305

23062306
// -----
23072307

2308+
//
2309+
// arm_streaming_compatible attribute.
2310+
//
2311+
2312+
// CHECK-LABEL: @streaming_compatible_func
2313+
// CHECK: #[[ATTR:[0-9]*]]
2314+
llvm.func @streaming_compatible_func() attributes {arm_streaming_compatible} {
2315+
llvm.return
2316+
}
2317+
2318+
// CHECK: attributes #[[ATTR]] = { "aarch64_pstate_sm_compatible" }
2319+
2320+
// -----
2321+
23082322
//
23092323
// Zero-initialize operation.
23102324
//

0 commit comments

Comments
 (0)