LLVM 24.0.0git
ThinLTOBitcodeWriter.cpp
Go to the documentation of this file.
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
15#include "llvm/IR/Constants.h"
16#include "llvm/IR/DebugInfo.h"
18#include "llvm/IR/Intrinsics.h"
19#include "llvm/IR/Module.h"
21#include "llvm/IR/PassManager.h"
23#include "llvm/Transforms/IPO.h"
29using namespace llvm;
30
31namespace {
32
33// Promote each local-linkage entity defined by ExportM and used by ImportM by
34// changing visibility and appending ".llvm." + ModuleId (matching
35// ModuleSummaryIndex::getGlobalNameForLocal so downstream PGO, SamplePGO,
36// MemProf, and linker symbol canonicalization strip the promotion suffix).
37void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
38 SetVector<GlobalValue *> *PromoteExtra = nullptr) {
40 for (auto &ExportGV : ExportM.global_values()) {
41 if (!ExportGV.hasLocalLinkage())
42 continue;
43
44 auto Name = ExportGV.getName();
45 GlobalValue *ImportGV = nullptr;
46 const bool MustPromote = PromoteExtra && PromoteExtra->count(&ExportGV);
47 if (!MustPromote) {
48 ImportGV = ImportM.getNamedValue(Name);
49 if (!ImportGV)
50 continue;
51 ImportGV->removeDeadConstantUsers();
52 if (ImportGV->use_empty()) {
53 ImportGV->eraseFromParent();
54 continue;
55 }
56 }
57
58 std::string NewName =
60
61 if (const auto *C = ExportGV.getComdat())
62 if (C->getName() == Name)
63 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
64
65 Constant *Aliasee = &ExportGV;
66 while (auto *GA = dyn_cast<GlobalAlias>(Aliasee))
67 Aliasee = GA->getAliasee();
68
69 // We must use the function's value type (FunctionType), not ptr - hence
70 // ExportGV.getValueType() rather than getType(). Otherwise, when an
71 // internal coroutine is imported into another module, IRMover sees a
72 // non-function value type for the unimported alias and materializes it as
73 // an external GlobalVariable rather than a Function declaration. That
74 // violates the verifier requirement that the coroutine argument of
75 // @llvm.coro.id must refer to a function. We could "pierce through" by
76 // stripping pointers, and cases other than coro do that, but this is
77 // cleaner.
78 auto *ExternalAlias = GlobalAlias::create(
79 ExportGV.getValueType(), ExportGV.getAddressSpace(),
80 GlobalValue::ExternalLinkage, NewName, Aliasee, &ExportM);
81 ExternalAlias->setVisibility(GlobalValue::HiddenVisibility);
82
83 if (MustPromote) {
84 ExportGV.replaceUsesWithIf(
85 ExternalAlias, [](Use &U) { return !isa<GlobalAlias>(U.getUser()); });
86 PromoteExtra->remove(&ExportGV);
87 PromoteExtra->insert(ExternalAlias);
88 }
89
90 if (ImportGV) {
91 ImportGV->setName(NewName);
93 ImportGV->reassignGUID();
94 }
95 }
96
97 if (!RenamedComdats.empty())
98 for (auto &GO : ExportM.global_objects())
99 if (auto *C = GO.getComdat()) {
100 auto Replacement = RenamedComdats.find(C);
101 if (Replacement != RenamedComdats.end())
102 GO.setComdat(Replacement->second);
103 }
104}
105
106// Promote all internal (i.e. distinct) type ids used by the module by replacing
107// them with external type ids formed using the module id.
108//
109// Note that this needs to be done before we clone the module because each clone
110// will receive its own set of distinct metadata nodes.
111void promoteTypeIds(Module &M, StringRef ModuleId) {
113 auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
114 Metadata *MD =
115 cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
116
117 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
118 Metadata *&GlobalMD = LocalToGlobal[MD];
119 if (!GlobalMD) {
120 std::string NewName =
121 (Twine(LocalToGlobal.size()) + "." + ModuleId).str();
122 GlobalMD = MDString::get(M.getContext(), NewName);
123 }
124
125 CI->setArgOperand(ArgNo,
126 MetadataAsValue::get(M.getContext(), GlobalMD));
127 }
128 };
129
130 if (Function *TypeTestFunc =
131 Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test)) {
132 for (const Use &U : TypeTestFunc->uses()) {
133 auto CI = cast<CallInst>(U.getUser());
134 ExternalizeTypeId(CI, 1);
135 }
136 }
137
138 if (Function *PublicTypeTestFunc =
139 Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test)) {
140 for (const Use &U : PublicTypeTestFunc->uses()) {
141 auto CI = cast<CallInst>(U.getUser());
142 ExternalizeTypeId(CI, 1);
143 }
144 }
145
146 if (Function *TypeCheckedLoadFunc =
147 Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load)) {
148 for (const Use &U : TypeCheckedLoadFunc->uses()) {
149 auto CI = cast<CallInst>(U.getUser());
150 ExternalizeTypeId(CI, 2);
151 }
152 }
153
154 if (Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
155 &M, Intrinsic::type_checked_load_relative)) {
156 for (const Use &U : TypeCheckedLoadRelativeFunc->uses()) {
157 auto CI = cast<CallInst>(U.getUser());
158 ExternalizeTypeId(CI, 2);
159 }
160 }
161
162 for (GlobalObject &GO : M.global_objects()) {
164 GO.getMetadata(LLVMContext::MD_type, MDs);
165
166 GO.eraseMetadata(LLVMContext::MD_type);
167 for (auto *MD : MDs) {
168 auto I = LocalToGlobal.find(MD->getOperand(1));
169 if (I == LocalToGlobal.end()) {
170 GO.addMetadata(LLVMContext::MD_type, *MD);
171 continue;
172 }
173 GO.addMetadata(
174 LLVMContext::MD_type,
175 *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
176 }
177
179 GO.getMetadata(LLVMContext::MD_callgraph, CGMDs);
180
181 GO.eraseMetadata(LLVMContext::MD_callgraph);
182 for (auto *MD : CGMDs) {
183 if (MD->getNumOperands() == 1) {
184 auto I = LocalToGlobal.find(MD->getOperand(0));
185 if (I == LocalToGlobal.end()) {
186 GO.addMetadata(LLVMContext::MD_callgraph, *MD);
187 continue;
188 }
189 GO.addMetadata(LLVMContext::MD_callgraph,
190 *MDNode::get(M.getContext(), {I->second}));
191 }
192 }
193 }
194}
195
196// Drop unused globals, and drop type information from function declarations.
197// FIXME: If we made functions typeless then there would be no need to do this.
198void simplifyExternals(Module &M) {
199 FunctionType *EmptyFT =
200 FunctionType::get(Type::getVoidTy(M.getContext()), false);
201
203 if (F.isDeclaration() && F.use_empty()) {
204 F.eraseFromParent();
205 continue;
206 }
207
208 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
209 // Changing the type of an intrinsic may invalidate the IR.
210 F.getName().starts_with("llvm."))
211 continue;
212
214 F.getAddressSpace(), "", &M);
215 NewF->copyAttributesFrom(&F);
216 // Only copy function attribtues.
217 NewF->setAttributes(AttributeList::get(M.getContext(),
218 AttributeList::FunctionIndex,
219 F.getAttributes().getFnAttrs()));
220 NewF->takeName(&F);
221 NewF->setMetadata(LLVMContext::MD_guid,
222 F.getMetadata(LLVMContext::MD_guid));
223 F.replaceAllUsesWith(NewF);
224 F.eraseFromParent();
225 }
226
227 for (GlobalIFunc &I : llvm::make_early_inc_range(M.ifuncs())) {
228 if (I.use_empty())
229 I.eraseFromParent();
230 else
231 assert(I.getResolverFunction() && "ifunc misses its resolver function");
232 }
233
234 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
235 if (GV.isDeclaration() && GV.use_empty()) {
236 GV.eraseFromParent();
237 continue;
238 }
239 }
240}
241
242static void
243filterModule(Module *M,
244 function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
245 std::vector<GlobalValue *> V;
246 for (GlobalValue &GV : M->global_values())
247 if (!ShouldKeepDefinition(&GV))
248 V.push_back(&GV);
249
250 for (GlobalValue *GV : V)
251 if (!convertToDeclaration(*GV))
252 GV->eraseFromParent();
253}
254
255void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
256 if (auto *F = dyn_cast<Function>(C))
257 return Fn(F);
258 if (isa<GlobalValue>(C))
259 return;
260 for (Value *Op : C->operands())
261 forEachVirtualFunction(cast<Constant>(Op), Fn);
262}
263
264// Clone any @llvm[.compiler].used over to the new module and append
265// values whose defs were cloned into that module.
266static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
267 bool CompilerUsed) {
269 // First collect those in the llvm[.compiler].used set.
270 collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
271 // Next build a set of the equivalent values defined in DestM.
272 for (auto *V : Used) {
273 auto *GV = DestM.getNamedValue(V->getName());
274 if (GV && !GV->isDeclaration())
275 NewUsed.push_back(GV);
276 }
277 // Finally, add them to a llvm[.compiler].used variable in DestM.
278 if (CompilerUsed)
279 appendToCompilerUsed(DestM, NewUsed);
280 else
281 appendToUsed(DestM, NewUsed);
282}
283
284#ifndef NDEBUG
285static bool enableUnifiedLTO(Module &M) {
286 bool UnifiedLTO = false;
287 if (auto *MD =
288 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("UnifiedLTO")))
289 UnifiedLTO = MD->getZExtValue();
290 return UnifiedLTO;
291}
292#endif
293
294bool mustEmitToMergedModule(const GlobalValue *GV) {
295 // The __cfi_check definition is filled in by the CrossDSOCFI pass which
296 // runs only in the merged module.
297 return GV->getName() == "__cfi_check";
298}
299
300// If it's possible to split M into regular and thin LTO parts, do so and write
301// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
302// regular LTO bitcode file to OS.
303void splitAndWriteThinLTOBitcode(
304 raw_ostream &OS, raw_ostream *ThinLinkOS,
305 function_ref<AAResults &(Function &)> AARGetter,
306 function_ref<const BlockFrequencyInfo &(Function &)> BFIGetter, Module &M,
307 const bool ShouldPreserveUseListOrder) {
308 std::string ModuleId = getUniqueModuleId(&M);
309 if (ModuleId.empty()) {
310 assert(!enableUnifiedLTO(M));
311 // We couldn't generate a module ID for this module, write it out as a
312 // regular LTO module with an index for summary-based dead stripping.
313 ProfileSummaryInfo PSI(M);
314 M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
315 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
316 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, &Index,
317 /*UnifiedLTO=*/false);
318
319 if (ThinLinkOS)
320 // We don't have a ThinLTO part, but still write the module to the
321 // ThinLinkOS if requested so that the expected output file is produced.
322 WriteBitcodeToFile(M, *ThinLinkOS, ShouldPreserveUseListOrder, &Index,
323 /*UnifiedLTO=*/false);
324
325 return;
326 }
327
328 promoteTypeIds(M, ModuleId);
329
330 // Collect the set of virtual functions that are eligible for virtual constant
331 // propagation. Each eligible function must not access memory, must return
332 // an integer of width <=64 bits, must take at least one argument, must not
333 // use its first argument (assumed to be "this") and all arguments other than
334 // the first one must be of <=64 bit integer type.
335 //
336 // Note that we test whether this copy of the function is readnone, rather
337 // than testing function attributes, which must hold for any copy of the
338 // function, even a less optimized version substituted at link time. This is
339 // sound because the virtual constant propagation optimizations effectively
340 // inline all implementations of the virtual function into each call site,
341 // rather than using function attributes to perform local optimization.
342 DenseSet<const Function *> EligibleVirtualFns;
343 // If any member of a comdat lives in MergedM, put all members of that
344 // comdat in MergedM to keep the comdat together.
345 DenseSet<const Comdat *> MergedMComdats;
346 for (GlobalVariable &GV : M.globals())
348 if (const auto *C = GV.getComdat())
349 MergedMComdats.insert(C);
350 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
351 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
352 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
353 !F->arg_begin()->use_empty())
354 return;
355 for (auto &Arg : drop_begin(F->args())) {
356 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
357 if (!ArgT || ArgT->getBitWidth() > 64)
358 return;
359 }
360 if (!F->isDeclaration() &&
361 computeFunctionBodyMemoryAccess(*F, AARGetter(*F))
362 .doesNotAccessMemory())
363 EligibleVirtualFns.insert(F);
364 });
365 }
366
368 std::unique_ptr<Module> MergedM(
369 CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
370 if (const auto *C = GV->getComdat())
371 if (MergedMComdats.count(C))
372 return true;
373 if (mustEmitToMergedModule(GV))
374 return true;
375 if (auto *F = dyn_cast<Function>(GV))
376 return EligibleVirtualFns.count(F);
377 if (auto *GVar =
380 return false;
381 }));
382 StripDebugInfo(*MergedM);
383 MergedM->removeModuleInlineAsm();
384
385 // Clone any llvm.*used globals to ensure the included values are
386 // not deleted.
387 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
388 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
389
390 for (Function &F : *MergedM)
391 if (!F.isDeclaration() && !mustEmitToMergedModule(&F)) {
392 // Reset the linkage of all functions eligible for virtual constant
393 // propagation. The canonical definitions live in the thin LTO module so
394 // that they can be imported.
396 F.setComdat(nullptr);
397 }
398
400
401 // Remove all globals with type metadata, globals with comdats that live in
402 // MergedM, and aliases pointing to such globals from the thin LTO module.
403 filterModule(&M, [&](const GlobalValue *GV) {
406 return false;
407 if (const auto *C = GV->getComdat())
408 if (MergedMComdats.count(C))
409 return false;
410 if (mustEmitToMergedModule(GV))
411 return false;
412 return true;
413 });
414
415 // CfiFunctions contains only symbols from M. promoteInternals tries to find
416 // match values from its first argument (the "exporting module") in
417 // CfiFunctions. So we only need CfiFunctions for the second promotion (M ->
418 // MergedM)
419 promoteInternals(*MergedM, M, ModuleId, nullptr);
420 promoteInternals(M, *MergedM, ModuleId, &CfiFunctions);
421
422 // FIXME: Try to re-use PSI from the original module here.
423 ProfileSummaryInfo PSI(M);
424
425 lowertypetests::createCfiMetadata(*MergedM, M, CfiFunctions.getArrayRef(),
426 PSI, BFIGetter);
427
428 simplifyExternals(*MergedM);
429
430 // FIXME: Try to re-use BSI from the original module here.
431 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
432
433 // Mark the merged module as requiring full LTO. We still want an index for
434 // it though, so that it can participate in summary-based dead stripping.
435 MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
436 ModuleSummaryIndex MergedMIndex =
437 buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
438
440
441 BitcodeWriter W(Buffer);
442 // Save the module hash produced for the full bitcode, which will
443 // be used in the backends, and use that in the minimized bitcode
444 // produced for the full link.
445 ModuleHash ModHash = {{0}};
446 W.writeModule(M, ShouldPreserveUseListOrder, &Index,
447 /*GenerateHash=*/true, &ModHash);
448 W.writeModule(*MergedM, ShouldPreserveUseListOrder, &MergedMIndex);
449 W.writeSymtab();
450 W.writeStrtab();
451 OS << Buffer;
452
453 // If a minimized bitcode module was requested for the thin link, only
454 // the information that is needed by thin link will be written in the
455 // given OS (the merged module will be written as usual).
456 if (ThinLinkOS) {
457 Buffer.clear();
458 BitcodeWriter W2(Buffer);
460 W2.writeThinLinkBitcode(M, Index, ModHash);
461 W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
462 &MergedMIndex);
463 W2.writeSymtab();
464 W2.writeStrtab();
465 *ThinLinkOS << Buffer;
466 }
467}
468
469// Check if the LTO Unit splitting has been enabled.
470bool enableSplitLTOUnit(Module &M) {
471 bool EnableSplitLTOUnit = false;
473 M.getModuleFlag("EnableSplitLTOUnit")))
474 EnableSplitLTOUnit = MD->getZExtValue();
475 return EnableSplitLTOUnit;
476}
477
478// Returns whether this module needs to be split (if splitting is enabled).
479bool requiresSplit(Module &M) {
480 for (auto &GO : M.global_objects()) {
481 if (GO.hasMetadata(LLVMContext::MD_type))
482 return true;
483 if (mustEmitToMergedModule(&GO))
484 return true;
485 }
486 return false;
487}
488
489bool writeThinLTOBitcode(
490 raw_ostream &OS, raw_ostream *ThinLinkOS,
491 function_ref<AAResults &(Function &)> AARGetter,
492 function_ref<const BlockFrequencyInfo &(Function &)> BFIGetter, Module &M,
493 const ModuleSummaryIndex *Index, const bool ShouldPreserveUseListOrder) {
494 std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
495 // See if this module needs to be split. If so, we try to split it
496 // or at least promote type ids to enable WPD.
497 if (requiresSplit(M)) {
498 if (enableSplitLTOUnit(M)) {
499 splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, BFIGetter, M,
500 ShouldPreserveUseListOrder);
501 return true;
502 }
503 // Promote type ids as needed for index-based WPD.
504 std::string ModuleId = getUniqueModuleId(&M);
505 if (!ModuleId.empty()) {
506 promoteTypeIds(M, ModuleId);
507 // Need to rebuild the index so that it contains type metadata
508 // for the newly promoted type ids.
509 // FIXME: Probably should not bother building the index at all
510 // in the caller of writeThinLTOBitcode (which does so via the
511 // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
512 // anyway whenever there is type metadata (here or in
513 // splitAndWriteThinLTOBitcode). Just always build it once via the
514 // buildModuleSummaryIndex when Module(s) are ready.
515 ProfileSummaryInfo PSI(M);
516 NewIndex = std::make_unique<ModuleSummaryIndex>(
517 buildModuleSummaryIndex(M, nullptr, &PSI));
518 Index = NewIndex.get();
519 }
520 }
521
522 // Write it out as an unsplit ThinLTO module.
523
524 // Save the module hash produced for the full bitcode, which will
525 // be used in the backends, and use that in the minimized bitcode
526 // produced for the full link.
527 ModuleHash ModHash = {{0}};
528 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index,
529 /*GenerateHash=*/true, &ModHash);
530 // If a minimized bitcode module was requested for the thin link, only
531 // the information that is needed by thin link will be written in the
532 // given OS.
533 if (ThinLinkOS && Index)
534 writeThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
535 return false;
536}
537
538} // anonymous namespace
539
544
545 bool Changed = writeThinLTOBitcode(
546 OS, ThinLinkOS,
547 [&FAM](Function &F) -> AAResults & {
548 return FAM.getResult<AAManager>(F);
549 },
550 [&FAM](Function &F) -> const BlockFrequencyInfo & {
551 return FAM.getResult<BlockFrequencyAnalysis>(F);
552 },
554 ShouldPreserveUseListOrder);
555
557}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This is the interface for LLVM's primary stateless and local alias analysis.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Provides passes for computing function attributes based on interprocedural analyses.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This is the interface to build a ModuleSummaryIndex for a module.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
FunctionAnalysisManager FAM
if(PassOpts->AAPipeline)
A manager for alias analyses.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
Definition Constant.h:44
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
bool empty() const
Definition DenseMap.h:716
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
unsigned size() const
Definition DenseMap.h:717
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:856
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:169
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition Function.h:332
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition Function.cpp:846
static LLVM_ABI GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition Globals.cpp:692
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:408
LLVM_ABI const Comdat * getComdat() const
Definition Globals.cpp:274
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:521
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:158
@ HiddenVisibility
The GV is hidden.
Definition GlobalValue.h:69
void setVisibility(VisibilityTypes V)
LLVM_ABI void reassignGUID()
Recompute and assign a GUID to this value, replacing the existing GUID.
Definition Globals.cpp:96
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:595
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:105
Root of the metadata hierarchy.
Definition Metadata.h:64
Analysis pass to provide the ModuleSummaryIndex object.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition Module.h:121
iterator_range< global_object_iterator > global_objects()
Definition Module.cpp:480
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition Module.cpp:177
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition Module.cpp:650
iterator_range< global_value_iterator > global_values()
Definition Module.cpp:488
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Analysis providing profile information.
A vector that has set insertion semantics.
Definition SetVector.h:57
ArrayRef< value_type > getArrayRef() const
Definition SetVector.h:91
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:272
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:389
bool use_empty() const
Definition Value.h:348
iterator_range< use_iterator > uses()
Definition Value.h:382
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Definition Value.cpp:395
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:188
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI void createCfiMetadata(Module &DestM, const Module &SrcM, ArrayRef< GlobalValue * > CfiFunctions, ProfileSummaryInfo &PSI, function_ref< const BlockFrequencyInfo &(Function &)> BFIGetter)
Creates cfi.functions, aliases, and symvers named metadata in DestM for CFI functions in CfiFunctions...
LLVM_ABI bool hasTypeMetadata(const GlobalObject &GO)
Returns whether a global or its associated global has attached type metadata.
LLVM_ABI SetVector< GlobalValue * > findCfiFunctions(Module &M)
Finds all functions and aliases in M that may need CFI jump table entries.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition Metadata.h:694
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MemoryEffects computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
LLVM_ABI bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback=[](const Function &F) -> const StackSafetyInfo *{ return nullptr;})
Direct function to compute a ModuleSummaryIndex from a given module.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
DWARFExpression::Operation Op
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition Module.cpp:991