From 070ffd29fb0a5a558e8f9bd464f784ff24ef1a54 Mon Sep 17 00:00:00 2001 From: Ahmed Bougacha Date: Sat, 11 Apr 2015 00:10:44 +0000 Subject: [PATCH] [Driver] Properly support -mglobal-merge using explicit options. Follow-up to r234666. With this, the -m[no-]global-merge options have the expected behavior. Previously, -mglobal-merge was ignored, and there was no way of enabling the optimization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234668 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 3 +- include/clang/Frontend/CodeGenOptions.def | 1 - lib/CodeGen/BackendUtil.cpp | 2 -- lib/Driver/Tools.cpp | 16 +++++---- lib/Frontend/CompilerInvocation.cpp | 1 - test/Driver/mglobal-merge.c | 40 +++++++++++++++++++++++ test/Driver/mno-global-merge.c | 20 ------------ 7 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 test/Driver/mglobal-merge.c delete mode 100644 test/Driver/mno-global-merge.c diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index ee5018615c..50bfd315c5 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1146,7 +1146,8 @@ def mfloat_abi_EQ : Joined<["-"], "mfloat-abi=">, Group; def mfpmath_EQ : Joined<["-"], "mfpmath=">, Group; def mfpu_EQ : Joined<["-"], "mfpu=">, Group; def mhwdiv_EQ : Joined<["-"], "mhwdiv=">, Group; -def mglobal_merge : Flag<["-"], "mglobal-merge">, Group; +def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, Flags<[CC1Option]>, + HelpText<"Enable merging of globals">; def mhard_float : Flag<["-"], "mhard-float">, Group; def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, Group; def mios_version_min_EQ : Joined<["-"], "mios-version-min=">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 188171b86e..aeea18da56 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -77,7 +77,6 @@ CODEGENOPT(NoExecStack , 1, 0) ///< Set when -Wa,--noexecstack is enabled. CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is ///< enabled. CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. -CODEGENOPT(NoGlobalMerge , 1, 0) ///< Set when -mno-global-merge is enabled. CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled. CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf. CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP zero diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 90f594fe15..7c443cc805 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -436,8 +436,6 @@ TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { BackendArgs.push_back("-time-passes"); for (unsigned i = 0, e = CodeGenOpts.BackendOptions.size(); i != e; ++i) BackendArgs.push_back(CodeGenOpts.BackendOptions[i].c_str()); - if (CodeGenOpts.NoGlobalMerge) - BackendArgs.push_back("-enable-global-merge=false"); BackendArgs.push_back(nullptr); llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1, BackendArgs.data()); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 012e69b7dc..4d0ca57659 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -861,12 +861,14 @@ void Clang::AddARMTargetArgs(const ArgList &Args, } } - // Setting -mno-global-merge disables the codegen global merge pass. Setting - // -mglobal-merge has no effect as the pass is enabled by default. + // Forward the -mglobal-merge option for explicit control over the pass. if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, options::OPT_mno_global_merge)) { + CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_global_merge)) - CmdArgs.push_back("-mno-global-merge"); + CmdArgs.push_back("-arm-global-merge=false"); + else + CmdArgs.push_back("-arm-global-merge=true"); } if (!Args.hasFlag(options::OPT_mimplicit_float, @@ -957,12 +959,14 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=1"); } - // Setting -mno-global-merge disables the codegen global merge pass. Setting - // -mglobal-merge has no effect as the pass is enabled by default. + // Forward the -mglobal-merge option for explicit control over the pass. if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, options::OPT_mno_global_merge)) { + CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_global_merge)) - CmdArgs.push_back("-mno-global-merge"); + CmdArgs.push_back("-aarch64-global-merge=false"); + else + CmdArgs.push_back("-aarch64-global-merge=true"); } if (Args.hasArg(options::OPT_ffixed_x18)) { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index cd0a7c4640..9632d4ea8c 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -455,7 +455,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags); - Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge); Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks); diff --git a/test/Driver/mglobal-merge.c b/test/Driver/mglobal-merge.c new file mode 100644 index 0000000000..ad76736a69 --- /dev/null +++ b/test/Driver/mglobal-merge.c @@ -0,0 +1,40 @@ +// RUN: %clang -target armv7-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mno-global-merge +// RUN: FileCheck --check-prefix=CHECK-NGM-ARM < %t %s + +// RUN: %clang -target aarch64-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mno-global-merge +// RUN: FileCheck --check-prefix=CHECK-NGM-AARCH64 < %t %s + +// RUN: %clang -target x86_64-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mno-global-merge +// RUN: FileCheck --check-prefix=CHECK-NONE < %t %s + +// CHECK-NGM-ARM: "-backend-option" "-arm-global-merge=false" +// CHECK-NGM-AARCH64: "-backend-option" "-aarch64-global-merge=false" + +// RUN: %clang -target armv7-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mglobal-merge +// RUN: FileCheck --check-prefix=CHECK-GM-ARM < %t %s + +// RUN: %clang -target aarch64-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mglobal-merge +// RUN: FileCheck --check-prefix=CHECK-GM-AARCH64 < %t %s + +// RUN: %clang -target x86_64-unknown-unknown -### -fsyntax-only %s 2> %t \ +// RUN: -mglobal-merge +// RUN: FileCheck --check-prefix=CHECK-NONE < %t %s + +// CHECK-GM-ARM: "-backend-option" "-arm-global-merge=true" +// CHECK-GM-AARCH64: "-backend-option" "-aarch64-global-merge=true" + +// RUN: %clang -target armv7-unknown-unknown -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-NONE < %t %s + +// RUN: %clang -target aarch64-unknown-unknown -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-NONE < %t %s + +// RUN: %clang -target x86_64-unknown-unknown -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-NONE < %t %s + +// CHECK-NONE-NOT: -global-merge= diff --git a/test/Driver/mno-global-merge.c b/test/Driver/mno-global-merge.c deleted file mode 100644 index a17848f04d..0000000000 --- a/test/Driver/mno-global-merge.c +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang -target armv7-apple-darwin10 \ -// RUN: -mno-global-merge -### -fsyntax-only %s 2> %t -// RUN: FileCheck --check-prefix=CHECK-NGM < %t %s - -// RUN: %clang -target arm64-apple-ios7 \ -// RUN: -mno-global-merge -### -fsyntax-only %s 2> %t -// RUN: FileCheck --check-prefix=CHECK-NGM < %t %s - -// CHECK-NGM: "-mno-global-merge" - -// RUN: %clang -target armv7-apple-darwin10 \ -// RUN: -mglobal-merge -### -fsyntax-only %s 2> %t -// RUN: FileCheck --check-prefix=CHECK-GM < %t %s - -// RUN: %clang -target arm64-apple-ios7 \ -// RUN: -mglobal-merge -### -fsyntax-only %s 2> %t -// RUN: FileCheck --check-prefix=CHECK-GM < %t %s - -// CHECK-GM-NOT: "-mglobal-merge" - -- 2.40.0