| From: Caroline Tice <cmtice@google.com> |
| Date: 10-Sep-2018 |
| |
| This patch reverts Clang commit r335284. It is one of two commits that were |
| identified in https://buganizer.corp.google.com/issues/113573336 as responsible |
| for crashes with LLVM r339409. The actual commit that this reverts is here: |
| https://reviews.llvm.org/D34156 |
| |
| This patch is intended to be temporary: Once the bug is fixed this patch can |
| be removed. |
| |
| Update: Zhizhou Yang <zhizhouy@google.com> |
| Data: 21-Jul-2019 |
| |
| This patch is rebased to Clang commit r365631. |
| |
| diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def |
| index a7aafcf2f4..2a8574e633 100644 |
| --- a/clang/include/clang/Basic/CodeGenOptions.def |
| +++ b/clang/include/clang/Basic/CodeGenOptions.def |
| @@ -113,7 +113,7 @@ 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(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin is enabled on the |
| +CODEGENOPT(EmitSummaryIndex, 1, 0) ///< Set when -flto=thin is enabled on the |
| ///< compile step. |
| CODEGENOPT(LTOUnit, 1, 0) ///< Emit IR to support LTO unit features (CFI, whole |
| ///< program vtable opt). |
| diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/lib/clang/CodeGen/BackendUtil.cpp |
| index 2f71664371..f767fee08e 100644 |
| --- a/clang/lib/CodeGen/BackendUtil.cpp |
| +++ b/clang/lib/CodeGen/BackendUtil.cpp |
| @@ -571,7 +571,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, |
| PMBuilder.Inliner = createFunctionInliningPass( |
| CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize, |
| (!CodeGenOpts.SampleProfileFile.empty() && |
| - CodeGenOpts.PrepareForThinLTO)); |
| + CodeGenOpts.EmitSummaryIndex)); |
| } |
| |
| PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; |
| @@ -584,7 +584,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, |
| // enabled when loop unrolling is enabled. |
| PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops; |
| PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions; |
| - PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO; |
| + PMBuilder.PrepareForThinLTO = CodeGenOpts.EmitSummaryIndex; |
| PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO; |
| PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; |
| |
| @@ -840,7 +840,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, |
| break; |
| |
| case Backend_EmitBC: |
| - if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { |
| + if (CodeGenOpts.EmitSummaryIndex) { |
| if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { |
| ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile); |
| if (!ThinLinkOS) |
| @@ -850,24 +850,9 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, |
| CodeGenOpts.EnableSplitLTOUnit); |
| PerModulePasses.add(createWriteThinLTOBitcodePass( |
| *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr)); |
| - } else { |
| - // Emit a module summary by default for Regular LTO except for ld64 |
| - // targets |
| - bool EmitLTOSummary = |
| - (CodeGenOpts.PrepareForLTO && |
| - !CodeGenOpts.DisableLLVMPasses && |
| - llvm::Triple(TheModule->getTargetTriple()).getVendor() != |
| - llvm::Triple::Apple); |
| - if (EmitLTOSummary) { |
| - if (!TheModule->getModuleFlag("ThinLTO")) |
| - TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0)); |
| - TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit", |
| - uint32_t(1)); |
| - } |
| - |
| - PerModulePasses.add(createBitcodeWriterPass( |
| - *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary)); |
| - } |
| + } else |
| + PerModulePasses.add( |
| + createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); |
| break; |
| |
| case Backend_EmitLL: |
| @@ -1106,7 +1091,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( |
| ModulePassManager MPM(CodeGenOpts.DebugPassManager); |
| |
| if (!CodeGenOpts.DisableLLVMPasses) { |
| - bool IsThinLTO = CodeGenOpts.PrepareForThinLTO; |
| + bool IsThinLTO = CodeGenOpts.EmitSummaryIndex; |
| bool IsLTO = CodeGenOpts.PrepareForLTO; |
| |
| if (CodeGenOpts.OptimizationLevel == 0) { |
| @@ -1269,7 +1254,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( |
| break; |
| |
| case Backend_EmitBC: |
| - if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { |
| + if (CodeGenOpts.EmitSummaryIndex && !CodeGenOpts.DisableLLVMPasses) { |
| if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { |
| ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile); |
| if (!ThinLinkOS) |
| @@ -1280,20 +1265,9 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( |
| MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os() |
| : nullptr)); |
| } else { |
| - // Emit a module summary by default for Regular LTO except for ld64 |
| - // targets |
| - bool EmitLTOSummary = |
| - (CodeGenOpts.PrepareForLTO && |
| - !CodeGenOpts.DisableLLVMPasses && |
| - llvm::Triple(TheModule->getTargetTriple()).getVendor() != |
| - llvm::Triple::Apple); |
| - if (EmitLTOSummary) { |
| - if (!TheModule->getModuleFlag("ThinLTO")) |
| - TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0)); |
| - TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit", |
| - uint32_t(1)); |
| - } |
| MPM.addPass( |
| - BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary)); |
| + BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, |
| + CodeGenOpts.EmitSummaryIndex, |
| + CodeGenOpts.EmitSummaryIndex)); |
| } |
| break; |
| |
| @@ -1311,10 +1299,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( |
| if (!CodeGenOpts.SplitDwarfOutput.empty()) { |
| DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput); |
| if (!DwoOS) |
| - return; |
| - } |
| - if (!AddEmitPasses(CodeGenPasses, Action, *OS, |
| - DwoOS ? &DwoOS->os() : nullptr)) |
| + return; } if (!AddEmitPasses(CodeGenPasses, Action, *OS, DwoOS ? &DwoOS->os() : nullptr)) |
| // FIXME: Should we handle this error differently? |
| return; |
| break; |
| diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp |
| index 4fc2a35d50..90c3031771 100644 |
| --- a/clang/lib/CodeGen/CGDebugInfo.cpp |
| +++ b/clang/lib/CodeGen/CGDebugInfo.cpp |
| @@ -613,7 +613,7 @@ void CGDebugInfo::CreateCompileUnit() { |
| // Create new compile unit. |
| TheCU = DBuilder.createCompileUnit( |
| LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "", |
| - LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO, |
| + LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex, |
| CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind, |
| DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling, |
| CGM.getTarget().getTriple().isNVPTX() |
| diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp |
| index b1a886241a..2712bc7ee9 100644 |
| --- a/clang/lib/Frontend/CompilerInvocation.cpp |
| +++ b/clang/lib/Frontend/CompilerInvocation.cpp |
| @@ -934,11 +934,11 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, |
| Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate); |
| |
| Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); |
| - Opts.PrepareForThinLTO = false; |
| + Opts.EmitSummaryIndex = false; |
| if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { |
| StringRef S = A->getValue(); |
| if (S == "thin") |
| - Opts.PrepareForThinLTO = true; |
| + Opts.EmitSummaryIndex = true; |
| else if (S != "full") |
| Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S; |
| } |
| diff --git a/clang/test/CodeGen/emit-summary-index.c b/clang/test/CodeGen/emit-summary-index.c |
| deleted file mode 100644 |
| index 61264102068..00000000000 |
| --- a/clang/test/CodeGen/emit-summary-index.c |
| +++ /dev/null |
| @@ -1,17 +0,0 @@ |
| -// ; Check that the -flto=thin option emits a ThinLTO summary |
| -// RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-bcanalyzer -dump | FileCheck %s |
| -// CHECK: <GLOBALVAL_SUMMARY_BLOCK |
| -// |
| -// ; Check that we do not emit a summary for regular LTO on Apple platforms |
| -// RUN: %clang_cc1 -flto -triple x86_64-apple-darwin -emit-llvm-bc < %s | llvm-bcanalyzer -dump | FileCheck --check-prefix=LTO %s |
| -// LTO-NOT: GLOBALVAL_SUMMARY_BLOCK |
| -// |
| -// ; Check that we emit a summary for regular LTO by default elsewhere |
| -// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-bcanalyzer -dump | FileCheck --check-prefix=LTOINDEX %s |
| -// LTOINDEX: <FULL_LTO_GLOBALVAL_SUMMARY_BLOCK |
| -// |
| -// ; Simulate -save-temps and check that it works (!"ThinLTO" module flag not added multiple times) |
| -// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc -disable-llvm-passes < %s -o %t.bc |
| -// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc -x ir < %t.bc | llvm-bcanalyzer -dump | FileCheck --check-prefix=LTOINDEX %s |
| - |
| -int main() {} |
| diff --git a/clang/test/Misc/thinlto.c b/clang/test/Misc/thinlto.c |
| new file mode 100644 |
| index 00000000000..ec0f03f5a2a |
| --- /dev/null |
| +++ b/clang/test/Misc/thinlto.c |
| @@ -0,0 +1,4 @@ |
| +// RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-bcanalyzer -dump | FileCheck %s |
| +// ; Check that the -flto=thin option emits a summary |
| +// CHECK: <GLOBALVAL_SUMMARY_BLOCK |
| +int main() {} |