Skip to content

Commit 45efaee

Browse files
committed
fix issues 108019
1 parent f5a65d8 commit 45efaee

22 files changed

+62
-36
lines changed

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ namespace llvm {
161161
/// DisableFramePointerElim - This returns true if frame pointer elimination
162162
/// optimization should be disabled for the given machine function.
163163
bool DisableFramePointerElim(const MachineFunction &MF) const;
164+
165+
/// DisableLeafFramePointerElim - This returns true if leaf frame pointer elimination
166+
/// optimization should be disabled for the given machine function.
167+
bool DisableLeafFramePointerElim(const MachineFunction &MF) const;
164168

165169
/// FramePointerIsReserved - This returns true if the frame pointer must
166170
/// always either point to a new frame record or be un-modified in the given

llvm/lib/CodeGen/TargetOptionsImpl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
4040
llvm_unreachable("unknown frame pointer flag");
4141
}
4242

43+
/// DisableLeafFramePointerElim - This returns true if leaf frame pointer elimination
44+
/// optimization should be disabled for the given machine function.
45+
bool TargetOptions::DisableLeafFramePointerElim(const MachineFunction &MF) const {
46+
const Function &F = MF.getFunction();
47+
48+
if (!F.hasFnAttribute("frame-pointer"))
49+
return false;
50+
StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
51+
if (FP == "all")
52+
return true;
53+
return false;
54+
}
55+
4356
bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const {
4457
// Check to see if the target want to forcibly keep frame pointer.
4558
if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
22712271
// is spilled in the order specified by getCalleeSavedRegs() to make it easier
22722272
// to combine multiple loads / stores.
22732273
bool CanEliminateFrame = !(requiresAAPCSFrameRecord(MF) && hasFP(MF));
2274+
bool CanEliminateLeafFrame = !MF.getTarget().Options.DisableLeafFramePointerElim(MF);
22742275
bool CS1Spilled = false;
22752276
bool LRSpilled = false;
22762277
unsigned NumGPRSpills = 0;
@@ -2513,7 +2514,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
25132514
<< "; EstimatedFPStack: " << MaxFixedOffset - MaxFPOffset
25142515
<< "; BigFrameOffsets: " << BigFrameOffsets << "\n");
25152516
if (BigFrameOffsets ||
2516-
!CanEliminateFrame || RegInfo->cannotEliminateFrame(MF)) {
2517+
!CanEliminateFrame || RegInfo->cannotEliminateFrame(MF) || !CanEliminateLeafFrame) {
25172518
AFI->setHasStackFrame(true);
25182519

25192520
if (HasFP) {

llvm/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@oStruct = external global %struct.Outer, align 4
1111

12-
define void @main(i8 %val8) nounwind {
12+
define void @main(i8 %val8) nounwind "frame-pointer"="none" {
1313
; CHECK-LABEL: main:
1414
; CHECK: @ %bb.0: @ %for.body.lr.ph
1515
; CHECK-NEXT: movw r0, :lower16:(L_oStruct$non_lazy_ptr-(LPC0_0+4))

llvm/test/CodeGen/ARM/arm-shrink-wrapping.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ if.end:
17321732
; Another infinite loop test this time with two nested infinite loop.
17331733
; infiniteloop3
17341734
; bx lr
1735-
define void @infiniteloop3() "frame-pointer"="all" {
1735+
define void @infiniteloop3() "frame-pointer"="none" {
17361736
; ARM-LABEL: infiniteloop3:
17371737
; ARM: @ %bb.0: @ %entry
17381738
; ARM-NEXT: mov r0, #0

llvm/test/CodeGen/ARM/call-tc.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ define void @t1() "frame-pointer"="all" {
1717
ret void
1818
}
1919

20-
define void @t2() "frame-pointer"="all" {
20+
define void @t2() "frame-pointer"="none" {
2121
; CHECKV6-LABEL: t2:
2222
; CHECKV6: bx r0
2323
; CHECKT2D-LABEL: t2:
@@ -102,7 +102,7 @@ bb:
102102

103103
; Make sure codegenprep is duplicating ret instructions to enable tail calls.
104104
; rdar://11140249
105-
define i32 @t8(i32 %x) nounwind ssp "frame-pointer"="all" {
105+
define i32 @t8(i32 %x) nounwind ssp "frame-pointer"="none" {
106106
entry:
107107
; CHECKT2D-LABEL: t8:
108108
; CHECKT2D-NOT: push

llvm/test/CodeGen/ARM/debug-frame.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ entry:
526526
; Test 4
527527
;-------------------------------------------------------------------------------
528528

529-
define void @test4() nounwind {
529+
define void @test4() nounwind "frame-pointer"="none" {
530530
entry:
531531
ret void
532532
}

llvm/test/CodeGen/ARM/ehabi.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ entry:
575575
; Test 4
576576
;-------------------------------------------------------------------------------
577577

578-
define void @test4() nounwind {
578+
define void @test4() nounwind "frame-pointer"="none" {
579579
entry:
580580
ret void
581581
}

llvm/test/CodeGen/ARM/frame-chain.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
define dso_local noundef i32 @leaf(i32 noundef %0) {
1111
; LEAF-FP-LABEL: leaf:
1212
; LEAF-FP: @ %bb.0:
13-
; LEAF-FP-NEXT: .pad #4
14-
; LEAF-FP-NEXT: sub sp, sp, #4
15-
; LEAF-FP-NEXT: str r0, [sp]
13+
; LEAF-FP-NEXT: .save {r11, lr}
14+
; LEAF-FP-NEXT: push {r11, lr}
15+
; LEAF-FP-NEXT: .setfp r11, sp
16+
; LEAF-FP-NEXT: mov r11, sp
17+
; LEAF-FP-NEXT: push {r0}
1618
; LEAF-FP-NEXT: add r0, r0, #4
17-
; LEAF-FP-NEXT: add sp, sp, #4
19+
; LEAF-FP-NEXT: mov sp, r11
20+
; LEAF-FP-NEXT: pop {r11, lr}
1821
; LEAF-FP-NEXT: mov pc, lr
1922
;
2023
; LEAF-FP-AAPCS-LABEL: leaf:

llvm/test/CodeGen/ARM/ifcvt5.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@x = external global ptr ; <ptr> [#uses=1]
77

8-
define void @foo(i32 %a) "frame-pointer"="all" {
8+
define void @foo(i32 %a) "frame-pointer"="none" {
99
; A8-LABEL: foo:
1010
; A8: @ %bb.0: @ %entry
1111
; A8-NEXT: movw r1, :lower16:(L_x$non_lazy_ptr-(LPC0_0+8))

0 commit comments

Comments
 (0)