Skip to content

[mlir][ArmSME] Add sve streaming compatible attribute #75222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mlir/include/mlir/Dialect/ArmSME/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def ArmStreamingMode : I32EnumAttr<"ArmStreamingMode", "Armv9 Streaming SVE mode
// StreamingLocally: PSTATE.SM is kept internal and the callee manages it
// on entry/exit.
I32EnumAttrCase<"StreamingLocally", 2, "arm_locally_streaming">,
// StreamingCompatible: the function may be entered in either
// non-streaming mode (PSTATE.SM=0) or in streaming mode (PSTATE.SM=1)
I32EnumAttrCase<"StreamingCompatible", 3, "arm_streaming_compatible">,
]>{
let cppNamespace = "mlir::arm_sme";
let genSpecializedAttr = 0;
Expand Down Expand Up @@ -61,7 +64,11 @@ def EnableArmStreaming
clEnumValN(mlir::arm_sme::ArmStreamingMode::StreamingLocally,
"streaming-locally",
"Streaming mode is internal to the function, callee "
"manages PSTATE.SM on entry/exit.")
"manages PSTATE.SM on entry/exit."),
clEnumValN(mlir::arm_sme::ArmStreamingMode::StreamingCompatible,
"streaming-compatible",
"Function supports both streaming and non-streaming "
"modes.")
)}]>,
Option<"zaMode", "za-mode", "mlir::arm_sme::ArmZaMode",
/*default=*/"mlir::arm_sme::ArmZaMode::Disabled",
Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_,
OptionalAttr<UnitAttr>:$arm_streaming,
OptionalAttr<UnitAttr>:$arm_locally_streaming,
OptionalAttr<UnitAttr>:$arm_streaming_compatible,
OptionalAttr<UnitAttr>:$arm_new_za,
OptionalAttr<StrAttr>:$section,
OptionalAttr<UnnamedAddr>:$unnamed_addr,
Expand Down
3 changes: 3 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ static void processMemoryEffects(llvm::Function *func, LLVMFuncOp funcOp) {
static constexpr std::array ExplicitAttributes{
StringLiteral("aarch64_pstate_sm_enabled"),
StringLiteral("aarch64_pstate_sm_body"),
StringLiteral("aarch64_pstate_sm_compatible"),
StringLiteral("aarch64_pstate_za_new"),
StringLiteral("vscale_range"),
StringLiteral("frame-pointer"),
Expand Down Expand Up @@ -1709,6 +1710,8 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
funcOp.setArmStreaming(true);
else if (func->hasFnAttribute("aarch64_pstate_sm_body"))
funcOp.setArmLocallyStreaming(true);
else if (func->hasFnAttribute("aarch64_pstate_sm_compatible"))
funcOp.setArmStreamingCompatible(true);

if (func->hasFnAttribute("aarch64_pstate_za_new"))
funcOp.setArmNewZa(true);
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
llvmFunc->addFnAttr("aarch64_pstate_sm_enabled");
else if (func.getArmLocallyStreaming())
llvmFunc->addFnAttr("aarch64_pstate_sm_body");
else if (func.getArmStreamingCompatible())
llvmFunc->addFnAttr("aarch64_pstate_sm_compatible");

if (func.getArmNewZa())
llvmFunc->addFnAttr("aarch64_pstate_za_new");
Expand Down
5 changes: 5 additions & 0 deletions mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// RUN: mlir-opt %s -enable-arm-streaming -verify-diagnostics | FileCheck %s
// RUN: mlir-opt %s -enable-arm-streaming=streaming-mode=streaming-locally -verify-diagnostics | FileCheck %s -check-prefix=CHECK-LOCALLY
// RUN: mlir-opt %s -enable-arm-streaming=streaming-mode=streaming-compatible -verify-diagnostics | FileCheck %s -check-prefix=CHECK-COMPATIBLE
// RUN: mlir-opt %s -enable-arm-streaming=za-mode=new-za -verify-diagnostics | FileCheck %s -check-prefix=CHECK-ENABLE-ZA
// RUN: mlir-opt %s -enable-arm-streaming=only-if-required-by-ops -verify-diagnostics | FileCheck %s -check-prefix=IF-REQUIRED

// CHECK-LABEL: @arm_streaming
// CHECK-SAME: attributes {arm_streaming}
// CHECK-LOCALLY-LABEL: @arm_streaming
// CHECK-LOCALLY-SAME: attributes {arm_locally_streaming}
// CHECK-COMPATIBLE-LABEL: @arm_streaming
// CHECK-COMPATIBLE-SAME: attributes {arm_streaming_compatible}
// CHECK-ENABLE-ZA-LABEL: @arm_streaming
// CHECK-ENABLE-ZA-SAME: attributes {arm_new_za, arm_streaming}
func.func @arm_streaming() { return }
Expand All @@ -15,6 +18,8 @@ func.func @arm_streaming() { return }
// CHECK-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-COMPATIBLE-LABEL: @not_arm_streaming
// CHECK-COMPATIBLE-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
func.func @not_arm_streaming() attributes {enable_arm_streaming_ignore} { return }
Expand Down
8 changes: 8 additions & 0 deletions mlir/test/Target/LLVMIR/Import/function-attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ define void @locally_streaming_func() "aarch64_pstate_sm_body" {

// -----

; CHECK-LABEL: @streaming_compatible_func
; CHECK-SAME: attributes {arm_streaming_compatible}
define void @streaming_compatible_func() "aarch64_pstate_sm_compatible" {
ret void
}

// -----

; CHECK-LABEL: @section_func
; CHECK-SAME: attributes {section = ".section.name"}
define void @section_func() section ".section.name" {
Expand Down
14 changes: 14 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,20 @@ llvm.func @locally_streaming_func() attributes {arm_locally_streaming} {

// -----

//
// arm_streaming_compatible attribute.
//

// CHECK-LABEL: @streaming_compatible_func
// CHECK: #[[ATTR:[0-9]*]]
llvm.func @streaming_compatible_func() attributes {arm_streaming_compatible} {
llvm.return
}

// CHECK: attributes #[[ATTR]] = { "aarch64_pstate_sm_compatible" }

// -----

//
// Zero-initialize operation.
//
Expand Down