Skip to content

Commit

Permalink
fix issues 108019
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxin049 committed Sep 23, 2024
1 parent f5a65d8 commit 45efaee
Showing 22 changed files with 62 additions and 36 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
@@ -161,6 +161,10 @@ namespace llvm {
/// DisableFramePointerElim - This returns true if frame pointer elimination
/// optimization should be disabled for the given machine function.
bool DisableFramePointerElim(const MachineFunction &MF) const;

/// DisableLeafFramePointerElim - This returns true if leaf frame pointer elimination
/// optimization should be disabled for the given machine function.
bool DisableLeafFramePointerElim(const MachineFunction &MF) const;

/// FramePointerIsReserved - This returns true if the frame pointer must
/// always either point to a new frame record or be un-modified in the given
13 changes: 13 additions & 0 deletions llvm/lib/CodeGen/TargetOptionsImpl.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,19 @@ bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
llvm_unreachable("unknown frame pointer flag");
}

/// DisableLeafFramePointerElim - This returns true if leaf frame pointer elimination
/// optimization should be disabled for the given machine function.
bool TargetOptions::DisableLeafFramePointerElim(const MachineFunction &MF) const {
const Function &F = MF.getFunction();

if (!F.hasFnAttribute("frame-pointer"))
return false;
StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
if (FP == "all")
return true;
return false;
}

bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const {
// Check to see if the target want to forcibly keep frame pointer.
if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
3 changes: 2 additions & 1 deletion llvm/lib/Target/ARM/ARMFrameLowering.cpp
Original file line number Diff line number Diff line change
@@ -2271,6 +2271,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
// is spilled in the order specified by getCalleeSavedRegs() to make it easier
// to combine multiple loads / stores.
bool CanEliminateFrame = !(requiresAAPCSFrameRecord(MF) && hasFP(MF));
bool CanEliminateLeafFrame = !MF.getTarget().Options.DisableLeafFramePointerElim(MF);
bool CS1Spilled = false;
bool LRSpilled = false;
unsigned NumGPRSpills = 0;
@@ -2513,7 +2514,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
<< "; EstimatedFPStack: " << MaxFixedOffset - MaxFPOffset
<< "; BigFrameOffsets: " << BigFrameOffsets << "\n");
if (BigFrameOffsets ||
!CanEliminateFrame || RegInfo->cannotEliminateFrame(MF)) {
!CanEliminateFrame || RegInfo->cannotEliminateFrame(MF) || !CanEliminateLeafFrame) {
AFI->setHasStackFrame(true);

if (HasFP) {
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

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

define void @main(i8 %val8) nounwind {
define void @main(i8 %val8) nounwind "frame-pointer"="none" {
; CHECK-LABEL: main:
; CHECK: @ %bb.0: @ %for.body.lr.ph
; CHECK-NEXT: movw r0, :lower16:(L_oStruct$non_lazy_ptr-(LPC0_0+4))
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/arm-shrink-wrapping.ll
Original file line number Diff line number Diff line change
@@ -1732,7 +1732,7 @@ if.end:
; Another infinite loop test this time with two nested infinite loop.
; infiniteloop3
; bx lr
define void @infiniteloop3() "frame-pointer"="all" {
define void @infiniteloop3() "frame-pointer"="none" {
; ARM-LABEL: infiniteloop3:
; ARM: @ %bb.0: @ %entry
; ARM-NEXT: mov r0, #0
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/ARM/call-tc.ll
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ define void @t1() "frame-pointer"="all" {
ret void
}

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

; Make sure codegenprep is duplicating ret instructions to enable tail calls.
; rdar://11140249
define i32 @t8(i32 %x) nounwind ssp "frame-pointer"="all" {
define i32 @t8(i32 %x) nounwind ssp "frame-pointer"="none" {
entry:
; CHECKT2D-LABEL: t8:
; CHECKT2D-NOT: push
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/debug-frame.ll
Original file line number Diff line number Diff line change
@@ -526,7 +526,7 @@ entry:
; Test 4
;-------------------------------------------------------------------------------

define void @test4() nounwind {
define void @test4() nounwind "frame-pointer"="none" {
entry:
ret void
}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/ehabi.ll
Original file line number Diff line number Diff line change
@@ -575,7 +575,7 @@ entry:
; Test 4
;-------------------------------------------------------------------------------

define void @test4() nounwind {
define void @test4() nounwind "frame-pointer"="none" {
entry:
ret void
}
11 changes: 7 additions & 4 deletions llvm/test/CodeGen/ARM/frame-chain.ll
Original file line number Diff line number Diff line change
@@ -10,11 +10,14 @@
define dso_local noundef i32 @leaf(i32 noundef %0) {
; LEAF-FP-LABEL: leaf:
; LEAF-FP: @ %bb.0:
; LEAF-FP-NEXT: .pad #4
; LEAF-FP-NEXT: sub sp, sp, #4
; LEAF-FP-NEXT: str r0, [sp]
; LEAF-FP-NEXT: .save {r11, lr}
; LEAF-FP-NEXT: push {r11, lr}
; LEAF-FP-NEXT: .setfp r11, sp
; LEAF-FP-NEXT: mov r11, sp
; LEAF-FP-NEXT: push {r0}
; LEAF-FP-NEXT: add r0, r0, #4
; LEAF-FP-NEXT: add sp, sp, #4
; LEAF-FP-NEXT: mov sp, r11
; LEAF-FP-NEXT: pop {r11, lr}
; LEAF-FP-NEXT: mov pc, lr
;
; LEAF-FP-AAPCS-LABEL: leaf:
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/ifcvt5.ll
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

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

define void @foo(i32 %a) "frame-pointer"="all" {
define void @foo(i32 %a) "frame-pointer"="none" {
; A8-LABEL: foo:
; A8: @ %bb.0: @ %entry
; A8-NEXT: movw r1, :lower16:(L_x$non_lazy_ptr-(LPC0_0+8))
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/ARM/ldrd.ll
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ define void @ldrd_postupdate_inc(ptr %p0) "frame-pointer"="all" {
; NORMAL: strd r1, r2, [r0], #-8
; CONSERVATIVE-NOT: strd
; CHECK: bx lr
define ptr @strd_postupdate_dec(ptr %p0, i32 %v0, i32 %v1) "frame-pointer"="all" {
define ptr @strd_postupdate_dec(ptr %p0, i32 %v0, i32 %v1) "frame-pointer"="none" {
%p0.1 = getelementptr i32, ptr %p0, i32 1
store i32 %v0, ptr %p0
store i32 %v1, ptr %p0.1
@@ -180,7 +180,7 @@ define ptr @strd_postupdate_dec(ptr %p0, i32 %v0, i32 %v1) "frame-pointer"="all"
; NORMAL: strd r1, r2, [r0], #8
; CONSERVATIVE-NOT: strd
; CHECK: bx lr
define ptr @strd_postupdate_inc(ptr %p0, i32 %v0, i32 %v1) "frame-pointer"="all" {
define ptr @strd_postupdate_inc(ptr %p0, i32 %v0, i32 %v1) "frame-pointer"="none" {
%p0.1 = getelementptr i32, ptr %p0, i32 1
store i32 %v0, ptr %p0
store i32 %v1, ptr %p0.1
9 changes: 5 additions & 4 deletions llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
; BOTH: [SP-8]{{.+}}8{{.+}}4
; DEBUG: a @ dot.c:13
; STRIPPED-NOT: a @ dot.c:13
define void @cleanup_array(ptr %0) #1 {
define void @cleanup_array(ptr %0) #3 {
%2 = alloca ptr, align 8
store ptr %0, ptr %2, align 8
call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
@@ -62,7 +62,7 @@ define void @cleanup_array(ptr %0) #1 {
; BOTH: [SP-8]{{.+}}8{{.+}}4
; DEBUG: res @ dot.c:21
; STRIPPED-NOT: res @ dot.c:21
define void @cleanup_result(ptr %0) #1 {
define void @cleanup_result(ptr %0) #3 {
%2 = alloca ptr, align 8
store ptr %0, ptr %2, align 8
call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
@@ -92,7 +92,7 @@ define void @cleanup_result(ptr %0) #1 {
; BOTH: [SP-40]{{.+}}4{{.+}}4
; DEBUG: i @ dot.c:55
; STRIPPED-NOT: i @ dot.c:55
define i32 @do_work(ptr %0, ptr %1, ptr %2) #1 {
define i32 @do_work(ptr %0, ptr %1, ptr %2) #3 {
%4 = alloca i32, align 4
%5 = alloca ptr, align 8
%6 = alloca ptr, align 8
@@ -144,7 +144,7 @@ define i32 @do_work(ptr %0, ptr %1, ptr %2) #1 {
; BOTH: [SP-20]{{.+}}4{{.*}}4
; DEBUG: i @ dot.c:69
; STRIPPED-NOT: i @ dot.c:69
define ptr @gen_array(i32 %0) #1 {
define ptr @gen_array(i32 %0) #3 {
%2 = alloca ptr, align 8
%3 = alloca i32, align 4
%4 = alloca ptr, align 8
@@ -227,6 +227,7 @@ uselistorder ptr @llvm.dbg.declare, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
attributes #1 = { "frame-pointer"="all" }
attributes #2 = { ssp "stack-protector-buffer-size"="5" "frame-pointer"="all" }
attributes #3 = { "frame-pointer"="none" }

!llvm.dbg.cu = !{!0, !2}
!llvm.module.flags = !{!18, !19, !20, !21, !22, !23, !24}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/stack-size-section.ll
Original file line number Diff line number Diff line change
@@ -29,4 +29,4 @@ define void @dynalloc(i32 %N) #0 {
ret void
}

attributes #0 = { "frame-pointer"="all" }
attributes #0 = { "frame-pointer"="none" }
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/ARM/v7k-abi-align.ll
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ define void @test_dpr_unwind_align_no_dprs() "frame-pointer"="all" {

; 128-bit vectors should use 128-bit (i.e. correctly aligned) slots on
; the stack.
define <4 x float> @test_v128_stack_pass([8 x double], float, <4 x float> %in) "frame-pointer"="all" {
define <4 x float> @test_v128_stack_pass([8 x double], float, <4 x float> %in) "frame-pointer"="none" {
; CHECK-LABEL: test_v128_stack_pass:
; CHECK: add r[[ADDR:[0-9]+]], sp, #16
; CHECK: vld1.64 {d0, d1}, [r[[ADDR]]:128]
@@ -140,7 +140,7 @@ define void @test_v128_stack_pass_varargs(<4 x float> %in) "frame-pointer"="all"

; To be compatible with AAPCS's va_start model (store r0-r3 at incoming SP, give
; a single pointer), 64-bit quantities must be pass
define i64 @test_64bit_gpr_align(i32, i64 %r2_r3, i32 %sp) "frame-pointer"="all" {
define i64 @test_64bit_gpr_align(i32, i64 %r2_r3, i32 %sp) "frame-pointer"="none" {
; CHECK-LABEL: test_64bit_gpr_align:
; CHECK: ldr [[RHS:r[0-9]+]], [sp]
; CHECK: adds r0, [[RHS]], r2
16 changes: 10 additions & 6 deletions llvm/test/CodeGen/Thumb/frame-chain.ll
Original file line number Diff line number Diff line change
@@ -8,12 +8,16 @@
define dso_local noundef i32 @leaf(i32 noundef %0) {
; LEAF-FP-LABEL: leaf:
; LEAF-FP: @ %bb.0:
; LEAF-FP-NEXT: .pad #4
; LEAF-FP-NEXT: sub sp, #4
; LEAF-FP-NEXT: str r0, [sp]
; LEAF-FP-NEXT: adds r0, r0, #4
; LEAF-FP-NEXT: add sp, #4
; LEAF-FP-NEXT: bx lr
; LEAF-FP-NEXT: .save {r7, lr}
; LEAF-FP-NEXT: push {r7, lr}
; LEAF-FP-NEXT: .setfp r7, sp
; LEAF-FP-NEXT: add r7, sp, #0
; LEAF-FP-NEXT: .pad #4
; LEAF-FP-NEXT: sub sp, #4
; LEAF-FP-NEXT: str r0, [sp]
; LEAF-FP-NEXT: adds r0, r0, #4
; LEAF-FP-NEXT: add sp, #4
; LEAF-FP-NEXT: pop {r7, pc}
;
; LEAF-FP-AAPCS-LABEL: leaf:
; LEAF-FP-AAPCS: @ %bb.0:
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/Thumb2/frame-pointer.ll
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ define void @leaf() {

; Leaf function, frame pointer is requested but we don't need any stack frame,
; so don't create a frame pointer.
define void @leaf_nofpelim() "frame-pointer"="all" {
define void @leaf_nofpelim() "frame-pointer"="none" {
; CHECK-LABEL: leaf_nofpelim:
; CHECK-NOT: push
; CHECK-NOT: sp
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/Thumb2/frameless.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -frame-pointer=all | not grep mov
; RUN: llc < %s -mtriple=thumbv7-linux -frame-pointer=all | not grep mov
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -frame-pointer=none | not grep mov
; RUN: llc < %s -mtriple=thumbv7-linux -frame-pointer=none | not grep mov

define void @t() nounwind readnone {
ret void
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/Thumb2/frameless2.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -frame-pointer=all | not grep r7
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -frame-pointer=none | not grep r7

%struct.noise3 = type { [3 x [17 x i32]] }
%struct.noiseguard = type { i32, i32, i32 }
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/Thumb2/machine-licm.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -relocation-model=dynamic-no-pic -frame-pointer=all | FileCheck %s
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -relocation-model=pic -frame-pointer=all | FileCheck %s --check-prefix=PIC
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -relocation-model=dynamic-no-pic -frame-pointer=none | FileCheck %s
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -relocation-model=pic -frame-pointer=none | FileCheck %s --check-prefix=PIC
; rdar://7353541
; rdar://7354376

Original file line number Diff line number Diff line change
@@ -60,4 +60,4 @@ define dso_local i32 @main() #0 {
ret i32 0
}

attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="all" }
attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="none" }
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ define dso_local i32 @main() #0 {
ret i32 0
}

attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="all" }
attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="none" }
; CHECK-LABEL: check_boundaries:
; CHECK: @ %bb.0:
; CHECK-NEXT: sub sp, sp, #20
Original file line number Diff line number Diff line change
@@ -121,4 +121,4 @@ define dso_local i32 @main() #0 {
ret i32 0
}

attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="all" }
attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="none" }

0 comments on commit 45efaee

Please sign in to comment.