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