wenlei created this revision. wenlei added reviewers: hoyFB, spatel. Herald added subscribers: cfe-commits, dang, dexonsmith, steven_wu, MaskRay, hiraditya, arichardson, inglorion, emaste. Herald added a reviewer: espindola. Herald added a project: clang.
-fveclib switch not propagated to LTO backends, and as a result, LTO populates vector list as if no math lib is used. This change fixed the driver to lld, and to backend propagation of -fveclib setting. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D77484 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp lld/ELF/Config.h lld/ELF/Driver.cpp lld/ELF/LTO.cpp lld/ELF/Options.td llvm/include/llvm/Target/TargetOptions.h llvm/lib/LTO/LTOBackend.cpp
Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -279,6 +279,7 @@ PassManagerBuilder PMB; PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())); + PMB.LibraryInfo->addVectorizableFunctionsFromVecLib(Conf.Options.VectLib); PMB.Inliner = createFunctionInliningPass(); PMB.ExportSummary = ExportSummary; PMB.ImportSummary = ImportSummary; Index: llvm/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/include/llvm/Target/TargetOptions.h +++ llvm/include/llvm/Target/TargetOptions.h @@ -15,6 +15,7 @@ #define LLVM_TARGET_TARGETOPTIONS_H #include "llvm/ADT/FloatingPointMode.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/MC/MCTargetOptions.h" #include <memory> @@ -320,6 +321,10 @@ /// the value of this option. FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; + /// Vector library used for vectorizable math function calls + TargetLibraryInfoImpl::VectorLibrary VectLib = + TargetLibraryInfoImpl::NoLibrary; + /// ThreadModel - This flag specifies the type of threading model to assume /// for things like atomics ThreadModel::Model ThreadModel = ThreadModel::POSIX; Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -488,6 +488,8 @@ def lto_obj_path_eq: J<"lto-obj-path=">; def lto_sample_profile: J<"lto-sample-profile=">, HelpText<"Sample profile file path">; +def lto_vector_library: J<"lto-vector-library=">, + HelpText<"Vector functions library">; def lto_whole_program_visibility: F<"lto-whole-program-visibility">, HelpText<"Asserts that the LTO link has whole program visibility">; def disable_verify: F<"disable-verify">; @@ -552,6 +554,9 @@ def: J<"plugin-opt=thinlto-prefix-replace=">, Alias<thinlto_prefix_replace_eq>, HelpText<"Alias for --thinlto-prefix-replace=">; +def: J<"plugin-opt=vector-library=">, + Alias<lto_vector_library>, + HelpText<"Alias for -lto-vector-library=">; // Ignore LTO plugin-related options. // clang -flto passes -plugin and -plugin-opt to the linker. This is required Index: lld/ELF/LTO.cpp =================================================================== --- lld/ELF/LTO.cpp +++ lld/ELF/LTO.cpp @@ -110,6 +110,7 @@ c.UseNewPM = config->ltoNewPassManager; c.DebugPassManager = config->ltoDebugPassManager; c.DwoDir = std::string(config->dwoDir); + c.Options.VectLib = config->VectLib; c.HasWholeProgramVisibility = config->ltoWholeProgramVisibility; Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -704,6 +704,20 @@ return OrphanHandlingPolicy::Place; } +static llvm::TargetLibraryInfoImpl::VectorLibrary +getVectLib(opt::InputArgList &args) { + StringRef s = args.getLastArgValue(OPT_lto_vector_library); + if (s == "Accelerate") + return llvm::TargetLibraryInfoImpl::Accelerate; + if (s == "MASSV") + return llvm::TargetLibraryInfoImpl::MASSV; + if (s == "SVML") + return llvm::TargetLibraryInfoImpl::SVML; + if (!s.empty() && s != "none") + error("unknown --vector-library type: " + s); + return llvm::TargetLibraryInfoImpl::NoLibrary; +} + // Parse --build-id or --build-id=<style>. We handle "tree" as a // synonym for "sha1" because all our hash functions including // -build-id=sha1 are actually tree hashes for performance reasons. @@ -988,6 +1002,7 @@ config->useAndroidRelrTags = args.hasFlag( OPT_use_android_relr_tags, OPT_no_use_android_relr_tags, false); config->unresolvedSymbols = getUnresolvedSymbolPolicy(args); + config->VectLib = getVectLib(args); config->warnBackrefs = args.hasFlag(OPT_warn_backrefs, OPT_no_warn_backrefs, false); config->warnCommon = args.hasFlag(OPT_warn_common, OPT_no_warn_common, false); Index: lld/ELF/Config.h =================================================================== --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -13,6 +13,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/CodeGen.h" @@ -128,6 +129,7 @@ llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>, uint64_t> callGraphProfile; + llvm::TargetLibraryInfoImpl::VectorLibrary VectLib; bool allowMultipleDefinition; bool allowShlibUndefined; bool androidPackDynRelocs; Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -491,6 +491,14 @@ if (!StatsFile.empty()) CmdArgs.push_back( Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile)); + + // Pass vector library setting for LTO-time vectorization + if (Arg *A = Args.getLastArg(options::OPT_fveclib)) { + StringRef Name = A->getValue(); + if (!Name.empty()) + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=vector-library=") + Name)); + } } void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits