From 7ebce5ede9640d833a233cfcbcbf8b79d20dcc1c Mon Sep 17 00:00:00 2001 From: Michael Zolotukhin Date: Tue, 17 Mar 2015 20:03:11 +0000 Subject: [PATCH] Add fveclib option. Review: http://reviews.llvm.org/D8097 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232533 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 2 ++ include/clang/Frontend/CodeGenOptions.def | 3 +++ include/clang/Frontend/CodeGenOptions.h | 5 +++++ lib/CodeGen/BackendUtil.cpp | 8 ++++++++ lib/Driver/Tools.cpp | 2 ++ lib/Frontend/CompilerInvocation.cpp | 10 ++++++++++ test/Driver/fveclib.c | 8 ++++++++ 7 files changed, 38 insertions(+) create mode 100644 test/Driver/fveclib.c diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 977e925117..1dc610bb2e 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -756,6 +756,8 @@ def fno_exceptions : Flag<["-"], "fno-exceptions">, Group; def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group, Flags<[CC1Option]>; def fno_inline_functions : Flag<["-"], "fno-inline-functions">, Group, Flags<[CC1Option]>; def fno_inline : Flag<["-"], "fno-inline">, Group, Flags<[CC1Option]>; +def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>, + HelpText<"Use the given vector functions library">; def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group, HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>; def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 377e652266..320763e97b 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -162,6 +162,9 @@ VALUE_CODEGENOPT(DwarfVersion, 3, 0) /// The kind of inlining to perform. ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NoInlining) +// Vector functions library to use. +ENUM_CODEGENOPT(VecLib, VectorLibrary, 1, NoLibrary) + /// The default TLS model to use. ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel) diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 819606429e..36c33c7e3b 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -46,6 +46,11 @@ public: OnlyAlwaysInlining // Only run the always inlining pass. }; + enum VectorLibrary { + NoLibrary, // Don't use any vector library. + Accelerate // Use the Accelerate framework. + }; + enum ObjCDispatchMethodKind { Legacy = 0, NonLegacy = 1, diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index fba75095e7..9a0e6e2849 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -237,6 +237,14 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple, TargetLibraryInfoImpl *TLII = new TargetLibraryInfoImpl(TargetTriple); if (!CodeGenOpts.SimplifyLibCalls) TLII->disableAllFunctions(); + + switch (CodeGenOpts.getVecLib()) { + case CodeGenOptions::Accelerate: + TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate); + break; + default: + break; + } return TLII; } diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d9f5dc0dd1..3650a94b92 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2864,6 +2864,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, else CmdArgs.push_back(Args.MakeArgString(getToolChain().getThreadModel())); + Args.AddLastArg(CmdArgs, options::OPT_fveclib); + if (!Args.hasFlag(options::OPT_fmerge_all_constants, options::OPT_fno_merge_all_constants)) CmdArgs.push_back("-fno-merge-all-constants"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 772c4e5a5d..cbe5435d04 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -367,6 +367,16 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.setInlining(Args.hasArg(OPT_fno_inline_functions) ? CodeGenOptions::OnlyAlwaysInlining : Opts.getInlining()); + if (Arg *A = Args.getLastArg(OPT_fveclib)) { + StringRef Name = A->getValue(); + if (Name == "Accelerate") + Opts.setVecLib(CodeGenOptions::Accelerate); + else if (Name == "none") + Opts.setVecLib(CodeGenOptions::NoLibrary); + else + Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; + } + if (Args.hasArg(OPT_gline_tables_only)) { Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) || diff --git a/test/Driver/fveclib.c b/test/Driver/fveclib.c new file mode 100644 index 0000000000..4515dd7731 --- /dev/null +++ b/test/Driver/fveclib.c @@ -0,0 +1,8 @@ +// RUN: %clang -### -c -fveclib=none %s 2>&1 | FileCheck -check-prefix CHECK-NOLIB %s +// RUN: %clang -### -c -fveclib=Accelerate %s 2>&1 | FileCheck -check-prefix CHECK-ACCELERATE %s +// RUN: not %clang -c -fveclib=something %s 2>&1 | FileCheck -check-prefix CHECK-INVALID %s + +// CHECK-NOLIB: "-fveclib=none" +// CHECK-ACCELERATE: "-fveclib=Accelerate" + +// CHECK-INVALID: error: invalid value 'something' in '-fveclib=something' -- 2.40.0