blob: 659cb9df00a2c27b773985f88ac5370fcd09cc40 [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"
Teresa Johnson94624ac2017-05-10 18:52:16 +000019#include "llvm/Analysis/ProfileSummaryInfo.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000020#include "llvm/Analysis/TypeMetadataUtils.h"
21#include "llvm/Bitcode/BitcodeWriter.h"
22#include "llvm/IR/Constants.h"
Peter Collingbourne28ffd322017-02-08 20:44:00 +000023#include "llvm/IR/DebugInfo.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000024#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/PassManager.h"
27#include "llvm/Pass.h"
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +000028#include "llvm/Support/FileSystem.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000029#include "llvm/Support/ScopedPrinter.h"
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +000030#include "llvm/Support/raw_ostream.h"
31#include "llvm/Transforms/IPO.h"
Peter Collingbourne002c2d52017-02-14 03:42:38 +000032#include "llvm/Transforms/IPO/FunctionAttrs.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000033#include "llvm/Transforms/Utils/Cloning.h"
Evgeniy Stepanov964f4662017-04-27 20:27:27 +000034#include "llvm/Transforms/Utils/ModuleUtils.h"
Peter Collingbourne1398a322016-12-16 00:26:30 +000035using namespace llvm;
36
37namespace {
38
Peter Collingbourne1398a322016-12-16 00:26:30 +000039// Promote each local-linkage entity defined by ExportM and used by ImportM by
40// changing visibility and appending the given ModuleId.
41void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId) {
Bob Haarman4075ccc2017-04-12 01:43:07 +000042 DenseMap<const Comdat *, Comdat *> RenamedComdats;
Peter Collingbourne6b193962017-03-30 23:43:08 +000043 for (auto &ExportGV : ExportM.global_values()) {
Peter Collingbourne1398a322016-12-16 00:26:30 +000044 if (!ExportGV.hasLocalLinkage())
Peter Collingbourne6b193962017-03-30 23:43:08 +000045 continue;
Peter Collingbourne1398a322016-12-16 00:26:30 +000046
Bob Haarman4075ccc2017-04-12 01:43:07 +000047 auto Name = ExportGV.getName();
48 GlobalValue *ImportGV = ImportM.getNamedValue(Name);
Peter Collingbourne1398a322016-12-16 00:26:30 +000049 if (!ImportGV || ImportGV->use_empty())
Peter Collingbourne6b193962017-03-30 23:43:08 +000050 continue;
Peter Collingbourne1398a322016-12-16 00:26:30 +000051
Bob Haarman4075ccc2017-04-12 01:43:07 +000052 std::string NewName = (Name + ModuleId).str();
53
54 if (const auto *C = ExportGV.getComdat())
55 if (C->getName() == Name)
56 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
Peter Collingbourne1398a322016-12-16 00:26:30 +000057
58 ExportGV.setName(NewName);
59 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
60 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
61
62 ImportGV->setName(NewName);
63 ImportGV->setVisibility(GlobalValue::HiddenVisibility);
Peter Collingbourne6b193962017-03-30 23:43:08 +000064 }
Bob Haarman4075ccc2017-04-12 01:43:07 +000065
66 if (!RenamedComdats.empty())
67 for (auto &GO : ExportM.global_objects())
68 if (auto *C = GO.getComdat()) {
69 auto Replacement = RenamedComdats.find(C);
70 if (Replacement != RenamedComdats.end())
71 GO.setComdat(Replacement->second);
72 }
Peter Collingbourne1398a322016-12-16 00:26:30 +000073}
74
75// Promote all internal (i.e. distinct) type ids used by the module by replacing
76// them with external type ids formed using the module id.
77//
78// Note that this needs to be done before we clone the module because each clone
79// will receive its own set of distinct metadata nodes.
80void promoteTypeIds(Module &M, StringRef ModuleId) {
81 DenseMap<Metadata *, Metadata *> LocalToGlobal;
82 auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
83 Metadata *MD =
84 cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
85
86 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
87 Metadata *&GlobalMD = LocalToGlobal[MD];
88 if (!GlobalMD) {
89 std::string NewName =
90 (to_string(LocalToGlobal.size()) + ModuleId).str();
91 GlobalMD = MDString::get(M.getContext(), NewName);
92 }
93
94 CI->setArgOperand(ArgNo,
95 MetadataAsValue::get(M.getContext(), GlobalMD));
96 }
97 };
98
99 if (Function *TypeTestFunc =
100 M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
101 for (const Use &U : TypeTestFunc->uses()) {
102 auto CI = cast<CallInst>(U.getUser());
103 ExternalizeTypeId(CI, 1);
104 }
105 }
106
107 if (Function *TypeCheckedLoadFunc =
108 M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
109 for (const Use &U : TypeCheckedLoadFunc->uses()) {
110 auto CI = cast<CallInst>(U.getUser());
111 ExternalizeTypeId(CI, 2);
112 }
113 }
114
115 for (GlobalObject &GO : M.global_objects()) {
116 SmallVector<MDNode *, 1> MDs;
117 GO.getMetadata(LLVMContext::MD_type, MDs);
118
119 GO.eraseMetadata(LLVMContext::MD_type);
120 for (auto MD : MDs) {
121 auto I = LocalToGlobal.find(MD->getOperand(1));
122 if (I == LocalToGlobal.end()) {
123 GO.addMetadata(LLVMContext::MD_type, *MD);
124 continue;
125 }
126 GO.addMetadata(
127 LLVMContext::MD_type,
128 *MDNode::get(M.getContext(),
129 ArrayRef<Metadata *>{MD->getOperand(0), I->second}));
130 }
131 }
132}
133
134// Drop unused globals, and drop type information from function declarations.
135// FIXME: If we made functions typeless then there would be no need to do this.
136void simplifyExternals(Module &M) {
137 FunctionType *EmptyFT =
138 FunctionType::get(Type::getVoidTy(M.getContext()), false);
139
140 for (auto I = M.begin(), E = M.end(); I != E;) {
141 Function &F = *I++;
142 if (F.isDeclaration() && F.use_empty()) {
143 F.eraseFromParent();
144 continue;
145 }
146
147 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT)
148 continue;
149
150 Function *NewF =
151 Function::Create(EmptyFT, GlobalValue::ExternalLinkage, "", &M);
152 NewF->setVisibility(F.getVisibility());
153 NewF->takeName(&F);
154 F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
155 F.eraseFromParent();
156 }
157
158 for (auto I = M.global_begin(), E = M.global_end(); I != E;) {
159 GlobalVariable &GV = *I++;
160 if (GV.isDeclaration() && GV.use_empty()) {
161 GV.eraseFromParent();
162 continue;
163 }
164 }
165}
166
167void filterModule(
Benjamin Kramer061f4a52017-01-13 14:39:03 +0000168 Module *M, function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
Bob Haarman6de81342017-04-05 00:42:07 +0000169 for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
170 I != E;) {
171 GlobalAlias *GA = &*I++;
172 if (ShouldKeepDefinition(GA))
173 continue;
174
175 GlobalObject *GO;
176 if (GA->getValueType()->isFunctionTy())
177 GO = Function::Create(cast<FunctionType>(GA->getValueType()),
178 GlobalValue::ExternalLinkage, "", M);
179 else
180 GO = new GlobalVariable(
181 *M, GA->getValueType(), false, GlobalValue::ExternalLinkage,
Serge Gueltonf4dc59b2017-05-11 08:53:00 +0000182 nullptr, "", nullptr,
Bob Haarman6de81342017-04-05 00:42:07 +0000183 GA->getThreadLocalMode(), GA->getType()->getAddressSpace());
184 GO->takeName(GA);
185 GA->replaceAllUsesWith(GO);
186 GA->eraseFromParent();
187 }
188
Peter Collingbourne1398a322016-12-16 00:26:30 +0000189 for (Function &F : *M) {
190 if (ShouldKeepDefinition(&F))
191 continue;
192
193 F.deleteBody();
Peter Collingbourne20a00932017-01-18 20:03:02 +0000194 F.setComdat(nullptr);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000195 F.clearMetadata();
196 }
197
198 for (GlobalVariable &GV : M->globals()) {
199 if (ShouldKeepDefinition(&GV))
200 continue;
201
202 GV.setInitializer(nullptr);
203 GV.setLinkage(GlobalValue::ExternalLinkage);
Peter Collingbourne20a00932017-01-18 20:03:02 +0000204 GV.setComdat(nullptr);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000205 GV.clearMetadata();
206 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000207}
208
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000209void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
210 if (auto *F = dyn_cast<Function>(C))
211 return Fn(F);
Peter Collingbourne3baa72a2017-03-02 23:10:17 +0000212 if (isa<GlobalValue>(C))
213 return;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000214 for (Value *Op : C->operands())
215 forEachVirtualFunction(cast<Constant>(Op), Fn);
216}
217
Peter Collingbourne1398a322016-12-16 00:26:30 +0000218// If it's possible to split M into regular and thin LTO parts, do so and write
219// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
220// regular LTO bitcode file to OS.
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000221void splitAndWriteThinLTOBitcode(
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000222 raw_ostream &OS, raw_ostream *ThinLinkOS,
223 function_ref<AAResults &(Function &)> AARGetter, Module &M) {
Evgeniy Stepanov964f4662017-04-27 20:27:27 +0000224 std::string ModuleId = getUniqueModuleId(&M);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000225 if (ModuleId.empty()) {
226 // We couldn't generate a module ID for this module, just write it out as a
227 // regular LTO module.
228 WriteBitcodeToFile(&M, OS);
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000229 if (ThinLinkOS)
230 // We don't have a ThinLTO part, but still write the module to the
231 // ThinLinkOS if requested so that the expected output file is produced.
232 WriteBitcodeToFile(&M, *ThinLinkOS);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000233 return;
234 }
235
236 promoteTypeIds(M, ModuleId);
237
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000238 // Returns whether a global has attached type metadata. Such globals may
239 // participate in CFI or whole-program devirtualization, so they need to
240 // appear in the merged module instead of the thin LTO module.
241 auto HasTypeMetadata = [&](const GlobalObject *GO) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000242 SmallVector<MDNode *, 1> MDs;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000243 GO->getMetadata(LLVMContext::MD_type, MDs);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000244 return !MDs.empty();
245 };
246
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000247 // Collect the set of virtual functions that are eligible for virtual constant
248 // propagation. Each eligible function must not access memory, must return
249 // an integer of width <=64 bits, must take at least one argument, must not
250 // use its first argument (assumed to be "this") and all arguments other than
251 // the first one must be of <=64 bit integer type.
252 //
253 // Note that we test whether this copy of the function is readnone, rather
254 // than testing function attributes, which must hold for any copy of the
255 // function, even a less optimized version substituted at link time. This is
256 // sound because the virtual constant propagation optimizations effectively
257 // inline all implementations of the virtual function into each call site,
258 // rather than using function attributes to perform local optimization.
259 std::set<const Function *> EligibleVirtualFns;
Bob Haarman4075ccc2017-04-12 01:43:07 +0000260 // If any member of a comdat lives in MergedM, put all members of that
261 // comdat in MergedM to keep the comdat together.
262 DenseSet<const Comdat *> MergedMComdats;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000263 for (GlobalVariable &GV : M.globals())
Bob Haarman4075ccc2017-04-12 01:43:07 +0000264 if (HasTypeMetadata(&GV)) {
265 if (const auto *C = GV.getComdat())
266 MergedMComdats.insert(C);
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000267 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
268 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
269 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
270 !F->arg_begin()->use_empty())
271 return;
272 for (auto &Arg : make_range(std::next(F->arg_begin()), F->arg_end())) {
273 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
274 if (!ArgT || ArgT->getBitWidth() > 64)
275 return;
276 }
277 if (computeFunctionBodyMemoryAccess(*F, AARGetter(*F)) == MAK_ReadNone)
278 EligibleVirtualFns.insert(F);
279 });
Bob Haarman4075ccc2017-04-12 01:43:07 +0000280 }
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000281
Peter Collingbourne1398a322016-12-16 00:26:30 +0000282 ValueToValueMapTy VMap;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000283 std::unique_ptr<Module> MergedM(
284 CloneModule(&M, VMap, [&](const GlobalValue *GV) -> bool {
Bob Haarman4075ccc2017-04-12 01:43:07 +0000285 if (const auto *C = GV->getComdat())
286 if (MergedMComdats.count(C))
287 return true;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000288 if (auto *F = dyn_cast<Function>(GV))
289 return EligibleVirtualFns.count(F);
290 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
291 return HasTypeMetadata(GVar);
292 return false;
293 }));
Peter Collingbourne28ffd322017-02-08 20:44:00 +0000294 StripDebugInfo(*MergedM);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000295
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000296 for (Function &F : *MergedM)
297 if (!F.isDeclaration()) {
298 // Reset the linkage of all functions eligible for virtual constant
299 // propagation. The canonical definitions live in the thin LTO module so
300 // that they can be imported.
301 F.setLinkage(GlobalValue::AvailableExternallyLinkage);
302 F.setComdat(nullptr);
303 }
304
Bob Haarman4075ccc2017-04-12 01:43:07 +0000305 // Remove all globals with type metadata, globals with comdats that live in
306 // MergedM, and aliases pointing to such globals from the thin LTO module.
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000307 filterModule(&M, [&](const GlobalValue *GV) {
308 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
Bob Haarman4075ccc2017-04-12 01:43:07 +0000309 if (HasTypeMetadata(GVar))
310 return false;
311 if (const auto *C = GV->getComdat())
312 if (MergedMComdats.count(C))
313 return false;
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000314 return true;
315 });
Peter Collingbourne1398a322016-12-16 00:26:30 +0000316
317 promoteInternals(*MergedM, M, ModuleId);
318 promoteInternals(M, *MergedM, ModuleId);
319
320 simplifyExternals(*MergedM);
321
Peter Collingbourne1398a322016-12-16 00:26:30 +0000322
323 // FIXME: Try to re-use BSI and PFI from the original module here.
Teresa Johnson94624ac2017-05-10 18:52:16 +0000324 ProfileSummaryInfo PSI(M);
325 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000326
327 SmallVector<char, 0> Buffer;
328
329 BitcodeWriter W(Buffer);
330 // Save the module hash produced for the full bitcode, which will
331 // be used in the backends, and use that in the minimized bitcode
332 // produced for the full link.
333 ModuleHash ModHash = {{0}};
Peter Collingbourne1398a322016-12-16 00:26:30 +0000334 W.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000335 /*GenerateHash=*/true, &ModHash);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000336 W.writeModule(MergedM.get());
Peter Collingbournea0f371a2017-04-17 17:51:36 +0000337 W.writeStrtab();
Peter Collingbourne1398a322016-12-16 00:26:30 +0000338 OS << Buffer;
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000339
340 // If a minimized bitcode module was requested for the thin link,
341 // strip the debug info (the merged module was already stripped above)
342 // and write it to the given OS.
343 if (ThinLinkOS) {
344 Buffer.clear();
345 BitcodeWriter W2(Buffer);
346 StripDebugInfo(M);
347 W2.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
348 /*GenerateHash=*/false, &ModHash);
349 W2.writeModule(MergedM.get());
Peter Collingbournea0f371a2017-04-17 17:51:36 +0000350 W2.writeStrtab();
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000351 *ThinLinkOS << Buffer;
352 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000353}
354
355// Returns whether this module needs to be split because it uses type metadata.
356bool requiresSplit(Module &M) {
357 SmallVector<MDNode *, 1> MDs;
358 for (auto &GO : M.global_objects()) {
359 GO.getMetadata(LLVMContext::MD_type, MDs);
360 if (!MDs.empty())
361 return true;
362 }
363
364 return false;
365}
366
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000367void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000368 function_ref<AAResults &(Function &)> AARGetter,
369 Module &M, const ModuleSummaryIndex *Index) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000370 // See if this module has any type metadata. If so, we need to split it.
371 if (requiresSplit(M))
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000372 return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000373
374 // Otherwise we can just write it out as a regular module.
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000375
376 // Save the module hash produced for the full bitcode, which will
377 // be used in the backends, and use that in the minimized bitcode
378 // produced for the full link.
379 ModuleHash ModHash = {{0}};
Peter Collingbourne1398a322016-12-16 00:26:30 +0000380 WriteBitcodeToFile(&M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000381 /*GenerateHash=*/true, &ModHash);
382 // If a minimized bitcode module was requested for the thin link,
383 // strip the debug info and write it to the given OS.
384 if (ThinLinkOS) {
385 StripDebugInfo(M);
386 WriteBitcodeToFile(&M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
387 Index,
388 /*GenerateHash=*/false, &ModHash);
389 }
Peter Collingbourne1398a322016-12-16 00:26:30 +0000390}
391
392class WriteThinLTOBitcode : public ModulePass {
393 raw_ostream &OS; // raw_ostream to print on
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000394 // The output stream on which to emit a minimized module for use
395 // just in the thin link, if requested.
396 raw_ostream *ThinLinkOS;
Peter Collingbourne1398a322016-12-16 00:26:30 +0000397
398public:
399 static char ID; // Pass identification, replacement for typeid
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000400 WriteThinLTOBitcode() : ModulePass(ID), OS(dbgs()), ThinLinkOS(nullptr) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000401 initializeWriteThinLTOBitcodePass(*PassRegistry::getPassRegistry());
402 }
403
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000404 explicit WriteThinLTOBitcode(raw_ostream &o, raw_ostream *ThinLinkOS)
405 : ModulePass(ID), OS(o), ThinLinkOS(ThinLinkOS) {
Peter Collingbourne1398a322016-12-16 00:26:30 +0000406 initializeWriteThinLTOBitcodePass(*PassRegistry::getPassRegistry());
407 }
408
409 StringRef getPassName() const override { return "ThinLTO Bitcode Writer"; }
410
411 bool runOnModule(Module &M) override {
412 const ModuleSummaryIndex *Index =
413 &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000414 writeThinLTOBitcode(OS, ThinLinkOS, LegacyAARGetter(*this), M, Index);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000415 return true;
416 }
417 void getAnalysisUsage(AnalysisUsage &AU) const override {
418 AU.setPreservesAll();
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000419 AU.addRequired<AssumptionCacheTracker>();
Peter Collingbourne1398a322016-12-16 00:26:30 +0000420 AU.addRequired<ModuleSummaryIndexWrapperPass>();
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000421 AU.addRequired<TargetLibraryInfoWrapperPass>();
Peter Collingbourne1398a322016-12-16 00:26:30 +0000422 }
423};
424} // anonymous namespace
425
426char WriteThinLTOBitcode::ID = 0;
427INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode",
428 "Write ThinLTO Bitcode", false, true)
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000429INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
Peter Collingbourne1398a322016-12-16 00:26:30 +0000430INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
Peter Collingbourne002c2d52017-02-14 03:42:38 +0000431INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
Peter Collingbourne1398a322016-12-16 00:26:30 +0000432INITIALIZE_PASS_END(WriteThinLTOBitcode, "write-thinlto-bitcode",
433 "Write ThinLTO Bitcode", false, true)
434
Teresa Johnson0c6a4ff2017-03-23 19:47:39 +0000435ModulePass *llvm::createWriteThinLTOBitcodePass(raw_ostream &Str,
436 raw_ostream *ThinLinkOS) {
437 return new WriteThinLTOBitcode(Str, ThinLinkOS);
Peter Collingbourne1398a322016-12-16 00:26:30 +0000438}