Skip to content

Commit 7d46590

Browse files
committed
[mlir][llvm] Add arm_streaming LLVM function attributes
This patch adds two optional attributes to 'llvm.func' op for the Armv9 Streaming SVE (SSVE) mode [1] that map 1-1 with LLVM function attributes [2]: * arm_streaming -> aarch64_pstate_sm_enabled * arm_locally_streaming -> aarch64_pstate_sm_body Streaming-mode is part of the interface (ABI) for functions with the first attribute and it's the responsibility of the caller to manage PSTATE.SM on entry/exit to functions with this attribute [3]. The LLVM backend will emit 'smstart sm' / 'smstop sm' [4] around calls to streaming functions. In locally streaming functions PSTATE.SM is kept internal and managed by the callee on entry/exit. The LLVM backend will emit 'smstart sm' / 'smstop sm' in the prologue / epilogue for functions with this attribute. The integration test for SSVE has been updated to no longer use the passthrough mechanism that's intended for prototyping. PATCH [1 / 2] in series for RFC: https://discourse.llvm.org/t/rfc-supporting-armv9-scalable-matrix-extension-sme-streaming-sve-ssve-mode-in-mlir/70678 [1] https://developer.arm.com/documentation/ddi0616/aa [2] https://llvm.org/docs/AArch64SME.html#introduction [3] https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#671pstatesm-interfaces [4] https://developer.arm.com/documentation/ddi0602/2023-03/Base-Instructions/SMSTART--Enables-access-to-Streaming-SVE-mode-and-SME-architectural-state--an-alias-of-MSR--immediate-- Reviewed By: awarzynski, dcaballe, WanderAway Differential Revision: https://reviews.llvm.org/D150932
1 parent 89242ed commit 7d46590

File tree

7 files changed

+64
-13
lines changed

7 files changed

+64
-13
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,9 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
15671567
OptionalAttr<DictArrayAttr>:$res_attrs,
15681568
OptionalAttr<I64Attr>:$function_entry_count,
15691569
OptionalAttr<LLVM_MemoryEffectsAttr>:$memory,
1570-
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_
1570+
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_,
1571+
OptionalAttr<UnitAttr>:$arm_streaming,
1572+
OptionalAttr<UnitAttr>:$arm_locally_streaming
15711573
);
15721574

15731575
let regions = (region AnyRegion:$body);

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,12 @@ static void processPassthroughAttrs(llvm::Function *func, LLVMFuncOp funcOp) {
15421542
attrName = llvm::Attribute::getNameFromAttrKind(attr.getKindAsEnum());
15431543
auto keyAttr = StringAttr::get(context, attrName);
15441544

1545+
// Skip the aarch64_pstate_sm_<body|enabled> since the LLVMFuncOp has an
1546+
// explicit attribute.
1547+
if (attrName == "aarch64_pstate_sm_enabled" ||
1548+
attrName == "aarch64_pstate_sm_body")
1549+
continue;
1550+
15451551
if (attr.isStringAttribute()) {
15461552
StringRef val = attr.getValueAsString();
15471553
if (val.empty()) {
@@ -1574,6 +1580,11 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
15741580
LLVMFuncOp funcOp) {
15751581
processMemoryEffects(func, funcOp);
15761582
processPassthroughAttrs(func, funcOp);
1583+
1584+
if (func->hasFnAttribute("aarch64_pstate_sm_enabled"))
1585+
funcOp.setArmStreaming(true);
1586+
else if (func->hasFnAttribute("aarch64_pstate_sm_body"))
1587+
funcOp.setArmLocallyStreaming(true);
15771588
}
15781589

15791590
DictionaryAttr

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,11 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
881881
if (auto gc = func.getGarbageCollector())
882882
llvmFunc->setGC(gc->str());
883883

884+
if (auto armStreaming = func.getArmStreaming())
885+
llvmFunc->addFnAttr("aarch64_pstate_sm_enabled");
886+
else if (auto armLocallyStreaming = func.getArmLocallyStreaming())
887+
llvmFunc->addFnAttr("aarch64_pstate_sm_body");
888+
884889
// First, create all blocks so we can jump to them.
885890
llvm::LLVMContext &llvmContext = llvmFunc->getContext();
886891
for (auto &bb : func) {

mlir/test/Integration/Dialect/Vector/CPU/ArmSME/test-ssve.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// NOTE: To run this test, your CPU must support SME.
1010

1111
// VLA memcopy in streaming mode.
12-
func.func @streaming_kernel_copy(%src : memref<?xi64>, %dst : memref<?xi64>, %size : index) attributes {passthrough = ["aarch64_pstate_sm_enabled"]} {
12+
func.func @streaming_kernel_copy(%src : memref<?xi64>, %dst : memref<?xi64>, %size : index) attributes {arm_streaming} {
1313
%c0 = arith.constant 0 : index
1414
%c2 = arith.constant 2 : index
1515
%vscale = vector.vscale

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,19 @@ define hidden void @hidden() {
193193
define protected void @protected() {
194194
ret void
195195
}
196+
197+
// -----
198+
199+
; CHECK-LABEL: @streaming_func
200+
; CHECK-SAME: attributes {arm_streaming}
201+
define void @streaming_func() "aarch64_pstate_sm_enabled" {
202+
ret void
203+
}
204+
205+
// -----
206+
207+
; CHECK-LABEL: @locally_streaming_func
208+
; CHECK-SAME: attributes {arm_locally_streaming}
209+
define void @locally_streaming_func() "aarch64_pstate_sm_body" {
210+
ret void
211+
}

mlir/test/Target/LLVMIR/arm-ssve.mlir

Lines changed: 0 additions & 11 deletions
This file was deleted.

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,3 +2209,31 @@ llvm.func @readwrite_func() attributes {
22092209
memory = #llvm.memory_effects<other = readwrite, argMem = readwrite, inaccessibleMem = readwrite>}
22102210

22112211
// CHECK: attributes #[[ATTR]] = { memory(readwrite) }
2212+
2213+
// -----
2214+
2215+
//
2216+
// arm_streaming attribute.
2217+
//
2218+
2219+
// CHECK-LABEL: @streaming_func
2220+
// CHECK: #[[ATTR:[0-9]*]]
2221+
llvm.func @streaming_func() attributes {arm_streaming} {
2222+
llvm.return
2223+
}
2224+
2225+
// CHECK: attributes #[[ATTR]] = { "aarch64_pstate_sm_enabled" }
2226+
2227+
// -----
2228+
2229+
//
2230+
// arm_locally_streaming attribute.
2231+
//
2232+
2233+
// CHECK-LABEL: @locally_streaming_func
2234+
// CHECK: #[[ATTR:[0-9]*]]
2235+
llvm.func @locally_streaming_func() attributes {arm_locally_streaming} {
2236+
llvm.return
2237+
}
2238+
2239+
// CHECK: attributes #[[ATTR]] = { "aarch64_pstate_sm_body" }

0 commit comments

Comments
 (0)