Skip to content

Commit

Permalink
[ARM] Pass subtarget feature "+long-calls" instead of passing backend…
Browse files Browse the repository at this point in the history
… option

"-arm-long-calls".

This change allows using -mlong-calls/-mno-long-calls for LTO and enabling or
disabling long call on a per-function basis.

rdar://problem/21529937

Differential Revision: http://reviews.llvm.org/D9414

llvm-svn: 241565
  • Loading branch information
ahatanaka committed Jul 7, 2015
1 parent 0a8890f commit 3fb33a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
26 changes: 10 additions & 16 deletions clang/lib/Driver/Tools.cpp
Expand Up @@ -638,6 +638,8 @@ static void getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector<const char *> &Features,
bool ForAS) {
bool KernelOrKext =
Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
StringRef FloatABI = tools::arm::getARMFloatABI(D, Args, Triple);
if (!ForAS) {
// FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
Expand Down Expand Up @@ -705,6 +707,14 @@ static void getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8_1a) {
Features.insert(Features.begin(), "+v8.1a");
}

if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
options::OPT_mno_long_calls)) {
if (A->getOption().matches(options::OPT_mlong_calls))
Features.push_back("+long-calls");
} else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6))) {
Features.push_back("+long-calls");
}
}

void Clang::AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs,
Expand Down Expand Up @@ -778,11 +788,6 @@ void Clang::AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs,

// Kernel code has more strict alignment requirements.
if (KernelOrKext) {
if (!Triple.isiOS() || Triple.isOSVersionLT(6)) {
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-long-calls");
}

CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-strict-align");

Expand Down Expand Up @@ -4074,17 +4079,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-arm-restrict-it");
}

if (TT.getArch() == llvm::Triple::arm ||
TT.getArch() == llvm::Triple::thumb) {
if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
options::OPT_mno_long_calls)) {
if (A->getOption().matches(options::OPT_mlong_calls)) {
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-long-calls");
}
}
}

// Forward -f options with positive and negative forms; we translate
// these by hand.
if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/arm-long-calls.c
@@ -0,0 +1,7 @@
// RUN: %clang_cc1 -triple thumbv7-apple-ios5 -target-feature +long-calls -emit-llvm -o - %s | FileCheck -check-prefix=LONGCALL %s
// RUN: %clang_cc1 -triple thumbv7-apple-ios5 -emit-llvm -o - %s | FileCheck -check-prefix=NOLONGCALL %s

// LONGCALL: attributes #0 = { {{.*}} "target-features"="+long-calls"
// NOLONGCALL-NOT: attributes #0 = { {{.*}} "target-features"="+long-calls"

int foo1(int a) { return a; }
2 changes: 1 addition & 1 deletion clang/test/Driver/apple-kext-mkernel.c
Expand Up @@ -11,7 +11,7 @@
// RUN: -arch armv7 -mkernel -mstrict-align -### -fsyntax-only %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-ARM < %t %s

// CHECK-ARM: "-backend-option" "-arm-long-calls"
// CHECK-ARM: "-target-feature" "+long-calls"
// CHECK-ARM: "-backend-option" "-arm-strict-align"
// CHECK-ARM-NOT: "-backend-option" "-arm-strict-align"
// CHECK-ARM: "-fno-builtin"
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Driver/arm-long-calls.c
Expand Up @@ -7,9 +7,9 @@
// RUN: %clang -target armv7-eabi -### -mlong-calls -mno-long-calls %s 2>&1 \
// RUN: | FileCheck %s -check-prefix CHECK-NO-LONG-CALLS

// CHECK-DEFAULT-NOT: "-backend-option" "-arm-long-calls"
// CHECK-DEFAULT-NOT: "-target-feature" "+long-calls"

// CHECK-LONG-CALLS: "-backend-option" "-arm-long-calls"
// CHECK-LONG-CALLS: "-target-feature" "+long-calls"

// CHECK-NO-LONG-CALLS-NOT: "-backend-option" "-arm-long-calls"
// CHECK-NO-LONG-CALLS-NOT: "-target-feature" "+long-calls"

0 comments on commit 3fb33a5

Please sign in to comment.