Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4721,9 +4721,11 @@ // Select the appropriate action. RewriteKind rewriteKind = RK_None; + bool DefaultUnified = Triple.isPS4(); bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto, - options::OPT_fno_unified_lto, false); + options::OPT_fno_unified_lto, + DefaultUnified); if (UnifiedLTO) CmdArgs.push_back("-funified-lto"); @@ -7286,7 +7288,8 @@ bool DefaultsSplitLTOUnit = (WholeProgramVTables || SanitizeArgs.needsLTO()) && - (LTOMode == LTOK_Full || TC.canSplitThinLTOUnit()); + (LTOMode == LTOK_Full || TC.canSplitThinLTOUnit()) || + UnifiedLTO; bool SplitLTOUnit = Args.hasFlag(options::OPT_fsplit_lto_unit, options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit); Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1777,6 +1777,12 @@ else if (S != "full") Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S; } + + if (Opts.UnifiedLTO && Opts.PrepareForLTO) { + Opts.PrepareForThinLTO = true; + Opts.PrepareForLTO = false; + } + if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) { if (IK.getLanguage() != Language::LLVM_IR) Diags.Report(diag::err_drv_argument_only_allowed_with) Index: clang/test/CodeGen/split-lto-unit.c =================================================================== --- clang/test/CodeGen/split-lto-unit.c +++ clang/test/CodeGen/split-lto-unit.c @@ -1,6 +1,7 @@ // ; Check that -flto=thin without -fsplit-lto-unit has EnableSplitLTOUnit = 0 // RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s // RUN: %clang_cc1 -flto=thin -emit-llvm < %s | FileCheck %s +// RUN: %clang_cc1 -flto=thin -funified-lto -triple=x86_64-scei-ps4 -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s // CHECK: !{i32 1, !"EnableSplitLTOUnit", i32 0} // // ; Check that -flto=thin with -fsplit-lto-unit has EnableSplitLTOUnit = 1 @@ -12,4 +13,9 @@ // RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT // RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT +// ; Check that regular LTO has EnableSplitLTOUnit = 1, if using distinct pipelines. For unified pipelines, use EnableSplitLTOUnit = 0. +// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT +// RUN: %clang_cc1 -flto -funified-lto -triple x86_64-scei-ps4 -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" +// RUN: %clang_cc1 -flto=thin -funified-lto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT + int main(void) {} Index: clang/test/Driver/split-lto-unit.c =================================================================== --- clang/test/Driver/split-lto-unit.c +++ clang/test/Driver/split-lto-unit.c @@ -5,8 +5,10 @@ // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit -fsanitize=cfi 2>&1 | FileCheck --check-prefix=ERROR2 %s // RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -fwhole-program-vtables -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s // RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -fwhole-program-vtables -flto=thin 2>&1 | FileCheck --check-prefix=NOUNIT %s -// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s -// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=thin 2>&1 | FileCheck --check-prefix=NOUNIT %s +// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=full -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s +// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=thin -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s +// RUN: %clang -target x86_64-unknown-linux -### %s -fwhole-program-vtables -flto=full -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s +// RUN: %clang -target x86_64-unknown-linux -### %s -fwhole-program-vtables -flto=thin -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s // UNIT: "-fsplit-lto-unit" // NOUNIT-NOT: "-fsplit-lto-unit"