[llvm] [AArch64] Accept __chkstk_darwin stack probes on Darwin (PR #210812)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 02:27:53 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Karim Alweheshy (karim-alweheshy)
<details>
<summary>Changes</summary>
Apple Swift 6.3 Darwin bitcode can carry the probe-stack=__chkstk_darwin function attribute. The upstream AArch64 backend only accepts inline-asm and currently terminates LTO with Unsupported stack probing method when it consumes such bitcode.
Accept the Apple spelling only for Darwin targets and lower it through the existing upstream inline stack-probing implementation. Other unknown probe kinds and non-Darwin uses remain rejected. This deliberately avoids depending on the Apple helper ABI while preserving the required page-touching behavior.
Validation:
- Apple clang 21 accepts the reduced IR and emits a reference to ___chkstk_darwin;
- the patched upstream LLVM 23 AArch64 backend lowers the same probe request through its inline sequence;
- a Swift 6.3 full-LTO link that originally failed on this attribute completes with the patch applied.
This is a draft to confirm that translating the downstream Darwin helper spelling to inline probing is preferable to adding the private helper lowering to upstream.
---
Full diff: https://github.com/llvm/llvm-project/pull/210812.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp (+5-1)
- (added) llvm/test/CodeGen/AArch64/swift-darwin-stack-probing.ll (+22)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
index 29aea3694497f..e6ad188eab206 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
@@ -160,7 +160,11 @@ AArch64FunctionInfo::AArch64FunctionInfo(const Function &F,
F.getParent()->getModuleFlag("probe-stack")))
ProbeKind = PS->getString();
if (ProbeKind.size()) {
- if (ProbeKind != "inline-asm")
+ // Apple Swift emits __chkstk_darwin for Darwin bitcode. Treat it as a
+ // request for the existing inline probe sequence; this backend does not
+ // provide Apple's out-of-tree helper-based implementation.
+ if (ProbeKind != "inline-asm" &&
+ !(STI->isTargetDarwin() && ProbeKind == "__chkstk_darwin"))
report_fatal_error("Unsupported stack probing method");
StackProbeSize = ProbeSize;
}
diff --git a/llvm/test/CodeGen/AArch64/swift-darwin-stack-probing.ll b/llvm/test/CodeGen/AArch64/swift-darwin-stack-probing.ll
new file mode 100644
index 0000000000000..f6a749c9a0506
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/swift-darwin-stack-probing.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple=arm64-apple-macosx -verify-machineinstrs < %s | FileCheck %s
+
+; Verify that the stack-probing attribute emitted by Apple Swift is accepted
+; on Darwin and lowered to the existing inline stack-probing sequence.
+
+define void @swift_darwin_stack_probe(ptr %out) #0 {
+; CHECK-LABEL: swift_darwin_stack_probe:
+; CHECK: sub sp, sp, #1, lsl #12
+; CHECK: ldr xzr, [sp]
+entry:
+ %frame = alloca i8, i64 4096, align 1
+ store ptr %frame, ptr %out, align 8
+ ret void
+}
+
+attributes #0 = {
+ noinline
+ "frame-pointer"="none"
+ "probe-stack"="__chkstk_darwin"
+ "stack-probe-size"="4096"
+ uwtable(async)
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210812
More information about the llvm-commits
mailing list