From: Simon Dardis Date: Fri, 27 May 2016 15:13:31 +0000 (+0000) Subject: [mips] Compact branch policy setting. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=536826934374f81983a1cb2bec3092bc1b9f7535;p=clang [mips] Compact branch policy setting. This patch adds the commandline option -mcompact-branches={never,optimal,always), which controls how LLVM generates compact branches for MIPSR6 targets. By default, the compact branch policy is 'optimal' where LLVM will generate the most appropriate branch for any situation. The 'never' and 'always' policy will disable or always generate compact branches wherever possible respectfully. Reviewers: dsanders, vkalintiris, atanasyan Differential Revision: http://reviews.llvm.org/D20729 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271000 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index b88a418d89..64ae4661d2 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -1140,6 +1140,16 @@ are listed below. This option restricts the generated code to use general registers only. This only applies to the AArch64 architecture. +.. option:: -mcompact-branches=[values] + + Control the usage of compact branches for MIPSR6. + + Valid values are: ``never``, ``optimal`` and ``always``. + The default value is ``optimal`` which generates compact branches + when a delay slot cannot be filled. ``never`` disables the usage of + compact branches and ``always`` generates compact branches whenever + possible. + **-f[no-]max-type-align=[number]** Instruct the code generator to not enforce a higher alignment than the given number (of bytes) when accessing memory via an opaque pointer or reference. diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 80114645db..c1d221e178 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -238,6 +238,9 @@ def warn_target_unsupported_nan2008 : Warning< def warn_target_unsupported_nanlegacy : Warning< "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">, InGroup; +def warn_target_unsupported_compact_branches : Warning< + "ignoring '-mcompact-branches=' option because the '%0' architecture does not" + " support it">, InGroup; def warn_drv_unable_to_find_directory_expected : Warning< "unable to find %0 directory, expected to be in '%1'">, diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 73df8998cd..979c81f636 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -56,6 +56,7 @@ def FloatConversion : def DoublePromotion : DiagGroup<"double-promotion">; def EnumTooLarge : DiagGroup<"enum-too-large">; def UnsupportedNan : DiagGroup<"unsupported-nan">; +def UnsupportedCB : DiagGroup<"unsupported-cb">; def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">; def NullConversion : DiagGroup<"null-conversion">; def ImplicitConversionFloatingPointToBool : diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index db9abbb9b9..c51acb89fa 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1621,6 +1621,7 @@ def mno_ldc1_sdc1 : Flag<["-"], "mno-ldc1-sdc1">, Group; def mcheck_zero_division : Flag<["-"], "mcheck-zero-division">, Group; def mno_check_zero_division : Flag<["-"], "mno-check-zero-division">, Group; +def mcompact_branches_EQ : Joined<["-"], "mcompact-branches=">, Group; def mdsp : Flag<["-"], "mdsp">, Group; def mno_dsp : Flag<["-"], "mno-dsp">, Group; def mdspr2 : Flag<["-"], "mdspr2">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 33de18d710..95f0a80140 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1436,6 +1436,19 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-mips-ssection-threshold=" + v)); A->claim(); } + + if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) { + StringRef Val = StringRef(A->getValue()); + if (mips::hasCompactBranches(CPUName)) { + if (Val == "never" || Val == "always" || Val == "optimal") { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Args.MakeArgString("-mips-compact-branches=" + Val)); + } else + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Val; + } else + D.Diag(diag::warn_target_unsupported_compact_branches) << CPUName; + } } /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. @@ -7065,6 +7078,14 @@ mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) { .Default(NanLegacy); } +bool mips::hasCompactBranches(StringRef &CPU) { + // mips32r6 and mips64r6 have compact branches. + return llvm::StringSwitch(CPU) + .Case("mips32r6", true) + .Case("mips64r6", true) + .Default(false); +} + bool mips::hasMipsAbiArg(const ArgList &Args, const char *Value) { Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index c2114bcfa8..2e546fc653 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -291,6 +291,7 @@ enum class FloatABI { }; NanEncoding getSupportedNanEncoding(StringRef &CPU); +bool hasCompactBranches(StringRef &CPU); void getMipsCPUAndABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName); diff --git a/test/Driver/mips-features.c b/test/Driver/mips-features.c index 461d778182..69fc20e1f2 100644 --- a/test/Driver/mips-features.c +++ b/test/Driver/mips-features.c @@ -116,6 +116,24 @@ // RUN: | FileCheck --check-prefix=CHECK-NANLEGACY %s // CHECK-NANLEGACY: "-target-feature" "-nan2008" // +// -mcompact-branches=never +// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \ +// RUN: -mcompact-branches=never 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CBNEVER %s +// CHECK-CBNEVER: "-mllvm" "-mips-compact-branches=never" +// +// -mcompact-branches=optimal +// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \ +// RUN: -mcompact-branches=optimal 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CBOPTIMAL %s +// CHECK-CBOPTIMAL: "-mllvm" "-mips-compact-branches=optimal" +// +// -mcompact-branches=always +// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \ +// RUN: -mcompact-branches=always 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CBALWAYS %s +// CHECK-CBALWAYS: "-mllvm" "-mips-compact-branches=always" +// // -mxgot // RUN: %clang -target mips-linux-gnu -### -c %s \ // RUN: -mno-xgot -mxgot 2>&1 \