Skip to content

Commit f986987

Browse files
committed
Enable frame pointer for all non-leaf functions on riscv64 Android
Bringing parity with aarch64-android google/android-riscv64#9 (comment) Reviewers: enh, danalbert, pirama, srhines Differential Revision: https://reviews.llvm.org/D150490
1 parent 2239fd5 commit f986987

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ static bool useFramePointerForTargetByDefault(const ArgList &Args,
420420
if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
421421
return true;
422422

423+
if (Triple.isAndroid()) {
424+
switch (Triple.getArch()) {
425+
case llvm::Triple::aarch64:
426+
case llvm::Triple::arm:
427+
case llvm::Triple::armeb:
428+
case llvm::Triple::thumb:
429+
case llvm::Triple::thumbeb:
430+
case llvm::Triple::riscv64:
431+
return true;
432+
default:
433+
break;
434+
}
435+
}
436+
423437
switch (Triple.getArch()) {
424438
case llvm::Triple::xcore:
425439
case llvm::Triple::wasm32:
@@ -459,9 +473,6 @@ static bool useFramePointerForTargetByDefault(const ArgList &Args,
459473
case llvm::Triple::armeb:
460474
case llvm::Triple::thumb:
461475
case llvm::Triple::thumbeb:
462-
if (Triple.isAndroid())
463-
return true;
464-
[[fallthrough]];
465476
case llvm::Triple::mips64:
466477
case llvm::Triple::mips64el:
467478
case llvm::Triple::mips:
@@ -515,7 +526,8 @@ getFramePointerKind(const ArgList &Args, const llvm::Triple &Triple) {
515526
bool OmitLeafFP =
516527
Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
517528
options::OPT_mno_omit_leaf_frame_pointer,
518-
Triple.isAArch64() || Triple.isPS() || Triple.isVE());
529+
Triple.isAArch64() || Triple.isPS() || Triple.isVE() ||
530+
(Triple.isAndroid() && Triple.isRISCV64()));
519531
if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
520532
(!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
521533
if (OmitLeafFP)

clang/test/Driver/frame-pointer-elim.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
107107
// RUN: %clang -### -target ve-unknown-linux-gnu -S %s 2>&1 | \
108108
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
109+
// RUN: %clang -### --target=aarch64-linux-android -S %s 2>&1 | \
110+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
111+
// RUN: %clang -### --target=aarch64-linux-android -S -O2 %s 2>&1 | \
112+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
113+
// RUN: %clang -### --target=aarch64-linux-android -S -Os %s 2>&1 | \
114+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
109115

110116
// RUN: %clang -### -target powerpc64 -S %s 2>&1 | \
111117
// RUN: FileCheck --check-prefix=KEEP-ALL %s
@@ -153,6 +159,9 @@
153159
// RUN: FileCheck --check-prefix=KEEP-ALL %s
154160
// RUN: %clang -### -target armv7a-linux-androideabi- -mthumb -mbig-endian -O1 -S %s 2>&1 | \
155161
// RUN: FileCheck --check-prefix=KEEP-ALL %s
156-
162+
// RUN: %clang -### --target=riscv64-linux-android -O1 -S %s 2>&1 | \
163+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
164+
// RUN: %clang -### --target=riscv64-linux-android -mbig-endian -O1 -S %s 2>&1 | \
165+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
157166
void f0() {}
158167
void f1() { f0(); }

clang/test/Driver/frame-pointer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
// RUN: %clang --target=riscv64-unknown-linux-gnu -### -S -O3 %s 2>&1 | FileCheck -check-prefix=CHECK3-64 %s
5858
// RUN: %clang --target=riscv64-unknown-linux-gnu -### -S -Os %s 2>&1 | FileCheck -check-prefix=CHECKs-64 %s
5959

60+
// RUN: %clang --target=riscv64-linux-android -### -S -O0 %s 2>&1 | FileCheck -check-prefix=CHECK-ANDROID-64 %s
61+
// RUN: %clang --target=riscv64-linux-android -### -S -O1 %s 2>&1 | FileCheck -check-prefix=CHECK-ANDROID-64 %s
62+
// RUN: %clang --target=riscv64-linux-android -### -S -Os %s 2>&1 | FileCheck -check-prefix=CHECK-ANDROID-64 %s
63+
6064
// RUN: %clang --target=loongarch32 -### -S -O0 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK0-32 %s
6165
// RUN: %clang --target=loongarch32 -### -S -O1 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK1-32 %s
6266
// RUN: %clang --target=loongarch32 -### -S -O2 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK2-32 %s
@@ -81,3 +85,5 @@
8185
// CHECK3-64-NOT: -mframe-pointer=all
8286
// CHECKs-64-NOT: -mframe-pointer=all
8387
// CHECK-MACHO-64: -mframe-pointer=all
88+
89+
// CHECK-ANDROID-64: -mframe-pointer=non-leaf

0 commit comments

Comments
 (0)