1//===- ThinLTOBitcodeWriter.cpp - Bitcode writing pass for ThinLTO --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
10#include "llvm/Analysis/BasicAliasAnalysis.h"
11#include "llvm/Analysis/BlockFrequencyInfo.h"
12#include "llvm/Analysis/ModuleSummaryAnalysis.h"
13#include "llvm/Analysis/ProfileSummaryInfo.h"
14#include "llvm/Bitcode/BitcodeWriter.h"
15#include "llvm/IR/Constants.h"
16#include "llvm/IR/DebugInfo.h"
17#include "llvm/IR/Instructions.h"
18#include "llvm/IR/Intrinsics.h"
19#include "llvm/IR/Module.h"
20#include "llvm/IR/PassManager.h"
21#include "llvm/Support/raw_ostream.h"
22#include "llvm/Transforms/IPO.h"
23#include "llvm/Transforms/IPO/FunctionAttrs.h"
24#include "llvm/Transforms/IPO/FunctionImport.h"
25#include "llvm/Transforms/IPO/LowerTypeTests.h"
26#include "llvm/Transforms/Utils/Cloning.h"
27#include "llvm/Transforms/Utils/ModuleUtils.h"
28using namespace llvm;
29
30namespace {
31
32// Determine if a promotion alias should be created for a symbol name.
33static bool allowPromotionAlias(const std::string &Name) {
34 // Promotion aliases are used only in inline assembly. It's safe to
35 // simply skip unusual names. Subset of MCAsmInfo::isAcceptableChar().
36 for (const char &C : Name) {
37 if (isAlnum(C) || C == '_' || C == '.')
38 continue;
39 return false;
40 }
41 return true;
42}
43
44// Promote each local-linkage entity defined by ExportM and used by ImportM by
45// changing visibility and appending the given ModuleId.
46void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
47 const SetVector<GlobalValue *> &PromoteExtra) {
48 DenseMap<const Comdat *, Comdat *> RenamedComdats;
49 for (auto &ExportGV : ExportM.global_values()) {
50 if (!ExportGV.hasLocalLinkage())
51 continue;
52
53 auto Name = ExportGV.getName();
54 GlobalValue *ImportGV = nullptr;
55 if (!PromoteExtra.count(key: &ExportGV)) {
56 ImportGV = ImportM.getNamedValue(Name);
57 if (!ImportGV)
58 continue;
59 ImportGV->removeDeadConstantUsers();
60 if (ImportGV->use_empty()) {
61 ImportGV->eraseFromParent();
62 continue;
63 }
64 }
65
66 std::string OldName = Name.str();
67 std::string NewName = (Name + ModuleId).str();
68
69 if (const auto *C = ExportGV.getComdat())
70 if (C->getName() == Name)
71 RenamedComdats.try_emplace(Key: C, Args: ExportM.getOrInsertComdat(Name: NewName));
72
73 ExportGV.setName(NewName);
74 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
75 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
76 // TODO: remove this reassign and instead create an alias.
77 ExportGV.reassignGUID();
78 if (ImportGV) {
79 ImportGV->setName(NewName);
80 ImportGV->setVisibility(GlobalValue::HiddenVisibility);
81 ImportGV->reassignGUID();
82 }
83
84 if (isa<Function>(Val: &ExportGV) && allowPromotionAlias(Name: OldName)) {
85 // Create a local alias with the original name to avoid breaking
86 // references from inline assembly.
87 std::string Alias =
88 ".lto_set_conditional " + OldName + "," + NewName + "\n";
89 ExportM.appendModuleInlineAsm(Fragment: Alias);
90 }
91 }
92
93 if (!RenamedComdats.empty())
94 for (auto &GO : ExportM.global_objects())
95 if (auto *C = GO.getComdat()) {
96 auto Replacement = RenamedComdats.find(Val: C);
97 if (Replacement != RenamedComdats.end())
98 GO.setComdat(Replacement->second);
99 }
100}
101
102// Promote all internal (i.e. distinct) type ids used by the module by replacing
103// them with external type ids formed using the module id.
104//
105// Note that this needs to be done before we clone the module because each clone
106// will receive its own set of distinct metadata nodes.
107void promoteTypeIds(Module &M, StringRef ModuleId) {
108 DenseMap<Metadata *, Metadata *> LocalToGlobal;
109 auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
110 Metadata *MD =
111 cast<MetadataAsValue>(Val: CI->getArgOperand(i: ArgNo))->getMetadata();
112
113 if (isa<MDNode>(Val: MD) && cast<MDNode>(Val: MD)->isDistinct()) {
114 Metadata *&GlobalMD = LocalToGlobal[MD];
115 if (!GlobalMD) {
116 std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
117 GlobalMD = MDString::get(Context&: M.getContext(), Str: NewName);
118 }
119
120 CI->setArgOperand(i: ArgNo,
121 v: MetadataAsValue::get(Context&: M.getContext(), MD: GlobalMD));
122 }
123 };
124
125 if (Function *TypeTestFunc =
126 Intrinsic::getDeclarationIfExists(M: &M, id: Intrinsic::type_test)) {
127 for (const Use &U : TypeTestFunc->uses()) {
128 auto CI = cast<CallInst>(Val: U.getUser());
129 ExternalizeTypeId(CI, 1);
130 }
131 }
132
133 if (Function *PublicTypeTestFunc =
134 Intrinsic::getDeclarationIfExists(M: &M, id: Intrinsic::public_type_test)) {
135 for (const Use &U : PublicTypeTestFunc->uses()) {
136 auto CI = cast<CallInst>(Val: U.getUser());
137 ExternalizeTypeId(CI, 1);
138 }
139 }
140
141 if (Function *TypeCheckedLoadFunc =
142 Intrinsic::getDeclarationIfExists(M: &M, id: Intrinsic::type_checked_load)) {
143 for (const Use &U : TypeCheckedLoadFunc->uses()) {
144 auto CI = cast<CallInst>(Val: U.getUser());
145 ExternalizeTypeId(CI, 2);
146 }
147 }
148
149 if (Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
150 M: &M, id: Intrinsic::type_checked_load_relative)) {
151 for (const Use &U : TypeCheckedLoadRelativeFunc->uses()) {
152 auto CI = cast<CallInst>(Val: U.getUser());
153 ExternalizeTypeId(CI, 2);
154 }
155 }
156
157 for (GlobalObject &GO : M.global_objects()) {
158 SmallVector<MDNode *, 1> MDs;
159 GO.getMetadata(KindID: LLVMContext::MD_type, MDs);
160
161 GO.eraseMetadata(KindID: LLVMContext::MD_type);
162 for (auto *MD : MDs) {
163 auto I = LocalToGlobal.find(Val: MD->getOperand(I: 1));
164 if (I == LocalToGlobal.end()) {
165 GO.addMetadata(KindID: LLVMContext::MD_type, MD&: *MD);
166 continue;
167 }
168 GO.addMetadata(
169 KindID: LLVMContext::MD_type,
170 MD&: *MDNode::get(Context&: M.getContext(), MDs: {MD->getOperand(I: 0), I->second}));
171 }
172
173 SmallVector<MDNode *, 1> CGMDs;
174 GO.getMetadata(KindID: LLVMContext::MD_callgraph, MDs&: CGMDs);
175
176 GO.eraseMetadata(KindID: LLVMContext::MD_callgraph);
177 for (auto *MD : CGMDs) {
178 if (MD->getNumOperands() == 1) {
179 auto I = LocalToGlobal.find(Val: MD->getOperand(I: 0));
180 if (I == LocalToGlobal.end()) {
181 GO.addMetadata(KindID: LLVMContext::MD_callgraph, MD&: *MD);
182 continue;
183 }
184 GO.addMetadata(KindID: LLVMContext::MD_callgraph,
185 MD&: *MDNode::get(Context&: M.getContext(), MDs: {I->second}));
186 }
187 }
188 }
189}
190
191// Drop unused globals, and drop type information from function declarations.
192// FIXME: If we made functions typeless then there would be no need to do this.
193void simplifyExternals(Module &M) {
194 FunctionType *EmptyFT =
195 FunctionType::get(Result: Type::getVoidTy(C&: M.getContext()), isVarArg: false);
196
197 for (Function &F : llvm::make_early_inc_range(Range&: M)) {
198 if (F.isDeclaration() && F.use_empty()) {
199 F.eraseFromParent();
200 continue;
201 }
202
203 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
204 // Changing the type of an intrinsic may invalidate the IR.
205 F.getName().starts_with(Prefix: "llvm."))
206 continue;
207
208 Function *NewF = Function::Create(Ty: EmptyFT, Linkage: GlobalValue::ExternalLinkage,
209 AddrSpace: F.getAddressSpace(), N: "", M: &M);
210 NewF->copyAttributesFrom(Src: &F);
211 // Only copy function attribtues.
212 NewF->setAttributes(AttributeList::get(C&: M.getContext(),
213 Index: AttributeList::FunctionIndex,
214 Attrs: F.getAttributes().getFnAttrs()));
215 NewF->takeName(V: &F);
216 NewF->setMetadata(KindID: LLVMContext::MD_guid,
217 Node: F.getMetadata(KindID: LLVMContext::MD_guid));
218 F.replaceAllUsesWith(V: NewF);
219 F.eraseFromParent();
220 }
221
222 for (GlobalIFunc &I : llvm::make_early_inc_range(Range: M.ifuncs())) {
223 if (I.use_empty())
224 I.eraseFromParent();
225 else
226 assert(I.getResolverFunction() && "ifunc misses its resolver function");
227 }
228
229 for (GlobalVariable &GV : llvm::make_early_inc_range(Range: M.globals())) {
230 if (GV.isDeclaration() && GV.use_empty()) {
231 GV.eraseFromParent();
232 continue;
233 }
234 }
235}
236
237static void
238filterModule(Module *M,
239 function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
240 std::vector<GlobalValue *> V;
241 for (GlobalValue &GV : M->global_values())
242 if (!ShouldKeepDefinition(&GV))
243 V.push_back(x: &GV);
244
245 for (GlobalValue *GV : V)
246 if (!convertToDeclaration(GV&: *GV))
247 GV->eraseFromParent();
248}
249
250void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
251 if (auto *F = dyn_cast<Function>(Val: C))
252 return Fn(F);
253 if (isa<GlobalValue>(Val: C))
254 return;
255 for (Value *Op : C->operands())
256 forEachVirtualFunction(C: cast<Constant>(Val: Op), Fn);
257}
258
259// Clone any @llvm[.compiler].used over to the new module and append
260// values whose defs were cloned into that module.
261static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
262 bool CompilerUsed) {
263 SmallVector<GlobalValue *, 4> Used, NewUsed;
264 // First collect those in the llvm[.compiler].used set.
265 collectUsedGlobalVariables(M: SrcM, Vec&: Used, CompilerUsed);
266 // Next build a set of the equivalent values defined in DestM.
267 for (auto *V : Used) {
268 auto *GV = DestM.getNamedValue(Name: V->getName());
269 if (GV && !GV->isDeclaration())
270 NewUsed.push_back(Elt: GV);
271 }
272 // Finally, add them to a llvm[.compiler].used variable in DestM.
273 if (CompilerUsed)
274 appendToCompilerUsed(M&: DestM, Values: NewUsed);
275 else
276 appendToUsed(M&: DestM, Values: NewUsed);
277}
278
279#ifndef NDEBUG
280static bool enableUnifiedLTO(Module &M) {
281 bool UnifiedLTO = false;
282 if (auto *MD =
283 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("UnifiedLTO")))
284 UnifiedLTO = MD->getZExtValue();
285 return UnifiedLTO;
286}
287#endif
288
289bool mustEmitToMergedModule(const GlobalValue *GV) {
290 // The __cfi_check definition is filled in by the CrossDSOCFI pass which
291 // runs only in the merged module.
292 return GV->getName() == "__cfi_check";
293}
294
295// If it's possible to split M into regular and thin LTO parts, do so and write
296// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
297// regular LTO bitcode file to OS.
298void splitAndWriteThinLTOBitcode(
299 raw_ostream &OS, raw_ostream *ThinLinkOS,
300 function_ref<AAResults &(Function &)> AARGetter,
301 function_ref<const BlockFrequencyInfo &(Function &)> BFIGetter, Module &M,
302 const bool ShouldPreserveUseListOrder) {
303 std::string ModuleId = getUniqueModuleId(M: &M);
304 if (ModuleId.empty()) {
305 assert(!enableUnifiedLTO(M));
306 // We couldn't generate a module ID for this module, write it out as a
307 // regular LTO module with an index for summary-based dead stripping.
308 ProfileSummaryInfo PSI(M);
309 M.addModuleFlag(Behavior: Module::Error, Key: "ThinLTO", Val: uint32_t(0));
310 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, GetBFICallback: nullptr, PSI: &PSI);
311 WriteBitcodeToFile(M, Out&: OS, ShouldPreserveUseListOrder, Index: &Index,
312 /*UnifiedLTO=*/GenerateHash: false);
313
314 if (ThinLinkOS)
315 // We don't have a ThinLTO part, but still write the module to the
316 // ThinLinkOS if requested so that the expected output file is produced.
317 WriteBitcodeToFile(M, Out&: *ThinLinkOS, ShouldPreserveUseListOrder, Index: &Index,
318 /*UnifiedLTO=*/GenerateHash: false);
319
320 return;
321 }
322
323 promoteTypeIds(M, ModuleId);
324
325 // Collect the set of virtual functions that are eligible for virtual constant
326 // propagation. Each eligible function must not access memory, must return
327 // an integer of width <=64 bits, must take at least one argument, must not
328 // use its first argument (assumed to be "this") and all arguments other than
329 // the first one must be of <=64 bit integer type.
330 //
331 // Note that we test whether this copy of the function is readnone, rather
332 // than testing function attributes, which must hold for any copy of the
333 // function, even a less optimized version substituted at link time. This is
334 // sound because the virtual constant propagation optimizations effectively
335 // inline all implementations of the virtual function into each call site,
336 // rather than using function attributes to perform local optimization.
337 DenseSet<const Function *> EligibleVirtualFns;
338 // If any member of a comdat lives in MergedM, put all members of that
339 // comdat in MergedM to keep the comdat together.
340 DenseSet<const Comdat *> MergedMComdats;
341 for (GlobalVariable &GV : M.globals())
342 if (!GV.isDeclaration() && lowertypetests::hasTypeMetadata(GO: GV)) {
343 if (const auto *C = GV.getComdat())
344 MergedMComdats.insert(V: C);
345 forEachVirtualFunction(C: GV.getInitializer(), Fn: [&](Function *F) {
346 auto *RT = dyn_cast<IntegerType>(Val: F->getReturnType());
347 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
348 !F->arg_begin()->use_empty())
349 return;
350 for (auto &Arg : drop_begin(RangeOrContainer: F->args())) {
351 auto *ArgT = dyn_cast<IntegerType>(Val: Arg.getType());
352 if (!ArgT || ArgT->getBitWidth() > 64)
353 return;
354 }
355 if (!F->isDeclaration() &&
356 computeFunctionBodyMemoryAccess(F&: *F, AAR&: AARGetter(*F))
357 .doesNotAccessMemory())
358 EligibleVirtualFns.insert(V: F);
359 });
360 }
361
362 ValueToValueMapTy VMap;
363 std::unique_ptr<Module> MergedM(
364 CloneModule(M, VMap, ShouldCloneDefinition: [&](const GlobalValue *GV) -> bool {
365 if (const auto *C = GV->getComdat())
366 if (MergedMComdats.count(V: C))
367 return true;
368 if (mustEmitToMergedModule(GV))
369 return true;
370 if (auto *F = dyn_cast<Function>(Val: GV))
371 return EligibleVirtualFns.count(V: F);
372 if (auto *GVar =
373 dyn_cast_or_null<GlobalVariable>(Val: GV->getAliaseeObject()))
374 return lowertypetests::hasTypeMetadata(GO: *GVar);
375 return false;
376 }));
377 StripDebugInfo(M&: *MergedM);
378 MergedM->removeModuleInlineAsm();
379
380 // Clone any llvm.*used globals to ensure the included values are
381 // not deleted.
382 cloneUsedGlobalVariables(SrcM: M, DestM&: *MergedM, /*CompilerUsed*/ false);
383 cloneUsedGlobalVariables(SrcM: M, DestM&: *MergedM, /*CompilerUsed*/ true);
384
385 for (Function &F : *MergedM)
386 if (!F.isDeclaration() && !mustEmitToMergedModule(GV: &F)) {
387 // Reset the linkage of all functions eligible for virtual constant
388 // propagation. The canonical definitions live in the thin LTO module so
389 // that they can be imported.
390 F.setLinkage(GlobalValue::AvailableExternallyLinkage);
391 F.setComdat(nullptr);
392 }
393
394 SetVector<GlobalValue *> CfiFunctions = lowertypetests::findCfiFunctions(M);
395
396 // Remove all globals with type metadata, globals with comdats that live in
397 // MergedM, and aliases pointing to such globals from the thin LTO module.
398 filterModule(M: &M, ShouldKeepDefinition: [&](const GlobalValue *GV) {
399 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(Val: GV->getAliaseeObject()))
400 if (lowertypetests::hasTypeMetadata(GO: *GVar))
401 return false;
402 if (const auto *C = GV->getComdat())
403 if (MergedMComdats.count(V: C))
404 return false;
405 if (mustEmitToMergedModule(GV))
406 return false;
407 return true;
408 });
409
410 // CfiFunctions contains only symbols from M. promoteInternals tries to find
411 // match values from its first argument (the "exporting module") in
412 // CfiFunctions. So we only need CfiFunctions for the second promotion (M ->
413 // MergedM)
414 promoteInternals(ExportM&: *MergedM, ImportM&: M, ModuleId, PromoteExtra: {});
415 promoteInternals(ExportM&: M, ImportM&: *MergedM, ModuleId, PromoteExtra: CfiFunctions);
416
417 // FIXME: Try to re-use PSI from the original module here.
418 ProfileSummaryInfo PSI(M);
419
420 lowertypetests::createCfiMetadata(DestM&: *MergedM, SrcM: M, CfiFunctions: CfiFunctions.getArrayRef(),
421 PSI, BFIGetter);
422
423 simplifyExternals(M&: *MergedM);
424
425 // FIXME: Try to re-use BSI from the original module here.
426 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, GetBFICallback: nullptr, PSI: &PSI);
427
428 // Mark the merged module as requiring full LTO. We still want an index for
429 // it though, so that it can participate in summary-based dead stripping.
430 MergedM->addModuleFlag(Behavior: Module::Error, Key: "ThinLTO", Val: uint32_t(0));
431 ModuleSummaryIndex MergedMIndex =
432 buildModuleSummaryIndex(M: *MergedM, GetBFICallback: nullptr, PSI: &PSI);
433
434 SmallVector<char, 0> Buffer;
435
436 BitcodeWriter W(Buffer);
437 // Save the module hash produced for the full bitcode, which will
438 // be used in the backends, and use that in the minimized bitcode
439 // produced for the full link.
440 ModuleHash ModHash = {._M_elems: {0}};
441 W.writeModule(M, ShouldPreserveUseListOrder, Index: &Index,
442 /*GenerateHash=*/true, ModHash: &ModHash);
443 W.writeModule(M: *MergedM, ShouldPreserveUseListOrder, Index: &MergedMIndex);
444 W.writeSymtab();
445 W.writeStrtab();
446 OS << Buffer;
447
448 // If a minimized bitcode module was requested for the thin link, only
449 // the information that is needed by thin link will be written in the
450 // given OS (the merged module will be written as usual).
451 if (ThinLinkOS) {
452 Buffer.clear();
453 BitcodeWriter W2(Buffer);
454 StripDebugInfo(M);
455 W2.writeThinLinkBitcode(M, Index, ModHash);
456 W2.writeModule(M: *MergedM, /*ShouldPreserveUseListOrder=*/false,
457 Index: &MergedMIndex);
458 W2.writeSymtab();
459 W2.writeStrtab();
460 *ThinLinkOS << Buffer;
461 }
462}
463
464// Check if the LTO Unit splitting has been enabled.
465bool enableSplitLTOUnit(Module &M) {
466 bool EnableSplitLTOUnit = false;
467 if (auto *MD = mdconst::extract_or_null<ConstantInt>(
468 MD: M.getModuleFlag(Key: "EnableSplitLTOUnit")))
469 EnableSplitLTOUnit = MD->getZExtValue();
470 return EnableSplitLTOUnit;
471}
472
473// Returns whether this module needs to be split (if splitting is enabled).
474bool requiresSplit(Module &M) {
475 for (auto &GO : M.global_objects()) {
476 if (GO.hasMetadata(KindID: LLVMContext::MD_type))
477 return true;
478 if (mustEmitToMergedModule(GV: &GO))
479 return true;
480 }
481 return false;
482}
483
484bool writeThinLTOBitcode(
485 raw_ostream &OS, raw_ostream *ThinLinkOS,
486 function_ref<AAResults &(Function &)> AARGetter,
487 function_ref<const BlockFrequencyInfo &(Function &)> BFIGetter, Module &M,
488 const ModuleSummaryIndex *Index, const bool ShouldPreserveUseListOrder) {
489 std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
490 // See if this module needs to be split. If so, we try to split it
491 // or at least promote type ids to enable WPD.
492 if (requiresSplit(M)) {
493 if (enableSplitLTOUnit(M)) {
494 splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, BFIGetter, M,
495 ShouldPreserveUseListOrder);
496 return true;
497 }
498 // Promote type ids as needed for index-based WPD.
499 std::string ModuleId = getUniqueModuleId(M: &M);
500 if (!ModuleId.empty()) {
501 promoteTypeIds(M, ModuleId);
502 // Need to rebuild the index so that it contains type metadata
503 // for the newly promoted type ids.
504 // FIXME: Probably should not bother building the index at all
505 // in the caller of writeThinLTOBitcode (which does so via the
506 // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
507 // anyway whenever there is type metadata (here or in
508 // splitAndWriteThinLTOBitcode). Just always build it once via the
509 // buildModuleSummaryIndex when Module(s) are ready.
510 ProfileSummaryInfo PSI(M);
511 NewIndex = std::make_unique<ModuleSummaryIndex>(
512 args: buildModuleSummaryIndex(M, GetBFICallback: nullptr, PSI: &PSI));
513 Index = NewIndex.get();
514 }
515 }
516
517 // Write it out as an unsplit ThinLTO module.
518
519 // Save the module hash produced for the full bitcode, which will
520 // be used in the backends, and use that in the minimized bitcode
521 // produced for the full link.
522 ModuleHash ModHash = {._M_elems: {0}};
523 WriteBitcodeToFile(M, Out&: OS, ShouldPreserveUseListOrder, Index,
524 /*GenerateHash=*/true, ModHash: &ModHash);
525 // If a minimized bitcode module was requested for the thin link, only
526 // the information that is needed by thin link will be written in the
527 // given OS.
528 if (ThinLinkOS && Index)
529 writeThinLinkBitcodeToFile(M, Out&: *ThinLinkOS, Index: *Index, ModHash);
530 return false;
531}
532
533} // anonymous namespace
534
535PreservedAnalyses
536llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
537 FunctionAnalysisManager &FAM =
538 AM.getResult<FunctionAnalysisManagerModuleProxy>(IR&: M).getManager();
539
540 bool Changed = writeThinLTOBitcode(
541 OS, ThinLinkOS,
542 AARGetter: [&FAM](Function &F) -> AAResults & {
543 return FAM.getResult<AAManager>(IR&: F);
544 },
545 BFIGetter: [&FAM](Function &F) -> const BlockFrequencyInfo & {
546 return FAM.getResult<BlockFrequencyAnalysis>(IR&: F);
547 },
548 M, Index: &AM.getResult<ModuleSummaryIndexAnalysis>(IR&: M),
549 ShouldPreserveUseListOrder);
550
551 return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
552}
553