Skip to content

Conversation

dtellenbach
Copy link
Member

This patch adds serialization of AArch64MachineFunctionInfo::HasStackFrame into MIR.

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2025

@llvm/pr-subscribers-backend-aarch64

Author: David Tellenbach (dtellenbach)

Changes

This patch adds serialization of AArch64MachineFunctionInfo::HasStackFrame into MIR.


Full diff: https://github.com/llvm/llvm-project/pull/158122.diff

3 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp (+4-1)
  • (modified) llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h (+2)
  • (added) llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir (+42)
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
index b4197a04840b7..e672e2972274f 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
@@ -28,7 +28,8 @@ yaml::AArch64FunctionInfo::AArch64FunctionInfo(
     : HasRedZone(MFI.hasRedZone()),
       StackSizeSVE(MFI.hasCalculatedStackSizeSVE()
                        ? std::optional<uint64_t>(MFI.getStackSizeSVE())
-                       : std::nullopt) {}
+                       : std::nullopt),
+      HasStackFrame(MFI.hasStackFrame()) {}
 
 void yaml::AArch64FunctionInfo::mappingImpl(yaml::IO &YamlIO) {
   MappingTraits<AArch64FunctionInfo>::mapping(YamlIO, *this);
@@ -40,6 +41,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..25d15cbff9461
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AArch64/hasstackframe.mir
@@ -0,0 +1,42 @@
+# 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
+machineFunctionInfo:
+  hasStackFrame:   false
+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
+...

@dtellenbach dtellenbach force-pushed the serialize_aarch64_has_stackframe branch from 7a20c8c to 4965591 Compare September 11, 2025 19:29
@dtellenbach dtellenbach enabled auto-merge (squash) September 11, 2025 19:53
… MIR

This patch adds serialization of AArch64MachineFunctionInfo::HasStackFrame
into MIR.
@dtellenbach dtellenbach force-pushed the serialize_aarch64_has_stackframe branch from f3ac5fd to e9e15cf Compare September 11, 2025 21:51
@dtellenbach dtellenbach merged commit 23d1ec6 into llvm:main Sep 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants