From: Mehdi Amini Date: Wed, 27 Apr 2016 04:24:10 +0000 (+0000) Subject: Support "preserving" the summary information when using setModule() API in LTOCodeGen... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=360ed847bc348423d2fce9c3ed82596a972fc9bb;p=platform%2Fupstream%2Fllvm.git Support "preserving" the summary information when using setModule() API in LTOCodeGenerator Another attempt at r267655... From: Mehdi Amini llvm-svn: 267665 --- diff --git a/llvm/include/llvm/LTO/LTOCodeGenerator.h b/llvm/include/llvm/LTO/LTOCodeGenerator.h index 4f78d27..91b034c 100644 --- a/llvm/include/llvm/LTO/LTOCodeGenerator.h +++ b/llvm/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/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 0130464..8497114 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/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/llvm/test/LTO/X86/set-merged-thin.ll b/llvm/test/LTO/X86/set-merged-thin.ll new file mode 100644 index 0000000..be2f97a --- /dev/null +++ b/llvm/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: