LLVM 23.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 // and MCAsmInfoXCOFF::isAcceptableChar().
38 for (const char &C : Name) {
39 if (isAlnum(C) || C == '_' || C == '.')
40 continue;
41 return false;
42 }
43 return true;
44}
45
46// Promote each local-linkage entity defined by ExportM and used by ImportM by
47// changing visibility and appending the given ModuleId.
48void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
49 const SetVector<GlobalValue *> &PromoteExtra) {
51 for (auto &ExportGV : ExportM.global_values()) {
52 if (!ExportGV.hasLocalLinkage())
53 continue;
54
55 auto Name = ExportGV.getName();
56 GlobalValue *ImportGV = nullptr;
57 if (!PromoteExtra.count(&ExportGV)) {
58 ImportGV = ImportM.getNamedValue(Name);
59 if (!ImportGV)
60 continue;
61 ImportGV->removeDeadConstantUsers();
62 if (ImportGV->use_empty()) {
63 ImportGV->eraseFromParent();
64 continue;
65 }
66 }
67
68 std::string OldName = Name.str();
69 std::string NewName = (Name + ModuleId).str();
70
71 if (const auto *C = ExportGV.getComdat())
72 if (C->getName() == Name)
73 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
74
75 ExportGV.setName(NewName);
76 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
77 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
78 // TODO: remove this reassign and instead create an alias.
79 ExportGV.reassignGUID();
80 if (ImportGV) {
81 ImportGV->setName(NewName);
83 ImportGV->reassignGUID();
84 }
85
86 if (isa<Function>(&ExportGV) && allowPromotionAlias(OldName)) {
87 // Create a local alias with the original name to avoid breaking
88 // references from inline assembly.
89 std::string Alias =
90 ".lto_set_conditional " + OldName + "," + NewName + "\n";
91 ExportM.appendModuleInlineAsm(Alias);
92 }
93 }
94
95 if (!RenamedComdats.empty())
96 for (auto &GO : ExportM.global_objects())
97 if (auto *C = GO.getComdat()) {
98 auto Replacement = RenamedComdats.find(C);
99 if (Replacement != RenamedComdats.end())
100 GO.setComdat(Replacement->second);
101 }
102}
103
104// Promote all internal (i.e. distinct) type ids used by the module by replacing
105// them with external type ids formed using the module id.
106//
107// Note that this needs to be done before we clone the module because each clone
108// will receive its own set of distinct metadata nodes.
109void promoteTypeIds(Module &M, StringRef ModuleId) {
111 auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
112 Metadata *MD =
113 cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
114
115 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
116 Metadata *&GlobalMD = LocalToGlobal[MD];
117 if (!GlobalMD) {
118 std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
119 GlobalMD = MDString::get(M.getContext(), NewName);
120 }
121
122 CI->setArgOperand(ArgNo,
123 MetadataAsValue::get(M.getContext(), GlobalMD));
124 }
125 };
126
127 if (Function *TypeTestFunc =
128 Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test)) {
129 for (const Use &U : TypeTestFunc->uses()) {
130 auto CI = cast<CallInst>(U.getUser());
131 ExternalizeTypeId(CI, 1);
132 }
133 }
134
135 if (Function *PublicTypeTestFunc =
136 Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test)) {
137 for (const Use &U : PublicTypeTestFunc->uses()) {
138 auto CI = cast<CallInst>(U.getUser());
139 ExternalizeTypeId(CI, 1);
140 }
141 }
142
143 if (Function *TypeCheckedLoadFunc =
144 Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load)) {
145 for (const Use &U : TypeCheckedLoadFunc->uses()) {
146 auto CI = cast<CallInst>(U.getUser());
147 ExternalizeTypeId(CI, 2);
148 }
149 }
150
151 if (Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
152 &M, Intrinsic::type_checked_load_relative)) {
153 for (const Use &U : TypeCheckedLoadRelativeFunc->uses()) {
154 auto CI = cast<CallInst>(U.getUser());
155 ExternalizeTypeId(CI, 2);
156 }
157 }
158
159 for (GlobalObject &GO : M.global_objects()) {
161 GO.getMetadata(LLVMContext::MD_type, MDs);
162
163 GO.eraseMetadata(LLVMContext::MD_type);
164 for (auto *MD : MDs) {
165 auto I = LocalToGlobal.find(MD->getOperand(1));
166 if (I == LocalToGlobal.end()) {
167 GO.addMetadata(LLVMContext::MD_type, *MD);
168 continue;
169 }
170 GO.addMetadata(
171 LLVMContext::MD_type,
172 *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
173 }
174
176 GO.getMetadata(LLVMContext::MD_callgraph, CGMDs);
177
178 GO.eraseMetadata(LLVMContext::MD_callgraph);
179 for (auto *MD : CGMDs) {
180 if (MD->getNumOperands() == 1) {
181 auto I = LocalToGlobal.find(MD->getOperand(0));
182 if (I == LocalToGlobal.end()) {
183 GO.addMetadata(LLVMContext::MD_callgraph, *MD);
184 continue;
185 }
186 GO.addMetadata(LLVMContext::MD_callgraph,
187 *MDNode::get(M.getContext(), {I->second}));
188 }
189 }
190 }
191}
192
193// Drop unused globals, and drop type information from function declarations.
194// FIXME: If we made functions typeless then there would be no need to do this.
195void simplifyExternals(Module &M) {
196 FunctionType *EmptyFT =
197 FunctionType::get(Type::getVoidTy(M.getContext()), false);
198
200 if (F.isDeclaration() && F.use_empty()) {
201 F.eraseFromParent();
202 continue;
203 }
204
205 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
206 // Changing the type of an intrinsic may invalidate the IR.
207 F.getName().starts_with("llvm."))
208 continue;
209
210 Function *NewF =
212 F.getAddressSpace(), "", &M);
213 NewF->copyAttributesFrom(&F);
214 // Only copy function attribtues.
215 NewF->setAttributes(AttributeList::get(M.getContext(),
216 AttributeList::FunctionIndex,
217 F.getAttributes().getFnAttrs()));
218 NewF->takeName(&F);
219 NewF->setMetadata(LLVMContext::MD_unique_id,
220 F.getMetadata(LLVMContext::MD_unique_id));
221 F.replaceAllUsesWith(NewF);
222 F.eraseFromParent();
223 }
224
225 for (GlobalIFunc &I : llvm::make_early_inc_range(M.ifuncs())) {
226 if (I.use_empty())
227 I.eraseFromParent();
228 else
229 assert(I.getResolverFunction() && "ifunc misses its resolver function");
230 }
231
232 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
233 if (GV.isDeclaration() && GV.use_empty()) {
234 GV.eraseFromParent();
235 continue;
236 }
237 }
238}
239
240static void
241filterModule(Module *M,
242 function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
243 std::vector<GlobalValue *> V;
244 for (GlobalValue &GV : M->global_values())
245 if (!ShouldKeepDefinition(&GV))
246 V.push_back(&GV);
247
248 for (GlobalValue *GV : V)
249 if (!convertToDeclaration(*GV))
250 GV->eraseFromParent();
251}
252
253void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
254 if (auto *F = dyn_cast<Function>(C))
255 return Fn(F);
256 if (isa<GlobalValue>(C))
257 return;
258 for (Value *Op : C->operands())
259 forEachVirtualFunction(cast<Constant>(Op), Fn);
260}
261
262// Clone any @llvm[.compiler].used over to the new module and append
263// values whose defs were cloned into that module.
264static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
265 bool CompilerUsed) {
267 // First collect those in the llvm[.compiler].used set.
268 collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
269 // Next build a set of the equivalent values defined in DestM.
270 for (auto *V : Used) {
271 auto *GV = DestM.getNamedValue(V->getName());
272 if (GV && !GV->isDeclaration())
273 NewUsed.push_back(GV);
274 }
275 // Finally, add them to a llvm[.compiler].used variable in DestM.
276 if (CompilerUsed)
277 appendToCompilerUsed(DestM, NewUsed);
278 else
279 appendToUsed(DestM, NewUsed);
280}
281
282#ifndef NDEBUG
283static bool enableUnifiedLTO(Module &M) {
284 bool UnifiedLTO = false;
285 if (auto *MD =
286 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("UnifiedLTO")))
287 UnifiedLTO = MD->getZExtValue();
288 return UnifiedLTO;
289}
290#endif
291
292bool mustEmitToMergedModule(const GlobalValue *GV) {
293 // The __cfi_check definition is filled in by the CrossDSOCFI pass which
294 // runs only in the merged module.
295 return GV->getName() == "__cfi_check";
296}
297
298// If it's possible to split M into regular and thin LTO parts, do so and write
299// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
300// regular LTO bitcode file to OS.
301void splitAndWriteThinLTOBitcode(
302 raw_ostream &OS, raw_ostream *ThinLinkOS,
303 function_ref<AAResults &(Function &)> AARGetter, Module &M,
304 const bool ShouldPreserveUseListOrder) {
305 std::string ModuleId = getUniqueModuleId(&M);
306 if (ModuleId.empty()) {
307 assert(!enableUnifiedLTO(M));
308 // We couldn't generate a module ID for this module, write it out as a
309 // regular LTO module with an index for summary-based dead stripping.
310 ProfileSummaryInfo PSI(M);
311 M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
312 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
313 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, &Index,
314 /*UnifiedLTO=*/false);
315
316 if (ThinLinkOS)
317 // We don't have a ThinLTO part, but still write the module to the
318 // ThinLinkOS if requested so that the expected output file is produced.
319 WriteBitcodeToFile(M, *ThinLinkOS, ShouldPreserveUseListOrder, &Index,
320 /*UnifiedLTO=*/false);
321
322 return;
323 }
324
325 promoteTypeIds(M, ModuleId);
326
327 // Returns whether a global or its associated global has attached type
328 // metadata. The former may participate in CFI or whole-program
329 // devirtualization, so they need to appear in the merged module instead of
330 // the thin LTO module. Similarly, globals that are associated with globals
331 // with type metadata need to appear in the merged module because they will
332 // reference the global's section directly.
333 auto HasTypeMetadata = [](const GlobalObject *GO) {
334 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
335 if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
336 if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
337 if (AssocGO->hasMetadata(LLVMContext::MD_type))
338 return true;
339 return GO->hasMetadata(LLVMContext::MD_type);
340 };
341
342 // Collect the set of virtual functions that are eligible for virtual constant
343 // propagation. Each eligible function must not access memory, must return
344 // an integer of width <=64 bits, must take at least one argument, must not
345 // use its first argument (assumed to be "this") and all arguments other than
346 // the first one must be of <=64 bit integer type.
347 //
348 // Note that we test whether this copy of the function is readnone, rather
349 // than testing function attributes, which must hold for any copy of the
350 // function, even a less optimized version substituted at link time. This is
351 // sound because the virtual constant propagation optimizations effectively
352 // inline all implementations of the virtual function into each call site,
353 // rather than using function attributes to perform local optimization.
354 DenseSet<const Function *> EligibleVirtualFns;
355 // If any member of a comdat lives in MergedM, put all members of that
356 // comdat in MergedM to keep the comdat together.
357 DenseSet<const Comdat *> MergedMComdats;
358 for (GlobalVariable &GV : M.globals())
359 if (!GV.isDeclaration() && HasTypeMetadata(&GV)) {
360 if (const auto *C = GV.getComdat())
361 MergedMComdats.insert(C);
362 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
363 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
364 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
365 !F->arg_begin()->use_empty())
366 return;
367 for (auto &Arg : drop_begin(F->args())) {
368 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
369 if (!ArgT || ArgT->getBitWidth() > 64)
370 return;
371 }
372 if (!F->isDeclaration() &&
373 computeFunctionBodyMemoryAccess(*F, AARGetter(*F))
374 .doesNotAccessMemory())
375 EligibleVirtualFns.insert(F);
376 });
377 }
378
380 std::unique_ptr<Module> MergedM(
381 CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
382 if (const auto *C = GV->getComdat())
383 if (MergedMComdats.count(C))
384 return true;
385 if (mustEmitToMergedModule(GV))
386 return true;
387 if (auto *F = dyn_cast<Function>(GV))
388 return EligibleVirtualFns.count(F);
389 if (auto *GVar =
391 return HasTypeMetadata(GVar);
392 return false;
393 }));
394 StripDebugInfo(*MergedM);
395 MergedM->removeModuleInlineAsm();
396
397 // Clone any llvm.*used globals to ensure the included values are
398 // not deleted.
399 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
400 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
401
402 for (Function &F : *MergedM)
403 if (!F.isDeclaration() && !mustEmitToMergedModule(&F)) {
404 // Reset the linkage of all functions eligible for virtual constant
405 // propagation. The canonical definitions live in the thin LTO module so
406 // that they can be imported.
408 F.setComdat(nullptr);
409 }
410
411 SetVector<GlobalValue *> CfiFunctions;
412 for (auto &F : M)
413 if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
414 CfiFunctions.insert(&F);
415 for (auto &A : M.aliases())
416 if (auto *F = dyn_cast<Function>(A.getAliasee()))
417 if (HasTypeMetadata(F))
418 CfiFunctions.insert(&A);
419
420 // Remove all globals with type metadata, globals with comdats that live in
421 // MergedM, and aliases pointing to such globals from the thin LTO module.
422 filterModule(&M, [&](const GlobalValue *GV) {
424 if (HasTypeMetadata(GVar))
425 return false;
426 if (const auto *C = GV->getComdat())
427 if (MergedMComdats.count(C))
428 return false;
429 if (mustEmitToMergedModule(GV))
430 return false;
431 return true;
432 });
433
434 // CfiFunctions contains only symbols from M. promoteInternals tries to find
435 // match values from its first argument (the "exporting module") in
436 // CfiFunctions. So we only need CfiFunctions for the second promotion (M ->
437 // MergedM)
438 promoteInternals(*MergedM, M, ModuleId, {});
439 promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
440
441 auto &Ctx = MergedM->getContext();
442 SmallVector<MDNode *, 8> CfiFunctionMDs;
443 for (auto *V : CfiFunctions) {
444 Function &F = *cast<Function>(V->getAliaseeObject());
446 F.getMetadata(LLVMContext::MD_type, Types);
447
449 Elts.push_back(MDString::get(Ctx, V->getName()));
453 else if (F.hasExternalWeakLinkage())
455 else
458 llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
459 GlobalValue::GUID GUID = V->getGUID();
461 llvm::ConstantInt::get(Type::getInt64Ty(Ctx), GUID)));
462 append_range(Elts, Types);
463 CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
464 }
465
466 if(!CfiFunctionMDs.empty()) {
467 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
468 for (auto *MD : CfiFunctionMDs)
469 NMD->addOperand(MD);
470 }
471
473 for (auto &A : M.aliases()) {
474 if (!isa<Function>(A.getAliasee()))
475 continue;
476
477 auto *F = cast<Function>(A.getAliasee());
478 FunctionAliases[F].push_back(&A);
479 }
480
481 if (!FunctionAliases.empty()) {
482 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
483 for (auto &Alias : FunctionAliases) {
485 Elts.push_back(MDString::get(Ctx, Alias.first->getName()));
486 for (auto *A : Alias.second)
487 Elts.push_back(MDString::get(Ctx, A->getName()));
488 NMD->addOperand(MDTuple::get(Ctx, Elts));
489 }
490 }
491
494 Function *F = M.getFunction(Name);
495 if (!F || F->use_empty())
496 return;
497
498 Symvers.push_back(MDTuple::get(
499 Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
500 });
501
502 if (!Symvers.empty()) {
503 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
504 for (auto *MD : Symvers)
505 NMD->addOperand(MD);
506 }
507
508 simplifyExternals(*MergedM);
509
510 // FIXME: Try to re-use BSI and PFI from the original module here.
511 ProfileSummaryInfo PSI(M);
512 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
513
514 // Mark the merged module as requiring full LTO. We still want an index for
515 // it though, so that it can participate in summary-based dead stripping.
516 MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
517 ModuleSummaryIndex MergedMIndex =
518 buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
519
521
522 BitcodeWriter W(Buffer);
523 // Save the module hash produced for the full bitcode, which will
524 // be used in the backends, and use that in the minimized bitcode
525 // produced for the full link.
526 ModuleHash ModHash = {{0}};
527 W.writeModule(M, ShouldPreserveUseListOrder, &Index,
528 /*GenerateHash=*/true, &ModHash);
529 W.writeModule(*MergedM, ShouldPreserveUseListOrder, &MergedMIndex);
530 W.writeSymtab();
531 W.writeStrtab();
532 OS << Buffer;
533
534 // If a minimized bitcode module was requested for the thin link, only
535 // the information that is needed by thin link will be written in the
536 // given OS (the merged module will be written as usual).
537 if (ThinLinkOS) {
538 Buffer.clear();
539 BitcodeWriter W2(Buffer);
541 W2.writeThinLinkBitcode(M, Index, ModHash);
542 W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
543 &MergedMIndex);
544 W2.writeSymtab();
545 W2.writeStrtab();
546 *ThinLinkOS << Buffer;
547 }
548}
549
550// Check if the LTO Unit splitting has been enabled.
551bool enableSplitLTOUnit(Module &M) {
552 bool EnableSplitLTOUnit = false;
554 M.getModuleFlag("EnableSplitLTOUnit")))
555 EnableSplitLTOUnit = MD->getZExtValue();
556 return EnableSplitLTOUnit;
557}
558
559// Returns whether this module needs to be split (if splitting is enabled).
560bool requiresSplit(Module &M) {
561 for (auto &GO : M.global_objects()) {
562 if (GO.hasMetadata(LLVMContext::MD_type))
563 return true;
564 if (mustEmitToMergedModule(&GO))
565 return true;
566 }
567 return false;
568}
569
570bool writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
571 function_ref<AAResults &(Function &)> AARGetter,
572 Module &M, const ModuleSummaryIndex *Index,
573 const bool ShouldPreserveUseListOrder) {
574 std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
575 // See if this module needs to be split. If so, we try to split it
576 // or at least promote type ids to enable WPD.
577 if (requiresSplit(M)) {
578 if (enableSplitLTOUnit(M)) {
579 splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M,
580 ShouldPreserveUseListOrder);
581 return true;
582 }
583 // Promote type ids as needed for index-based WPD.
584 std::string ModuleId = getUniqueModuleId(&M);
585 if (!ModuleId.empty()) {
586 promoteTypeIds(M, ModuleId);
587 // Need to rebuild the index so that it contains type metadata
588 // for the newly promoted type ids.
589 // FIXME: Probably should not bother building the index at all
590 // in the caller of writeThinLTOBitcode (which does so via the
591 // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
592 // anyway whenever there is type metadata (here or in
593 // splitAndWriteThinLTOBitcode). Just always build it once via the
594 // buildModuleSummaryIndex when Module(s) are ready.
595 ProfileSummaryInfo PSI(M);
596 NewIndex = std::make_unique<ModuleSummaryIndex>(
597 buildModuleSummaryIndex(M, nullptr, &PSI));
598 Index = NewIndex.get();
599 }
600 }
601
602 // Write it out as an unsplit ThinLTO module.
603
604 // Save the module hash produced for the full bitcode, which will
605 // be used in the backends, and use that in the minimized bitcode
606 // produced for the full link.
607 ModuleHash ModHash = {{0}};
608 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index,
609 /*GenerateHash=*/true, &ModHash);
610 // If a minimized bitcode module was requested for the thin link, only
611 // the information that is needed by thin link will be written in the
612 // given OS.
613 if (ThinLinkOS && Index)
614 writeThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
615 return false;
616}
617
618} // anonymous namespace
619
624
625 bool Changed = writeThinLTOBitcode(
626 OS, ThinLinkOS,
627 [&FAM](Function &F) -> AAResults & {
628 return FAM.getResult<AAManager>(F);
629 },
631 ShouldPreserveUseListOrder);
632
634}
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:451
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:621
iterator_range< global_value_iterator > global_values()
Definition Module.cpp:459
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:898