Skip to content

Commit e155f03

Browse files
committed
IRGen: Always eliminate frame pointers of leaf functions
rdar://20933449
1 parent b8c74b4 commit e155f03

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ bool swift::irgen::shouldRemoveTargetFeature(StringRef feature) {
988988

989989
void IRGenModule::setHasFramePointer(llvm::AttrBuilder &Attrs,
990990
bool HasFramePointer) {
991-
Attrs.addAttribute("frame-pointer", HasFramePointer ? "all" : "none");
991+
Attrs.addAttribute("frame-pointer", HasFramePointer ? "non-leaf" : "none");
992992
}
993993

994994
void IRGenModule::setHasFramePointer(llvm::Function *F,

test/IRGen/c_globals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ public func testCaptureGlobal() {
3232
}
3333

3434
// CHECK-DAG: attributes [[CLANG_FUNC_ATTR]] = { noinline nounwind {{.*}}"frame-pointer"="all"{{.*}}
35-
// CHECK-DAG: attributes [[SWIFT_FUNC_ATTR]] = { {{.*}}"frame-pointer"="all" {{.*}}"target-cpu"
35+
// CHECK-DAG: attributes [[SWIFT_FUNC_ATTR]] = { {{.*}}"frame-pointer"="non-leaf" {{.*}}"target-cpu"

test/IRGen/framepointer.sil

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK
2+
// RUN: %target-swift-frontend -primary-file %s -S | %FileCheck %s --check-prefix=CHECKASM --check-prefix=CHECKASM-%target-os-%target-cpu
3+
4+
sil_stage canonical
5+
6+
import Swift
7+
8+
sil @leaf_function_no_frame_pointer : $@convention(thin) (Int32) -> Int32 {
9+
entry(%i : $Int32):
10+
return %i : $Int32
11+
}
12+
13+
sil @non_leaf_function_with_frame_pointer : $@convention(thin) (Int32) -> Int32 {
14+
entry(%i : $Int32):
15+
%f = function_ref @leaf_function_no_frame_pointer : $@convention(thin) (Int32) -> Int32
16+
%r = apply %f(%i) : $@convention(thin) (Int32) -> Int32
17+
return %r : $Int32
18+
}
19+
20+
// CHECK: define{{.*}} swiftcc i32 @leaf_function_no_frame_pointer(i32 %0) [[ATTR:#.*]] {
21+
// CHECK: entry:
22+
// CHECK: ret i32 %0
23+
// CHECK: }
24+
25+
// CHECK: define{{.*}} swiftcc i32 @non_leaf_function_with_frame_pointer(i32 %0) [[ATTR]] {
26+
// CHECK: entry:
27+
// CHECK: %1 = call swiftcc i32 @leaf_function_no_frame_pointer(i32 %0)
28+
// CHECK: ret i32 %1
29+
// CHECK: }
30+
31+
// CHECK: attributes [[ATTR]] = {{{.*}}"frame-pointer"="non-leaf"
32+
33+
// Silence other os-archs.
34+
// CHECKASM: {{.*}}
35+
36+
// CHECKASM-macosx-x86_64-LABEL: _leaf_function_no_frame_pointer:
37+
// CHECKASM-macosx-x86_64-NOT: push
38+
// CHECKASM-macosx-x86_64: movl %edi, %eax
39+
// CHECKASM-macosx-x86_64-NOT: pop
40+
// CHECKASM-macosx-x86_64: ret
41+
42+
43+
// CHECKASM-macosx-x86_64-LABEL: _non_leaf_function_with_frame_pointer:
44+
// CHECKASM-macosx-x86_64: pushq %rbp
45+
// CHECKASM-macosx-x86_64: movq %rsp, %rbp
46+
// CHECKASM-macosx-x86_64: callq _leaf_function_no_frame_pointer
47+
// CHECKASM-macosx-x86_64: popq %rbp
48+
// CHECKASM-macosx-x86_64: ret

test/Misc/tbi.sil

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@
1919

2020
// NO_TBI-LABEL: .globl _testTBI
2121
// NO_TBI: _testTBI
22-
// NO_TBI-NEXT: stp
23-
// NO_TBI-NEXT: mov
2422
// NO_TBI-NEXT: and
2523
// NO_TBI-NEXT: ldr
26-
// NO_TBI-NEXT: ldp
2724
// NO_TBI-NEXT: ret
2825

2926
// TBI-LABEL: .globl _testTBI
3027
// TBI: _testTBI:
31-
// TBI-NEXT: stp
32-
// TBI-NEXT: mov
3328
// TBI-NEXT: ldr
34-
// TBI-NEXT: ldp
3529
// TBI-NEXT: ret
3630

3731
sil_stage canonical

0 commit comments

Comments
 (0)