Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -756,6 +756,8 @@ 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, Index: include/clang/Frontend/CodeGenOptions.h =================================================================== --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -46,6 +46,11 @@ 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, Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -161,6 +161,9 @@ /// 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) Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -237,6 +237,14 @@ 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; } Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2851,6 +2851,8 @@ 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"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -367,6 +367,16 @@ 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) || Index: test/Driver/fveclib.c =================================================================== --- /dev/null +++ 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'