From 681157a8a950b61ac9b4ea0776d1f2fefab09ad9 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 15 Oct 2015 13:41:51 +0000 Subject: [PATCH] Revert "Clang support for -flto=thin." (bot failures) Rolling this back for now since there are a couple of bot failures on the new tests I added, and I won't have a chance to look at them in detail until later this afternoon. I think the new tests need some restrictions on having the gold plugin available. This reverts commit r250398. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250402 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 21 +------- include/clang/Driver/Options.td | 9 ++-- include/clang/Frontend/CodeGenOptions.def | 2 - lib/CodeGen/BackendUtil.cpp | 4 +- lib/Driver/Driver.cpp | 36 +++----------- lib/Driver/SanitizerArgs.cpp | 2 +- lib/Driver/Tools.cpp | 26 +++++----- lib/Frontend/CompilerInvocation.cpp | 4 +- test/Driver/clang_f_opts.c | 2 +- test/Driver/lto.c | 58 +++++++---------------- test/Driver/thinlto.c | 37 --------------- test/Misc/thinlto.c | 9 ---- 12 files changed, 43 insertions(+), 167 deletions(-) delete mode 100644 test/Driver/thinlto.c delete mode 100644 test/Misc/thinlto.c diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 213ae38843..a7c5b6dbb8 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -52,14 +52,6 @@ namespace driver { class SanitizerArgs; class ToolChain; -/// Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options. -enum LTOKind { - LTOK_None, - LTOK_Full, - LTOK_Thin, - LTOK_Unknown -}; - /// Driver - Encapsulate logic for constructing compilation processes /// from a set of gcc-driver-like command line arguments. class Driver { @@ -82,9 +74,6 @@ class Driver { SaveTempsObj } SaveTemps; - /// LTO mode selected via -f(no-)?lto(=.*)? options. - LTOKind LTOMode; - public: // Diag - Forwarding function for diagnostics. DiagnosticBuilder Diag(unsigned DiagID) const { @@ -422,17 +411,9 @@ public: /// handle this action. bool ShouldUseClangCompiler(const JobAction &JA) const; - /// Returns true if we are performing any kind of LTO. - bool isUsingLTO() const { return LTOMode != LTOK_None; } - - /// Get the specific kind of LTO being performed. - LTOKind getLTOMode() const { return LTOMode; } + bool IsUsingLTO(const llvm::opt::ArgList &Args) const; private: - /// Parse the \p Args list for LTO options and record the type of LTO - /// compilation based on which -f(no-)?lto(=.*)? option occurs last. - void setLTOMode(const llvm::opt::ArgList &Args); - /// \brief Retrieves a ToolChain for a particular \p Target triple. /// /// Will cache ToolChains for the life of the driver object, and create them diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 8bd925b688..a75ef549d8 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -687,12 +687,9 @@ def finstrument_functions : Flag<["-"], "finstrument-functions">, Group def flat__namespace : Flag<["-"], "flat_namespace">; def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group; def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group; -def flto_EQ : Joined<["-"], "flto=">, Flags<[CC1Option]>, Group, - HelpText<"Set LTO mode to either 'full' or 'thin'">; -def flto : Flag<["-"], "flto">, Flags<[CC1Option]>, Group, - HelpText<"Enable LTO in 'full' mode">; -def fno_lto : Flag<["-"], "fno-lto">, Group, - HelpText<"Disable LTO mode (default)">; +def flto_EQ : Joined<["-"], "flto=">, Group; +def flto : Flag<["-"], "flto">, Flags<[CC1Option]>, Group; +def fno_lto : Flag<["-"], "fno-lto">, Group; def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">, Group, Flags<[DriverOption, CoreOption]>; def fmerge_all_constants : Flag<["-"], "fmerge-all-constants">, Group; diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 5b8483ca9c..b7050875cf 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -73,8 +73,6 @@ CODEGENOPT(LessPreciseFPMAD , 1, 0) ///< Enable less precise MAD instructions t ///< be generated. CODEGENOPT(PrepareForLTO , 1, 0) ///< Set when -flto is enabled on the ///< compile step. -CODEGENOPT(EmitFunctionSummary, 1, 0) ///< Set when -flto=thin is enabled on the - ///< compile step. CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants. CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled. CODEGENOPT(MSVolatile , 1, 0) ///< Set when /volatile:ms is enabled. diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 682ec8f36f..3ba0f80c93 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -605,8 +605,8 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, break; case Backend_EmitBC: - getPerModulePasses()->add(createBitcodeWriterPass( - *OS, CodeGenOpts.EmitLLVMUseLists, CodeGenOpts.EmitFunctionSummary)); + getPerModulePasses()->add( + createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); break; case Backend_EmitLL: diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index fb5d38ab42..0b842cd617 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -50,8 +50,7 @@ Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, DiagnosticsEngine &Diags, IntrusiveRefCntPtr VFS) : Opts(createDriverOptTable()), Diags(Diags), VFS(VFS), Mode(GCCMode), - SaveTemps(SaveTempsNone), LTOMode(LTOK_None), - ClangExecutable(ClangExecutable), + SaveTemps(SaveTempsNone), ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), UseStdLib(true), DefaultTargetTriple(DefaultTargetTriple), DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr), @@ -367,31 +366,6 @@ static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple, return Target; } -// \brief Parse the LTO options and record the type of LTO compilation -// based on which -f(no-)?lto(=.*)? option occurs last. -void Driver::setLTOMode(const llvm::opt::ArgList &Args) { - LTOMode = LTOK_None; - if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ, - options::OPT_fno_lto, false)) - return; - - StringRef LTOName("full"); - - const Arg *A = Args.getLastArg(options::OPT_flto_EQ); - if (A) LTOName = A->getValue(); - - LTOMode = llvm::StringSwitch(LTOName) - .Case("full", LTOK_Full) - .Case("thin", LTOK_Thin) - .Default(LTOK_Unknown); - - if (LTOMode == LTOK_Unknown) { - assert(A); - Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() - << A->getValue(); - } -} - Compilation *Driver::BuildCompilation(ArrayRef ArgList) { llvm::PrettyStackTraceString CrashInfo("Compilation construction"); @@ -475,8 +449,6 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { .Default(SaveTempsCwd); } - setLTOMode(Args); - std::unique_ptr UArgs = llvm::make_unique(std::move(Args)); @@ -1595,7 +1567,7 @@ Driver::ConstructPhaseAction(const ToolChain &TC, const ArgList &Args, types::TY_LLVM_BC); } case phases::Backend: { - if (isUsingLTO()) { + if (IsUsingLTO(Args)) { types::ID Output = Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC; return llvm::make_unique(std::move(Input), Output); @@ -1616,6 +1588,10 @@ Driver::ConstructPhaseAction(const ToolChain &TC, const ArgList &Args, llvm_unreachable("invalid phase in ConstructPhaseAction"); } +bool Driver::IsUsingLTO(const ArgList &Args) const { + return Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false); +} + void Driver::BuildJobs(Compilation &C) const { llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index 8c417ef432..66140a1e32 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -283,7 +283,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, } // Check that LTO is enabled if we need it. - if ((Kinds & NeedsLTO) && !D.isUsingLTO()) { + if ((Kinds & NeedsLTO) && !D.IsUsingLTO(Args)) { D.Diag(diag::err_drv_argument_only_allowed_with) << lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto"; } diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index a72e85e4e4..56cbb900c2 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1648,7 +1648,7 @@ static std::string getCPUName(const ArgList &Args, const llvm::Triple &T, } static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, - ArgStringList &CmdArgs, bool IsThinLTO) { + ArgStringList &CmdArgs) { // Tell the linker to load the plugin. This has to come before AddLinkerInputs // as gold requires -plugin to come before any -plugin-opt that -Wl might // forward. @@ -1664,8 +1664,6 @@ static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, std::string CPU = getCPUName(Args, ToolChain.getTriple()); if (!CPU.empty()) CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU)); - - if (IsThinLTO) CmdArgs.push_back("-plugin-opt=thinlto"); } /// This is a helper function for validating the optional refinement step @@ -2847,7 +2845,6 @@ static VersionTuple getMSCompatibilityVersion(unsigned Version) { static void claimNoWarnArgs(const ArgList &Args) { // Don't warn about unused -f(no-)?lto. This can happen when we're // preprocessing, precompiling or assembling. - Args.ClaimAllArgs(options::OPT_flto_EQ); Args.ClaimAllArgs(options::OPT_flto); Args.ClaimAllArgs(options::OPT_fno_lto); } @@ -3275,6 +3272,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } else { assert((isa(JA) || isa(JA)) && "Invalid action for clang tool."); + + if (JA.getType() == types::TY_LTO_IR || JA.getType() == types::TY_LTO_BC) { + CmdArgs.push_back("-flto"); + } if (JA.getType() == types::TY_Nothing) { CmdArgs.push_back("-fsyntax-only"); } else if (JA.getType() == types::TY_LLVM_IR || @@ -3305,9 +3306,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // the use-list order, since serialization to bitcode is part of the flow. if (JA.getType() == types::TY_LLVM_BC) CmdArgs.push_back("-emit-llvm-uselists"); - - if (D.isUsingLTO()) - Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ); } // We normally speed up the clang process a bit by skipping destructors at @@ -6458,8 +6456,8 @@ void cloudabi::Linker::ConstructJob(Compilation &C, const JobAction &JA, {options::OPT_T_Group, options::OPT_e, options::OPT_s, options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); - if (D.isUsingLTO()) - AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin); + if (D.IsUsingLTO(Args)) + AddGoldPlugin(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); @@ -6602,7 +6600,7 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, options::OPT_fno_application_extension, false)) CmdArgs.push_back("-application_extension"); - if (D.isUsingLTO()) { + if (D.IsUsingLTO(Args)) { // If we are using LTO, then automatically create a temporary file path for // the linker to use, so that it's lifetime will extend past a possible // dsymutil step. @@ -7604,8 +7602,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); - if (D.isUsingLTO()) - AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin); + if (D.IsUsingLTO(Args)) + AddGoldPlugin(ToolChain, Args, CmdArgs); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); @@ -8479,8 +8477,8 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); - if (D.isUsingLTO()) - AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin); + if (D.IsUsingLTO(Args)) + AddGoldPlugin(ToolChain, Args, CmdArgs); if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("--no-demangle"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 61144fc558..4220487e4d 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -499,9 +499,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions); - Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); - const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ); - Opts.EmitFunctionSummary = A && A->containsValue("thin"); + Opts.PrepareForLTO = Args.hasArg(OPT_flto); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index 25a1930bdd..98198f51d1 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -373,7 +373,7 @@ // CHECK-WARNING-DAG: optimization flag '-ftracer' is not supported // CHECK-WARNING-DAG: optimization flag '-funroll-all-loops' is not supported // CHECK-WARNING-DAG: optimization flag '-funswitch-loops' is not supported -// CHECK-WARNING-DAG: unsupported argument '1' to option 'flto=' +// CHECK-WARNING-DAG: optimization flag '-flto=1' is not supported // CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported // CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported // CHECK-WARNING-DAG: optimization flag '-falign-loops' is not supported diff --git a/test/Driver/lto.c b/test/Driver/lto.c index 33c2d5131c..62300bd8fa 100644 --- a/test/Driver/lto.c +++ b/test/Driver/lto.c @@ -1,51 +1,25 @@ // -flto causes a switch to llvm-bc object files. -// RUN: %clang -ccc-print-phases -c %s -flto 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s -// -// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir -// CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc +// RUN: %clang -ccc-print-phases -c %s -flto 2> %t.log +// RUN: grep '2: compiler, {1}, ir' %t.log +// RUN: grep '3: backend, {2}, lto-bc' %t.log -// RUN: %clang -ccc-print-phases %s -flto 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s -// -// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c -// CHECK-COMPILELINK-ACTIONS: 1: preprocessor, {0}, cpp-output -// CHECK-COMPILELINK-ACTIONS: 2: compiler, {1}, ir -// CHECK-COMPILELINK-ACTIONS: 3: backend, {2}, lto-bc -// CHECK-COMPILELINK-ACTIONS: 4: linker, {3}, image +// RUN: %clang -ccc-print-phases %s -flto 2> %t.log +// RUN: grep '0: input, ".*lto.c", c' %t.log +// RUN: grep '1: preprocessor, {0}, cpp-output' %t.log +// RUN: grep '2: compiler, {1}, ir' %t.log +// RUN: grep '3: backend, {2}, lto-bc' %t.log +// RUN: grep '4: linker, {3}, image' %t.log // llvm-bc and llvm-ll outputs need to match regular suffixes // (unfortunately). -// RUN: %clang %s -flto -save-temps -### 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-SUFFIXES < %t %s -// -// CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.i" "-x" "c" "{{.*}}lto.c" -// CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.bc" {{.*}}"{{.*}}lto.i" -// CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.o" {{.*}}"{{.*}}lto.bc" -// CHECK-COMPILELINK-SUFFIXES: "{{.*}}a.{{(out|exe)}}" {{.*}}"{{.*}}lto.o" +// RUN: %clang %s -flto -save-temps -### 2> %t.log +// RUN: grep '"-o" ".*lto\.i" "-x" "c" ".*lto\.c"' %t.log +// RUN: grep '"-o" ".*lto\.bc" .*".*lto\.i"' %t.log +// RUN: grep '"-o" ".*lto\.o" .*".*lto\.bc"' %t.log +// RUN: grep '".*a\.\(out\|exe\)" .*".*lto\.o"' %t.log -// RUN: %clang %s -flto -S -### 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILE-SUFFIXES < %t %s -// -// CHECK-COMPILE-SUFFIXES: "-o" "{{.*}}lto.s" "-x" "c" "{{.*}}lto.c" +// RUN: %clang %s -flto -S -### 2> %t.log +// RUN: grep '"-o" ".*lto\.s" "-x" "c" ".*lto\.c"' %t.log // RUN: not %clang %s -emit-llvm 2>&1 | FileCheck --check-prefix=LLVM-LINK %s // LLVM-LINK: -emit-llvm cannot be used when linking - -// -flto should cause link using gold plugin -// RUN: %clang -### %s -flto 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-LTO-ACTION < %t %s -// -// CHECK-LINK-LTO-ACTION: "-plugin" "{{.*}}/LLVMgold.so" - -// -flto=full should cause link using gold plugin -// RUN: %clang -### %s -flto=full 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-FULL-ACTION < %t %s -// -// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}/LLVMgold.so" - -// Check that subsequent -fno-lto takes precedence -// RUN: %clang -### %s -flto=full -fno-lto 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-NOLTO-ACTION < %t %s -// -// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}/LLVMgold.so" diff --git a/test/Driver/thinlto.c b/test/Driver/thinlto.c deleted file mode 100644 index dfd671b9e9..0000000000 --- a/test/Driver/thinlto.c +++ /dev/null @@ -1,37 +0,0 @@ -// -flto=thin causes a switch to llvm-bc object files. -// RUN: %clang -ccc-print-phases -c %s -flto=thin 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s -// -// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir -// CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc - -// RUN: %clang -ccc-print-phases %s -flto=thin 2> %t -// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s -// -// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.c", c -// CHECK-COMPILELINK-ACTIONS: 1: preprocessor, {0}, cpp-output -// CHECK-COMPILELINK-ACTIONS: 2: compiler, {1}, ir -// CHECK-COMPILELINK-ACTIONS: 3: backend, {2}, lto-bc -// CHECK-COMPILELINK-ACTIONS: 4: linker, {3}, image - -// -flto=thin should cause link using gold plugin with thinlto option, -// also confirm that it takes precedence over earlier -fno-lto and -flto=full. -// RUN: %clang -### %s -flto=full -fno-lto -flto=thin 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-ACTION < %t %s -// -// CHECK-LINK-THIN-ACTION: "-plugin" "{{.*}}/LLVMgold.so" -// CHECK-LINK-THIN-ACTION: "-plugin-opt=thinlto" - -// Check that subsequent -flto=full takes precedence -// RUN: %clang -### %s -flto=thin -flto=full 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-FULL-ACTION < %t %s -// -// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}/LLVMgold.so" -// CHECK-LINK-FULL-ACTION-NOT: "-plugin-opt=thinlto" - -// Check that subsequent -fno-lto takes precedence -// RUN: %clang -### %s -flto=thin -fno-lto 2> %t -// RUN: FileCheck -check-prefix=CHECK-LINK-NOLTO-ACTION < %t %s -// -// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}/LLVMgold.so" -// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin-opt=thinlto" diff --git a/test/Misc/thinlto.c b/test/Misc/thinlto.c deleted file mode 100644 index 9134cbe5c5..0000000000 --- a/test/Misc/thinlto.c +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-bcanalyzer -dump | FileCheck %s -// CHECK: