From 6e6426ce69cf39355207f5651d01ae3c54ad5bc9 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 27 Apr 2016 04:24:10 +0000 Subject: [PATCH] Support "preserving" the summary information when using setModule() API in LTOCodeGenerator Another attempt at r267655... From: Mehdi Amini llvm-svn: 267665 --- include/llvm/LTO/LTOCodeGenerator.h | 1 + lib/LTO/LTOCodeGenerator.cpp | 9 ++++++- test/LTO/X86/set-merged-thin.ll | 37 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/LTO/X86/set-merged-thin.ll diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index 4f78d27b10d..91b034cd905 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -201,6 +201,7 @@ private: LLVMContext &Context; std::unique_ptr MergedModule; + bool MainModuleHasSummary = false; std::unique_ptr TheLinker; std::unique_ptr TargetMach; bool EmitDwarfDebugInfo = false; diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 01304641598..8497114f64f 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/Passes.h" +#include "llvm/Analysis/ModuleSummaryAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Bitcode/ReaderWriter.h" @@ -145,6 +146,7 @@ void LTOCodeGenerator::setModule(std::unique_ptr Mod) { MergedModule = Mod->takeModule(); TheLinker = make_unique(*MergedModule); + MainModuleHasSummary = Mod->isThinLTO(); const std::vector &Undefs = Mod->getAsmUndefinedRefs(); for (int I = 0, E = Undefs.size(); I != E; ++I) @@ -209,8 +211,13 @@ bool LTOCodeGenerator::writeMergedModules(const char *Path) { return false; } + std::unique_ptr Index; + if (MainModuleHasSummary) + Index = ModuleSummaryIndexBuilder(MergedModule.get()).takeIndex(); + // write bitcode to it - WriteBitcodeToFile(MergedModule.get(), Out.os(), ShouldEmbedUselists); + WriteBitcodeToFile(MergedModule.get(), Out.os(), ShouldEmbedUselists, + Index.get()); Out.os().close(); if (Out.os().has_error()) { diff --git a/test/LTO/X86/set-merged-thin.ll b/test/LTO/X86/set-merged-thin.ll new file mode 100644 index 00000000000..be2f97ab4d9 --- /dev/null +++ b/test/LTO/X86/set-merged-thin.ll @@ -0,0 +1,37 @@ +; RUN: opt -module-summary < %s > %t1 +; RUN: llvm-lto -save-merged-module -exported-symbol=_main -set-merged-module -o %t2 %t1 +; RUN: llvm-bcanalyzer -dump %t2.merged.bc | FileCheck %s +; Verify that the module includes the ThinLTO summary +; CHECK: