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