Skip to content

Commit 4a85a0c

Browse files
committed
[clang][ARM] disable frame pointers by default for bare metal ARM targets
because: - This brings Clang in line with GCC for which this is the default for ARM - It frees up a register, so performance increase, especially on Thumb/6-M - It will also decrease code size
1 parent a742741 commit 4a85a0c

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
128128
}
129129
}
130130

131+
namespace clang {
132+
namespace driver {
133+
namespace toolchains {
131134
/// Is the triple {arm,armeb,thumb,thumbeb}-none-none-{eabi,eabihf} ?
132-
static bool isARMBareMetal(const llvm::Triple &Triple) {
135+
bool isARMBareMetal(const llvm::Triple &Triple) {
133136
if (Triple.getArch() != llvm::Triple::arm &&
134137
Triple.getArch() != llvm::Triple::thumb &&
135138
Triple.getArch() != llvm::Triple::armeb &&
@@ -148,6 +151,9 @@ static bool isARMBareMetal(const llvm::Triple &Triple) {
148151

149152
return true;
150153
}
154+
} // namespace clang
155+
} // namespace driver
156+
} // namespace clang
151157

152158
/// Is the triple {aarch64.aarch64_be}-none-elf?
153159
static bool isAArch64BareMetal(const llvm::Triple &Triple) {

clang/lib/Driver/ToolChains/BareMetal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace driver {
1919

2020
namespace toolchains {
2121

22+
bool isARMBareMetal(const llvm::Triple &Triple);
23+
2224
class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
2325
public:
2426
BareMetal(const Driver &D, const llvm::Triple &Triple,

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Arch/SystemZ.h"
2020
#include "Arch/VE.h"
2121
#include "Arch/X86.h"
22+
#include "BareMetal.h"
2223
#include "HIPAMD.h"
2324
#include "Hexagon.h"
2425
#include "MSP430.h"
@@ -151,6 +152,10 @@ static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
151152
}
152153
}
153154

155+
if (toolchains::isARMBareMetal(Triple)) {
156+
return false;
157+
}
158+
154159
return true;
155160
}
156161

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,34 @@
162162
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
163163
// RUN: not %clang -### --target=riscv64-linux-android -mbig-endian -O1 -S %s 2>&1 | \
164164
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
165+
166+
// On ARM backend bare metal targets, frame pointer is omitted
167+
// RUN: %clang -### --target=arm-arm-none-eabi -S %s 2>&1 | \
168+
// RUN: FileCheck --check-prefix=KEEP-NONE %s
169+
// RUN: %clang -### --target=arm-arm-none-eabihf -S %s 2>&1 | \
170+
// RUN: FileCheck --check-prefix=KEEP-NONE %s
171+
// RUN: %clang -### --target=arm-arm-none-eabi -S -fno-omit-frame-pointer %s 2>&1 | \
172+
// RUN: FileCheck --check-prefix=KEEP-ALL %s
173+
// RUN: %clang -### --target=arm-arm-none-eabihf -S -fno-omit-frame-pointer %s 2>&1 | \
174+
// RUN: FileCheck --check-prefix=KEEP-ALL %s
175+
// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 %s 2>&1 | \
176+
// RUN: FileCheck --check-prefix=KEEP-NONE %s
177+
// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 %s 2>&1 | \
178+
// RUN: FileCheck --check-prefix=KEEP-NONE %s
179+
// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 -fno-omit-frame-pointer %s 2>&1 | \
180+
// RUN: FileCheck --check-prefix=KEEP-ALL %s
181+
// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 -fno-omit-frame-pointer %s 2>&1 | \
182+
// RUN: FileCheck --check-prefix=KEEP-ALL %s
183+
184+
// AArch64 bare metal targets behave like hosted targets
185+
// RUN: %clang -### --target=aarch64-none-elf -S %s 2>&1 | \
186+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
187+
// RUN: %clang -### --target=aarch64-none-elf -S -O1 %s 2>&1 | \
188+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
189+
// RUN: %clang -### --target=aarch64-none-elf -S -fno-omit-frame-pointer %s 2>&1 | \
190+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
191+
// RUN: %clang -### --target=aarch64-none-elf -S -O1 -fno-omit-frame-pointer %s 2>&1 | \
192+
// RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
193+
165194
void f0() {}
166195
void f1() { f0(); }

0 commit comments

Comments
 (0)