diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 46 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains.h | 2 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 20 |
4 files changed, 65 insertions, 10 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 6a85dabdeb6..eaf29de2aaf 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -50,7 +50,7 @@ Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, DiagnosticsEngine &Diags, IntrusiveRefCntPtr<vfs::FileSystem> VFS) : Opts(createDriverOptTable()), Diags(Diags), VFS(VFS), Mode(GCCMode), - SaveTemps(SaveTempsNone), LTOMode(LTOK_None), + SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None), ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), UseStdLib(true), DefaultTargetTriple(DefaultTargetTriple), @@ -479,6 +479,19 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { .Default(SaveTempsCwd); } + // Ignore -fembed-bitcode options with LTO + // since the output will be bitcode anyway. + if (!Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false)) { + if (Args.hasArg(options::OPT_fembed_bitcode)) + BitcodeEmbed = EmbedBitcode; + else if (Args.hasArg(options::OPT_fembed_bitcode_marker)) + BitcodeEmbed = EmbedMarker; + } else { + // claim the bitcode option under LTO so no warning is issued. + Args.ClaimAllArgs(options::OPT_fembed_bitcode); + Args.ClaimAllArgs(options::OPT_fembed_bitcode_marker); + } + setLTOMode(Args); std::unique_ptr<llvm::opt::InputArgList> UArgs = @@ -1723,7 +1736,8 @@ void Driver::BuildJobs(Compilation &C) const { // CudaHostAction, updates CollapsedCHA with the pointer to it so the // caller can deal with extra handling such action requires. static const Tool *selectToolForJob(Compilation &C, bool SaveTemps, - const ToolChain *TC, const JobAction *JA, + bool EmbedBitcode, const ToolChain *TC, + const JobAction *JA, const ActionList *&Inputs, const CudaHostAction *&CollapsedCHA) { const Tool *ToolForJob = nullptr; @@ -1739,10 +1753,12 @@ static const Tool *selectToolForJob(Compilation &C, bool SaveTemps, !C.getArgs().hasArg(options::OPT__SLASH_Fa) && isa<AssembleJobAction>(JA) && Inputs->size() == 1 && isa<BackendJobAction>(*Inputs->begin())) { - // A BackendJob is always preceded by a CompileJob, and without - // -save-temps they will always get combined together, so instead of - // checking the backend tool, check if the tool for the CompileJob - // has an integrated assembler. + // A BackendJob is always preceded by a CompileJob, and without -save-temps + // or -fembed-bitcode, they will always get combined together, so instead of + // checking the backend tool, check if the tool for the CompileJob has an + // integrated assembler. For -fembed-bitcode, CompileJob is still used to + // look up tools for BackendJob, but they need to match before we can split + // them. const ActionList *BackendInputs = &(*Inputs)[0]->getInputs(); // Compile job may be wrapped in CudaHostAction, extract it if // that's the case and update CollapsedCHA if we combine phases. @@ -1753,6 +1769,14 @@ static const Tool *selectToolForJob(Compilation &C, bool SaveTemps, const Tool *Compiler = TC->SelectTool(*CompileJA); if (!Compiler) return nullptr; + // When using -fembed-bitcode, it is required to have the same tool (clang) + // for both CompilerJA and BackendJA. Otherwise, combine two stages. + if (EmbedBitcode) { + JobAction *InputJA = cast<JobAction>(*Inputs->begin()); + const Tool *BackendTool = TC->SelectTool(*InputJA); + if (BackendTool == Compiler) + CompileJA = InputJA; + } if (Compiler->hasIntegratedAssembler()) { Inputs = &CompileJA->getInputs(); ToolForJob = Compiler; @@ -1761,8 +1785,8 @@ static const Tool *selectToolForJob(Compilation &C, bool SaveTemps, } // A backend job should always be combined with the preceding compile job - // unless OPT_save_temps is enabled and the compiler is capable of emitting - // LLVM IR as an intermediate output. + // unless OPT_save_temps or OPT_fembed_bitcode is enabled and the compiler is + // capable of emitting LLVM IR as an intermediate output. if (isa<BackendJobAction>(JA)) { // Check if the compiler supports emitting LLVM IR. assert(Inputs->size() == 1); @@ -1775,7 +1799,8 @@ static const Tool *selectToolForJob(Compilation &C, bool SaveTemps, const Tool *Compiler = TC->SelectTool(*CompileJA); if (!Compiler) return nullptr; - if (!Compiler->canEmitIR() || !SaveTemps) { + if (!Compiler->canEmitIR() || + (!SaveTemps && !EmbedBitcode)) { Inputs = &CompileJA->getInputs(); ToolForJob = Compiler; CollapsedCHA = CHA; @@ -1889,7 +1914,8 @@ InputInfo Driver::BuildJobsForActionNoCache( const JobAction *JA = cast<JobAction>(A); const CudaHostAction *CollapsedCHA = nullptr; const Tool *T = - selectToolForJob(C, isSaveTempsEnabled(), TC, JA, Inputs, CollapsedCHA); + selectToolForJob(C, isSaveTempsEnabled(), embedBitcodeEnabled(), TC, JA, + Inputs, CollapsedCHA); if (!T) return InputInfo(); diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index a0fad02b6c6..6cc512b6a16 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1103,6 +1103,13 @@ bool Darwin::UseSjLjExceptions(const ArgList &Args) const { return !Triple.isWatchABI(); } +bool Darwin::SupportsEmbeddedBitcode() const { + assert(TargetInitialized && "Target not initialized!"); + if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) + return false; + return true; +} + bool MachO::isPICDefault() const { return true; } bool MachO::isPIEDefault() const { return false; } diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index b956ac94052..aab4d337683 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -542,6 +542,8 @@ public: bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override; + bool SupportsEmbeddedBitcode() const override; + SanitizerMask getSupportedSanitizers() const override; }; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index e5dbe9bae0c..a0fceb9672a 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3625,6 +3625,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ); } + // Embed-bitcode option. + if (C.getDriver().embedBitcodeEnabled() && + (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) { + // Add flags implied by -fembed-bitcode. + CmdArgs.push_back("-fembed-bitcode"); + // Disable all llvm IR level optimizations. + CmdArgs.push_back("-disable-llvm-optzns"); + } + if (C.getDriver().embedBitcodeMarkerOnly()) + CmdArgs.push_back("-fembed-bitcode-marker"); + // We normally speed up the clang process a bit by skipping destructors at // exit, but when we're generating diagnostics we can rely on some of the // cleanup. @@ -7262,6 +7273,15 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, else CmdArgs.push_back("-no_pie"); } + // for embed-bitcode, use -bitcode_bundle in linker command + if (C.getDriver().embedBitcodeEnabled() || + C.getDriver().embedBitcodeMarkerOnly()) { + // Check if the toolchain supports bitcode build flow. + if (MachOTC.SupportsEmbeddedBitcode()) + CmdArgs.push_back("-bitcode_bundle"); + else + D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain); + } Args.AddLastArg(CmdArgs, options::OPT_prebind); Args.AddLastArg(CmdArgs, options::OPT_noprebind); |