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"
23#include "llvm/Transforms/IPO.h"
29using namespace llvm;
30
31namespace {
32
33// Determine if a promotion alias should be created for a symbol name.
34static bool allowPromotionAlias(const std::string &Name) {
35 // Promotion aliases are used only in inline assembly. It's safe to
36 // simply skip unusual names. Subset of MCAsmInfo::isAcceptableChar().
37 for (const char &C : Name) {
38 if (isAlnum(C) || C == '_' || C == '.')
39 continue;
40 return false;
41 }
42 return true;
43}
44
45// Promote each local-linkage entity defined by ExportM and used by ImportM by
46// changing visibility and appending the given ModuleId.
47void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
48 const SetVector<GlobalValue *> &PromoteExtra) {
50 for (auto &ExportGV : ExportM.global_values()) {
51 if (!ExportGV.hasLocalLinkage())
52 continue;
53
54 auto Name = ExportGV.getName();
55 GlobalValue *ImportGV = nullptr;
56 if (!PromoteExtra.count(&ExportGV)) {
57 ImportGV = ImportM.getNamedValue(Name);
58 if (!ImportGV)
59 continue;
60 ImportGV->removeDeadConstantUsers();
61 if (ImportGV->use_empty()) {
62 ImportGV->eraseFromParent();
63 continue;
64 }
65 }
66
67 std::string OldName = Name.str();
68 std::string NewName = (Name + ModuleId).str();
69
70 if (const auto *C = ExportGV.getComdat())
71 if (C->getName() == Name)
72 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
73
74 ExportGV.setName(NewName);
75 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
76 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
77 // TODO: remove this reassign and instead create an alias.
78 ExportGV.reassignGUID();
79 if (ImportGV) {
80 ImportGV->setName(NewName);
82 ImportGV->reassignGUID();
83 }
84
85 if (isa<Function>(&ExportGV) && allowPromotionAlias(OldName)) {
86 // Create a local alias with the original name to avoid breaking
87 // references from inline assembly.
88 std::string Alias =
89 ".lto_set_conditional " + OldName + "," + NewName + "\n";
90 ExportM.appendModuleInlineAsm(Alias);
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
209 Function *NewF =
211 F.getAddressSpace(), "", &M);
212 NewF->copyAttributesFrom(&F);
213 // Only copy function attribtues.
214 NewF->setAttributes(AttributeList::get(M.getContext(),
215 AttributeList::FunctionIndex,
216 F.getAttributes().getFnAttrs()));
217 NewF->takeName(&F);
218 NewF->setMetadata(LLVMContext::MD_guid,
219 F.getMetadata(LLVMContext::MD_guid));
220 F.replaceAllUsesWith(NewF);
221 F.eraseFromParent();
222 }
223
224 for (GlobalIFunc &I : llvm::make_early_inc_range(M.ifuncs())) {
225 if (I.use_empty())
226 I.eraseFromParent();
227 else
228 assert(I.getResolverFunction() && "ifunc misses its resolver function");
229 }
230
231 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
232 if (GV.isDeclaration() && GV.use_empty()) {
233 GV.eraseFromParent();
234 continue;
235 }
236 }
237}
238
239static void
240filterModule(Module *M,
241 function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
242 std::vector<GlobalValue *> V;
243 for (GlobalValue &GV : M->global_values())
244 if (!ShouldKeepDefinition(&GV))
245 V.push_back(&GV);
246
247 for (GlobalValue *GV : V)
248 if (!convertToDeclaration(*GV))
249 GV->eraseFromParent();
250}
251
252void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
253 if (auto *F = dyn_cast<Function>(C))
254 return Fn(F);
255 if (isa<GlobalValue>(C))
256 return;
257 for (Value *Op : C->operands())
258 forEachVirtualFunction(cast<Constant>(Op), Fn);
259}
260
261// Clone any @llvm[.compiler].used over to the new module and append
262// values whose defs were cloned into that module.
263static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
264 bool CompilerUsed) {
266 // First collect those in the llvm[.compiler].used set.
267 collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
268 // Next build a set of the equivalent values defined in DestM.
269 for (auto *V : Used) {
270 auto *GV = DestM.getNamedValue(V->getName());
271 if (GV && !GV->isDeclaration())
272 NewUsed.push_back(GV);
273 }
274 // Finally, add them to a llvm[.compiler].used variable in DestM.
275 if (CompilerUsed)
276 appendToCompilerUsed(DestM, NewUsed);
277 else
278 appendToUsed(DestM, NewUsed);
279}
280
281#ifndef NDEBUG
282static bool enableUnifiedLTO(Module &M) {
283 bool UnifiedLTO = false;
284 if (auto *MD =
285 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("UnifiedLTO")))
286 UnifiedLTO = MD->getZExtValue();
287 return UnifiedLTO;
288}
289#endif
290
291bool mustEmitToMergedModule(const GlobalValue *GV) {
292 // The __cfi_check definition is filled in by the CrossDSOCFI pass which
293 // runs only in the merged module.
294 return GV->getName() == "__cfi_check";
295}
296
297// If it's possible to split M into regular and thin LTO parts, do so and write
298// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
299// regular LTO bitcode file to OS.
300void splitAndWriteThinLTOBitcode(
301 raw_ostream &OS, raw_ostream *ThinLinkOS,
302 function_ref<AAResults &(Function &)> AARGetter, 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 // Returns whether a global or its associated global has attached type
327 // metadata. The former may participate in CFI or whole-program
328 // devirtualization, so they need to appear in the merged module instead of
329 // the thin LTO module. Similarly, globals that are associated with globals
330 // with type metadata need to appear in the merged module because they will
331 // reference the global's section directly.
332 auto HasTypeMetadata = [](const GlobalObject *GO) {
333 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
334 if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
335 if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
336 if (AssocGO->hasMetadata(LLVMContext::MD_type))
337 return true;
338 return GO->hasMetadata(LLVMContext::MD_type);
339 };
340
341 // Collect the set of virtual functions that are eligible for virtual constant
342 // propagation. Each eligible function must not access memory, must return
343 // an integer of width <=64 bits, must take at least one argument, must not
344 // use its first argument (assumed to be "this") and all arguments other than
345 // the first one must be of <=64 bit integer type.
346 //
347 // Note that we test whether this copy of the function is readnone, rather
348 // than testing function attributes, which must hold for any copy of the
349 // function, even a less optimized version substituted at link time. This is
350 // sound because the virtual constant propagation optimizations effectively
351 // inline all implementations of the virtual function into each call site,
352 // rather than using function attributes to perform local optimization.
353 DenseSet<const Function *> EligibleVirtualFns;
354 // If any member of a comdat lives in MergedM, put all members of that
355 // comdat in MergedM to keep the comdat together.
356 DenseSet<const Comdat *> MergedMComdats;
357 for (GlobalVariable &GV : M.globals())
358 if (!GV.isDeclaration() && HasTypeMetadata(&GV)) {
359 if (const auto *C = GV.getComdat())
360 MergedMComdats.insert(C);
361 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
362 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
363 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
364 !F->arg_begin()->use_empty())
365 return;
366 for (auto &Arg : drop_begin(F->args())) {
367 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
368 if (!ArgT || ArgT->getBitWidth() > 64)
369 return;
370 }
371 if (!F->isDeclaration() &&
372 computeFunctionBodyMemoryAccess(*F, AARGetter(*F))
373 .doesNotAccessMemory())
374 EligibleVirtualFns.insert(F);
375 });
376 }
377
379 std::unique_ptr<Module> MergedM(
380 CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
381 if (const auto *C = GV->getComdat())
382 if (MergedMComdats.count(C))
383 return true;
384 if (mustEmitToMergedModule(GV))
385 return true;
386 if (auto *F = dyn_cast<Function>(GV))
387 return EligibleVirtualFns.count(F);
388 if (auto *GVar =
390 return HasTypeMetadata(GVar);
391 return false;
392 }));
393 StripDebugInfo(*MergedM);
394 MergedM->removeModuleInlineAsm();
395
396 // Clone any llvm.*used globals to ensure the included values are
397 // not deleted.
398 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
399 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
400
401 for (Function &F : *MergedM)
402 if (!F.isDeclaration() && !mustEmitToMergedModule(&F)) {
403 // Reset the linkage of all functions eligible for virtual constant
404 // propagation. The canonical definitions live in the thin LTO module so
405 // that they can be imported.
407 F.setComdat(nullptr);
408 }
409
410 SetVector<GlobalValue *> CfiFunctions;
411 for (auto &F : M)
412 if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
413 CfiFunctions.insert(&F);
414 for (auto &A : M.aliases())
415 if (auto *F = dyn_cast<Function>(A.getAliasee()))
416 if (HasTypeMetadata(F))
417 CfiFunctions.insert(&A);
418
419 // Remove all globals with type metadata, globals with comdats that live in
420 // MergedM, and aliases pointing to such globals from the thin LTO module.
421 filterModule(&M, [&](const GlobalValue *GV) {
423 if (HasTypeMetadata(GVar))
424 return false;
425 if (const auto *C = GV->getComdat())
426 if (MergedMComdats.count(C))
427 return false;
428 if (mustEmitToMergedModule(GV))
429 return false;
430 return true;
431 });
432
433 // CfiFunctions contains only symbols from M. promoteInternals tries to find
434 // match values from its first argument (the "exporting module") in
435 // CfiFunctions. So we only need CfiFunctions for the second promotion (M ->
436 // MergedM)
437 promoteInternals(*MergedM, M, ModuleId, {});
438 promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
439
440 auto &Ctx = MergedM->getContext();
441 SmallVector<MDNode *, 8> CfiFunctionMDs;
442 for (auto *V : CfiFunctions) {
443 Function &F = *cast<Function>(V->getAliaseeObject());
445 F.getMetadata(LLVMContext::MD_type, Types);
446
448 Elts.push_back(MDString::get(Ctx, V->getName()));
452 else if (F.hasExternalWeakLinkage())
454 else
457 llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
458 GlobalValue::GUID GUID = V->getGUID();
460 llvm::ConstantInt::get(Type::getInt64Ty(Ctx), GUID)));
461 append_range(Elts, Types);
462 CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
463 }
464
465 if(!CfiFunctionMDs.empty()) {
466 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
467 for (auto *MD : CfiFunctionMDs)
468 NMD->addOperand(MD);
469 }
470
472 for (auto &A : M.aliases()) {
473 if (!isa<Function>(A.getAliasee()))
474 continue;
475
476 auto *F = cast<Function>(A.getAliasee());
477 FunctionAliases[F].push_back(&A);
478 }
479
480 if (!FunctionAliases.empty()) {
481 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
482 for (auto &Alias : FunctionAliases) {
484 Elts.push_back(MDString::get(Ctx, Alias.first->getName()));
485 for (auto *A : Alias.second)
486 Elts.push_back(MDString::get(Ctx, A->getName()));
487 NMD->addOperand(MDTuple::get(Ctx, Elts));
488 }
489 }
490
493 Function *F = M.getFunction(Name);
494 if (!F || F->use_empty())
495 return;
496
497 Symvers.push_back(MDTuple::get(
498 Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
499 });
500
501 if (!Symvers.empty()) {
502 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
503 for (auto *MD : Symvers)
504 NMD->addOperand(MD);
505 }
506
507 simplifyExternals(*MergedM);
508
509 // FIXME: Try to re-use BSI and PFI from the original module here.
510 ProfileSummaryInfo PSI(M);
511 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
512
513 // Mark the merged module as requiring full LTO. We still want an index for
514 // it though, so that it can participate in summary-based dead stripping.
515 MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
516 ModuleSummaryIndex MergedMIndex =
517 buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
518
520
521 BitcodeWriter W(Buffer);
522 // Save the module hash produced for the full bitcode, which will
523 // be used in the backends, and use that in the minimized bitcode
524 // produced for the full link.
525 ModuleHash ModHash = {{0}};
526 W.writeModule(M, ShouldPreserveUseListOrder, &Index,
527 /*GenerateHash=*/true, &ModHash);
528 W.writeModule(*MergedM, ShouldPreserveUseListOrder, &MergedMIndex);
529 W.writeSymtab();
530 W.writeStrtab();
531 OS << Buffer;
532
533 // If a minimized bitcode module was requested for the thin link, only
534 // the information that is needed by thin link will be written in the
535 // given OS (the merged module will be written as usual).
536 if (ThinLinkOS) {
537 Buffer.clear();
538 BitcodeWriter W2(Buffer);
540 W2.writeThinLinkBitcode(M, Index, ModHash);
541 W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
542 &MergedMIndex);
543 W2.writeSymtab();
544 W2.writeStrtab();
545 *ThinLinkOS << Buffer;
546 }
547}
548
549// Check if the LTO Unit splitting has been enabled.
550bool enableSplitLTOUnit(Module &M) {
551 bool EnableSplitLTOUnit = false;
553 M.getModuleFlag("EnableSplitLTOUnit")))
554 EnableSplitLTOUnit = MD->getZExtValue();
555 return EnableSplitLTOUnit;
556}
557
558// Returns whether this module needs to be split (if splitting is enabled).
559bool requiresSplit(Module &M) {
560 for (auto &GO : M.global_objects()) {
561 if (GO.hasMetadata(LLVMContext::MD_type))
562 return true;
563 if (mustEmitToMergedModule(&GO))
564 return true;
565 }
566 return false;
567}
568
569bool writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
570 function_ref<AAResults &(Function &)> AARGetter,
571 Module &M, const ModuleSummaryIndex *Index,
572 const bool ShouldPreserveUseListOrder) {
573 std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
574 // See if this module needs to be split. If so, we try to split it
575 // or at least promote type ids to enable WPD.
576 if (requiresSplit(M)) {
577 if (enableSplitLTOUnit(M)) {
578 splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M,
579 ShouldPreserveUseListOrder);
580 return true;
581 }
582 // Promote type ids as needed for index-based WPD.
583 std::string ModuleId = getUniqueModuleId(&M);
584 if (!ModuleId.empty()) {
585 promoteTypeIds(M, ModuleId);
586 // Need to rebuild the index so that it contains type metadata
587 // for the newly promoted type ids.
588 // FIXME: Probably should not bother building the index at all
589 // in the caller of writeThinLTOBitcode (which does so via the
590 // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
591 // anyway whenever there is type metadata (here or in
592 // splitAndWriteThinLTOBitcode). Just always build it once via the
593 // buildModuleSummaryIndex when Module(s) are ready.
594 ProfileSummaryInfo PSI(M);
595 NewIndex = std::make_unique<ModuleSummaryIndex>(
596 buildModuleSummaryIndex(M, nullptr, &PSI));
597 Index = NewIndex.get();
598 }
599 }
600
601 // Write it out as an unsplit ThinLTO module.
602
603 // Save the module hash produced for the full bitcode, which will
604 // be used in the backends, and use that in the minimized bitcode
605 // produced for the full link.
606 ModuleHash ModHash = {{0}};
607 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index,
608 /*GenerateHash=*/true, &ModHash);
609 // If a minimized bitcode module was requested for the thin link, only
610 // the information that is needed by thin link will be written in the
611 // given OS.
612 if (ThinLinkOS && Index)
613 writeThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
614 return false;
615}
616
617} // anonymous namespace
618
623
624 bool Changed = writeThinLTOBitcode(
625 OS, ThinLinkOS,
626 [&FAM](Function &F) -> AAResults & {
627 return FAM.getResult<AAManager>(F);
628 },
630 ShouldPreserveUseListOrder);
631
633}
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< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Finalize Linkage
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.
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
This class represents a function call, abstracting a target machine's calling convention.
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:537
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:223
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:299
unsigned size() const
Definition DenseMap.h:172
bool empty() const
Definition DenseMap.h:171
iterator end()
Definition DenseMap.h:141
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:168
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition Function.h:331
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition Function.cpp:838
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
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
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
Metadata node.
Definition Metadata.h:1069
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1565
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:614
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1511
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:38
bool empty() const
Definition MapVector.h:79
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:110
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 LLVM_ABI void CollectAsmSymvers(const Module &M, function_ref< void(StringRef, StringRef)> AsmSymver)
Parse inline ASM and collect the symvers directives that are defined in the current module.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition Module.h:120
void appendModuleInlineAsm(GlobalAsmFragment Fragment)
Append to the module-scope inline assembly blocks.
Definition Module.h:393
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 tuple of MDNodes.
Definition Metadata.h:1753
LLVM_ABI void addOperand(MDNode *M)
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
size_type count(const_arg_type key) const
Count the number of elements of a given key in the SetVector.
Definition SetVector.h:262
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
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 IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:310
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:282
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:307
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:346
iterator_range< use_iterator > uses()
Definition Value.h:380
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
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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 bool isJumpTableCanonical(Function *F)
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:683
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...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
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:633
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 isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
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.
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
@ CFL_WeakDeclaration
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:908