blob: 65deb82cd2a5fbd11a13df6f5d9321c08ced3561 [file] [log] [blame]
Peter Collingbourne1398a322016-12-16 00:26:30 +00001//===- ThinLTOBitcodeWriter.cpp - Bitcode writing pass for ThinLTO --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass prepares a module containing type metadata for ThinLTO by splitting
11// it into regular and thin LTO parts if possible, and writing both parts to
12// a multi-module bitcode file. Modules that do not contain type metadata are
13// written unmodified as a single module.
14//
15//===----------------------------------------------------------------------===//
16
Peter Collingbourne002c2d52017-02-14 03:42:38 +000017#include "llvm/Analysis/BasicAliasAnalysis.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000018#include "llvm/Analysis/ModuleSummaryAnalysis.h"
19#include "llvm/Analysis/TypeMetadataUtils.h"
20#include "llvm/Bitcode/BitcodeWriter.h"
21#include "llvm/IR/Constants.h"
Peter Collingbourne28ffd322017-02-08 20:44:00 +000022#include "llvm/IR/DebugInfo.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000023#include "llvm/IR/Intrinsics.h"
24#include "llvm/IR/Module.h"
25#include "llvm/IR/PassManager.h"
26#include "llvm/Pass.h"
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +000027#include "llvm/Support/FileSystem.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000028#include "llvm/Support/ScopedPrinter.h"
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +000029#include "llvm/Support/raw_ostream.h"
30#include "llvm/Transforms/IPO.h"
Peter Collingbourne002c2d52017-02-14 03:42:38 +000031#include "llvm/Transforms/IPO/FunctionAttrs.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000032#include "llvm/Transforms/Utils/Cloning.h"
33using namespace llvm;
34
35namespace {
36
Evgeniy Stepanovba7c2e92017-04-10 20:36:30 +000037// Produce a unique identifier for this module by taking the MD5 sum of the
38// names of the module's strong external symbols. This identifier is
39// normally guaranteed to be unique, or the program would fail to link due to
40// multiply defined symbols.
41//
42// If the module has no strong external symbols (such a module may still have a
43// semantic effect if it performs global initialization), we cannot produce a
44// unique identifier for this module, so we return the empty string, which
45// causes the entire module to be written as a regular LTO module.
46std::string getModuleId(Module *M) {
47 MD5 Md5;
48 bool ExportsSymbols = false;
49 for (auto &GV : M->global_values()) {
50 if (GV.isDeclaration() || GV.getName().startswith("llvm.") ||
51 !GV.hasExternalLinkage())
52 continue;
53 ExportsSymbols = true;
54 Md5.update(GV.getName());
55 Md5.update(ArrayRef<uint8_t>{0});
56 }
57
58 if (!ExportsSymbols)
59 return "";
60
61 MD5::MD5Result R;
62 Md5.final(R);
63
64 SmallString<32> Str;
65 MD5::stringifyResult(R, Str);
66 return ("$" + Str).str();
67}
68
Peter Collingbourne1398a322016-12-16 00:26:30 +000069// Promote each local-linkage entity defined by ExportM and used by ImportM by
70// changing visibility and appending the given ModuleId.
71void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId) {
Bob Haarman4075ccc2017-04-12 01:43:07 +000072 DenseMap<const Comdat *, Comdat *> RenamedComdats;
Peter Collingbourne6b193962017-03-30 23:43:08 +000073 for (auto &ExportGV : ExportM.global_values()) {
Peter Collingbourne1398a322016-12-16 00:26:30 +000074 if (!ExportGV.hasLocalLinkage())
Peter Collingbourne6b193962017-03-30 23:43:08 +000075 continue;
Peter Collingbourne1398a322016-12-16 00:26:30 +000076
Bob Haarman4075ccc2017-04-12 01:43:07 +000077 auto Name = ExportGV.getName();
78 GlobalValue *ImportGV = ImportM.getNamedValue(Name);
Peter Collingbourne1398a322016-12-16 00:26:30 +000079 if (!ImportGV || ImportGV->use_empty())
Peter Collingbourne6b193962017-03-30 23:43:08 +000080 continue;
Peter Collingbourne1398a322016-12-16 00:26:30 +000081
Bob Haarman4075ccc2017-04-12 01:43:07 +000082 std::string NewName = (Name + ModuleId).str();
83
84 if (const auto *C = ExportGV.getComdat())
85 if (C->getName() == Name)
86 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
Peter Collingbourne1398a322016-12-16 00:26:30 +000087
88 ExportGV.setName(NewName);
89 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
90 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
91
92 ImportGV->setName(NewName);
93 ImportGV->setVisibility(GlobalValue::HiddenVisibility);
Peter Collingbourne6b193962017-03-30 23:43:08 +000094 }
Bob Haarman4075ccc2017-04-12 01:43:07 +000095
96 if (!RenamedComdats.empty())
97 for (auto &GO : ExportM.global_objects())
98 if (auto *C = GO.getComdat()) {
99 auto Replacement = RenamedComdats.find(C);
100 if (Replacement != RenamedComdats.end())
101 GO.setComdat(Replacement->second);
102 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000103}
104
105// Promote all internal (i.e. distinct) type ids used by the module by replacing
106// them with external type ids formed using the module id.
107//
108// Note that this needs to be done before we clone the module because each clone
109// will receive its own set of distinct metadata nodes.
110void promoteTypeIds(Module &M, StringRef ModuleId) {
111 DenseMap<Metadata *, Metadata *> LocalToGlobal;
112 auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
113 Metadata *MD =
114 cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
115
116 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
117 Metadata *&GlobalMD = LocalToGlobal[MD];
118 if (!GlobalMD) {
119 std::string NewName =
120 (to_string(LocalToGlobal.size()) + ModuleId).str();
121 GlobalMD = MDString::get(M.getContext(), NewName);
122 }
123
124 CI->setArgOperand(ArgNo,
125 MetadataAsValue::get(M.getContext(), GlobalMD));
126 }
127 };
128
129 if (Function *TypeTestFunc =
130 M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
131 for (const Use &U : TypeTestFunc->uses()) {
132 auto CI = cast<CallInst>(U.getUser());
133 ExternalizeTypeId(CI, 1);
134 }
135 }
136
137 if (Function *TypeCheckedLoadFunc =
138 M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
139 for (const Use &U : TypeCheckedLoadFunc->uses()) {
140 auto CI = cast<CallInst>(U.getUser());
141 ExternalizeTypeId(CI, 2);
142 }
143 }
144
145 for (GlobalObject &GO : M.global_objects()) {
146 SmallVector<MDNode *, 1> MDs;
147 GO.getMetadata(LLVMContext::MD_type, MDs);
148
149 GO.eraseMetadata(LLVMContext::MD_type);
150 for (auto MD : MDs) {
151 auto I = LocalToGlobal.find(MD->getOperand(1));
152 if (I == LocalToGlobal.end()) {
153 GO.addMetadata(LLVMContext::MD_type, *MD);
154 continue;
155 }
156 GO.addMetadata(
157 LLVMContext::MD_type,
158 *MDNode::get(M.getContext(),
159 ArrayRef<Metadata *>{MD->getOperand(0), I->second}));
160 }
161 }
162}
163
164// Drop unused globals, and drop type information from function declarations.
165// FIXME: If we made functions typeless then there would be no need to do this.
166void simplifyExternals(Module &M) {
167 FunctionType *EmptyFT =
168 FunctionType::get(Type::getVoidTy(M.getContext()), false);
169
170 for (auto I = M.begin(), E = M.end(); I != E;) {
171 Function &F = *I++;
172 if (F.isDeclaration() && F.use_empty()) {
173 F.eraseFromParent();
174 continue;
175 }
176
177 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT)
178 continue;
179
180 Function *NewF =
181 Function::Create(EmptyFT, GlobalValue::ExternalLinkage, "", &M);
182 NewF->setVisibility(F.getVisibility());
183 NewF->takeName(&F);
184 F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
185 F.eraseFromParent();
186 }
187
188 for (auto I = M.global_begin(), E = M.global_end(); I != E;) {
189 GlobalVariable &GV = *I++;
190 if (GV.isDeclaration() && GV.use_empty()) {
191 GV.eraseFromParent();
192 continue;
193 }
194 }
195}
196
197void filterModule(
Benjamin Kramer061f4a52017-01-13 14:39:03 +0000198 Module *M, function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
Bob Haarman6de81342017-04-05 00:42:07 +0000199 for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
200 I != E;) {
201 GlobalAlias *GA = &*I++;
202 if (ShouldKeepDefinition(GA))
203 continue;
204
205 GlobalObject *GO;
206 if (GA->getValueType()->isFunctionTy())
207 GO = Function::Create(cast<FunctionType>(GA->getValueType()),
208 GlobalValue::ExternalLinkage, "", M);
209 else
210 GO = new GlobalVariable(
211 *M, GA->getValueType(), false, GlobalValue::ExternalLinkage,
212 (Constant *)nullptr, "", (GlobalVariable *)nullptr,
213 GA->getThreadLocalMode(), GA->getType()->getAddressSpace());
214 GO->takeName(GA);
215 GA->replaceAllUsesWith(GO);
216 GA->eraseFromParent();
217 }
218
Peter Collingbourne1398a322016-12-16 00:26:30 +0000219 for (Function &F : *M) {
220 if (ShouldKeepDefinition(&F))
221 continue;
222
223 F.deleteBody();
Peter Collingbourne20a00932017-01-18 20:03:02 +0000224 F.setComdat(nullptr);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000225 F.clearMetadata();
226 }
227
228 for (GlobalVariable &GV : M->globals()) {
229 if (ShouldKeepDefinition(&GV))
230 continue;
231
232 GV.setInitializer(nullptr);
233 GV.setLinkage(GlobalValue::ExternalLinkage);
Peter Collingbourne20a00932017-01-18 20:03:02 +0000234 GV.setComdat(nullptr);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000235 GV.clearMetadata();
236 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000237}
238
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000239void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
240 if (auto *F = dyn_cast<Function>(C))
241 return Fn(F);
Peter Collingbourne3baa72a2017-03-02 23:10:17 +0000242 if (isa<GlobalValue>(C))
243 return;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000244 for (Value *Op : C->operands())
245 forEachVirtualFunction(cast<Constant>(Op), Fn);
246}
247
Peter Collingbourne1398a322016-12-16 00:26:30 +0000248// If it's possible to split M into regular and thin LTO parts, do so and write
249// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
250// regular LTO bitcode file to OS.
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000251void splitAndWriteThinLTOBitcode(
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000252 raw_ostream &OS, raw_ostream *ThinLinkOS,
253 function_ref<AAResults &(Function &)> AARGetter, Module &M) {
Evgeniy Stepanovba7c2e92017-04-10 20:36:30 +0000254 std::string ModuleId = getModuleId(&M);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000255 if (ModuleId.empty()) {
256 // We couldn't generate a module ID for this module, just write it out as a
257 // regular LTO module.
258 WriteBitcodeToFile(&M, OS);
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000259 if (ThinLinkOS)
260 // We don't have a ThinLTO part, but still write the module to the
261 // ThinLinkOS if requested so that the expected output file is produced.
262 WriteBitcodeToFile(&M, *ThinLinkOS);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000263 return;
264 }
265
266 promoteTypeIds(M, ModuleId);
267
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000268 // Returns whether a global has attached type metadata. Such globals may
269 // participate in CFI or whole-program devirtualization, so they need to
270 // appear in the merged module instead of the thin LTO module.
271 auto HasTypeMetadata = [&](const GlobalObject *GO) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000272 SmallVector<MDNode *, 1> MDs;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000273 GO->getMetadata(LLVMContext::MD_type, MDs);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000274 return !MDs.empty();
275 };
276
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000277 // Collect the set of virtual functions that are eligible for virtual constant
278 // propagation. Each eligible function must not access memory, must return
279 // an integer of width <=64 bits, must take at least one argument, must not
280 // use its first argument (assumed to be "this") and all arguments other than
281 // the first one must be of <=64 bit integer type.
282 //
283 // Note that we test whether this copy of the function is readnone, rather
284 // than testing function attributes, which must hold for any copy of the
285 // function, even a less optimized version substituted at link time. This is
286 // sound because the virtual constant propagation optimizations effectively
287 // inline all implementations of the virtual function into each call site,
288 // rather than using function attributes to perform local optimization.
289 std::set<const Function *> EligibleVirtualFns;
Bob Haarman4075ccc2017-04-12 01:43:07 +0000290 // If any member of a comdat lives in MergedM, put all members of that
291 // comdat in MergedM to keep the comdat together.
292 DenseSet<const Comdat *> MergedMComdats;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000293 for (GlobalVariable &GV : M.globals())
Bob Haarman4075ccc2017-04-12 01:43:07 +0000294 if (HasTypeMetadata(&GV)) {
295 if (const auto *C = GV.getComdat())
296 MergedMComdats.insert(C);
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000297 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
298 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
299 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
300 !F->arg_begin()->use_empty())
301 return;
302 for (auto &Arg : make_range(std::next(F->arg_begin()), F->arg_end())) {
303 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
304 if (!ArgT || ArgT->getBitWidth() > 64)
305 return;
306 }
307 if (computeFunctionBodyMemoryAccess(*F, AARGetter(*F)) == MAK_ReadNone)
308 EligibleVirtualFns.insert(F);
309 });
Bob Haarman4075ccc2017-04-12 01:43:07 +0000310 }
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000311
Peter Collingbourne1398a322016-12-16 00:26:30 +0000312 ValueToValueMapTy VMap;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000313 std::unique_ptr<Module> MergedM(
314 CloneModule(&M, VMap, [&](const GlobalValue *GV) -> bool {
Bob Haarman4075ccc2017-04-12 01:43:07 +0000315 if (const auto *C = GV->getComdat())
316 if (MergedMComdats.count(C))
317 return true;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000318 if (auto *F = dyn_cast<Function>(GV))
319 return EligibleVirtualFns.count(F);
320 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
321 return HasTypeMetadata(GVar);
322 return false;
323 }));
Peter Collingbourne28ffd322017-02-08 20:44:00 +0000324 StripDebugInfo(*MergedM);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000325
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000326 for (Function &F : *MergedM)
327 if (!F.isDeclaration()) {
328 // Reset the linkage of all functions eligible for virtual constant
329 // propagation. The canonical definitions live in the thin LTO module so
330 // that they can be imported.
331 F.setLinkage(GlobalValue::AvailableExternallyLinkage);
332 F.setComdat(nullptr);
333 }
334
Bob Haarman4075ccc2017-04-12 01:43:07 +0000335 // Remove all globals with type metadata, globals with comdats that live in
336 // MergedM, and aliases pointing to such globals from the thin LTO module.
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000337 filterModule(&M, [&](const GlobalValue *GV) {
338 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
Bob Haarman4075ccc2017-04-12 01:43:07 +0000339 if (HasTypeMetadata(GVar))
340 return false;
341 if (const auto *C = GV->getComdat())
342 if (MergedMComdats.count(C))
343 return false;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000344 return true;
345 });
Peter Collingbourne1398a322016-12-16 00:26:30 +0000346
347 promoteInternals(*MergedM, M, ModuleId);
348 promoteInternals(M, *MergedM, ModuleId);
349
350 simplifyExternals(*MergedM);
351
Peter Collingbourne1398a322016-12-16 00:26:30 +0000352
353 // FIXME: Try to re-use BSI and PFI from the original module here.
354 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, nullptr);
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000355
356 SmallVector<char, 0> Buffer;
357
358 BitcodeWriter W(Buffer);
359 // Save the module hash produced for the full bitcode, which will
360 // be used in the backends, and use that in the minimized bitcode
361 // produced for the full link.
362 ModuleHash ModHash = {{0}};
Peter Collingbourne1398a322016-12-16 00:26:30 +0000363 W.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000364 /*GenerateHash=*/true, &ModHash);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000365 W.writeModule(MergedM.get());
Peter Collingbourne1398a322016-12-16 00:26:30 +0000366 OS << Buffer;
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000367
368 // If a minimized bitcode module was requested for the thin link,
369 // strip the debug info (the merged module was already stripped above)
370 // and write it to the given OS.
371 if (ThinLinkOS) {
372 Buffer.clear();
373 BitcodeWriter W2(Buffer);
374 StripDebugInfo(M);
375 W2.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
376 /*GenerateHash=*/false, &ModHash);
377 W2.writeModule(MergedM.get());
378 *ThinLinkOS << Buffer;
379 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000380}
381
382// Returns whether this module needs to be split because it uses type metadata.
383bool requiresSplit(Module &M) {
384 SmallVector<MDNode *, 1> MDs;
385 for (auto &GO : M.global_objects()) {
386 GO.getMetadata(LLVMContext::MD_type, MDs);
387 if (!MDs.empty())
388 return true;
389 }
390
391 return false;
392}
393
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000394void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000395 function_ref<AAResults &(Function &)> AARGetter,
396 Module &M, const ModuleSummaryIndex *Index) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000397 // See if this module has any type metadata. If so, we need to split it.
398 if (requiresSplit(M))
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000399 return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000400
401 // Otherwise we can just write it out as a regular module.
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000402
403 // Save the module hash produced for the full bitcode, which will
404 // be used in the backends, and use that in the minimized bitcode
405 // produced for the full link.
406 ModuleHash ModHash = {{0}};
Peter Collingbourne1398a322016-12-16 00:26:30 +0000407 WriteBitcodeToFile(&M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000408 /*GenerateHash=*/true, &ModHash);
409 // If a minimized bitcode module was requested for the thin link,
410 // strip the debug info and write it to the given OS.
411 if (ThinLinkOS) {
412 StripDebugInfo(M);
413 WriteBitcodeToFile(&M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
414 Index,
415 /*GenerateHash=*/false, &ModHash);
416 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000417}
418
419class WriteThinLTOBitcode : public ModulePass {
420 raw_ostream &OS; // raw_ostream to print on
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000421 // The output stream on which to emit a minimized module for use
422 // just in the thin link, if requested.
423 raw_ostream *ThinLinkOS;
Peter Collingbourne1398a322016-12-16 00:26:30 +0000424
425public:
426 static char ID; // Pass identification, replacement for typeid
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000427 WriteThinLTOBitcode() : ModulePass(ID), OS(dbgs()), ThinLinkOS(nullptr) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000428 initializeWriteThinLTOBitcodePass(*PassRegistry::getPassRegistry());
429 }
430
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000431 explicit WriteThinLTOBitcode(raw_ostream &o, raw_ostream *ThinLinkOS)
432 : ModulePass(ID), OS(o), ThinLinkOS(ThinLinkOS) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000433 initializeWriteThinLTOBitcodePass(*PassRegistry::getPassRegistry());
434 }
435
436 StringRef getPassName() const override { return "ThinLTO Bitcode Writer"; }
437
438 bool runOnModule(Module &M) override {
439 const ModuleSummaryIndex *Index =
440 &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000441 writeThinLTOBitcode(OS, ThinLinkOS, LegacyAARGetter(*this), M, Index);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000442 return true;
443 }
444 void getAnalysisUsage(AnalysisUsage &AU) const override {
445 AU.setPreservesAll();
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000446 AU.addRequired<AssumptionCacheTracker>();
Peter Collingbourne1398a322016-12-16 00:26:30 +0000447 AU.addRequired<ModuleSummaryIndexWrapperPass>();
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000448 AU.addRequired<TargetLibraryInfoWrapperPass>();
Peter Collingbourne1398a322016-12-16 00:26:30 +0000449 }
450};
451} // anonymous namespace
452
453char WriteThinLTOBitcode::ID = 0;
454INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode",
455 "Write ThinLTO Bitcode", false, true)
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000456INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
Peter Collingbourne1398a322016-12-16 00:26:30 +0000457INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000458INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
Peter Collingbourne1398a322016-12-16 00:26:30 +0000459INITIALIZE_PASS_END(WriteThinLTOBitcode, "write-thinlto-bitcode",
460 "Write ThinLTO Bitcode", false, true)
461
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000462ModulePass *llvm::createWriteThinLTOBitcodePass(raw_ostream &Str,
463 raw_ostream *ThinLinkOS) {
464 return new WriteThinLTOBitcode(Str, ThinLinkOS);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000465}