annotate lib/LTO/ThinLTOCodeGenerator.cpp @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1 //===-ThinLTOCodeGenerator.cpp - LLVM Link Time Optimizer -----------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
6 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
8 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
9 // This file implements the Thin Link Time Optimization library. This library is
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
10 // intended to be used by linker to optimize code at link time.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
11 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
13
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
14 #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
15
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
16 #include "llvm/ADT/Statistic.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
17 #include "llvm/ADT/StringExtras.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
18 #include "llvm/Analysis/ModuleSummaryAnalysis.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
19 #include "llvm/Analysis/ProfileSummaryInfo.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
20 #include "llvm/Analysis/TargetLibraryInfo.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
21 #include "llvm/Analysis/TargetTransformInfo.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
22 #include "llvm/Bitcode/BitcodeReader.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
23 #include "llvm/Bitcode/BitcodeWriter.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
24 #include "llvm/Bitcode/BitcodeWriterPass.h"
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
25 #include "llvm/Config/llvm-config.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
26 #include "llvm/IR/DebugInfo.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
27 #include "llvm/IR/DiagnosticPrinter.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
28 #include "llvm/IR/LLVMContext.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
29 #include "llvm/IR/LegacyPassManager.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
30 #include "llvm/IR/Mangler.h"
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
31 #include "llvm/IR/PassTimingInfo.h"
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
32 #include "llvm/IR/RemarkStreamer.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
33 #include "llvm/IR/Verifier.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
34 #include "llvm/IRReader/IRReader.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
35 #include "llvm/LTO/LTO.h"
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
36 #include "llvm/LTO/SummaryBasedOptimizations.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
37 #include "llvm/MC/SubtargetFeature.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
38 #include "llvm/Object/IRObjectFile.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
39 #include "llvm/Support/CachePruning.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
40 #include "llvm/Support/Debug.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
41 #include "llvm/Support/Error.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
42 #include "llvm/Support/Path.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
43 #include "llvm/Support/SHA1.h"
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
44 #include "llvm/Support/SmallVectorMemoryBuffer.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
45 #include "llvm/Support/TargetRegistry.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
46 #include "llvm/Support/ThreadPool.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
47 #include "llvm/Support/Threading.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
48 #include "llvm/Support/ToolOutputFile.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
49 #include "llvm/Support/VCSRevision.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
50 #include "llvm/Target/TargetMachine.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
51 #include "llvm/Transforms/IPO.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
52 #include "llvm/Transforms/IPO/FunctionImport.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
53 #include "llvm/Transforms/IPO/Internalize.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
54 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
55 #include "llvm/Transforms/ObjCARC.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
56 #include "llvm/Transforms/Utils/FunctionImportUtils.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
57
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
58 #include <numeric>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
59
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
60 #if !defined(_MSC_VER) && !defined(__MINGW32__)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
61 #include <unistd.h>
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
62 #else
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
63 #include <io.h>
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
64 #endif
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
65
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
66 using namespace llvm;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
67
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
68 #define DEBUG_TYPE "thinlto"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
69
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
70 namespace llvm {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
71 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
72 extern cl::opt<bool> LTODiscardValueNames;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
73 extern cl::opt<std::string> RemarksFilename;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
74 extern cl::opt<std::string> RemarksPasses;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
75 extern cl::opt<bool> RemarksWithHotness;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
76 extern cl::opt<std::string> RemarksFormat;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
77 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
78
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
79 namespace {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
80
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
81 static cl::opt<int>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
82 ThreadCount("threads", cl::init(llvm::heavyweight_hardware_concurrency()));
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
83
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
84 // Simple helper to save temporary files for debug.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
85 static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
86 unsigned count, StringRef Suffix) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
87 if (TempDir.empty())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
88 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
89 // User asked to save temps, let dump the bitcode file after import.
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
90 std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
91 std::error_code EC;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
92 raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
93 if (EC)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
94 report_fatal_error(Twine("Failed to open ") + SaveTempPath +
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
95 " to save optimized bitcode\n");
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
96 WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
97 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
98
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
99 static const GlobalValueSummary *
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
100 getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
101 // If there is any strong definition anywhere, get it.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
102 auto StrongDefForLinker = llvm::find_if(
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
103 GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
104 auto Linkage = Summary->linkage();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
105 return !GlobalValue::isAvailableExternallyLinkage(Linkage) &&
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
106 !GlobalValue::isWeakForLinker(Linkage);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
107 });
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
108 if (StrongDefForLinker != GVSummaryList.end())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
109 return StrongDefForLinker->get();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
110 // Get the first *linker visible* definition for this global in the summary
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
111 // list.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
112 auto FirstDefForLinker = llvm::find_if(
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
113 GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
114 auto Linkage = Summary->linkage();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
115 return !GlobalValue::isAvailableExternallyLinkage(Linkage);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
116 });
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
117 // Extern templates can be emitted as available_externally.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
118 if (FirstDefForLinker == GVSummaryList.end())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
119 return nullptr;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
120 return FirstDefForLinker->get();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
121 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
122
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
123 // Populate map of GUID to the prevailing copy for any multiply defined
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
124 // symbols. Currently assume first copy is prevailing, or any strong
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
125 // definition. Can be refined with Linker information in the future.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
126 static void computePrevailingCopies(
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
127 const ModuleSummaryIndex &Index,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
128 DenseMap<GlobalValue::GUID, const GlobalValueSummary *> &PrevailingCopy) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
129 auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
130 return GVSummaryList.size() > 1;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
131 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
132
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
133 for (auto &I : Index) {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
134 if (HasMultipleCopies(I.second.SummaryList))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
135 PrevailingCopy[I.first] =
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
136 getFirstDefinitionForLinker(I.second.SummaryList);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
137 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
138 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
139
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
140 static StringMap<lto::InputFile *>
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
141 generateModuleMap(std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
142 StringMap<lto::InputFile *> ModuleMap;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
143 for (auto &M : Modules) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
144 assert(ModuleMap.find(M->getName()) == ModuleMap.end() &&
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
145 "Expect unique Buffer Identifier");
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
146 ModuleMap[M->getName()] = M.get();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
147 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
148 return ModuleMap;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
149 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
150
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
151 static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
152 if (renameModuleForThinLTO(TheModule, Index))
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
153 report_fatal_error("renameModuleForThinLTO failed");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
154 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
155
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
156 namespace {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
157 class ThinLTODiagnosticInfo : public DiagnosticInfo {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
158 const Twine &Msg;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
159 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
160 ThinLTODiagnosticInfo(const Twine &DiagMsg,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
161 DiagnosticSeverity Severity = DS_Error)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
162 : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
163 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
164 };
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
165 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
166
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
167 /// Verify the module and strip broken debug info.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
168 static void verifyLoadedModule(Module &TheModule) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
169 bool BrokenDebugInfo = false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
170 if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
171 report_fatal_error("Broken module found, compilation aborted!");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
172 if (BrokenDebugInfo) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
173 TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
174 "Invalid debug info found, debug info will be stripped", DS_Warning));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
175 StripDebugInfo(TheModule);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
176 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
177 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
178
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
179 static std::unique_ptr<Module> loadModuleFromInput(lto::InputFile *Input,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
180 LLVMContext &Context,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
181 bool Lazy,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
182 bool IsImporting) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
183 auto &Mod = Input->getSingleBitcodeModule();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
184 SMDiagnostic Err;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
185 Expected<std::unique_ptr<Module>> ModuleOrErr =
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
186 Lazy ? Mod.getLazyModule(Context,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
187 /* ShouldLazyLoadMetadata */ true, IsImporting)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
188 : Mod.parseModule(Context);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
189 if (!ModuleOrErr) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
190 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
191 SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
192 SourceMgr::DK_Error, EIB.message());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
193 Err.print("ThinLTO", errs());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
194 });
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
195 report_fatal_error("Can't load module, abort.");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
196 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
197 if (!Lazy)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
198 verifyLoadedModule(*ModuleOrErr.get());
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
199 return std::move(*ModuleOrErr);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
200 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
201
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
202 static void
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
203 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
204 StringMap<lto::InputFile*> &ModuleMap,
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
205 const FunctionImporter::ImportMapTy &ImportList) {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
206 auto Loader = [&](StringRef Identifier) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
207 auto &Input = ModuleMap[Identifier];
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
208 return loadModuleFromInput(Input, TheModule.getContext(),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
209 /*Lazy=*/true, /*IsImporting*/ true);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
210 };
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
211
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
212 FunctionImporter Importer(Index, Loader);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
213 Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
214 if (!Result) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
215 handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
216 SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
217 SourceMgr::DK_Error, EIB.message());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
218 Err.print("ThinLTO", errs());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
219 });
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
220 report_fatal_error("importFunctions failed");
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
221 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
222 // Verify again after cross-importing.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
223 verifyLoadedModule(TheModule);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
224 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
225
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
226 static void optimizeModule(Module &TheModule, TargetMachine &TM,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
227 unsigned OptLevel, bool Freestanding) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
228 // Populate the PassManager
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
229 PassManagerBuilder PMB;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
230 PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
231 if (Freestanding)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
232 PMB.LibraryInfo->disableAllFunctions();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
233 PMB.Inliner = createFunctionInliningPass();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
234 // FIXME: should get it from the bitcode?
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
235 PMB.OptLevel = OptLevel;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
236 PMB.LoopVectorize = true;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
237 PMB.SLPVectorize = true;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
238 // Already did this in verifyLoadedModule().
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
239 PMB.VerifyInput = false;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
240 PMB.VerifyOutput = false;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
241
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
242 legacy::PassManager PM;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
243
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
244 // Add the TTI (required to inform the vectorizer about register size for
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
245 // instance)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
246 PM.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
247
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
248 // Add optimizations
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
249 PMB.populateThinLTOPassManager(PM);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
250
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
251 PM.run(TheModule);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
252 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
253
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
254 static void
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
255 addUsedSymbolToPreservedGUID(const lto::InputFile &File,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
256 DenseSet<GlobalValue::GUID> &PreservedGUID) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
257 for (const auto &Sym : File.symbols()) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
258 if (Sym.isUsed())
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
259 PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
260 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
261 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
262
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
263 // Convert the PreservedSymbols map from "Name" based to "GUID" based.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
264 static DenseSet<GlobalValue::GUID>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
265 computeGUIDPreservedSymbols(const StringSet<> &PreservedSymbols,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
266 const Triple &TheTriple) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
267 DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
268 for (auto &Entry : PreservedSymbols) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
269 StringRef Name = Entry.first();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
270 if (TheTriple.isOSBinFormatMachO() && Name.size() > 0 && Name[0] == '_')
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
271 Name = Name.drop_front();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
272 GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name));
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
273 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
274 return GUIDPreservedSymbols;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
275 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
276
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
277 std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
278 TargetMachine &TM) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
279 SmallVector<char, 128> OutputBuffer;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
280
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
281 // CodeGen
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
282 {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
283 raw_svector_ostream OS(OutputBuffer);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
284 legacy::PassManager PM;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
285
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
286 // If the bitcode files contain ARC code and were compiled with optimization,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
287 // the ObjCARCContractPass must be run, so do it unconditionally here.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
288 PM.add(createObjCARCContractPass());
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
289
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
290 // Setup the codegen now.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
291 if (TM.addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_ObjectFile,
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
292 /* DisableVerify */ true))
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
293 report_fatal_error("Failed to setup codegen");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
294
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
295 // Run codegen now. resulting binary is in OutputBuffer.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
296 PM.run(TheModule);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
297 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
298 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
299 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
300
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
301 /// Manage caching for a single Module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
302 class ModuleCacheEntry {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
303 SmallString<128> EntryPath;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
304
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
305 public:
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
306 // Create a cache entry. This compute a unique hash for the Module considering
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
307 // the current list of export/import, and offer an interface to query to
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
308 // access the content in the cache.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
309 ModuleCacheEntry(
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
310 StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
311 const FunctionImporter::ImportMapTy &ImportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
312 const FunctionImporter::ExportSetTy &ExportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
313 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
314 const GVSummaryMapTy &DefinedGVSummaries, unsigned OptLevel,
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
315 bool Freestanding, const TargetMachineBuilder &TMBuilder) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
316 if (CachePath.empty())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
317 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
318
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
319 if (!Index.modulePaths().count(ModuleID))
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
320 // The module does not have an entry, it can't have a hash at all
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
321 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
322
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
323 if (all_of(Index.getModuleHash(ModuleID),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
324 [](uint32_t V) { return V == 0; }))
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
325 // No hash entry, no caching!
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
326 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
327
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
328 llvm::lto::Config Conf;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
329 Conf.OptLevel = OptLevel;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
330 Conf.Options = TMBuilder.Options;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
331 Conf.CPU = TMBuilder.MCpu;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
332 Conf.MAttrs.push_back(TMBuilder.MAttr);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
333 Conf.RelocModel = TMBuilder.RelocModel;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
334 Conf.CGOptLevel = TMBuilder.CGOptLevel;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
335 Conf.Freestanding = Freestanding;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
336 SmallString<40> Key;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
337 computeLTOCacheKey(Key, Conf, Index, ModuleID, ImportList, ExportList,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
338 ResolvedODR, DefinedGVSummaries);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
339
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
340 // This choice of file name allows the cache to be pruned (see pruneCache()
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
341 // in include/llvm/Support/CachePruning.h).
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
342 sys::path::append(EntryPath, CachePath, "llvmcache-" + Key);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
343 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
344
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
345 // Access the path to this entry in the cache.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
346 StringRef getEntryPath() { return EntryPath; }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
347
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
348 // Try loading the buffer for this cache entry.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
349 ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
350 if (EntryPath.empty())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
351 return std::error_code();
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
352 SmallString<64> ResultPath;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
353 Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
354 Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
355 if (!FDOrErr)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
356 return errorToErrorCode(FDOrErr.takeError());
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
357 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getOpenFile(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
358 *FDOrErr, EntryPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
359 sys::fs::closeFile(*FDOrErr);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
360 return MBOrErr;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
361 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
362
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
363 // Cache the Produced object file
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
364 void write(const MemoryBuffer &OutputBuffer) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
365 if (EntryPath.empty())
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
366 return;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
367
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
368 // Write to a temporary to avoid race condition
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
369 SmallString<128> TempFilename;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
370 SmallString<128> CachePath(EntryPath);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
371 int TempFD;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
372 llvm::sys::path::remove_filename(CachePath);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
373 sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
374 std::error_code EC =
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
375 sys::fs::createUniqueFile(TempFilename, TempFD, TempFilename);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
376 if (EC) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
377 errs() << "Error: " << EC.message() << "\n";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
378 report_fatal_error("ThinLTO: Can't get a temporary file");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
379 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
380 {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
381 raw_fd_ostream OS(TempFD, /* ShouldClose */ true);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
382 OS << OutputBuffer.getBuffer();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
383 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
384 // Rename temp file to final destination; rename is atomic
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
385 EC = sys::fs::rename(TempFilename, EntryPath);
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
386 if (EC)
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
387 sys::fs::remove(TempFilename);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
388 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
389 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
390
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
391 static std::unique_ptr<MemoryBuffer>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
392 ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
393 StringMap<lto::InputFile *> &ModuleMap, TargetMachine &TM,
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
394 const FunctionImporter::ImportMapTy &ImportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
395 const FunctionImporter::ExportSetTy &ExportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
396 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
397 const GVSummaryMapTy &DefinedGlobals,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
398 const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
399 bool DisableCodeGen, StringRef SaveTempsDir,
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
400 bool Freestanding, unsigned OptLevel, unsigned count) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
401
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
402 // "Benchmark"-like optimization: single-source case
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
403 bool SingleModule = (ModuleMap.size() == 1);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
404
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
405 if (!SingleModule) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
406 promoteModule(TheModule, Index);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
407
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
408 // Apply summary-based prevailing-symbol resolution decisions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
409 thinLTOResolvePrevailingInModule(TheModule, DefinedGlobals);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
410
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
411 // Save temps: after promotion.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
412 saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
413 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
414
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
415 // Be friendly and don't nuke totally the module when the client didn't
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
416 // supply anything to preserve.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
417 if (!ExportList.empty() || !GUIDPreservedSymbols.empty()) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
418 // Apply summary-based internalization decisions.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
419 thinLTOInternalizeModule(TheModule, DefinedGlobals);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
420 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
421
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
422 // Save internalized bitcode
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
423 saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
424
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
425 if (!SingleModule) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
426 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
427
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
428 // Save temps: after cross-module import.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
429 saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
430 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
431
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
432 optimizeModule(TheModule, TM, OptLevel, Freestanding);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
433
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
434 saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
435
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
436 if (DisableCodeGen) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
437 // Configured to stop before CodeGen, serialize the bitcode and return.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
438 SmallVector<char, 128> OutputBuffer;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
439 {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
440 raw_svector_ostream OS(OutputBuffer);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
441 ProfileSummaryInfo PSI(TheModule);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
442 auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
443 WriteBitcodeToFile(TheModule, OS, true, &Index);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
444 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
445 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
446 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
447
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
448 return codegenModule(TheModule, TM);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
449 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
450
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
451 /// Resolve prevailing symbols. Record resolutions in the \p ResolvedODR map
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
452 /// for caching, and in the \p Index for application during the ThinLTO
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
453 /// backends. This is needed for correctness for exported symbols (ensure
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
454 /// at least one copy kept) and a compile-time optimization (to drop duplicate
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
455 /// copies when possible).
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
456 static void resolvePrevailingInIndex(
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
457 ModuleSummaryIndex &Index,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
458 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
459 &ResolvedODR,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
460 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
461
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
462 DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
463 computePrevailingCopies(Index, PrevailingCopy);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
464
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
465 auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
466 const auto &Prevailing = PrevailingCopy.find(GUID);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
467 // Not in map means that there was only one copy, which must be prevailing.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
468 if (Prevailing == PrevailingCopy.end())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
469 return true;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
470 return Prevailing->second == S;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
471 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
472
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
473 auto recordNewLinkage = [&](StringRef ModuleIdentifier,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
474 GlobalValue::GUID GUID,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
475 GlobalValue::LinkageTypes NewLinkage) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
476 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
477 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
478
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
479 thinLTOResolvePrevailingInIndex(Index, isPrevailing, recordNewLinkage,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
480 GUIDPreservedSymbols);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
481 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
482
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
483 // Initialize the TargetMachine builder for a given Triple
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
484 static void initTMBuilder(TargetMachineBuilder &TMBuilder,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
485 const Triple &TheTriple) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
486 // Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
487 // FIXME this looks pretty terrible...
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
488 if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
489 if (TheTriple.getArch() == llvm::Triple::x86_64)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
490 TMBuilder.MCpu = "core2";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
491 else if (TheTriple.getArch() == llvm::Triple::x86)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
492 TMBuilder.MCpu = "yonah";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
493 else if (TheTriple.getArch() == llvm::Triple::aarch64)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
494 TMBuilder.MCpu = "cyclone";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
495 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
496 TMBuilder.TheTriple = std::move(TheTriple);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
497 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
498
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
499 } // end anonymous namespace
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
500
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
501 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
502 MemoryBufferRef Buffer(Data, Identifier);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
503
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
504 auto InputOrError = lto::InputFile::create(Buffer);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
505 if (!InputOrError)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
506 report_fatal_error("ThinLTO cannot create input file: " +
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
507 toString(InputOrError.takeError()));
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
508
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
509 auto TripleStr = (*InputOrError)->getTargetTriple();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
510 Triple TheTriple(TripleStr);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
511
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
512 if (Modules.empty())
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
513 initTMBuilder(TMBuilder, Triple(TheTriple));
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
514 else if (TMBuilder.TheTriple != TheTriple) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
515 if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
516 report_fatal_error("ThinLTO modules with incompatible triples not "
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
517 "supported");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
518 initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
519 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
520
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
521 Modules.emplace_back(std::move(*InputOrError));
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
522 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
523
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
524 void ThinLTOCodeGenerator::preserveSymbol(StringRef Name) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
525 PreservedSymbols.insert(Name);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
526 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
527
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
528 void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
529 // FIXME: At the moment, we don't take advantage of this extra information,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
530 // we're conservatively considering cross-references as preserved.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
531 // CrossReferencedSymbols.insert(Name);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
532 PreservedSymbols.insert(Name);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
533 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
534
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
535 // TargetMachine factory
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
536 std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
537 std::string ErrMsg;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
538 const Target *TheTarget =
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
539 TargetRegistry::lookupTarget(TheTriple.str(), ErrMsg);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
540 if (!TheTarget) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
541 report_fatal_error("Can't load target for this Triple: " + ErrMsg);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
542 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
543
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
544 // Use MAttr as the default set of features.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
545 SubtargetFeatures Features(MAttr);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
546 Features.getDefaultSubtargetFeatures(TheTriple);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
547 std::string FeatureStr = Features.getString();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
548
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
549 return std::unique_ptr<TargetMachine>(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
550 TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
551 RelocModel, None, CGOptLevel));
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
552 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
553
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
554 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
555 * Produce the combined summary index from all the bitcode files:
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
556 * "thin-link".
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
557 */
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
558 std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
559 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
560 llvm::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
561 uint64_t NextModuleId = 0;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
562 for (auto &Mod : Modules) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
563 auto &M = Mod->getSingleBitcodeModule();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
564 if (Error Err =
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
565 M.readSummary(*CombinedIndex, Mod->getName(), NextModuleId++)) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
566 // FIXME diagnose
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
567 logAllUnhandledErrors(
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
568 std::move(Err), errs(),
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
569 "error: can't create module summary index for buffer: ");
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
570 return nullptr;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
571 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
572 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
573 return CombinedIndex;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
574 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
575
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
576 static void internalizeAndPromoteInIndex(
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
577 const StringMap<FunctionImporter::ExportSetTy> &ExportLists,
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
578 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
579 ModuleSummaryIndex &Index) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
580 auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
581 const auto &ExportList = ExportLists.find(ModuleIdentifier);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
582 return (ExportList != ExportLists.end() &&
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
583 ExportList->second.count(GUID)) ||
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
584 GUIDPreservedSymbols.count(GUID);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
585 };
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
586
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
587 thinLTOInternalizeAndPromoteInIndex(Index, isExported);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
588 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
589
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
590 static void computeDeadSymbolsInIndex(
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
591 ModuleSummaryIndex &Index,
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
592 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
593 // We have no symbols resolution available. And can't do any better now in the
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
594 // case where the prevailing symbol is in a native object. It can be refined
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
595 // with linker information in the future.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
596 auto isPrevailing = [&](GlobalValue::GUID G) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
597 return PrevailingType::Unknown;
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
598 };
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
599 computeDeadSymbolsWithConstProp(Index, GUIDPreservedSymbols, isPrevailing,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
600 /* ImportEnabled = */ true);
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
601 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
602
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
603 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
604 * Perform promotion and renaming of exported internal functions.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
605 * Index is updated to reflect linkage changes from weak resolution.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
606 */
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
607 void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
608 const lto::InputFile &File) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
609 auto ModuleCount = Index.modulePaths().size();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
610 auto ModuleIdentifier = TheModule.getModuleIdentifier();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
611
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
612 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
613 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
614 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
615
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
616 // Convert the preserved symbols set from string to GUID
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
617 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
618 PreservedSymbols, Triple(TheModule.getTargetTriple()));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
619
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
620 // Add used symbol to the preserved symbols.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
621 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
622
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
623 // Compute "dead" symbols, we don't want to import/export these!
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
624 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
625
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
626 // Generate import/export list
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
627 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
628 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
629 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
630 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
631
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
632 // Resolve prevailing symbols
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
633 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
634 resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
635
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
636 thinLTOResolvePrevailingInModule(
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
637 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
638
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
639 // Promote the exported values in the index, so that they are promoted
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
640 // in the module.
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
641 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, Index);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
642
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
643 promoteModule(TheModule, Index);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
644 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
645
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
646 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
647 * Perform cross-module importing for the module identified by ModuleIdentifier.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
648 */
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
649 void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
650 ModuleSummaryIndex &Index,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
651 const lto::InputFile &File) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
652 auto ModuleMap = generateModuleMap(Modules);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
653 auto ModuleCount = Index.modulePaths().size();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
654
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
655 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
656 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
657 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
658
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
659 // Convert the preserved symbols set from string to GUID
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
660 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
661 PreservedSymbols, Triple(TheModule.getTargetTriple()));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
662
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
663 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
664
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
665 // Compute "dead" symbols, we don't want to import/export these!
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
666 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
667
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
668 // Generate import/export list
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
669 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
670 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
671 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
672 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
673 auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
674
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
675 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
676 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
677
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
678 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
679 * Compute the list of summaries needed for importing into module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
680 */
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
681 void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
682 Module &TheModule, ModuleSummaryIndex &Index,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
683 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
684 const lto::InputFile &File) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
685 auto ModuleCount = Index.modulePaths().size();
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
686 auto ModuleIdentifier = TheModule.getModuleIdentifier();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
687
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
688 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
689 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
690 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
691
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
692 // Convert the preserved symbols set from string to GUID
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
693 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
694 PreservedSymbols, Triple(TheModule.getTargetTriple()));
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
695
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
696 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
697
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
698 // Compute "dead" symbols, we don't want to import/export these!
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
699 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
700
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
701 // Generate import/export list
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
702 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
703 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
704 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
705 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
706
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
707 llvm::gatherImportedSummariesForModule(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
708 ModuleIdentifier, ModuleToDefinedGVSummaries,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
709 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
710 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
711
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
712 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
713 * Emit the list of files needed for importing into module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
714 */
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
715 void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
716 ModuleSummaryIndex &Index,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
717 const lto::InputFile &File) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
718 auto ModuleCount = Index.modulePaths().size();
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
719 auto ModuleIdentifier = TheModule.getModuleIdentifier();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
720
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
721 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
722 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
723 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
724
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
725 // Convert the preserved symbols set from string to GUID
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
726 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
727 PreservedSymbols, Triple(TheModule.getTargetTriple()));
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
728
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
729 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
730
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
731 // Compute "dead" symbols, we don't want to import/export these!
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
732 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
733
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
734 // Generate import/export list
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
735 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
736 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
737 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
738 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
739
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
740 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
741 llvm::gatherImportedSummariesForModule(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
742 ModuleIdentifier, ModuleToDefinedGVSummaries,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
743 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
744
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
745 std::error_code EC;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
746 if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
747 ModuleToSummariesForIndex)))
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
748 report_fatal_error(Twine("Failed to open ") + OutputName +
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
749 " to save imports lists\n");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
750 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
751
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
752 /**
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
753 * Perform internalization. Runs promote and internalization together.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
754 * Index is updated to reflect linkage changes.
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
755 */
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
756 void ThinLTOCodeGenerator::internalize(Module &TheModule,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
757 ModuleSummaryIndex &Index,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
758 const lto::InputFile &File) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
759 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
760 auto ModuleCount = Index.modulePaths().size();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
761 auto ModuleIdentifier = TheModule.getModuleIdentifier();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
762
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
763 // Convert the preserved symbols set from string to GUID
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
764 auto GUIDPreservedSymbols =
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
765 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
766
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
767 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
768
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
769 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
770 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
771 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
772
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
773 // Compute "dead" symbols, we don't want to import/export these!
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
774 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
775
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
776 // Generate import/export list
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
777 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
778 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
779 ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
780 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
781 auto &ExportList = ExportLists[ModuleIdentifier];
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
782
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
783 // Be friendly and don't nuke totally the module when the client didn't
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
784 // supply anything to preserve.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
785 if (ExportList.empty() && GUIDPreservedSymbols.empty())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
786 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
787
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
788 // Resolve prevailing symbols
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
789 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
790 resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
791
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
792 // Promote the exported values in the index, so that they are promoted
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
793 // in the module.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
794 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, Index);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
795
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
796 promoteModule(TheModule, Index);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
797
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
798 // Internalization
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
799 thinLTOResolvePrevailingInModule(
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
800 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
801
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
802 thinLTOInternalizeModule(TheModule,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
803 ModuleToDefinedGVSummaries[ModuleIdentifier]);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
804 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
805
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
806 /**
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
807 * Perform post-importing ThinLTO optimizations.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
808 */
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
809 void ThinLTOCodeGenerator::optimize(Module &TheModule) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
810 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
811
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
812 // Optimize now
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
813 optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
814 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
815
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
816 /// Write out the generated object file, either from CacheEntryPath or from
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
817 /// OutputBuffer, preferring hard-link when possible.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
818 /// Returns the path to the generated file in SavedObjectsDirectoryPath.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
819 std::string
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
820 ThinLTOCodeGenerator::writeGeneratedObject(int count, StringRef CacheEntryPath,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
821 const MemoryBuffer &OutputBuffer) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
822 auto ArchName = TMBuilder.TheTriple.getArchName();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
823 SmallString<128> OutputPath(SavedObjectsDirectoryPath);
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
824 llvm::sys::path::append(OutputPath,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
825 Twine(count) + "." + ArchName + ".thinlto.o");
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
826 OutputPath.c_str(); // Ensure the string is null terminated.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
827 if (sys::fs::exists(OutputPath))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
828 sys::fs::remove(OutputPath);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
829
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
830 // We don't return a memory buffer to the linker, just a list of files.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
831 if (!CacheEntryPath.empty()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
832 // Cache is enabled, hard-link the entry (or copy if hard-link fails).
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
833 auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
834 if (!Err)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
835 return OutputPath.str();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
836 // Hard linking failed, try to copy.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
837 Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
838 if (!Err)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
839 return OutputPath.str();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
840 // Copy failed (could be because the CacheEntry was removed from the cache
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
841 // in the meantime by another process), fall back and try to write down the
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
842 // buffer to the output.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
843 errs() << "error: can't link or copy from cached entry '" << CacheEntryPath
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
844 << "' to '" << OutputPath << "'\n";
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
845 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
846 // No cache entry, just write out the buffer.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
847 std::error_code Err;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
848 raw_fd_ostream OS(OutputPath, Err, sys::fs::OF_None);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
849 if (Err)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
850 report_fatal_error("Can't open output '" + OutputPath + "'\n");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
851 OS << OutputBuffer.getBuffer();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
852 return OutputPath.str();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
853 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
854
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
855 // Main entry point for the ThinLTO processing
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
856 void ThinLTOCodeGenerator::run() {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
857 // Prepare the resulting object vector
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
858 assert(ProducedBinaries.empty() && "The generator should not be reused");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
859 if (SavedObjectsDirectoryPath.empty())
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
860 ProducedBinaries.resize(Modules.size());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
861 else {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
862 sys::fs::create_directories(SavedObjectsDirectoryPath);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
863 bool IsDir;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
864 sys::fs::is_directory(SavedObjectsDirectoryPath, IsDir);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
865 if (!IsDir)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
866 report_fatal_error("Unexistent dir: '" + SavedObjectsDirectoryPath + "'");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
867 ProducedBinaryFiles.resize(Modules.size());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
868 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
869
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
870 if (CodeGenOnly) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
871 // Perform only parallel codegen and return.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
872 ThreadPool Pool;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
873 int count = 0;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
874 for (auto &Mod : Modules) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
875 Pool.async([&](int count) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
876 LLVMContext Context;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
877 Context.setDiscardValueNames(LTODiscardValueNames);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
878
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
879 // Parse module now
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
880 auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
881 /*IsImporting*/ false);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
882
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
883 // CodeGen
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
884 auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create());
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
885 if (SavedObjectsDirectoryPath.empty())
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
886 ProducedBinaries[count] = std::move(OutputBuffer);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
887 else
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
888 ProducedBinaryFiles[count] =
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
889 writeGeneratedObject(count, "", *OutputBuffer);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
890 }, count++);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
891 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
892
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
893 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
894 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
895
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
896 // Sequential linking phase
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
897 auto Index = linkCombinedIndex();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
898
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
899 // Save temps: index.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
900 if (!SaveTempsDir.empty()) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
901 auto SaveTempPath = SaveTempsDir + "index.bc";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
902 std::error_code EC;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
903 raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
904 if (EC)
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
905 report_fatal_error(Twine("Failed to open ") + SaveTempPath +
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
906 " to save optimized bitcode\n");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
907 WriteIndexToFile(*Index, OS);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
908 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
909
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
910
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
911 // Prepare the module map.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
912 auto ModuleMap = generateModuleMap(Modules);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
913 auto ModuleCount = Modules.size();
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
914
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
915 // Collect for each module the list of function it defines (GUID -> Summary).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
916 StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
917 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
918
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
919 // Convert the preserved symbols set from string to GUID, this is needed for
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
920 // computing the caching hash and the internalization.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
921 auto GUIDPreservedSymbols =
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
922 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
923
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
924 // Add used symbol from inputs to the preserved symbols.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
925 for (const auto &M : Modules)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
926 addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
927
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
928 // Compute "dead" symbols, we don't want to import/export these!
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
929 computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
930
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
931 // Synthesize entry counts for functions in the combined index.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
932 computeSyntheticCounts(*Index);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
933
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
934 // Collect the import/export lists for all modules from the call-graph in the
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
935 // combined index.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
936 StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
937 StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
938 ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
939 ExportLists);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
940
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
941 // We use a std::map here to be able to have a defined ordering when
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
942 // producing a hash for the cache entry.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
943 // FIXME: we should be able to compute the caching hash for the entry based
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
944 // on the index, and nuke this map.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
945 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
946
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
947 // Resolve prevailing symbols, this has to be computed early because it
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
948 // impacts the caching.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
949 resolvePrevailingInIndex(*Index, ResolvedODR, GUIDPreservedSymbols);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
950
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
951 // Use global summary-based analysis to identify symbols that can be
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
952 // internalized (because they aren't exported or preserved as per callback).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
953 // Changes are made in the index, consumed in the ThinLTO backends.
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
954 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, *Index);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
955
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
956 // Make sure that every module has an entry in the ExportLists, ImportList,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
957 // GVSummary and ResolvedODR maps to enable threaded access to these maps
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
958 // below.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
959 for (auto &Module : Modules) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
960 auto ModuleIdentifier = Module->getName();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
961 ExportLists[ModuleIdentifier];
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
962 ImportLists[ModuleIdentifier];
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
963 ResolvedODR[ModuleIdentifier];
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
964 ModuleToDefinedGVSummaries[ModuleIdentifier];
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
965 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
966
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
967 // Compute the ordering we will process the inputs: the rough heuristic here
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
968 // is to sort them per size so that the largest module get schedule as soon as
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
969 // possible. This is purely a compile-time optimization.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
970 std::vector<int> ModulesOrdering;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
971 ModulesOrdering.resize(Modules.size());
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
972 std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
973 llvm::sort(ModulesOrdering, [&](int LeftIndex, int RightIndex) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
974 auto LSize =
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
975 Modules[LeftIndex]->getSingleBitcodeModule().getBuffer().size();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
976 auto RSize =
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
977 Modules[RightIndex]->getSingleBitcodeModule().getBuffer().size();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
978 return LSize > RSize;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
979 });
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
980
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
981 // Parallel optimizer + codegen
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
982 {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
983 ThreadPool Pool(ThreadCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
984 for (auto IndexCount : ModulesOrdering) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
985 auto &Mod = Modules[IndexCount];
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
986 Pool.async([&](int count) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
987 auto ModuleIdentifier = Mod->getName();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
988 auto &ExportList = ExportLists[ModuleIdentifier];
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
989
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
990 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
991
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
992 // The module may be cached, this helps handling it.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
993 ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
994 ImportLists[ModuleIdentifier], ExportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
995 ResolvedODR[ModuleIdentifier],
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
996 DefinedGVSummaries, OptLevel, Freestanding,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
997 TMBuilder);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
998 auto CacheEntryPath = CacheEntry.getEntryPath();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
999
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1000 {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1001 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1002 LLVM_DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss")
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1003 << " '" << CacheEntryPath << "' for buffer "
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1004 << count << " " << ModuleIdentifier << "\n");
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1005
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1006 if (ErrOrBuffer) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1007 // Cache Hit!
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1008 if (SavedObjectsDirectoryPath.empty())
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1009 ProducedBinaries[count] = std::move(ErrOrBuffer.get());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1010 else
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1011 ProducedBinaryFiles[count] = writeGeneratedObject(
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1012 count, CacheEntryPath, *ErrOrBuffer.get());
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1013 return;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1014 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1015 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1016
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1017 LLVMContext Context;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1018 Context.setDiscardValueNames(LTODiscardValueNames);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1019 Context.enableDebugTypeODRUniquing();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1020 auto DiagFileOrErr = lto::setupOptimizationRemarks(
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1021 Context, RemarksFilename, RemarksPasses, RemarksFormat,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1022 RemarksWithHotness, count);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1023 if (!DiagFileOrErr) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1024 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1025 report_fatal_error("ThinLTO: Can't get an output file for the "
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1026 "remarks");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1027 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1028
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1029 // Parse module now
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1030 auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1031 /*IsImporting*/ false);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1032
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1033 // Save temps: original file.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1034 saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1035
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1036 auto &ImportList = ImportLists[ModuleIdentifier];
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1037 // Run the main process now, and generates a binary
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1038 auto OutputBuffer = ProcessThinLTOModule(
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1039 *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1040 ExportList, GUIDPreservedSymbols,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1041 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1042 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1043
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1044 // Commit to the cache (if enabled)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1045 CacheEntry.write(*OutputBuffer);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1046
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1047 if (SavedObjectsDirectoryPath.empty()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1048 // We need to generated a memory buffer for the linker.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1049 if (!CacheEntryPath.empty()) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1050 // When cache is enabled, reload from the cache if possible.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1051 // Releasing the buffer from the heap and reloading it from the
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1052 // cache file with mmap helps us to lower memory pressure.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1053 // The freed memory can be used for the next input file.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1054 // The final binary link will read from the VFS cache (hopefully!)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1055 // or from disk (if the memory pressure was too high).
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1056 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1057 if (auto EC = ReloadedBufferOrErr.getError()) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1058 // On error, keep the preexisting buffer and print a diagnostic.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1059 errs() << "error: can't reload cached file '" << CacheEntryPath
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1060 << "': " << EC.message() << "\n";
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1061 } else {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1062 OutputBuffer = std::move(*ReloadedBufferOrErr);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1063 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1064 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1065 ProducedBinaries[count] = std::move(OutputBuffer);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1066 return;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1067 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1068 ProducedBinaryFiles[count] = writeGeneratedObject(
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1069 count, CacheEntryPath, *OutputBuffer);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1070 }, IndexCount);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1071 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1072 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1073
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1074 pruneCache(CacheOptions.Path, CacheOptions.Policy);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1075
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1076 // If statistics were requested, print them out now.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1077 if (llvm::AreStatisticsEnabled())
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1078 llvm::PrintStatistics();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1079 reportAndResetTimings();
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1080 }