Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 1 | //===-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 | |
| 15 | #include "llvm/LTO/ThinLTOCodeGenerator.h" |
| 16 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 17 | #ifdef HAVE_LLVM_REVISION |
| 18 | #include "LLVMLTORevision.h" |
| 19 | #endif |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 20 | |
| 21 | #include "UpdateCompilerUsed.h" |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Statistic.h" |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/TargetLibraryInfo.h" |
| 26 | #include "llvm/Analysis/TargetTransformInfo.h" |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 27 | #include "llvm/Bitcode/BitcodeWriterPass.h" |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 28 | #include "llvm/Bitcode/ReaderWriter.h" |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 29 | #include "llvm/ExecutionEngine/ObjectMemoryBuffer.h" |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 30 | #include "llvm/IR/DiagnosticPrinter.h" |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 31 | #include "llvm/IR/LLVMContext.h" |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 32 | #include "llvm/IR/LegacyPassManager.h" |
| 33 | #include "llvm/IR/Mangler.h" |
| 34 | #include "llvm/IRReader/IRReader.h" |
| 35 | #include "llvm/Linker/Linker.h" |
| 36 | #include "llvm/MC/SubtargetFeature.h" |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 37 | #include "llvm/Object/IRObjectFile.h" |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 38 | #include "llvm/Object/ModuleSummaryIndexObjectFile.h" |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Debug.h" |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 40 | #include "llvm/Support/CachePruning.h" |
| 41 | #include "llvm/Support/Debug.h" |
| 42 | #include "llvm/Support/Path.h" |
| 43 | #include "llvm/Support/SHA1.h" |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 44 | #include "llvm/Support/SourceMgr.h" |
| 45 | #include "llvm/Support/TargetRegistry.h" |
| 46 | #include "llvm/Support/ThreadPool.h" |
| 47 | #include "llvm/Target/TargetMachine.h" |
| 48 | #include "llvm/Transforms/IPO.h" |
| 49 | #include "llvm/Transforms/IPO/FunctionImport.h" |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 50 | #include "llvm/Transforms/IPO/Internalize.h" |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 51 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| 52 | #include "llvm/Transforms/ObjCARC.h" |
| 53 | #include "llvm/Transforms/Utils/FunctionImportUtils.h" |
| 54 | |
| 55 | using namespace llvm; |
| 56 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 57 | #define DEBUG_TYPE "thinlto" |
| 58 | |
Mehdi Amini | 09b4a8d | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 59 | namespace llvm { |
| 60 | // Flags -discard-value-names, defined in LTOCodeGenerator.cpp |
| 61 | extern cl::opt<bool> LTODiscardValueNames; |
| 62 | } |
| 63 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 64 | namespace { |
| 65 | |
| 66 | static cl::opt<int> ThreadCount("threads", |
| 67 | cl::init(std::thread::hardware_concurrency())); |
| 68 | |
| 69 | static void diagnosticHandler(const DiagnosticInfo &DI) { |
| 70 | DiagnosticPrinterRawOStream DP(errs()); |
| 71 | DI.print(DP); |
| 72 | errs() << '\n'; |
| 73 | } |
| 74 | |
| 75 | // Simple helper to load a module from bitcode |
| 76 | static std::unique_ptr<Module> |
| 77 | loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context, |
| 78 | bool Lazy) { |
| 79 | SMDiagnostic Err; |
| 80 | ErrorOr<std::unique_ptr<Module>> ModuleOrErr(nullptr); |
| 81 | if (Lazy) { |
| 82 | ModuleOrErr = |
| 83 | getLazyBitcodeModule(MemoryBuffer::getMemBuffer(Buffer, false), Context, |
| 84 | /* ShouldLazyLoadMetadata */ Lazy); |
| 85 | } else { |
| 86 | ModuleOrErr = parseBitcodeFile(Buffer, Context); |
| 87 | } |
| 88 | if (std::error_code EC = ModuleOrErr.getError()) { |
| 89 | Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, |
| 90 | EC.message()); |
| 91 | Err.print("ThinLTO", errs()); |
| 92 | report_fatal_error("Can't load module, abort."); |
| 93 | } |
| 94 | return std::move(ModuleOrErr.get()); |
| 95 | } |
| 96 | |
| 97 | // Simple helper to save temporary files for debug. |
| 98 | static void saveTempBitcode(const Module &TheModule, StringRef TempDir, |
| 99 | unsigned count, StringRef Suffix) { |
| 100 | if (TempDir.empty()) |
| 101 | return; |
| 102 | // User asked to save temps, let dump the bitcode file after import. |
| 103 | auto SaveTempPath = TempDir + llvm::utostr(count) + Suffix; |
| 104 | std::error_code EC; |
| 105 | raw_fd_ostream OS(SaveTempPath.str(), EC, sys::fs::F_None); |
| 106 | if (EC) |
| 107 | report_fatal_error(Twine("Failed to open ") + SaveTempPath + |
| 108 | " to save optimized bitcode\n"); |
Teresa Johnson | 3c35e09 | 2016-04-04 21:19:31 +0000 | [diff] [blame] | 109 | WriteBitcodeToFile(&TheModule, OS, /* ShouldPreserveUseListOrder */ true); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 112 | bool IsFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList, |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 113 | const ModuleSummaryIndex &Index, |
| 114 | StringRef ModulePath) { |
| 115 | // Get the first *linker visible* definition for this global in the summary |
| 116 | // list. |
| 117 | auto FirstDefForLinker = llvm::find_if( |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 118 | GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) { |
| 119 | auto Linkage = Summary->linkage(); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 120 | return !GlobalValue::isAvailableExternallyLinkage(Linkage); |
| 121 | }); |
| 122 | // If \p GV is not the first definition, give up... |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 123 | if ((*FirstDefForLinker)->modulePath() != ModulePath) |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 124 | return false; |
| 125 | // If there is any strong definition anywhere, do not bother emitting this. |
| 126 | if (llvm::any_of( |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 127 | GVSummaryList, |
| 128 | [](const std::unique_ptr<GlobalValueSummary> &Summary) { |
| 129 | auto Linkage = Summary->linkage(); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 130 | return !GlobalValue::isAvailableExternallyLinkage(Linkage) && |
| 131 | !GlobalValue::isWeakForLinker(Linkage); |
| 132 | })) |
| 133 | return false; |
| 134 | return true; |
Hans Wennborg | fa6e414 | 2016-04-02 01:03:41 +0000 | [diff] [blame] | 135 | } |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 136 | |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 137 | static GlobalValue::LinkageTypes |
| 138 | ResolveODR(const ModuleSummaryIndex &Index, |
| 139 | const FunctionImporter::ExportSetTy &ExportList, |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 140 | const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 141 | StringRef ModuleIdentifier, GlobalValue::GUID GUID, |
| 142 | const GlobalValueSummary &GV) { |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 143 | auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) { |
| 144 | return GVSummaryList.size() > 1; |
| 145 | }; |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 146 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 147 | auto OriginalLinkage = GV.linkage(); |
| 148 | switch (OriginalLinkage) { |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 149 | case GlobalValue::ExternalLinkage: |
| 150 | case GlobalValue::AvailableExternallyLinkage: |
| 151 | case GlobalValue::AppendingLinkage: |
| 152 | case GlobalValue::InternalLinkage: |
| 153 | case GlobalValue::PrivateLinkage: |
| 154 | case GlobalValue::ExternalWeakLinkage: |
| 155 | case GlobalValue::CommonLinkage: |
| 156 | case GlobalValue::LinkOnceAnyLinkage: |
| 157 | case GlobalValue::WeakAnyLinkage: |
| 158 | break; |
| 159 | case GlobalValue::LinkOnceODRLinkage: |
| 160 | case GlobalValue::WeakODRLinkage: { |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 161 | auto &GVSummaryList = Index.findGlobalValueSummaryList(GUID)->second; |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 162 | // We need to emit only one of these, the first module will keep |
| 163 | // it, but turned into a weak while the others will drop it. |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 164 | if (!HasMultipleCopies(GVSummaryList)) { |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 165 | // Exported LinkonceODR needs to be promoted to not be discarded |
| 166 | if (GlobalValue::isDiscardableIfUnused(OriginalLinkage) && |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 167 | (ExportList.count(GUID) || GUIDPreservedSymbols.count(GUID))) |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 168 | return GlobalValue::WeakODRLinkage; |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 169 | break; |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 170 | } |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 171 | if (IsFirstDefinitionForLinker(GVSummaryList, Index, ModuleIdentifier)) |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 172 | return GlobalValue::WeakODRLinkage; |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 173 | else if (isa<AliasSummary>(&GV)) |
| 174 | // Alias can't be turned into available_externally. |
| 175 | return OriginalLinkage; |
| 176 | return GlobalValue::AvailableExternallyLinkage; |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 179 | return OriginalLinkage; |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /// Resolve LinkOnceODR and WeakODR. |
| 183 | /// |
| 184 | /// We'd like to drop these function if they are no longer referenced in the |
| 185 | /// current module. However there is a chance that another module is still |
| 186 | /// referencing them because of the import. We make sure we always emit at least |
| 187 | /// one copy. |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 188 | static void ResolveODR( |
| 189 | const ModuleSummaryIndex &Index, |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 190 | const FunctionImporter::ExportSetTy &ExportList, |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 191 | const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 192 | const GVSummaryMapTy &DefinedGlobals, StringRef ModuleIdentifier, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 193 | std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR) { |
Mehdi Amini | 8dcc808 | 2016-04-14 08:46:22 +0000 | [diff] [blame] | 194 | if (Index.modulePaths().size() == 1) |
| 195 | // Nothing to do if we don't have multiple modules |
| 196 | return; |
| 197 | |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 198 | // We won't optimize the globals that are referenced by an alias for now |
| 199 | // Ideally we should turn the alias into a global and duplicate the definition |
| 200 | // when needed. |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 201 | DenseSet<GlobalValueSummary *> GlobalInvolvedWithAlias; |
| 202 | for (auto &GA : DefinedGlobals) { |
| 203 | if (auto AS = dyn_cast<AliasSummary>(GA.second)) |
| 204 | GlobalInvolvedWithAlias.insert(&AS->getAliasee()); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 205 | } |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 206 | |
| 207 | for (auto &GV : DefinedGlobals) { |
| 208 | if (GlobalInvolvedWithAlias.count(GV.second)) |
| 209 | continue; |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 210 | auto NewLinkage = |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 211 | ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleIdentifier, GV.first, *GV.second); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 212 | if (NewLinkage != GV.second->linkage()) { |
| 213 | ResolvedODR[GV.first] = NewLinkage; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /// Fixup linkage, see ResolveODR() above. |
| 219 | void fixupODR( |
| 220 | Module &TheModule, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 221 | const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR) { |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 222 | // Process functions and global now |
| 223 | for (auto &GV : TheModule) { |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 224 | auto NewLinkage = ResolvedODR.find(GV.getGUID()); |
| 225 | if (NewLinkage == ResolvedODR.end()) |
| 226 | continue; |
| 227 | DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from " |
| 228 | << GV.getLinkage() << " to " << NewLinkage->second << "\n"); |
| 229 | GV.setLinkage(NewLinkage->second); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 230 | } |
| 231 | for (auto &GV : TheModule.globals()) { |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 232 | auto NewLinkage = ResolvedODR.find(GV.getGUID()); |
| 233 | if (NewLinkage == ResolvedODR.end()) |
| 234 | continue; |
| 235 | DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from " |
| 236 | << GV.getLinkage() << " to " << NewLinkage->second << "\n"); |
| 237 | GV.setLinkage(NewLinkage->second); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 238 | } |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 239 | for (auto &GV : TheModule.aliases()) { |
| 240 | auto NewLinkage = ResolvedODR.find(GV.getGUID()); |
| 241 | if (NewLinkage == ResolvedODR.end()) |
| 242 | continue; |
| 243 | DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from " |
| 244 | << GV.getLinkage() << " to " << NewLinkage->second << "\n"); |
| 245 | GV.setLinkage(NewLinkage->second); |
| 246 | } |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 249 | static StringMap<MemoryBufferRef> |
| 250 | generateModuleMap(const std::vector<MemoryBufferRef> &Modules) { |
| 251 | StringMap<MemoryBufferRef> ModuleMap; |
| 252 | for (auto &ModuleBuffer : Modules) { |
| 253 | assert(ModuleMap.find(ModuleBuffer.getBufferIdentifier()) == |
| 254 | ModuleMap.end() && |
| 255 | "Expect unique Buffer Identifier"); |
| 256 | ModuleMap[ModuleBuffer.getBufferIdentifier()] = ModuleBuffer; |
| 257 | } |
| 258 | return ModuleMap; |
| 259 | } |
| 260 | |
| 261 | /// Provide a "loader" for the FunctionImporter to access function from other |
| 262 | /// modules. |
| 263 | class ModuleLoader { |
| 264 | /// The context that will be used for importing. |
| 265 | LLVMContext &Context; |
| 266 | |
| 267 | /// Map from Module identifier to MemoryBuffer. Used by clients like the |
| 268 | /// FunctionImported to request loading a Module. |
| 269 | StringMap<MemoryBufferRef> &ModuleMap; |
| 270 | |
| 271 | public: |
| 272 | ModuleLoader(LLVMContext &Context, StringMap<MemoryBufferRef> &ModuleMap) |
| 273 | : Context(Context), ModuleMap(ModuleMap) {} |
| 274 | |
| 275 | /// Load a module on demand. |
| 276 | std::unique_ptr<Module> operator()(StringRef Identifier) { |
| 277 | return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true); |
| 278 | } |
| 279 | }; |
| 280 | |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 281 | static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index) { |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 282 | if (renameModuleForThinLTO(TheModule, Index)) |
| 283 | report_fatal_error("renameModuleForThinLTO failed"); |
| 284 | } |
| 285 | |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 286 | static void |
| 287 | crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index, |
| 288 | StringMap<MemoryBufferRef> &ModuleMap, |
| 289 | const FunctionImporter::ImportMapTy &ImportList) { |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 290 | ModuleLoader Loader(TheModule.getContext(), ModuleMap); |
| 291 | FunctionImporter Importer(Index, Loader); |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 292 | Importer.importFunctions(TheModule, ImportList); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void optimizeModule(Module &TheModule, TargetMachine &TM) { |
| 296 | // Populate the PassManager |
| 297 | PassManagerBuilder PMB; |
| 298 | PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple()); |
| 299 | PMB.Inliner = createFunctionInliningPass(); |
| 300 | // FIXME: should get it from the bitcode? |
| 301 | PMB.OptLevel = 3; |
| 302 | PMB.LoopVectorize = true; |
| 303 | PMB.SLPVectorize = true; |
| 304 | PMB.VerifyInput = true; |
| 305 | PMB.VerifyOutput = false; |
| 306 | |
| 307 | legacy::PassManager PM; |
| 308 | |
| 309 | // Add the TTI (required to inform the vectorizer about register size for |
| 310 | // instance) |
| 311 | PM.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis())); |
| 312 | |
| 313 | // Add optimizations |
| 314 | PMB.populateThinLTOPassManager(PM); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 315 | |
| 316 | PM.run(TheModule); |
| 317 | } |
| 318 | |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 319 | // Create a DenseSet of GlobalValue to be used with the Internalizer. |
| 320 | static DenseSet<const GlobalValue *> computePreservedSymbolsForModule( |
| 321 | Module &TheModule, const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, |
| 322 | const FunctionImporter::ExportSetTy &ExportList) { |
| 323 | DenseSet<const GlobalValue *> PreservedGV; |
| 324 | if (GUIDPreservedSymbols.empty()) |
| 325 | // Early exit: internalize is disabled when there is nothing to preserve. |
| 326 | return PreservedGV; |
| 327 | |
| 328 | auto AddPreserveGV = [&](const GlobalValue &GV) { |
| 329 | auto GUID = GV.getGUID(); |
| 330 | if (GUIDPreservedSymbols.count(GUID) || ExportList.count(GUID)) |
| 331 | PreservedGV.insert(&GV); |
| 332 | }; |
| 333 | |
| 334 | for (auto &GV : TheModule) |
| 335 | AddPreserveGV(GV); |
| 336 | for (auto &GV : TheModule.globals()) |
| 337 | AddPreserveGV(GV); |
| 338 | for (auto &GV : TheModule.aliases()) |
| 339 | AddPreserveGV(GV); |
| 340 | |
| 341 | return PreservedGV; |
| 342 | } |
| 343 | |
| 344 | // Run internalization on \p TheModule |
| 345 | static void |
| 346 | doInternalizeModule(Module &TheModule, const TargetMachine &TM, |
| 347 | const DenseSet<const GlobalValue *> &PreservedGV) { |
| 348 | if (PreservedGV.empty()) { |
| 349 | // Be friendly and don't nuke totally the module when the client didn't |
| 350 | // supply anything to preserve. |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | // Parse inline ASM and collect the list of symbols that are not defined in |
| 355 | // the current module. |
| 356 | StringSet<> AsmUndefinedRefs; |
| 357 | object::IRObjectFile::CollectAsmUndefinedRefs( |
| 358 | Triple(TheModule.getTargetTriple()), TheModule.getModuleInlineAsm(), |
| 359 | [&AsmUndefinedRefs](StringRef Name, object::BasicSymbolRef::Flags Flags) { |
| 360 | if (Flags & object::BasicSymbolRef::SF_Undefined) |
| 361 | AsmUndefinedRefs.insert(Name); |
| 362 | }); |
| 363 | |
| 364 | // Update the llvm.compiler_used globals to force preserving libcalls and |
| 365 | // symbols referenced from asm |
| 366 | UpdateCompilerUsed(TheModule, TM, AsmUndefinedRefs); |
| 367 | |
| 368 | // Declare a callback for the internalize pass that will ask for every |
| 369 | // candidate GlobalValue if it can be internalized or not. |
| 370 | auto MustPreserveGV = |
| 371 | [&](const GlobalValue &GV) -> bool { return PreservedGV.count(&GV); }; |
| 372 | |
| 373 | llvm::internalizeModule(TheModule, MustPreserveGV); |
| 374 | } |
| 375 | |
| 376 | // Convert the PreservedSymbols map from "Name" based to "GUID" based. |
| 377 | static DenseSet<GlobalValue::GUID> |
| 378 | computeGUIDPreservedSymbols(const StringSet<> &PreservedSymbols, |
| 379 | const Triple &TheTriple) { |
| 380 | DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size()); |
| 381 | for (auto &Entry : PreservedSymbols) { |
| 382 | StringRef Name = Entry.first(); |
| 383 | if (TheTriple.isOSBinFormatMachO() && Name.size() > 0 && Name[0] == '_') |
| 384 | Name = Name.drop_front(); |
| 385 | GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name)); |
| 386 | } |
| 387 | return GUIDPreservedSymbols; |
| 388 | } |
| 389 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 390 | std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule, |
| 391 | TargetMachine &TM) { |
| 392 | SmallVector<char, 128> OutputBuffer; |
| 393 | |
| 394 | // CodeGen |
| 395 | { |
| 396 | raw_svector_ostream OS(OutputBuffer); |
| 397 | legacy::PassManager PM; |
Mehdi Amini | 215d59e | 2016-04-01 08:22:59 +0000 | [diff] [blame] | 398 | |
| 399 | // If the bitcode files contain ARC code and were compiled with optimization, |
| 400 | // the ObjCARCContractPass must be run, so do it unconditionally here. |
| 401 | PM.add(createObjCARCContractPass()); |
| 402 | |
| 403 | // Setup the codegen now. |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 404 | if (TM.addPassesToEmitFile(PM, OS, TargetMachine::CGFT_ObjectFile, |
| 405 | /* DisableVerify */ true)) |
| 406 | report_fatal_error("Failed to setup codegen"); |
| 407 | |
| 408 | // Run codegen now. resulting binary is in OutputBuffer. |
| 409 | PM.run(TheModule); |
| 410 | } |
| 411 | return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer)); |
| 412 | } |
| 413 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 414 | /// Manage caching for a single Module. |
| 415 | class ModuleCacheEntry { |
| 416 | SmallString<128> EntryPath; |
| 417 | |
| 418 | public: |
| 419 | // Create a cache entry. This compute a unique hash for the Module considering |
| 420 | // the current list of export/import, and offer an interface to query to |
| 421 | // access the content in the cache. |
| 422 | ModuleCacheEntry( |
| 423 | StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID, |
| 424 | const FunctionImporter::ImportMapTy &ImportList, |
| 425 | const FunctionImporter::ExportSetTy &ExportList, |
| 426 | const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 427 | const GVSummaryMapTy &DefinedFunctions, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 428 | const DenseSet<GlobalValue::GUID> &PreservedSymbols) { |
| 429 | if (CachePath.empty()) |
| 430 | return; |
| 431 | |
| 432 | // Compute the unique hash for this entry |
| 433 | // This is based on the current compiler version, the module itself, the |
| 434 | // export list, the hash for every single module in the import list, the |
| 435 | // list of ResolvedODR for the module, and the list of preserved symbols. |
| 436 | |
| 437 | SHA1 Hasher; |
| 438 | |
| 439 | // Start with the compiler revision |
| 440 | Hasher.update(LLVM_VERSION_STRING); |
| 441 | #ifdef HAVE_LLVM_REVISION |
| 442 | Hasher.update(LLVM_REVISION); |
| 443 | #endif |
| 444 | |
| 445 | // Include the hash for the current module |
| 446 | auto ModHash = Index.getModuleHash(ModuleID); |
| 447 | Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash))); |
| 448 | for (auto F : ExportList) |
| 449 | // The export list can impact the internalization, be conservative here |
| 450 | Hasher.update(ArrayRef<uint8_t>((uint8_t *)&F, sizeof(F))); |
| 451 | |
| 452 | // Include the hash for every module we import functions from |
| 453 | for (auto &Entry : ImportList) { |
| 454 | auto ModHash = Index.getModuleHash(Entry.first()); |
| 455 | Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash))); |
| 456 | } |
| 457 | |
| 458 | // Include the hash for the resolved ODR. |
| 459 | for (auto &Entry : ResolvedODR) { |
Sjoerd Meijer | 41beee6 | 2016-04-27 18:35:02 +0000 | [diff] [blame] | 460 | Hasher.update(ArrayRef<uint8_t>((const uint8_t *)&Entry.first, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 461 | sizeof(GlobalValue::GUID))); |
Sjoerd Meijer | 41beee6 | 2016-04-27 18:35:02 +0000 | [diff] [blame] | 462 | Hasher.update(ArrayRef<uint8_t>((const uint8_t *)&Entry.second, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 463 | sizeof(GlobalValue::LinkageTypes))); |
| 464 | } |
| 465 | |
| 466 | // Include the hash for the preserved symbols. |
| 467 | for (auto &Entry : PreservedSymbols) { |
| 468 | if (DefinedFunctions.count(Entry)) |
| 469 | Hasher.update( |
Sjoerd Meijer | 41beee6 | 2016-04-27 18:35:02 +0000 | [diff] [blame] | 470 | ArrayRef<uint8_t>((const uint8_t *)&Entry, sizeof(GlobalValue::GUID))); |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | sys::path::append(EntryPath, CachePath, toHex(Hasher.result())); |
| 474 | } |
| 475 | |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 476 | // Access the path to this entry in the cache. |
| 477 | StringRef getEntryPath() { return EntryPath; } |
| 478 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 479 | // Try loading the buffer for this cache entry. |
| 480 | ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() { |
| 481 | if (EntryPath.empty()) |
| 482 | return std::error_code(); |
| 483 | return MemoryBuffer::getFile(EntryPath); |
| 484 | } |
| 485 | |
| 486 | // Cache the Produced object file |
| 487 | void write(MemoryBufferRef OutputBuffer) { |
| 488 | if (EntryPath.empty()) |
| 489 | return; |
| 490 | |
| 491 | // Write to a temporary to avoid race condition |
| 492 | SmallString<128> TempFilename; |
| 493 | int TempFD; |
| 494 | std::error_code EC = |
| 495 | sys::fs::createTemporaryFile("Thin", "tmp.o", TempFD, TempFilename); |
| 496 | if (EC) { |
| 497 | errs() << "Error: " << EC.message() << "\n"; |
| 498 | report_fatal_error("ThinLTO: Can't get a temporary file"); |
| 499 | } |
| 500 | { |
| 501 | raw_fd_ostream OS(TempFD, /* ShouldClose */ true); |
| 502 | OS << OutputBuffer.getBuffer(); |
| 503 | } |
| 504 | // Rename to final destination (hopefully race condition won't matter here) |
Mehdi Amini | 2a16a5f | 2016-05-14 04:58:38 +0000 | [diff] [blame] | 505 | EC = sys::fs::rename(TempFilename, EntryPath); |
| 506 | if (EC) { |
Mehdi Amini | b02139d | 2016-05-14 05:16:35 +0000 | [diff] [blame^] | 507 | sys::fs::remove(TempFilename); |
| 508 | raw_fd_ostream OS(EntryPath, EC, sys::fs::F_None); |
| 509 | if (EC) |
| 510 | report_fatal_error(Twine("Failed to open ") + EntryPath + |
| 511 | " to save cached entry\n"); |
| 512 | OS << OutputBuffer.getBuffer(); |
Mehdi Amini | 2a16a5f | 2016-05-14 04:58:38 +0000 | [diff] [blame] | 513 | } |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 514 | } |
| 515 | }; |
| 516 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 517 | static std::unique_ptr<MemoryBuffer> ProcessThinLTOModule( |
| 518 | Module &TheModule, const ModuleSummaryIndex &Index, |
| 519 | StringMap<MemoryBufferRef> &ModuleMap, TargetMachine &TM, |
| 520 | const FunctionImporter::ImportMapTy &ImportList, |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 521 | const FunctionImporter::ExportSetTy &ExportList, |
| 522 | const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 523 | std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 524 | ThinLTOCodeGenerator::CachingOptions CacheOptions, bool DisableCodeGen, |
| 525 | StringRef SaveTempsDir, unsigned count) { |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 526 | |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 527 | // Prepare for internalization by computing the set of symbols to preserve. |
| 528 | // We need to compute the list of symbols to preserve during internalization |
| 529 | // before doing any promotion because after renaming we won't (easily) match |
| 530 | // to the original name. |
| 531 | auto PreservedGV = computePreservedSymbolsForModule( |
| 532 | TheModule, GUIDPreservedSymbols, ExportList); |
| 533 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 534 | // "Benchmark"-like optimization: single-source case |
| 535 | bool SingleModule = (ModuleMap.size() == 1); |
| 536 | |
| 537 | if (!SingleModule) { |
| 538 | promoteModule(TheModule, Index); |
| 539 | |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 540 | // Resolve the LinkOnce/Weak ODR, trying to turn them into |
| 541 | // "available_externally" when possible. |
| 542 | // This is a compile-time optimization. |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 543 | fixupODR(TheModule, ResolvedODR); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 544 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 545 | // Save temps: after promotion. |
Mehdi Amini | 4b300e0a | 2016-05-05 05:14:16 +0000 | [diff] [blame] | 546 | saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc"); |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 547 | } |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 548 | |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 549 | // Internalization |
| 550 | doInternalizeModule(TheModule, TM, PreservedGV); |
| 551 | |
| 552 | // Save internalized bitcode |
Mehdi Amini | 4b300e0a | 2016-05-05 05:14:16 +0000 | [diff] [blame] | 553 | saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc"); |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 554 | |
| 555 | if (!SingleModule) { |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 556 | crossImportIntoModule(TheModule, Index, ModuleMap, ImportList); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 557 | |
| 558 | // Save temps: after cross-module import. |
Mehdi Amini | 4b300e0a | 2016-05-05 05:14:16 +0000 | [diff] [blame] | 559 | saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc"); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | optimizeModule(TheModule, TM); |
| 563 | |
Mehdi Amini | 4b300e0a | 2016-05-05 05:14:16 +0000 | [diff] [blame] | 564 | saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc"); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 565 | |
Mehdi Amini | 43b657b | 2016-04-01 06:47:02 +0000 | [diff] [blame] | 566 | if (DisableCodeGen) { |
| 567 | // Configured to stop before CodeGen, serialize the bitcode and return. |
| 568 | SmallVector<char, 128> OutputBuffer; |
| 569 | { |
| 570 | raw_svector_ostream OS(OutputBuffer); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 571 | ModuleSummaryIndexBuilder IndexBuilder(&TheModule); |
| 572 | WriteBitcodeToFile(&TheModule, OS, true, &IndexBuilder.getIndex()); |
Mehdi Amini | 43b657b | 2016-04-01 06:47:02 +0000 | [diff] [blame] | 573 | } |
| 574 | return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer)); |
| 575 | } |
| 576 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 577 | return codegenModule(TheModule, TM); |
| 578 | } |
| 579 | |
| 580 | // Initialize the TargetMachine builder for a given Triple |
| 581 | static void initTMBuilder(TargetMachineBuilder &TMBuilder, |
| 582 | const Triple &TheTriple) { |
| 583 | // Set a default CPU for Darwin triples (copied from LTOCodeGenerator). |
| 584 | // FIXME this looks pretty terrible... |
| 585 | if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) { |
| 586 | if (TheTriple.getArch() == llvm::Triple::x86_64) |
| 587 | TMBuilder.MCpu = "core2"; |
| 588 | else if (TheTriple.getArch() == llvm::Triple::x86) |
| 589 | TMBuilder.MCpu = "yonah"; |
| 590 | else if (TheTriple.getArch() == llvm::Triple::aarch64) |
| 591 | TMBuilder.MCpu = "cyclone"; |
| 592 | } |
| 593 | TMBuilder.TheTriple = std::move(TheTriple); |
| 594 | } |
| 595 | |
| 596 | } // end anonymous namespace |
| 597 | |
| 598 | void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) { |
| 599 | MemoryBufferRef Buffer(Data, Identifier); |
| 600 | if (Modules.empty()) { |
| 601 | // First module added, so initialize the triple and some options |
| 602 | LLVMContext Context; |
| 603 | Triple TheTriple(getBitcodeTargetTriple(Buffer, Context)); |
| 604 | initTMBuilder(TMBuilder, Triple(TheTriple)); |
| 605 | } |
| 606 | #ifndef NDEBUG |
| 607 | else { |
| 608 | LLVMContext Context; |
| 609 | assert(TMBuilder.TheTriple.str() == |
| 610 | getBitcodeTargetTriple(Buffer, Context) && |
| 611 | "ThinLTO modules with different triple not supported"); |
| 612 | } |
| 613 | #endif |
| 614 | Modules.push_back(Buffer); |
| 615 | } |
| 616 | |
| 617 | void ThinLTOCodeGenerator::preserveSymbol(StringRef Name) { |
| 618 | PreservedSymbols.insert(Name); |
| 619 | } |
| 620 | |
| 621 | void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) { |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 622 | // FIXME: At the moment, we don't take advantage of this extra information, |
| 623 | // we're conservatively considering cross-references as preserved. |
| 624 | // CrossReferencedSymbols.insert(Name); |
| 625 | PreservedSymbols.insert(Name); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | // TargetMachine factory |
| 629 | std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const { |
| 630 | std::string ErrMsg; |
| 631 | const Target *TheTarget = |
| 632 | TargetRegistry::lookupTarget(TheTriple.str(), ErrMsg); |
| 633 | if (!TheTarget) { |
| 634 | report_fatal_error("Can't load target for this Triple: " + ErrMsg); |
| 635 | } |
| 636 | |
| 637 | // Use MAttr as the default set of features. |
| 638 | SubtargetFeatures Features(MAttr); |
| 639 | Features.getDefaultSubtargetFeatures(TheTriple); |
| 640 | std::string FeatureStr = Features.getString(); |
| 641 | return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine( |
| 642 | TheTriple.str(), MCpu, FeatureStr, Options, RelocModel, |
| 643 | CodeModel::Default, CGOptLevel)); |
| 644 | } |
| 645 | |
| 646 | /** |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 647 | * Produce the combined summary index from all the bitcode files: |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 648 | * "thin-link". |
| 649 | */ |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 650 | std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() { |
| 651 | std::unique_ptr<ModuleSummaryIndex> CombinedIndex; |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 652 | uint64_t NextModuleId = 0; |
| 653 | for (auto &ModuleBuffer : Modules) { |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 654 | ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr = |
| 655 | object::ModuleSummaryIndexObjectFile::create(ModuleBuffer, |
Teresa Johnson | 6fb3f19 | 2016-04-22 01:52:00 +0000 | [diff] [blame] | 656 | diagnosticHandler); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 657 | if (std::error_code EC = ObjOrErr.getError()) { |
| 658 | // FIXME diagnose |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 659 | errs() << "error: can't create ModuleSummaryIndexObjectFile for buffer: " |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 660 | << EC.message() << "\n"; |
| 661 | return nullptr; |
| 662 | } |
| 663 | auto Index = (*ObjOrErr)->takeIndex(); |
| 664 | if (CombinedIndex) { |
| 665 | CombinedIndex->mergeFrom(std::move(Index), ++NextModuleId); |
| 666 | } else { |
| 667 | CombinedIndex = std::move(Index); |
| 668 | } |
| 669 | } |
| 670 | return CombinedIndex; |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Perform promotion and renaming of exported internal functions. |
| 675 | */ |
| 676 | void ThinLTOCodeGenerator::promote(Module &TheModule, |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 677 | ModuleSummaryIndex &Index) { |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 678 | auto ModuleCount = Index.modulePaths().size(); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 679 | auto ModuleIdentifier = TheModule.getModuleIdentifier(); |
| 680 | // Collect for each module the list of function it defines (GUID -> Summary). |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 681 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries; |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 682 | Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 683 | |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 684 | // Generate import/export list |
| 685 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 686 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
| 687 | ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists, |
| 688 | ExportLists); |
| 689 | auto &ExportList = ExportLists[ModuleIdentifier]; |
| 690 | |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 691 | // Convert the preserved symbols set from string to GUID |
| 692 | auto GUIDPreservedSymbols = |
| 693 | computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple); |
| 694 | |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 695 | // Resolve the LinkOnceODR, trying to turn them into "available_externally" |
| 696 | // where possible. |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 697 | // This is a compile-time optimization. |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 698 | // We use a std::map here to be able to have a defined ordering when |
| 699 | // producing a hash for the cache entry. |
| 700 | std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR; |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 701 | ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleToDefinedGVSummaries[ModuleIdentifier], |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 702 | ModuleIdentifier, ResolvedODR); |
| 703 | fixupODR(TheModule, ResolvedODR); |
Mehdi Amini | 5a2e5d3 | 2016-04-01 21:53:50 +0000 | [diff] [blame] | 704 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 705 | promoteModule(TheModule, Index); |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Perform cross-module importing for the module identified by ModuleIdentifier. |
| 710 | */ |
| 711 | void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule, |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 712 | ModuleSummaryIndex &Index) { |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 713 | auto ModuleMap = generateModuleMap(Modules); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 714 | auto ModuleCount = Index.modulePaths().size(); |
| 715 | |
| 716 | // Collect for each module the list of function it defines (GUID -> Summary). |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 717 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 718 | Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 719 | |
| 720 | // Generate import/export list |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 721 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 722 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 723 | ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists, |
| 724 | ExportLists); |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 725 | auto &ImportList = ImportLists[TheModule.getModuleIdentifier()]; |
| 726 | |
| 727 | crossImportIntoModule(TheModule, Index, ModuleMap, ImportList); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /** |
Teresa Johnson | 84174c3 | 2016-05-10 13:48:23 +0000 | [diff] [blame] | 731 | * Compute the list of summaries needed for importing into module. |
| 732 | */ |
| 733 | void ThinLTOCodeGenerator::gatherImportedSummariesForModule( |
| 734 | StringRef ModulePath, ModuleSummaryIndex &Index, |
| 735 | std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) { |
| 736 | auto ModuleCount = Index.modulePaths().size(); |
| 737 | |
| 738 | // Collect for each module the list of function it defines (GUID -> Summary). |
| 739 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount); |
| 740 | Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
| 741 | |
| 742 | // Generate import/export list |
| 743 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 744 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
| 745 | ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists, |
| 746 | ExportLists); |
| 747 | |
| 748 | llvm::gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries, |
| 749 | ImportLists, |
| 750 | ModuleToSummariesForIndex); |
| 751 | } |
| 752 | |
| 753 | /** |
Teresa Johnson | 8570fe4 | 2016-05-10 15:54:09 +0000 | [diff] [blame] | 754 | * Emit the list of files needed for importing into module. |
| 755 | */ |
| 756 | void ThinLTOCodeGenerator::emitImports(StringRef ModulePath, |
| 757 | StringRef OutputName, |
| 758 | ModuleSummaryIndex &Index) { |
| 759 | auto ModuleCount = Index.modulePaths().size(); |
| 760 | |
| 761 | // Collect for each module the list of function it defines (GUID -> Summary). |
| 762 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount); |
| 763 | Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
| 764 | |
| 765 | // Generate import/export list |
| 766 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 767 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
| 768 | ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists, |
| 769 | ExportLists); |
| 770 | |
| 771 | std::error_code EC; |
| 772 | if ((EC = EmitImportsFiles(ModulePath, OutputName, ImportLists))) |
| 773 | report_fatal_error(Twine("Failed to open ") + OutputName + |
| 774 | " to save imports lists\n"); |
| 775 | } |
| 776 | |
| 777 | /** |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 778 | * Perform internalization. |
| 779 | */ |
| 780 | void ThinLTOCodeGenerator::internalize(Module &TheModule, |
| 781 | ModuleSummaryIndex &Index) { |
| 782 | initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple())); |
| 783 | auto ModuleCount = Index.modulePaths().size(); |
| 784 | auto ModuleIdentifier = TheModule.getModuleIdentifier(); |
| 785 | |
| 786 | // Convert the preserved symbols set from string to GUID |
| 787 | auto GUIDPreservedSymbols = |
| 788 | computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple); |
| 789 | |
| 790 | // Collect for each module the list of function it defines (GUID -> Summary). |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 791 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount); |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 792 | Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
| 793 | |
| 794 | // Generate import/export list |
| 795 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 796 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
| 797 | ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists, |
| 798 | ExportLists); |
| 799 | auto &ExportList = ExportLists[ModuleIdentifier]; |
| 800 | |
| 801 | // Internalization |
| 802 | auto PreservedGV = computePreservedSymbolsForModule( |
| 803 | TheModule, GUIDPreservedSymbols, ExportList); |
| 804 | doInternalizeModule(TheModule, *TMBuilder.create(), PreservedGV); |
| 805 | } |
| 806 | |
| 807 | /** |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 808 | * Perform post-importing ThinLTO optimizations. |
| 809 | */ |
| 810 | void ThinLTOCodeGenerator::optimize(Module &TheModule) { |
| 811 | initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple())); |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 812 | |
| 813 | // Optimize now |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 814 | optimizeModule(TheModule, *TMBuilder.create()); |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Perform ThinLTO CodeGen. |
| 819 | */ |
| 820 | std::unique_ptr<MemoryBuffer> ThinLTOCodeGenerator::codegen(Module &TheModule) { |
| 821 | initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple())); |
| 822 | return codegenModule(TheModule, *TMBuilder.create()); |
| 823 | } |
| 824 | |
| 825 | // Main entry point for the ThinLTO processing |
| 826 | void ThinLTOCodeGenerator::run() { |
Mehdi Amini | 43b657b | 2016-04-01 06:47:02 +0000 | [diff] [blame] | 827 | if (CodeGenOnly) { |
| 828 | // Perform only parallel codegen and return. |
| 829 | ThreadPool Pool; |
| 830 | assert(ProducedBinaries.empty() && "The generator should not be reused"); |
| 831 | ProducedBinaries.resize(Modules.size()); |
| 832 | 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 |
| 839 | auto TheModule = loadModuleFromBuffer(ModuleBuffer, Context, false); |
| 840 | |
| 841 | // CodeGen |
| 842 | ProducedBinaries[count] = codegen(*TheModule); |
| 843 | }, count++); |
| 844 | } |
| 845 | |
| 846 | return; |
| 847 | } |
| 848 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 849 | // Sequential linking phase |
| 850 | auto Index = linkCombinedIndex(); |
| 851 | |
| 852 | // Save temps: index. |
| 853 | if (!SaveTempsDir.empty()) { |
| 854 | auto SaveTempPath = SaveTempsDir + "index.bc"; |
| 855 | std::error_code EC; |
| 856 | raw_fd_ostream OS(SaveTempPath, EC, sys::fs::F_None); |
| 857 | if (EC) |
| 858 | report_fatal_error(Twine("Failed to open ") + SaveTempPath + |
| 859 | " to save optimized bitcode\n"); |
Teresa Johnson | 76a1c1d | 2016-03-11 18:52:24 +0000 | [diff] [blame] | 860 | WriteIndexToFile(*Index, OS); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | // Prepare the resulting object vector |
| 864 | assert(ProducedBinaries.empty() && "The generator should not be reused"); |
| 865 | ProducedBinaries.resize(Modules.size()); |
| 866 | |
| 867 | // Prepare the module map. |
| 868 | auto ModuleMap = generateModuleMap(Modules); |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 869 | auto ModuleCount = Modules.size(); |
| 870 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 871 | // Collect for each module the list of function it defines (GUID -> Summary). |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 872 | StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 873 | Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); |
| 874 | |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 875 | // Collect the import/export lists for all modules from the call-graph in the |
| 876 | // combined index. |
| 877 | StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount); |
| 878 | StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 879 | ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists, |
| 880 | ExportLists); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 881 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 882 | // Convert the preserved symbols set from string to GUID, this is needed for |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 883 | // computing the caching hash and the internalization. |
| 884 | auto GUIDPreservedSymbols = |
| 885 | computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple); |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 886 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 887 | // Parallel optimizer + codegen |
| 888 | { |
| 889 | ThreadPool Pool(ThreadCount); |
| 890 | int count = 0; |
| 891 | for (auto &ModuleBuffer : Modules) { |
| 892 | Pool.async([&](int count) { |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 893 | auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier(); |
Mehdi Amini | a71a5a6 | 2016-04-21 05:47:17 +0000 | [diff] [blame] | 894 | auto &ExportList = ExportLists[ModuleIdentifier]; |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 895 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 896 | auto &DefinedFunctions = ModuleToDefinedGVSummaries[ModuleIdentifier]; |
| 897 | |
| 898 | // Resolve ODR, this has to be done early because it impacts the caching |
| 899 | // We use a std::map here to be able to have a defined ordering when |
| 900 | // producing a hash for the cache entry. |
| 901 | std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR; |
Mehdi Amini | aa309b1 | 2016-04-26 10:35:01 +0000 | [diff] [blame] | 902 | ResolveODR(*Index, ExportList, GUIDPreservedSymbols, DefinedFunctions, ModuleIdentifier, |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 903 | ResolvedODR); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 904 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 905 | // The module may be cached, this helps handling it. |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 906 | ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier, |
| 907 | ImportLists[ModuleIdentifier], ExportList, |
| 908 | ResolvedODR, DefinedFunctions, |
| 909 | GUIDPreservedSymbols); |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 910 | |
| 911 | { |
| 912 | auto ErrOrBuffer = CacheEntry.tryLoadingBuffer(); |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 913 | DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss") << " '" |
| 914 | << CacheEntry.getEntryPath() << "' for buffer " << count |
| 915 | << " " << ModuleIdentifier << "\n"); |
| 916 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 917 | if (ErrOrBuffer) { |
| 918 | // Cache Hit! |
| 919 | ProducedBinaries[count] = std::move(ErrOrBuffer.get()); |
| 920 | return; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | LLVMContext Context; |
| 925 | Context.setDiscardValueNames(LTODiscardValueNames); |
| 926 | Context.enableDebugTypeODRUniquing(); |
| 927 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 928 | // Parse module now |
| 929 | auto TheModule = loadModuleFromBuffer(ModuleBuffer, Context, false); |
| 930 | |
| 931 | // Save temps: original file. |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 932 | saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc"); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 933 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 934 | auto &ImportList = ImportLists[ModuleIdentifier]; |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 935 | // Run the main process now, and generates a binary |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 936 | auto OutputBuffer = ProcessThinLTOModule( |
Mehdi Amini | 01e3213 | 2016-03-26 05:40:34 +0000 | [diff] [blame] | 937 | *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList, |
Mehdi Amini | 059464f | 2016-04-24 03:18:01 +0000 | [diff] [blame] | 938 | ExportList, GUIDPreservedSymbols, ResolvedODR, CacheOptions, |
| 939 | DisableCodeGen, SaveTempsDir, count); |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 940 | |
| 941 | CacheEntry.write(*OutputBuffer); |
| 942 | ProducedBinaries[count] = std::move(OutputBuffer); |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 943 | }, count); |
| 944 | count++; |
| 945 | } |
| 946 | } |
| 947 | |
Mehdi Amini | f95f77a | 2016-04-21 05:54:23 +0000 | [diff] [blame] | 948 | CachePruning(CacheOptions.Path) |
| 949 | .setPruningInterval(CacheOptions.PruningInterval) |
| 950 | .setEntryExpiration(CacheOptions.Expiration) |
| 951 | .setMaxSize(CacheOptions.MaxPercentageOfAvailableSpace) |
| 952 | .prune(); |
| 953 | |
Mehdi Amini | 7c4a1a8 | 2016-03-09 01:37:22 +0000 | [diff] [blame] | 954 | // If statistics were requested, print them out now. |
| 955 | if (llvm::AreStatisticsEnabled()) |
| 956 | llvm::PrintStatistics(); |
| 957 | } |