r301361 - [Hexagon] Set -ffp-contract=fast at -O3 unless explicitly specified
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 25 13:51:51 PDT 2017
Author: kparzysz
Date: Tue Apr 25 15:51:51 2017
New Revision: 301361
URL: http://llvm.org/viewvc/llvm-project?rev=301361&view=rev
Log:
[Hexagon] Set -ffp-contract=fast at -O3 unless explicitly specified
Modified:
cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
cfe/trunk/lib/Driver/ToolChains/Hexagon.h
cfe/trunk/test/Driver/hexagon-toolchain-elf.c
Modified: cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp?rev=301361&r1=301360&r2=301361&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp Tue Apr 25 15:51:51 2017
@@ -402,6 +402,39 @@ Tool *HexagonToolChain::buildLinker() co
return new tools::hexagon::Linker(*this);
}
+unsigned HexagonToolChain::getOptimizationLevel(
+ const llvm::opt::ArgList &DriverArgs) const {
+ // Copied in large part from lib/Frontend/CompilerInvocation.cpp.
+ Arg *A = DriverArgs.getLastArg(options::OPT_O_Group);
+ if (!A)
+ return 0;
+
+ if (A->getOption().matches(options::OPT_O0))
+ return 0;
+ if (A->getOption().matches(options::OPT_Ofast))
+ return 3;
+ assert(A->getNumValues() != 0);
+ StringRef S(A->getValue());
+ if (S == "s" || S == "z" || S.empty())
+ return 2;
+ if (S == "g")
+ return 1;
+
+ unsigned OptLevel;
+ if (S.getAsInteger(10, OptLevel))
+ return 0;
+ return OptLevel;
+}
+
+void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+ if (DriverArgs.hasArg(options::OPT_ffp_contract))
+ return;
+ unsigned OptLevel = getOptimizationLevel(DriverArgs);
+ if (OptLevel >= 3)
+ CC1Args.push_back("-ffp-contract=fast");
+}
+
void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nostdinc) ||
Modified: cfe/trunk/lib/Driver/ToolChains/Hexagon.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Hexagon.h?rev=301361&r1=301360&r2=301361&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Hexagon.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Hexagon.h Tue Apr 25 15:51:51 2017
@@ -61,11 +61,15 @@ protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
+ unsigned getOptimizationLevel(const llvm::opt::ArgList &DriverArgs) const;
+
public:
HexagonToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
~HexagonToolChain() override;
+ void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
Modified: cfe/trunk/test/Driver/hexagon-toolchain-elf.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/hexagon-toolchain-elf.c?rev=301361&r1=301360&r2=301361&view=diff
==============================================================================
--- cfe/trunk/test/Driver/hexagon-toolchain-elf.c (original)
+++ cfe/trunk/test/Driver/hexagon-toolchain-elf.c Tue Apr 25 15:51:51 2017
@@ -97,6 +97,22 @@
// CHECK024: "-cc1" {{.*}} "-target-cpu" "hexagonv62"
// CHECK024: hexagon-link{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v62/crt0
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -O3 \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK025 %s
+// CHECK025: "-ffp-contract=fast"
+// CHECK025: hexagon-link
+
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -O3 -ffp-contract=off \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK026 %s
+// CHECK026-NOT: "-ffp-contract=fast"
+// CHECK026: hexagon-link
+
// -----------------------------------------------------------------------------
// Test Linker related args
// -----------------------------------------------------------------------------
More information about the cfe-commits
mailing list