[llvm] [AArch64][MIR] Serialize AArch64MachineFunctionInfo::HasStackFrame to MIR (PR #158122)
David Tellenbach via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 12:29:18 PDT 2025
https://github.com/dtellenbach updated https://github.com/llvm/llvm-project/pull/158122
>From 49655910fa8e607a0f9525137b839796b310a6a4 Mon Sep 17 00:00:00 2001
From: David Tellenbach <dtellenbach at apple.com>
Date: Thu, 11 Sep 2025 19:49:49 +0200
Subject: [PATCH] [AArch64][MIR] Serialize
AArch64MachineFunctionInfo::HasStackFrame
This patch adds serialization of AArch64MachineFunctionInfo::HasStackFrame
into MIR
---
.../AArch64/AArch64MachineFunctionInfo.cpp | 7 +++-
.../AArch64/AArch64MachineFunctionInfo.h | 2 +
.../CodeGen/MIR/AArch64/hasstackframe.mir | 40 +++++++++++++++++++
3 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
index b4197a04840b7..a81f5b3d436a9 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
@@ -28,7 +28,10 @@ yaml::AArch64FunctionInfo::AArch64FunctionInfo(
: HasRedZone(MFI.hasRedZone()),
StackSizeSVE(MFI.hasCalculatedStackSizeSVE()
? std::optional<uint64_t>(MFI.getStackSizeSVE())
- : std::nullopt) {}
+ : std::nullopt),
+ HasStackFrame(MFI.hasStackFrame()
+ ? std::optional<bool>(MFI.hasStackFrame())
+ : std::nullopt) {}
void yaml::AArch64FunctionInfo::mappingImpl(yaml::IO &YamlIO) {
MappingTraits<AArch64FunctionInfo>::mapping(YamlIO, *this);
@@ -40,6 +43,8 @@ void AArch64FunctionInfo::initializeBaseYamlFields(
HasRedZone = YamlMFI.HasRedZone;
if (YamlMFI.StackSizeSVE)
setStackSizeSVE(*YamlMFI.StackSizeSVE);
+ if (YamlMFI.HasStackFrame)
+ setHasStackFrame(*YamlMFI.HasStackFrame);
}
static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
index 993cff112ba84..98fd018bf33a9 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
@@ -600,6 +600,7 @@ namespace yaml {
struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
std::optional<bool> HasRedZone;
std::optional<uint64_t> StackSizeSVE;
+ std::optional<bool> HasStackFrame;
AArch64FunctionInfo() = default;
AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI);
@@ -612,6 +613,7 @@ template <> struct MappingTraits<AArch64FunctionInfo> {
static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) {
YamlIO.mapOptional("hasRedZone", MFI.HasRedZone);
YamlIO.mapOptional("stackSizeSVE", MFI.StackSizeSVE);
+ YamlIO.mapOptional("hasStackFrame", MFI.HasStackFrame);
}
};
diff --git a/llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir b/llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir
new file mode 100644
index 0000000000000..a044c7f79baab
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir
@@ -0,0 +1,40 @@
+# RUN: llc -run-pass=prologepilog -mtriple arm64-apple-ios -o - -simplify-mir -verify-machineinstrs %s | FileCheck %s
+
+# CHECK: hasStackFrame: true
+
+--- |
+
+ define i32 @f(i32 %a, i32 %b) #0 {
+ %local_array = alloca [10 x i32], align 4
+ %temp = alloca i32, align 4
+ store i32 %a, ptr %temp, align 4
+ %loaded = load i32, ptr %temp, align 4
+ %gep = getelementptr inbounds [10 x i32], ptr %local_array, i64 0, i64 5
+ store i32 %loaded, ptr %gep, align 4
+ %result = add i32 %loaded, %b
+ %blah = call i32 @foo(i32 noundef %result)
+ ret i32 %blah
+ }
+
+ declare i32 @foo(i32 noundef)
+
+...
+---
+name: f
+frameInfo:
+ adjustsStack: true
+stack:
+ - { id: 0, name: local_array, size: 40, alignment: 4, local-offset: -40 }
+ - { id: 1, name: temp, size: 4, alignment: 4, local-offset: -44 }
+body: |
+ bb.0:
+ liveins: $w0, $w1
+
+ STRWui renamable $w0, %stack.1.temp, 0
+ STRWui renamable $w0, %stack.0.local_array, 5
+ ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+ $w0 = ADDWrr killed renamable $w0, killed renamable $w1
+ BL @foo, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
+ ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+ RET_ReallyLR implicit $w0
+...
More information about the llvm-commits
mailing list