LLVM 17.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/Pass.h"
25#include "llvm/Transforms/IPO.h"
31using namespace llvm;
32
33namespace {
34
35// Determine if a promotion alias should be created for a symbol name.
36static bool allowPromotionAlias(const std::string &Name) {
37 // Promotion aliases are used only in inline assembly. It's safe to
38 // simply skip unusual names. Subset of MCAsmInfo::isAcceptableChar()
39 // and MCAsmInfoXCOFF::isAcceptableChar().
40 for (const char &C : Name) {
41 if (isAlnum(C) || C == '_' || C == '.')
42 continue;
43 return false;
44 }
45 return true;
46}
47
48// Promote each local-linkage entity defined by ExportM and used by ImportM by
49// changing visibility and appending the given ModuleId.
50void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
51 SetVector<GlobalValue *> &PromoteExtra) {
53 for (auto &ExportGV : ExportM.global_values()) {
54 if (!ExportGV.hasLocalLinkage())
55 continue;
56
57 auto Name = ExportGV.getName();
58 GlobalValue *ImportGV = nullptr;
59 if (!PromoteExtra.count(&ExportGV)) {
60 ImportGV = ImportM.getNamedValue(Name);
61 if (!ImportGV)
62 continue;
63 ImportGV->removeDeadConstantUsers();
64 if (ImportGV->use_empty()) {
65 ImportGV->eraseFromParent();
66 continue;
67 }
68 }
69
70 std::string OldName = Name.str();
71 std::string NewName = (Name + ModuleId).str();
72
73 if (const auto *C = ExportGV.getComdat())
74 if (C->getName() == Name)
75 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
76
77 ExportGV.setName(NewName);
78 ExportGV.setLinkage(GlobalValue::ExternalLinkage);
79 ExportGV.setVisibility(GlobalValue::HiddenVisibility);
80
81 if (ImportGV) {
82 ImportGV->setName(NewName);
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 M.getFunction(Intrinsic::getName(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 M.getFunction(Intrinsic::getName(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 M.getFunction(Intrinsic::getName(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 for (GlobalObject &GO : M.global_objects()) {
153 GO.getMetadata(LLVMContext::MD_type, MDs);
154
155 GO.eraseMetadata(LLVMContext::MD_type);
156 for (auto *MD : MDs) {
157 auto I = LocalToGlobal.find(MD->getOperand(1));
158 if (I == LocalToGlobal.end()) {
159 GO.addMetadata(LLVMContext::MD_type, *MD);
160 continue;
161 }
162 GO.addMetadata(
163 LLVMContext::MD_type,
164 *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
165 }
166 }
167}
168
169// Drop unused globals, and drop type information from function declarations.
170// FIXME: If we made functions typeless then there would be no need to do this.
171void simplifyExternals(Module &M) {
172 FunctionType *EmptyFT =
173 FunctionType::get(Type::getVoidTy(M.getContext()), false);
174
176 if (F.isDeclaration() && F.use_empty()) {
177 F.eraseFromParent();
178 continue;
179 }
180
181 if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
182 // Changing the type of an intrinsic may invalidate the IR.
183 F.getName().startswith("llvm."))
184 continue;
185
186 Function *NewF =
188 F.getAddressSpace(), "", &M);
189 NewF->copyAttributesFrom(&F);
190 // Only copy function attribtues.
191 NewF->setAttributes(AttributeList::get(M.getContext(),
193 F.getAttributes().getFnAttrs()));
194 NewF->takeName(&F);
195 F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
196 F.eraseFromParent();
197 }
198
199 for (GlobalIFunc &I : llvm::make_early_inc_range(M.ifuncs())) {
200 if (I.use_empty())
201 I.eraseFromParent();
202 else
203 assert(I.getResolverFunction() && "ifunc misses its resolver function");
204 }
205
206 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
207 if (GV.isDeclaration() && GV.use_empty()) {
208 GV.eraseFromParent();
209 continue;
210 }
211 }
212}
213
214static void
215filterModule(Module *M,
216 function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
217 std::vector<GlobalValue *> V;
218 for (GlobalValue &GV : M->global_values())
219 if (!ShouldKeepDefinition(&GV))
220 V.push_back(&GV);
221
222 for (GlobalValue *GV : V)
223 if (!convertToDeclaration(*GV))
224 GV->eraseFromParent();
225}
226
227void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
228 if (auto *F = dyn_cast<Function>(C))
229 return Fn(F);
230 if (isa<GlobalValue>(C))
231 return;
232 for (Value *Op : C->operands())
233 forEachVirtualFunction(cast<Constant>(Op), Fn);
234}
235
236// Clone any @llvm[.compiler].used over to the new module and append
237// values whose defs were cloned into that module.
238static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
239 bool CompilerUsed) {
241 // First collect those in the llvm[.compiler].used set.
242 collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
243 // Next build a set of the equivalent values defined in DestM.
244 for (auto *V : Used) {
245 auto *GV = DestM.getNamedValue(V->getName());
246 if (GV && !GV->isDeclaration())
247 NewUsed.push_back(GV);
248 }
249 // Finally, add them to a llvm[.compiler].used variable in DestM.
250 if (CompilerUsed)
251 appendToCompilerUsed(DestM, NewUsed);
252 else
253 appendToUsed(DestM, NewUsed);
254}
255
256// If it's possible to split M into regular and thin LTO parts, do so and write
257// a multi-module bitcode file with the two parts to OS. Otherwise, write only a
258// regular LTO bitcode file to OS.
259void splitAndWriteThinLTOBitcode(
260 raw_ostream &OS, raw_ostream *ThinLinkOS,
261 function_ref<AAResults &(Function &)> AARGetter, Module &M) {
262 std::string ModuleId = getUniqueModuleId(&M);
263 if (ModuleId.empty()) {
264 // We couldn't generate a module ID for this module, write it out as a
265 // regular LTO module with an index for summary-based dead stripping.
266 ProfileSummaryInfo PSI(M);
267 M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
269 WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, &Index);
270
271 if (ThinLinkOS)
272 // We don't have a ThinLTO part, but still write the module to the
273 // ThinLinkOS if requested so that the expected output file is produced.
274 WriteBitcodeToFile(M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
275 &Index);
276
277 return;
278 }
279
280 promoteTypeIds(M, ModuleId);
281
282 // Returns whether a global or its associated global has attached type
283 // metadata. The former may participate in CFI or whole-program
284 // devirtualization, so they need to appear in the merged module instead of
285 // the thin LTO module. Similarly, globals that are associated with globals
286 // with type metadata need to appear in the merged module because they will
287 // reference the global's section directly.
288 auto HasTypeMetadata = [](const GlobalObject *GO) {
289 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
290 if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
291 if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
292 if (AssocGO->hasMetadata(LLVMContext::MD_type))
293 return true;
294 return GO->hasMetadata(LLVMContext::MD_type);
295 };
296
297 // Collect the set of virtual functions that are eligible for virtual constant
298 // propagation. Each eligible function must not access memory, must return
299 // an integer of width <=64 bits, must take at least one argument, must not
300 // use its first argument (assumed to be "this") and all arguments other than
301 // the first one must be of <=64 bit integer type.
302 //
303 // Note that we test whether this copy of the function is readnone, rather
304 // than testing function attributes, which must hold for any copy of the
305 // function, even a less optimized version substituted at link time. This is
306 // sound because the virtual constant propagation optimizations effectively
307 // inline all implementations of the virtual function into each call site,
308 // rather than using function attributes to perform local optimization.
309 DenseSet<const Function *> EligibleVirtualFns;
310 // If any member of a comdat lives in MergedM, put all members of that
311 // comdat in MergedM to keep the comdat together.
312 DenseSet<const Comdat *> MergedMComdats;
313 for (GlobalVariable &GV : M.globals())
314 if (HasTypeMetadata(&GV)) {
315 if (const auto *C = GV.getComdat())
316 MergedMComdats.insert(C);
317 forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
318 auto *RT = dyn_cast<IntegerType>(F->getReturnType());
319 if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
320 !F->arg_begin()->use_empty())
321 return;
322 for (auto &Arg : drop_begin(F->args())) {
323 auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
324 if (!ArgT || ArgT->getBitWidth() > 64)
325 return;
326 }
327 if (!F->isDeclaration() &&
328 computeFunctionBodyMemoryAccess(*F, AARGetter(*F))
329 .doesNotAccessMemory())
330 EligibleVirtualFns.insert(F);
331 });
332 }
333
335 std::unique_ptr<Module> MergedM(
336 CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
337 if (const auto *C = GV->getComdat())
338 if (MergedMComdats.count(C))
339 return true;
340 if (auto *F = dyn_cast<Function>(GV))
341 return EligibleVirtualFns.count(F);
342 if (auto *GVar =
343 dyn_cast_or_null<GlobalVariable>(GV->getAliaseeObject()))
344 return HasTypeMetadata(GVar);
345 return false;
346 }));
347 StripDebugInfo(*MergedM);
348 MergedM->setModuleInlineAsm("");
349
350 // Clone any llvm.*used globals to ensure the included values are
351 // not deleted.
352 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
353 cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
354
355 for (Function &F : *MergedM)
356 if (!F.isDeclaration()) {
357 // Reset the linkage of all functions eligible for virtual constant
358 // propagation. The canonical definitions live in the thin LTO module so
359 // that they can be imported.
361 F.setComdat(nullptr);
362 }
363
364 SetVector<GlobalValue *> CfiFunctions;
365 for (auto &F : M)
366 if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
367 CfiFunctions.insert(&F);
368
369 // Remove all globals with type metadata, globals with comdats that live in
370 // MergedM, and aliases pointing to such globals from the thin LTO module.
371 filterModule(&M, [&](const GlobalValue *GV) {
372 if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getAliaseeObject()))
373 if (HasTypeMetadata(GVar))
374 return false;
375 if (const auto *C = GV->getComdat())
376 if (MergedMComdats.count(C))
377 return false;
378 return true;
379 });
380
381 promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
382 promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
383
384 auto &Ctx = MergedM->getContext();
385 SmallVector<MDNode *, 8> CfiFunctionMDs;
386 for (auto *V : CfiFunctions) {
387 Function &F = *cast<Function>(V);
389 F.getMetadata(LLVMContext::MD_type, Types);
390
392 Elts.push_back(MDString::get(Ctx, F.getName()));
396 else if (F.hasExternalWeakLinkage())
398 else
402 append_range(Elts, Types);
403 CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
404 }
405
406 if(!CfiFunctionMDs.empty()) {
407 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
408 for (auto *MD : CfiFunctionMDs)
409 NMD->addOperand(MD);
410 }
411
412 SmallVector<MDNode *, 8> FunctionAliases;
413 for (auto &A : M.aliases()) {
414 if (!isa<Function>(A.getAliasee()))
415 continue;
416
417 auto *F = cast<Function>(A.getAliasee());
418
419 Metadata *Elts[] = {
420 MDString::get(Ctx, A.getName()),
421 MDString::get(Ctx, F->getName()),
423 ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())),
425 ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())),
426 };
427
428 FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
429 }
430
431 if (!FunctionAliases.empty()) {
432 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
433 for (auto *MD : FunctionAliases)
434 NMD->addOperand(MD);
435 }
436
439 Function *F = M.getFunction(Name);
440 if (!F || F->use_empty())
441 return;
442
443 Symvers.push_back(MDTuple::get(
444 Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
445 });
446
447 if (!Symvers.empty()) {
448 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
449 for (auto *MD : Symvers)
450 NMD->addOperand(MD);
451 }
452
453 simplifyExternals(*MergedM);
454
455 // FIXME: Try to re-use BSI and PFI from the original module here.
456 ProfileSummaryInfo PSI(M);
458
459 // Mark the merged module as requiring full LTO. We still want an index for
460 // it though, so that it can participate in summary-based dead stripping.
461 MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
462 ModuleSummaryIndex MergedMIndex =
463 buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
464
466
467 BitcodeWriter W(Buffer);
468 // Save the module hash produced for the full bitcode, which will
469 // be used in the backends, and use that in the minimized bitcode
470 // produced for the full link.
471 ModuleHash ModHash = {{0}};
472 W.writeModule(M, /*ShouldPreserveUseListOrder=*/false, &Index,
473 /*GenerateHash=*/true, &ModHash);
474 W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex);
475 W.writeSymtab();
476 W.writeStrtab();
477 OS << Buffer;
478
479 // If a minimized bitcode module was requested for the thin link, only
480 // the information that is needed by thin link will be written in the
481 // given OS (the merged module will be written as usual).
482 if (ThinLinkOS) {
483 Buffer.clear();
484 BitcodeWriter W2(Buffer);
486 W2.writeThinLinkBitcode(M, Index, ModHash);
487 W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
488 &MergedMIndex);
489 W2.writeSymtab();
490 W2.writeStrtab();
491 *ThinLinkOS << Buffer;
492 }
493}
494
495// Check if the LTO Unit splitting has been enabled.
496bool enableSplitLTOUnit(Module &M) {
497 bool EnableSplitLTOUnit = false;
498 if (auto *MD = mdconst::extract_or_null<ConstantInt>(
499 M.getModuleFlag("EnableSplitLTOUnit")))
500 EnableSplitLTOUnit = MD->getZExtValue();
501 return EnableSplitLTOUnit;
502}
503
504// Returns whether this module needs to be split because it uses type metadata.
505bool hasTypeMetadata(Module &M) {
506 for (auto &GO : M.global_objects()) {
507 if (GO.hasMetadata(LLVMContext::MD_type))
508 return true;
509 }
510 return false;
511}
512
513void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
514 function_ref<AAResults &(Function &)> AARGetter,
515 Module &M, const ModuleSummaryIndex *Index) {
516 std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
517 // See if this module has any type metadata. If so, we try to split it
518 // or at least promote type ids to enable WPD.
519 if (hasTypeMetadata(M)) {
520 if (enableSplitLTOUnit(M))
521 return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
522 // Promote type ids as needed for index-based WPD.
523 std::string ModuleId = getUniqueModuleId(&M);
524 if (!ModuleId.empty()) {
525 promoteTypeIds(M, ModuleId);
526 // Need to rebuild the index so that it contains type metadata
527 // for the newly promoted type ids.
528 // FIXME: Probably should not bother building the index at all
529 // in the caller of writeThinLTOBitcode (which does so via the
530 // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
531 // anyway whenever there is type metadata (here or in
532 // splitAndWriteThinLTOBitcode). Just always build it once via the
533 // buildModuleSummaryIndex when Module(s) are ready.
534 ProfileSummaryInfo PSI(M);
535 NewIndex = std::make_unique<ModuleSummaryIndex>(
536 buildModuleSummaryIndex(M, nullptr, &PSI));
537 Index = NewIndex.get();
538 }
539 }
540
541 // Write it out as an unsplit ThinLTO module.
542
543 // Save the module hash produced for the full bitcode, which will
544 // be used in the backends, and use that in the minimized bitcode
545 // produced for the full link.
546 ModuleHash ModHash = {{0}};
547 WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
548 /*GenerateHash=*/true, &ModHash);
549 // If a minimized bitcode module was requested for the thin link, only
550 // the information that is needed by thin link will be written in the
551 // given OS.
552 if (ThinLinkOS && Index)
553 writeThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
554}
555
556} // anonymous namespace
557
562 writeThinLTOBitcode(OS, ThinLinkOS,
563 [&FAM](Function &F) -> AAResults & {
564 return FAM.getResult<AAManager>(F);
565 },
567 return PreservedAnalyses::all();
568}
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...
std::string Name
Provides passes for computing function attributes based on interprocedural analyses.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This is the interface to build a ModuleSummaryIndex for a module.
Module.h This file contains the declarations for the Module class.
if(VerifyEach)
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
A manager for alias analyses.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1353
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1358
This class represents a function call, abstracting a target machine's calling convention.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2220
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
This is an important base class in LLVM.
Definition: Constant.h:41
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:708
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:235
unsigned size() const
Definition: DenseMap.h:99
bool empty() const
Definition: DenseMap.h:98
iterator end()
Definition: DenseMap.h:84
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:316
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:743
const Comdat * getComdat() const
Definition: Globals.cpp:185
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:369
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:88
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:250
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:933
Metadata node.
Definition: Metadata.h:943
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:497
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1356
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
Root of the metadata hierarchy.
Definition: Metadata.h:61
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 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:65
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition: Module.h:118
iterator_range< global_object_iterator > global_objects()
Definition: Module.cpp:413
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition: Module.cpp:110
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:582
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Definition: Module.h:313
iterator_range< global_value_iterator > global_values()
Definition: Module.cpp:421
A tuple of MDNodes.
Definition: Metadata.h:1587
void addOperand(MDNode *M)
Definition: Metadata.cpp:1221
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
Analysis providing profile information.
A vector that has set insertion semantics.
Definition: SetVector.h:40
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:208
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:375
bool use_empty() const
Definition: Value.h:344
iterator_range< use_iterator > uses()
Definition: Value.h:376
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:381
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
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:97
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:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:979
bool isJumpTableCanonical(Function *F)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MemoryEffects computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
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.
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 a range to a container.
Definition: STLExtras.h:2129
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:748
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
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.
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 StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:545
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Definition: CloneModule.cpp:37
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
@ CFL_Definition
@ CFL_Declaration
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:807