blob: d9ec68fe3eb50a3234d16e2e40d9715df5e9730f [file] [log] [blame]
Mehdi Amini7c4a1a82016-03-09 01:37:22 +00001//===-ThinLTOCodeGenerator.cpp - LLVM Link Time Optimizer -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Thin Link Time Optimization library. This library is
11// intended to be used by linker to optimize code at link time.
12//
13//===----------------------------------------------------------------------===//
14
Peter Collingbourne5c732202016-07-14 21:21:16 +000015#include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000016
Teresa Johnsoncec0cae2016-03-14 21:18:10 +000017#include "llvm/ADT/Statistic.h"
Teresa Johnson26ab5772016-03-15 00:04:37 +000018#include "llvm/ADT/StringExtras.h"
Teresa Johnson2d5487c2016-04-11 13:58:45 +000019#include "llvm/Analysis/ModuleSummaryAnalysis.h"
Piotr Padlewskid9830eb2016-09-26 20:37:32 +000020#include "llvm/Analysis/ProfileSummaryInfo.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000021#include "llvm/Analysis/TargetLibraryInfo.h"
22#include "llvm/Analysis/TargetTransformInfo.h"
Teresa Johnsonad176792016-11-11 05:34:58 +000023#include "llvm/Bitcode/BitcodeReader.h"
24#include "llvm/Bitcode/BitcodeWriter.h"
Teresa Johnsoncec0cae2016-03-14 21:18:10 +000025#include "llvm/Bitcode/BitcodeWriterPass.h"
Nico Weber432a3882018-04-30 14:59:11 +000026#include "llvm/Config/llvm-config.h"
Adrian Prantl981a7992017-05-20 00:00:08 +000027#include "llvm/IR/DebugInfo.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000028#include "llvm/IR/DiagnosticPrinter.h"
Teresa Johnson26ab5772016-03-15 00:04:37 +000029#include "llvm/IR/LLVMContext.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000030#include "llvm/IR/LegacyPassManager.h"
31#include "llvm/IR/Mangler.h"
Fedor Sergeeva43fd952018-09-26 13:01:43 +000032#include "llvm/IR/PassTimingInfo.h"
Adrian Prantl981a7992017-05-20 00:00:08 +000033#include "llvm/IR/Verifier.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000034#include "llvm/IRReader/IRReader.h"
Teresa Johnsondf6edc52016-05-23 22:54:06 +000035#include "llvm/LTO/LTO.h"
Easwaran Raman5a7056f2018-12-13 19:54:27 +000036#include "llvm/LTO/SummaryBasedOptimizations.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000037#include "llvm/MC/SubtargetFeature.h"
Mehdi Amini059464f2016-04-24 03:18:01 +000038#include "llvm/Object/IRObjectFile.h"
Mehdi Aminif95f77a2016-04-21 05:54:23 +000039#include "llvm/Support/CachePruning.h"
40#include "llvm/Support/Debug.h"
Mehdi Amini19f176b2016-11-19 18:20:05 +000041#include "llvm/Support/Error.h"
Mehdi Aminif95f77a2016-04-21 05:54:23 +000042#include "llvm/Support/Path.h"
43#include "llvm/Support/SHA1.h"
Weiming Zhao79f2d092018-04-16 03:44:03 +000044#include "llvm/Support/SmallVectorMemoryBuffer.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000045#include "llvm/Support/TargetRegistry.h"
46#include "llvm/Support/ThreadPool.h"
Teresa Johnsonec544c52016-10-19 17:35:01 +000047#include "llvm/Support/Threading.h"
Mehdi Amini19f176b2016-11-19 18:20:05 +000048#include "llvm/Support/ToolOutputFile.h"
Peter Collingbourne942fa562017-04-13 01:26:12 +000049#include "llvm/Support/VCSRevision.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000050#include "llvm/Target/TargetMachine.h"
51#include "llvm/Transforms/IPO.h"
52#include "llvm/Transforms/IPO/FunctionImport.h"
Mehdi Amini059464f2016-04-24 03:18:01 +000053#include "llvm/Transforms/IPO/Internalize.h"
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000054#include "llvm/Transforms/IPO/PassManagerBuilder.h"
55#include "llvm/Transforms/ObjCARC.h"
56#include "llvm/Transforms/Utils/FunctionImportUtils.h"
57
Mehdi Amini819e9cd2016-05-16 19:33:07 +000058#include <numeric>
59
Andrew Ng089303d2018-07-04 14:17:10 +000060#if !defined(_MSC_VER) && !defined(__MINGW32__)
61#include <unistd.h>
62#else
63#include <io.h>
64#endif
65
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000066using namespace llvm;
67
Mehdi Amini1aafabf2016-04-16 07:02:16 +000068#define DEBUG_TYPE "thinlto"
69
Mehdi Amini09b4a8d2016-03-10 01:28:54 +000070namespace llvm {
71// Flags -discard-value-names, defined in LTOCodeGenerator.cpp
72extern cl::opt<bool> LTODiscardValueNames;
Mehdi Amini19f176b2016-11-19 18:20:05 +000073extern cl::opt<std::string> LTORemarksFilename;
Adam Nemet4c207a62016-12-02 17:53:56 +000074extern cl::opt<bool> LTOPassRemarksWithHotness;
Mehdi Amini09b4a8d2016-03-10 01:28:54 +000075}
76
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000077namespace {
78
Teresa Johnsonec544c52016-10-19 17:35:01 +000079static cl::opt<int>
80 ThreadCount("threads", cl::init(llvm::heavyweight_hardware_concurrency()));
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000081
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000082// Simple helper to save temporary files for debug.
83static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
84 unsigned count, StringRef Suffix) {
85 if (TempDir.empty())
86 return;
87 // User asked to save temps, let dump the bitcode file after import.
Benjamin Kramer3a13ed62017-12-28 16:58:54 +000088 std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str();
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000089 std::error_code EC;
Teresa Johnsonc44a1222016-08-15 23:24:57 +000090 raw_fd_ostream OS(SaveTempPath, EC, sys::fs::F_None);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000091 if (EC)
92 report_fatal_error(Twine("Failed to open ") + SaveTempPath +
93 " to save optimized bitcode\n");
Rafael Espindola6a86e252018-02-14 19:11:32 +000094 WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +000095}
96
Teresa Johnson4d2613f2016-05-24 17:24:25 +000097static const GlobalValueSummary *
98getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
99 // If there is any strong definition anywhere, get it.
100 auto StrongDefForLinker = llvm::find_if(
101 GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
102 auto Linkage = Summary->linkage();
103 return !GlobalValue::isAvailableExternallyLinkage(Linkage) &&
104 !GlobalValue::isWeakForLinker(Linkage);
105 });
106 if (StrongDefForLinker != GVSummaryList.end())
107 return StrongDefForLinker->get();
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000108 // Get the first *linker visible* definition for this global in the summary
109 // list.
110 auto FirstDefForLinker = llvm::find_if(
Teresa Johnson28e457b2016-04-24 14:57:11 +0000111 GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
112 auto Linkage = Summary->linkage();
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000113 return !GlobalValue::isAvailableExternallyLinkage(Linkage);
114 });
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000115 // Extern templates can be emitted as available_externally.
116 if (FirstDefForLinker == GVSummaryList.end())
117 return nullptr;
118 return FirstDefForLinker->get();
Hans Wennborgfa6e4142016-04-02 01:03:41 +0000119}
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000120
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000121// Populate map of GUID to the prevailing copy for any multiply defined
122// symbols. Currently assume first copy is prevailing, or any strong
123// definition. Can be refined with Linker information in the future.
124static void computePrevailingCopies(
125 const ModuleSummaryIndex &Index,
126 DenseMap<GlobalValue::GUID, const GlobalValueSummary *> &PrevailingCopy) {
Teresa Johnson28e457b2016-04-24 14:57:11 +0000127 auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
128 return GVSummaryList.size() > 1;
129 };
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000130
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000131 for (auto &I : Index) {
Peter Collingbourne9667b912017-05-04 18:03:25 +0000132 if (HasMultipleCopies(I.second.SummaryList))
133 PrevailingCopy[I.first] =
134 getFirstDefinitionForLinker(I.second.SummaryList);
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000135 }
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000136}
137
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000138static StringMap<MemoryBufferRef>
Mehdi Aminia0ddb1e2017-02-14 02:20:51 +0000139generateModuleMap(const std::vector<ThinLTOBuffer> &Modules) {
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000140 StringMap<MemoryBufferRef> ModuleMap;
141 for (auto &ModuleBuffer : Modules) {
142 assert(ModuleMap.find(ModuleBuffer.getBufferIdentifier()) ==
143 ModuleMap.end() &&
144 "Expect unique Buffer Identifier");
Mehdi Aminia0ddb1e2017-02-14 02:20:51 +0000145 ModuleMap[ModuleBuffer.getBufferIdentifier()] = ModuleBuffer.getMemBuffer();
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000146 }
147 return ModuleMap;
148}
149
Teresa Johnson26ab5772016-03-15 00:04:37 +0000150static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index) {
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000151 if (renameModuleForThinLTO(TheModule, Index))
152 report_fatal_error("renameModuleForThinLTO failed");
153}
154
Adrian Prantl981a7992017-05-20 00:00:08 +0000155namespace {
156class ThinLTODiagnosticInfo : public DiagnosticInfo {
157 const Twine &Msg;
158public:
159 ThinLTODiagnosticInfo(const Twine &DiagMsg,
160 DiagnosticSeverity Severity = DS_Error)
161 : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
162 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
163};
164}
165
166/// Verify the module and strip broken debug info.
167static void verifyLoadedModule(Module &TheModule) {
168 bool BrokenDebugInfo = false;
Adrian Prantla8b2ddb2017-10-02 18:31:29 +0000169 if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
Adrian Prantl981a7992017-05-20 00:00:08 +0000170 report_fatal_error("Broken module found, compilation aborted!");
171 if (BrokenDebugInfo) {
172 TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
173 "Invalid debug info found, debug info will be stripped", DS_Warning));
174 StripDebugInfo(TheModule);
175 }
176}
177
Peter Collingbournedac43b42016-12-01 05:52:32 +0000178static std::unique_ptr<Module>
179loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
Teresa Johnsona61f5e32016-12-16 21:25:01 +0000180 bool Lazy, bool IsImporting) {
Peter Collingbournedac43b42016-12-01 05:52:32 +0000181 SMDiagnostic Err;
182 Expected<std::unique_ptr<Module>> ModuleOrErr =
Teresa Johnsona61f5e32016-12-16 21:25:01 +0000183 Lazy
184 ? getLazyBitcodeModule(Buffer, Context,
185 /* ShouldLazyLoadMetadata */ true, IsImporting)
186 : parseBitcodeFile(Buffer, Context);
Peter Collingbournedac43b42016-12-01 05:52:32 +0000187 if (!ModuleOrErr) {
188 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
189 SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
190 SourceMgr::DK_Error, EIB.message());
191 Err.print("ThinLTO", errs());
192 });
193 report_fatal_error("Can't load module, abort.");
194 }
Adrian Prantl981a7992017-05-20 00:00:08 +0000195 if (!Lazy)
196 verifyLoadedModule(*ModuleOrErr.get());
Peter Collingbournedac43b42016-12-01 05:52:32 +0000197 return std::move(ModuleOrErr.get());
198}
199
Mehdi Amini01e32132016-03-26 05:40:34 +0000200static void
201crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
202 StringMap<MemoryBufferRef> &ModuleMap,
203 const FunctionImporter::ImportMapTy &ImportList) {
Peter Collingbournedac43b42016-12-01 05:52:32 +0000204 auto Loader = [&](StringRef Identifier) {
205 return loadModuleFromBuffer(ModuleMap[Identifier], TheModule.getContext(),
Teresa Johnsona61f5e32016-12-16 21:25:01 +0000206 /*Lazy=*/true, /*IsImporting*/ true);
Peter Collingbournedac43b42016-12-01 05:52:32 +0000207 };
208
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000209 FunctionImporter Importer(Index, Loader);
Adrian Prantl66043792017-05-19 23:32:21 +0000210 Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
Mehdi Amini83a807e2017-01-08 00:30:27 +0000211 if (!Result) {
212 handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) {
213 SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
214 SourceMgr::DK_Error, EIB.message());
215 Err.print("ThinLTO", errs());
216 });
Peter Collingbourne7f00d0a2016-11-09 17:49:19 +0000217 report_fatal_error("importFunctions failed");
Mehdi Amini83a807e2017-01-08 00:30:27 +0000218 }
Adrian Prantl981a7992017-05-20 00:00:08 +0000219 // Verify again after cross-importing.
220 verifyLoadedModule(TheModule);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000221}
222
Mehdi Aminicc7fbf72016-12-28 19:37:16 +0000223static void optimizeModule(Module &TheModule, TargetMachine &TM,
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000224 unsigned OptLevel, bool Freestanding) {
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000225 // Populate the PassManager
226 PassManagerBuilder PMB;
227 PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000228 if (Freestanding)
229 PMB.LibraryInfo->disableAllFunctions();
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000230 PMB.Inliner = createFunctionInliningPass();
231 // FIXME: should get it from the bitcode?
Mehdi Aminicc7fbf72016-12-28 19:37:16 +0000232 PMB.OptLevel = OptLevel;
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000233 PMB.LoopVectorize = true;
234 PMB.SLPVectorize = true;
Adrian Prantl981a7992017-05-20 00:00:08 +0000235 // Already did this in verifyLoadedModule().
236 PMB.VerifyInput = false;
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000237 PMB.VerifyOutput = false;
238
239 legacy::PassManager PM;
240
241 // Add the TTI (required to inform the vectorizer about register size for
242 // instance)
243 PM.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
244
245 // Add optimizations
246 PMB.populateThinLTOPassManager(PM);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000247
248 PM.run(TheModule);
249}
250
Mehdi Amini059464f2016-04-24 03:18:01 +0000251// Convert the PreservedSymbols map from "Name" based to "GUID" based.
252static DenseSet<GlobalValue::GUID>
Mehdi Amini1380edf2017-02-03 07:41:43 +0000253computeGUIDPreservedSymbols(const StringSet<> &PreservedSymbols,
254 const Triple &TheTriple) {
255 DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
256 for (auto &Entry : PreservedSymbols) {
Mehdi Amini059464f2016-04-24 03:18:01 +0000257 StringRef Name = Entry.first();
258 if (TheTriple.isOSBinFormatMachO() && Name.size() > 0 && Name[0] == '_')
259 Name = Name.drop_front();
Mehdi Amini1380edf2017-02-03 07:41:43 +0000260 GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name));
Mehdi Amini059464f2016-04-24 03:18:01 +0000261 }
Mehdi Amini1380edf2017-02-03 07:41:43 +0000262 return GUIDPreservedSymbols;
Mehdi Amini059464f2016-04-24 03:18:01 +0000263}
264
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000265std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
266 TargetMachine &TM) {
267 SmallVector<char, 128> OutputBuffer;
268
269 // CodeGen
270 {
271 raw_svector_ostream OS(OutputBuffer);
272 legacy::PassManager PM;
Mehdi Amini215d59e2016-04-01 08:22:59 +0000273
274 // If the bitcode files contain ARC code and were compiled with optimization,
275 // the ObjCARCContractPass must be run, so do it unconditionally here.
276 PM.add(createObjCARCContractPass());
277
278 // Setup the codegen now.
Peter Collingbourne9a451142018-05-21 20:16:41 +0000279 if (TM.addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_ObjectFile,
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000280 /* DisableVerify */ true))
281 report_fatal_error("Failed to setup codegen");
282
283 // Run codegen now. resulting binary is in OutputBuffer.
284 PM.run(TheModule);
285 }
Weiming Zhao79f2d092018-04-16 03:44:03 +0000286 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000287}
288
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000289/// Manage caching for a single Module.
290class ModuleCacheEntry {
291 SmallString<128> EntryPath;
292
293public:
294 // Create a cache entry. This compute a unique hash for the Module considering
295 // the current list of export/import, and offer an interface to query to
296 // access the content in the cache.
297 ModuleCacheEntry(
298 StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID,
299 const FunctionImporter::ImportMapTy &ImportList,
300 const FunctionImporter::ExportSetTy &ExportList,
301 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
Teresa Johnson5f312ad2018-11-26 20:40:37 +0000302 const GVSummaryMapTy &DefinedGVSummaries, unsigned OptLevel,
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000303 bool Freestanding, const TargetMachineBuilder &TMBuilder) {
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000304 if (CachePath.empty())
305 return;
306
Mehdi Amini00fa1402016-10-08 04:44:18 +0000307 if (!Index.modulePaths().count(ModuleID))
308 // The module does not have an entry, it can't have a hash at all
309 return;
310
Teresa Johnson5f312ad2018-11-26 20:40:37 +0000311 if (all_of(Index.getModuleHash(ModuleID),
312 [](uint32_t V) { return V == 0; }))
Mehdi Aminif82bda02016-10-08 04:44:23 +0000313 // No hash entry, no caching!
314 return;
315
Teresa Johnson5f312ad2018-11-26 20:40:37 +0000316 llvm::lto::Config Conf;
317 Conf.OptLevel = OptLevel;
318 Conf.Options = TMBuilder.Options;
319 Conf.CPU = TMBuilder.MCpu;
320 Conf.MAttrs.push_back(TMBuilder.MAttr);
321 Conf.RelocModel = TMBuilder.RelocModel;
322 Conf.CGOptLevel = TMBuilder.CGOptLevel;
323 Conf.Freestanding = Freestanding;
324 SmallString<40> Key;
325 computeLTOCacheKey(Key, Conf, Index, ModuleID, ImportList, ExportList,
326 ResolvedODR, DefinedGVSummaries);
Eugene Leviantbf46e742018-11-16 07:08:00 +0000327
Peter Collingbourne25a17ba2017-03-20 16:41:57 +0000328 // This choice of file name allows the cache to be pruned (see pruneCache()
329 // in include/llvm/Support/CachePruning.h).
Teresa Johnson5f312ad2018-11-26 20:40:37 +0000330 sys::path::append(EntryPath, CachePath, "llvmcache-" + Key);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000331 }
332
Mehdi Amini059464f2016-04-24 03:18:01 +0000333 // Access the path to this entry in the cache.
334 StringRef getEntryPath() { return EntryPath; }
335
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000336 // Try loading the buffer for this cache entry.
337 ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
338 if (EntryPath.empty())
339 return std::error_code();
Andrew Ng089303d2018-07-04 14:17:10 +0000340 int FD;
341 SmallString<64> ResultPath;
342 std::error_code EC = sys::fs::openFileForRead(
343 Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);
344 if (EC)
345 return EC;
346 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
347 MemoryBuffer::getOpenFile(FD, EntryPath,
348 /*FileSize*/ -1,
349 /*RequiresNullTerminator*/ false);
350 close(FD);
351 return MBOrErr;
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000352 }
353
354 // Cache the Produced object file
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000355 void write(const MemoryBuffer &OutputBuffer) {
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000356 if (EntryPath.empty())
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000357 return;
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000358
359 // Write to a temporary to avoid race condition
360 SmallString<128> TempFilename;
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +0000361 SmallString<128> CachePath(EntryPath);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000362 int TempFD;
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +0000363 llvm::sys::path::remove_filename(CachePath);
364 sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
Fangrui Songf78650a2018-07-30 19:41:25 +0000365 std::error_code EC =
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +0000366 sys::fs::createUniqueFile(TempFilename, TempFD, TempFilename);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000367 if (EC) {
368 errs() << "Error: " << EC.message() << "\n";
369 report_fatal_error("ThinLTO: Can't get a temporary file");
370 }
371 {
372 raw_fd_ostream OS(TempFD, /* ShouldClose */ true);
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000373 OS << OutputBuffer.getBuffer();
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000374 }
Fangrui Songf78650a2018-07-30 19:41:25 +0000375 // Rename temp file to final destination; rename is atomic
Mehdi Amini2a16a5f2016-05-14 04:58:38 +0000376 EC = sys::fs::rename(TempFilename, EntryPath);
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +0000377 if (EC)
Mehdi Aminib02139d2016-05-14 05:16:35 +0000378 sys::fs::remove(TempFilename);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000379 }
380};
381
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000382static std::unique_ptr<MemoryBuffer>
383ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
384 StringMap<MemoryBufferRef> &ModuleMap, TargetMachine &TM,
385 const FunctionImporter::ImportMapTy &ImportList,
386 const FunctionImporter::ExportSetTy &ExportList,
387 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
388 const GVSummaryMapTy &DefinedGlobals,
Benjamin Kramerc321e532016-06-08 19:09:22 +0000389 const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000390 bool DisableCodeGen, StringRef SaveTempsDir,
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000391 bool Freestanding, unsigned OptLevel, unsigned count) {
Mehdi Amini059464f2016-04-24 03:18:01 +0000392
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000393 // "Benchmark"-like optimization: single-source case
394 bool SingleModule = (ModuleMap.size() == 1);
395
396 if (!SingleModule) {
397 promoteModule(TheModule, Index);
398
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000399 // Apply summary-based prevailing-symbol resolution decisions.
400 thinLTOResolvePrevailingInModule(TheModule, DefinedGlobals);
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000401
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000402 // Save temps: after promotion.
Mehdi Amini4b300e0a2016-05-05 05:14:16 +0000403 saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc");
Mehdi Amini059464f2016-04-24 03:18:01 +0000404 }
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000405
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000406 // Be friendly and don't nuke totally the module when the client didn't
407 // supply anything to preserve.
408 if (!ExportList.empty() || !GUIDPreservedSymbols.empty()) {
409 // Apply summary-based internalization decisions.
410 thinLTOInternalizeModule(TheModule, DefinedGlobals);
411 }
Mehdi Amini059464f2016-04-24 03:18:01 +0000412
413 // Save internalized bitcode
Mehdi Amini4b300e0a2016-05-05 05:14:16 +0000414 saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc");
Mehdi Amini059464f2016-04-24 03:18:01 +0000415
416 if (!SingleModule) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000417 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000418
419 // Save temps: after cross-module import.
Mehdi Amini4b300e0a2016-05-05 05:14:16 +0000420 saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000421 }
422
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000423 optimizeModule(TheModule, TM, OptLevel, Freestanding);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000424
Mehdi Amini4b300e0a2016-05-05 05:14:16 +0000425 saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000426
Mehdi Amini43b657b2016-04-01 06:47:02 +0000427 if (DisableCodeGen) {
428 // Configured to stop before CodeGen, serialize the bitcode and return.
429 SmallVector<char, 128> OutputBuffer;
430 {
431 raw_svector_ostream OS(OutputBuffer);
Dehao Chen5461d8b2016-09-28 21:00:58 +0000432 ProfileSummaryInfo PSI(TheModule);
Teresa Johnson94624ac2017-05-10 18:52:16 +0000433 auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
Rafael Espindola6a86e252018-02-14 19:11:32 +0000434 WriteBitcodeToFile(TheModule, OS, true, &Index);
Mehdi Amini43b657b2016-04-01 06:47:02 +0000435 }
Weiming Zhao79f2d092018-04-16 03:44:03 +0000436 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
Mehdi Amini43b657b2016-04-01 06:47:02 +0000437 }
438
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000439 return codegenModule(TheModule, TM);
440}
441
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000442/// Resolve prevailing symbols. Record resolutions in the \p ResolvedODR map
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000443/// for caching, and in the \p Index for application during the ThinLTO
444/// backends. This is needed for correctness for exported symbols (ensure
445/// at least one copy kept) and a compile-time optimization (to drop duplicate
446/// copies when possible).
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000447static void resolvePrevailingInIndex(
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000448 ModuleSummaryIndex &Index,
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000449 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
450 &ResolvedODR) {
451
452 DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
453 computePrevailingCopies(Index, PrevailingCopy);
454
455 auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
456 const auto &Prevailing = PrevailingCopy.find(GUID);
457 // Not in map means that there was only one copy, which must be prevailing.
458 if (Prevailing == PrevailingCopy.end())
459 return true;
460 return Prevailing->second == S;
461 };
462
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000463 auto recordNewLinkage = [&](StringRef ModuleIdentifier,
464 GlobalValue::GUID GUID,
465 GlobalValue::LinkageTypes NewLinkage) {
466 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
467 };
468
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000469 thinLTOResolvePrevailingInIndex(Index, isPrevailing, recordNewLinkage);
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000470}
471
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000472// Initialize the TargetMachine builder for a given Triple
473static void initTMBuilder(TargetMachineBuilder &TMBuilder,
474 const Triple &TheTriple) {
475 // Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
476 // FIXME this looks pretty terrible...
477 if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
478 if (TheTriple.getArch() == llvm::Triple::x86_64)
479 TMBuilder.MCpu = "core2";
480 else if (TheTriple.getArch() == llvm::Triple::x86)
481 TMBuilder.MCpu = "yonah";
482 else if (TheTriple.getArch() == llvm::Triple::aarch64)
483 TMBuilder.MCpu = "cyclone";
484 }
485 TMBuilder.TheTriple = std::move(TheTriple);
486}
487
488} // end anonymous namespace
489
490void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
Johan Engelendcebe4f2017-09-17 18:11:26 +0000491 ThinLTOBuffer Buffer(Data, Identifier);
Akira Hatanakab10bff12017-05-18 03:52:29 +0000492 LLVMContext Context;
493 StringRef TripleStr;
494 ErrorOr<std::string> TripleOrErr = expectedToErrorOrAndEmitErrors(
495 Context, getBitcodeTargetTriple(Buffer.getMemBuffer()));
496
497 if (TripleOrErr)
498 TripleStr = *TripleOrErr;
499
500 Triple TheTriple(TripleStr);
501
502 if (Modules.empty())
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000503 initTMBuilder(TMBuilder, Triple(TheTriple));
Akira Hatanakab10bff12017-05-18 03:52:29 +0000504 else if (TMBuilder.TheTriple != TheTriple) {
505 if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
506 report_fatal_error("ThinLTO modules with incompatible triples not "
507 "supported");
508 initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000509 }
Akira Hatanakab10bff12017-05-18 03:52:29 +0000510
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000511 Modules.push_back(Buffer);
512}
513
514void ThinLTOCodeGenerator::preserveSymbol(StringRef Name) {
515 PreservedSymbols.insert(Name);
516}
517
518void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
Mehdi Amini1380edf2017-02-03 07:41:43 +0000519 // FIXME: At the moment, we don't take advantage of this extra information,
520 // we're conservatively considering cross-references as preserved.
521 // CrossReferencedSymbols.insert(Name);
522 PreservedSymbols.insert(Name);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000523}
524
525// TargetMachine factory
526std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
527 std::string ErrMsg;
528 const Target *TheTarget =
529 TargetRegistry::lookupTarget(TheTriple.str(), ErrMsg);
530 if (!TheTarget) {
531 report_fatal_error("Can't load target for this Triple: " + ErrMsg);
532 }
533
534 // Use MAttr as the default set of features.
535 SubtargetFeatures Features(MAttr);
536 Features.getDefaultSubtargetFeatures(TheTriple);
537 std::string FeatureStr = Features.getString();
Mehdi Aminicc7fbf72016-12-28 19:37:16 +0000538
Rafael Espindola79e238a2017-08-03 02:16:21 +0000539 return std::unique_ptr<TargetMachine>(
540 TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
541 RelocModel, None, CGOptLevel));
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000542}
543
544/**
Teresa Johnson26ab5772016-03-15 00:04:37 +0000545 * Produce the combined summary index from all the bitcode files:
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000546 * "thin-link".
547 */
Teresa Johnson26ab5772016-03-15 00:04:37 +0000548std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
Peter Collingbourne74d22dd2017-05-01 22:04:36 +0000549 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
Teresa Johnson4ffc3e72018-06-06 22:22:01 +0000550 llvm::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000551 uint64_t NextModuleId = 0;
552 for (auto &ModuleBuffer : Modules) {
Peter Collingbourne74d22dd2017-05-01 22:04:36 +0000553 if (Error Err = readModuleSummaryIndex(ModuleBuffer.getMemBuffer(),
554 *CombinedIndex, NextModuleId++)) {
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000555 // FIXME diagnose
Peter Collingbourne6de481a2016-11-11 19:50:39 +0000556 logAllUnhandledErrors(
Peter Collingbourne74d22dd2017-05-01 22:04:36 +0000557 std::move(Err), errs(),
Peter Collingbournec15d60b2017-05-01 20:42:32 +0000558 "error: can't create module summary index for buffer: ");
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000559 return nullptr;
560 }
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000561 }
562 return CombinedIndex;
563}
564
George Rimar2421b6f2018-01-17 10:33:05 +0000565static void internalizeAndPromoteInIndex(
566 const StringMap<FunctionImporter::ExportSetTy> &ExportLists,
567 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
568 ModuleSummaryIndex &Index) {
569 auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
570 const auto &ExportList = ExportLists.find(ModuleIdentifier);
571 return (ExportList != ExportLists.end() &&
572 ExportList->second.count(GUID)) ||
573 GUIDPreservedSymbols.count(GUID);
574 };
575
576 thinLTOInternalizeAndPromoteInIndex(Index, isExported);
577}
578
George Rimareaf51722018-01-29 08:03:30 +0000579static void computeDeadSymbolsInIndex(
580 ModuleSummaryIndex &Index,
581 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
582 // We have no symbols resolution available. And can't do any better now in the
583 // case where the prevailing symbol is in a native object. It can be refined
584 // with linker information in the future.
585 auto isPrevailing = [&](GlobalValue::GUID G) {
586 return PrevailingType::Unknown;
587 };
Eugene Leviantbf46e742018-11-16 07:08:00 +0000588 computeDeadSymbolsWithConstProp(Index, GUIDPreservedSymbols, isPrevailing,
589 /* ImportEnabled = */ true);
George Rimareaf51722018-01-29 08:03:30 +0000590}
591
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000592/**
593 * Perform promotion and renaming of exported internal functions.
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000594 * Index is updated to reflect linkage changes from weak resolution.
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000595 */
596void ThinLTOCodeGenerator::promote(Module &TheModule,
Teresa Johnson26ab5772016-03-15 00:04:37 +0000597 ModuleSummaryIndex &Index) {
Mehdi Aminia71a5a62016-04-21 05:47:17 +0000598 auto ModuleCount = Index.modulePaths().size();
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000599 auto ModuleIdentifier = TheModule.getModuleIdentifier();
Teresa Johnson4fef68c2016-11-14 19:21:41 +0000600
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000601 // Collect for each module the list of function it defines (GUID -> Summary).
Teresa Johnsonc851d212016-04-25 21:09:51 +0000602 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000603 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000604
Teresa Johnson6c475a72017-01-05 21:34:18 +0000605 // Convert the preserved symbols set from string to GUID
Mehdi Amini1380edf2017-02-03 07:41:43 +0000606 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
Teresa Johnson6c475a72017-01-05 21:34:18 +0000607 PreservedSymbols, Triple(TheModule.getTargetTriple()));
608
609 // Compute "dead" symbols, we don't want to import/export these!
George Rimareaf51722018-01-29 08:03:30 +0000610 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
Teresa Johnson6c475a72017-01-05 21:34:18 +0000611
Mehdi Aminia71a5a62016-04-21 05:47:17 +0000612 // Generate import/export list
613 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
614 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
615 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
Evgeniy Stepanov56584bb2017-06-01 20:30:06 +0000616 ExportLists);
Mehdi Aminia71a5a62016-04-21 05:47:17 +0000617
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000618 // Resolve prevailing symbols
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000619 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000620 resolvePrevailingInIndex(Index, ResolvedODR);
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000621
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000622 thinLTOResolvePrevailingInModule(
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000623 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
Mehdi Amini5a2e5d32016-04-01 21:53:50 +0000624
Teresa Johnson4fef68c2016-11-14 19:21:41 +0000625 // Promote the exported values in the index, so that they are promoted
626 // in the module.
George Rimar2421b6f2018-01-17 10:33:05 +0000627 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, Index);
Teresa Johnson4fef68c2016-11-14 19:21:41 +0000628
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000629 promoteModule(TheModule, Index);
630}
631
632/**
633 * Perform cross-module importing for the module identified by ModuleIdentifier.
634 */
635void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
Teresa Johnson26ab5772016-03-15 00:04:37 +0000636 ModuleSummaryIndex &Index) {
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000637 auto ModuleMap = generateModuleMap(Modules);
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000638 auto ModuleCount = Index.modulePaths().size();
639
640 // Collect for each module the list of function it defines (GUID -> Summary).
Teresa Johnsonc851d212016-04-25 21:09:51 +0000641 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000642 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
Mehdi Amini01e32132016-03-26 05:40:34 +0000643
Teresa Johnson6c475a72017-01-05 21:34:18 +0000644 // Convert the preserved symbols set from string to GUID
Mehdi Amini1380edf2017-02-03 07:41:43 +0000645 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
Teresa Johnson6c475a72017-01-05 21:34:18 +0000646 PreservedSymbols, Triple(TheModule.getTargetTriple()));
647
648 // Compute "dead" symbols, we don't want to import/export these!
George Rimareaf51722018-01-29 08:03:30 +0000649 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
Teresa Johnson6c475a72017-01-05 21:34:18 +0000650
Mehdi Amini01e32132016-03-26 05:40:34 +0000651 // Generate import/export list
Mehdi Amini01e32132016-03-26 05:40:34 +0000652 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
653 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000654 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
Evgeniy Stepanov56584bb2017-06-01 20:30:06 +0000655 ExportLists);
Mehdi Amini01e32132016-03-26 05:40:34 +0000656 auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
657
658 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000659}
660
661/**
Teresa Johnson84174c32016-05-10 13:48:23 +0000662 * Compute the list of summaries needed for importing into module.
663 */
664void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
Teresa Johnson93f99962018-11-29 17:02:42 +0000665 Module &TheModule, ModuleSummaryIndex &Index,
Teresa Johnson84174c32016-05-10 13:48:23 +0000666 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
667 auto ModuleCount = Index.modulePaths().size();
Teresa Johnson93f99962018-11-29 17:02:42 +0000668 auto ModuleIdentifier = TheModule.getModuleIdentifier();
Teresa Johnson84174c32016-05-10 13:48:23 +0000669
670 // Collect for each module the list of function it defines (GUID -> Summary).
671 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
672 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
673
Teresa Johnson93f99962018-11-29 17:02:42 +0000674 // Convert the preserved symbols set from string to GUID
675 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
676 PreservedSymbols, Triple(TheModule.getTargetTriple()));
677
678 // Compute "dead" symbols, we don't want to import/export these!
679 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
680
Teresa Johnson84174c32016-05-10 13:48:23 +0000681 // Generate import/export list
682 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
683 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
684 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
685 ExportLists);
686
Teresa Johnson93f99962018-11-29 17:02:42 +0000687 llvm::gatherImportedSummariesForModule(
688 ModuleIdentifier, ModuleToDefinedGVSummaries,
689 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
Teresa Johnson84174c32016-05-10 13:48:23 +0000690}
691
692/**
Teresa Johnson8570fe42016-05-10 15:54:09 +0000693 * Emit the list of files needed for importing into module.
694 */
Teresa Johnson93f99962018-11-29 17:02:42 +0000695void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
Teresa Johnson8570fe42016-05-10 15:54:09 +0000696 ModuleSummaryIndex &Index) {
697 auto ModuleCount = Index.modulePaths().size();
Teresa Johnson93f99962018-11-29 17:02:42 +0000698 auto ModuleIdentifier = TheModule.getModuleIdentifier();
Teresa Johnson8570fe42016-05-10 15:54:09 +0000699
700 // Collect for each module the list of function it defines (GUID -> Summary).
701 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
702 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
703
Teresa Johnson93f99962018-11-29 17:02:42 +0000704 // Convert the preserved symbols set from string to GUID
705 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
706 PreservedSymbols, Triple(TheModule.getTargetTriple()));
707
708 // Compute "dead" symbols, we don't want to import/export these!
709 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
710
Teresa Johnson8570fe42016-05-10 15:54:09 +0000711 // Generate import/export list
712 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
713 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
714 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
715 ExportLists);
716
Teresa Johnsonc0320ef2018-07-10 20:06:04 +0000717 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
Teresa Johnson93f99962018-11-29 17:02:42 +0000718 llvm::gatherImportedSummariesForModule(
719 ModuleIdentifier, ModuleToDefinedGVSummaries,
720 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
Teresa Johnsonc0320ef2018-07-10 20:06:04 +0000721
Teresa Johnson8570fe42016-05-10 15:54:09 +0000722 std::error_code EC;
Teresa Johnson93f99962018-11-29 17:02:42 +0000723 if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,
724 ModuleToSummariesForIndex)))
Teresa Johnson8570fe42016-05-10 15:54:09 +0000725 report_fatal_error(Twine("Failed to open ") + OutputName +
726 " to save imports lists\n");
727}
728
729/**
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000730 * Perform internalization. Index is updated to reflect linkage changes.
Mehdi Amini059464f2016-04-24 03:18:01 +0000731 */
732void ThinLTOCodeGenerator::internalize(Module &TheModule,
733 ModuleSummaryIndex &Index) {
734 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
735 auto ModuleCount = Index.modulePaths().size();
736 auto ModuleIdentifier = TheModule.getModuleIdentifier();
737
738 // Convert the preserved symbols set from string to GUID
739 auto GUIDPreservedSymbols =
Mehdi Amini1380edf2017-02-03 07:41:43 +0000740 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
Mehdi Amini059464f2016-04-24 03:18:01 +0000741
742 // Collect for each module the list of function it defines (GUID -> Summary).
Teresa Johnsonc851d212016-04-25 21:09:51 +0000743 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
Mehdi Amini059464f2016-04-24 03:18:01 +0000744 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
745
Teresa Johnson6c475a72017-01-05 21:34:18 +0000746 // Compute "dead" symbols, we don't want to import/export these!
George Rimareaf51722018-01-29 08:03:30 +0000747 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
Teresa Johnson6c475a72017-01-05 21:34:18 +0000748
Mehdi Amini059464f2016-04-24 03:18:01 +0000749 // Generate import/export list
750 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
751 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
752 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
Evgeniy Stepanov56584bb2017-06-01 20:30:06 +0000753 ExportLists);
Mehdi Amini059464f2016-04-24 03:18:01 +0000754 auto &ExportList = ExportLists[ModuleIdentifier];
755
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000756 // Be friendly and don't nuke totally the module when the client didn't
757 // supply anything to preserve.
758 if (ExportList.empty() && GUIDPreservedSymbols.empty())
759 return;
760
Mehdi Amini059464f2016-04-24 03:18:01 +0000761 // Internalization
George Rimar2421b6f2018-01-17 10:33:05 +0000762 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, Index);
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000763 thinLTOInternalizeModule(TheModule,
764 ModuleToDefinedGVSummaries[ModuleIdentifier]);
Mehdi Amini059464f2016-04-24 03:18:01 +0000765}
766
767/**
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000768 * Perform post-importing ThinLTO optimizations.
769 */
770void ThinLTOCodeGenerator::optimize(Module &TheModule) {
771 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
Mehdi Amini059464f2016-04-24 03:18:01 +0000772
773 // Optimize now
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000774 optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000775}
776
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000777/// Write out the generated object file, either from CacheEntryPath or from
778/// OutputBuffer, preferring hard-link when possible.
779/// Returns the path to the generated file in SavedObjectsDirectoryPath.
780static std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
781 StringRef SavedObjectsDirectoryPath,
782 const MemoryBuffer &OutputBuffer) {
783 SmallString<128> OutputPath(SavedObjectsDirectoryPath);
784 llvm::sys::path::append(OutputPath, Twine(count) + ".thinlto.o");
785 OutputPath.c_str(); // Ensure the string is null terminated.
786 if (sys::fs::exists(OutputPath))
787 sys::fs::remove(OutputPath);
788
789 // We don't return a memory buffer to the linker, just a list of files.
790 if (!CacheEntryPath.empty()) {
791 // Cache is enabled, hard-link the entry (or copy if hard-link fails).
792 auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
793 if (!Err)
794 return OutputPath.str();
795 // Hard linking failed, try to copy.
796 Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
797 if (!Err)
798 return OutputPath.str();
799 // Copy failed (could be because the CacheEntry was removed from the cache
800 // in the meantime by another process), fall back and try to write down the
801 // buffer to the output.
802 errs() << "error: can't link or copy from cached entry '" << CacheEntryPath
803 << "' to '" << OutputPath << "'\n";
804 }
805 // No cache entry, just write out the buffer.
806 std::error_code Err;
807 raw_fd_ostream OS(OutputPath, Err, sys::fs::F_None);
808 if (Err)
809 report_fatal_error("Can't open output '" + OutputPath + "'\n");
810 OS << OutputBuffer.getBuffer();
811 return OutputPath.str();
812}
813
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000814// Main entry point for the ThinLTO processing
815void ThinLTOCodeGenerator::run() {
Mehdi Aminib2990462017-01-20 22:45:34 +0000816 // Prepare the resulting object vector
817 assert(ProducedBinaries.empty() && "The generator should not be reused");
818 if (SavedObjectsDirectoryPath.empty())
819 ProducedBinaries.resize(Modules.size());
820 else {
821 sys::fs::create_directories(SavedObjectsDirectoryPath);
822 bool IsDir;
823 sys::fs::is_directory(SavedObjectsDirectoryPath, IsDir);
824 if (!IsDir)
825 report_fatal_error("Unexistent dir: '" + SavedObjectsDirectoryPath + "'");
826 ProducedBinaryFiles.resize(Modules.size());
827 }
828
Mehdi Amini43b657b2016-04-01 06:47:02 +0000829 if (CodeGenOnly) {
830 // Perform only parallel codegen and return.
831 ThreadPool Pool;
Mehdi Amini43b657b2016-04-01 06:47:02 +0000832 int count = 0;
833 for (auto &ModuleBuffer : Modules) {
834 Pool.async([&](int count) {
835 LLVMContext Context;
836 Context.setDiscardValueNames(LTODiscardValueNames);
837
838 // Parse module now
Mehdi Aminia0ddb1e2017-02-14 02:20:51 +0000839 auto TheModule =
840 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(), Context, false,
841 /*IsImporting*/ false);
Mehdi Amini43b657b2016-04-01 06:47:02 +0000842
843 // CodeGen
Steven Wucf902032018-09-04 22:54:17 +0000844 auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create());
Mehdi Aminib2990462017-01-20 22:45:34 +0000845 if (SavedObjectsDirectoryPath.empty())
846 ProducedBinaries[count] = std::move(OutputBuffer);
847 else
848 ProducedBinaryFiles[count] = writeGeneratedObject(
849 count, "", SavedObjectsDirectoryPath, *OutputBuffer);
Mehdi Amini43b657b2016-04-01 06:47:02 +0000850 }, count++);
851 }
852
853 return;
854 }
855
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000856 // Sequential linking phase
857 auto Index = linkCombinedIndex();
858
859 // Save temps: index.
860 if (!SaveTempsDir.empty()) {
861 auto SaveTempPath = SaveTempsDir + "index.bc";
862 std::error_code EC;
863 raw_fd_ostream OS(SaveTempPath, EC, sys::fs::F_None);
864 if (EC)
865 report_fatal_error(Twine("Failed to open ") + SaveTempPath +
866 " to save optimized bitcode\n");
Teresa Johnson76a1c1d2016-03-11 18:52:24 +0000867 WriteIndexToFile(*Index, OS);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000868 }
869
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000870
871 // Prepare the module map.
872 auto ModuleMap = generateModuleMap(Modules);
Mehdi Amini01e32132016-03-26 05:40:34 +0000873 auto ModuleCount = Modules.size();
874
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000875 // Collect for each module the list of function it defines (GUID -> Summary).
Teresa Johnsonc851d212016-04-25 21:09:51 +0000876 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000877 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
878
Teresa Johnson6c475a72017-01-05 21:34:18 +0000879 // Convert the preserved symbols set from string to GUID, this is needed for
880 // computing the caching hash and the internalization.
881 auto GUIDPreservedSymbols =
Mehdi Amini1380edf2017-02-03 07:41:43 +0000882 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
Teresa Johnson6c475a72017-01-05 21:34:18 +0000883
884 // Compute "dead" symbols, we don't want to import/export these!
George Rimareaf51722018-01-29 08:03:30 +0000885 computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
Teresa Johnson6c475a72017-01-05 21:34:18 +0000886
Easwaran Raman5a7056f2018-12-13 19:54:27 +0000887 // Synthesize entry counts for functions in the combined index.
888 computeSyntheticCounts(*Index);
889
Mehdi Amini01e32132016-03-26 05:40:34 +0000890 // Collect the import/export lists for all modules from the call-graph in the
891 // combined index.
892 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
893 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000894 ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists,
Evgeniy Stepanov56584bb2017-06-01 20:30:06 +0000895 ExportLists);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000896
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000897 // We use a std::map here to be able to have a defined ordering when
898 // producing a hash for the cache entry.
899 // FIXME: we should be able to compute the caching hash for the entry based
900 // on the index, and nuke this map.
901 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
902
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000903 // Resolve prevailing symbols, this has to be computed early because it
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000904 // impacts the caching.
Pirama Arumuga Nainare61652a2018-11-08 20:10:07 +0000905 resolvePrevailingInIndex(*Index, ResolvedODR);
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000906
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000907 // Use global summary-based analysis to identify symbols that can be
908 // internalized (because they aren't exported or preserved as per callback).
909 // Changes are made in the index, consumed in the ThinLTO backends.
George Rimar2421b6f2018-01-17 10:33:05 +0000910 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, *Index);
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000911
Steven Wuec53c892018-09-14 19:38:21 +0000912 // Make sure that every module has an entry in the ExportLists, ImportList,
913 // GVSummary and ResolvedODR maps to enable threaded access to these maps
914 // below.
915 for (auto &Module : Modules) {
916 auto ModuleIdentifier = Module.getBufferIdentifier();
917 ExportLists[ModuleIdentifier];
918 ImportLists[ModuleIdentifier];
919 ResolvedODR[ModuleIdentifier];
920 ModuleToDefinedGVSummaries[ModuleIdentifier];
Teresa Johnson141149f2016-05-24 18:44:01 +0000921 }
Mehdi Aminiaf52f282016-05-15 05:49:47 +0000922
Mehdi Amini819e9cd2016-05-16 19:33:07 +0000923 // Compute the ordering we will process the inputs: the rough heuristic here
924 // is to sort them per size so that the largest module get schedule as soon as
925 // possible. This is purely a compile-time optimization.
926 std::vector<int> ModulesOrdering;
927 ModulesOrdering.resize(Modules.size());
928 std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
Fangrui Song0cac7262018-09-27 02:13:45 +0000929 llvm::sort(ModulesOrdering, [&](int LeftIndex, int RightIndex) {
930 auto LSize = Modules[LeftIndex].getBuffer().size();
931 auto RSize = Modules[RightIndex].getBuffer().size();
932 return LSize > RSize;
933 });
Mehdi Amini819e9cd2016-05-16 19:33:07 +0000934
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000935 // Parallel optimizer + codegen
936 {
937 ThreadPool Pool(ThreadCount);
Mehdi Amini819e9cd2016-05-16 19:33:07 +0000938 for (auto IndexCount : ModulesOrdering) {
939 auto &ModuleBuffer = Modules[IndexCount];
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000940 Pool.async([&](int count) {
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000941 auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier();
Mehdi Aminia71a5a62016-04-21 05:47:17 +0000942 auto &ExportList = ExportLists[ModuleIdentifier];
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000943
Eugene Leviantbf46e742018-11-16 07:08:00 +0000944 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000945
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000946 // The module may be cached, this helps handling it.
Mehdi Amini059464f2016-04-24 03:18:01 +0000947 ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
948 ImportLists[ModuleIdentifier], ExportList,
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000949 ResolvedODR[ModuleIdentifier],
Teresa Johnson5f312ad2018-11-26 20:40:37 +0000950 DefinedGVSummaries, OptLevel, Freestanding,
951 TMBuilder);
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000952 auto CacheEntryPath = CacheEntry.getEntryPath();
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000953
954 {
955 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000956 LLVM_DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss")
957 << " '" << CacheEntryPath << "' for buffer "
958 << count << " " << ModuleIdentifier << "\n");
Mehdi Amini059464f2016-04-24 03:18:01 +0000959
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000960 if (ErrOrBuffer) {
961 // Cache Hit!
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000962 if (SavedObjectsDirectoryPath.empty())
963 ProducedBinaries[count] = std::move(ErrOrBuffer.get());
964 else
965 ProducedBinaryFiles[count] = writeGeneratedObject(
966 count, CacheEntryPath, SavedObjectsDirectoryPath,
967 *ErrOrBuffer.get());
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000968 return;
969 }
970 }
971
972 LLVMContext Context;
973 Context.setDiscardValueNames(LTODiscardValueNames);
974 Context.enableDebugTypeODRUniquing();
Davide Italiano690ed9d2017-02-10 23:49:38 +0000975 auto DiagFileOrErr = lto::setupOptimizationRemarks(
Bob Haarmanfb2d3422018-03-08 01:13:10 +0000976 Context, LTORemarksFilename, LTOPassRemarksWithHotness, count);
Mehdi Amini19f176b2016-11-19 18:20:05 +0000977 if (!DiagFileOrErr) {
978 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
979 report_fatal_error("ThinLTO: Can't get an output file for the "
980 "remarks");
981 }
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000982
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000983 // Parse module now
Mehdi Aminia0ddb1e2017-02-14 02:20:51 +0000984 auto TheModule =
985 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(), Context, false,
986 /*IsImporting*/ false);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000987
988 // Save temps: original file.
Mehdi Amini059464f2016-04-24 03:18:01 +0000989 saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
Mehdi Amini7c4a1a82016-03-09 01:37:22 +0000990
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000991 auto &ImportList = ImportLists[ModuleIdentifier];
Mehdi Amini059464f2016-04-24 03:18:01 +0000992 // Run the main process now, and generates a binary
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000993 auto OutputBuffer = ProcessThinLTOModule(
Mehdi Amini01e32132016-03-26 05:40:34 +0000994 *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
Teresa Johnson4d2613f2016-05-24 17:24:25 +0000995 ExportList, GUIDPreservedSymbols,
996 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
Mehdi Aminib5a46c12017-03-28 18:55:44 +0000997 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count);
Mehdi Aminif95f77a2016-04-21 05:54:23 +0000998
Mehdi Amini8e13bc42016-12-14 04:56:42 +0000999 // Commit to the cache (if enabled)
1000 CacheEntry.write(*OutputBuffer);
1001
1002 if (SavedObjectsDirectoryPath.empty()) {
1003 // We need to generated a memory buffer for the linker.
1004 if (!CacheEntryPath.empty()) {
Fangrui Songf78650a2018-07-30 19:41:25 +00001005 // When cache is enabled, reload from the cache if possible.
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +00001006 // Releasing the buffer from the heap and reloading it from the
Fangrui Songf78650a2018-07-30 19:41:25 +00001007 // cache file with mmap helps us to lower memory pressure.
1008 // The freed memory can be used for the next input file.
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +00001009 // The final binary link will read from the VFS cache (hopefully!)
1010 // or from disk (if the memory pressure was too high).
Mehdi Amini8e13bc42016-12-14 04:56:42 +00001011 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1012 if (auto EC = ReloadedBufferOrErr.getError()) {
Ekaterina Romanova0b01dfb2018-03-30 21:35:42 +00001013 // On error, keep the preexisting buffer and print a diagnostic.
Mehdi Amini8e13bc42016-12-14 04:56:42 +00001014 errs() << "error: can't reload cached file '" << CacheEntryPath
1015 << "': " << EC.message() << "\n";
1016 } else {
1017 OutputBuffer = std::move(*ReloadedBufferOrErr);
1018 }
1019 }
1020 ProducedBinaries[count] = std::move(OutputBuffer);
1021 return;
1022 }
1023 ProducedBinaryFiles[count] = writeGeneratedObject(
1024 count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
Mehdi Amini819e9cd2016-05-16 19:33:07 +00001025 }, IndexCount);
Mehdi Amini7c4a1a82016-03-09 01:37:22 +00001026 }
1027 }
1028
Peter Collingbournecead56f2017-03-15 22:54:18 +00001029 pruneCache(CacheOptions.Path, CacheOptions.Policy);
Mehdi Aminif95f77a2016-04-21 05:54:23 +00001030
Mehdi Amini7c4a1a82016-03-09 01:37:22 +00001031 // If statistics were requested, print them out now.
1032 if (llvm::AreStatisticsEnabled())
1033 llvm::PrintStatistics();
James Henderson852f6fd2017-05-16 09:43:21 +00001034 reportAndResetTimings();
Mehdi Amini7c4a1a82016-03-09 01:37:22 +00001035}