LLVM 24.0.0git
Module.cpp
Go to the documentation of this file.
1//===- Module.cpp - Implement the Module class ----------------------------===//
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//
9// This file implements the Module class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Module.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/ADT/Twine.h"
20#include "llvm/IR/Attributes.h"
21#include "llvm/IR/Comdat.h"
22#include "llvm/IR/Constants.h"
23#include "llvm/IR/DataLayout.h"
26#include "llvm/IR/Function.h"
28#include "llvm/IR/GlobalAlias.h"
29#include "llvm/IR/GlobalIFunc.h"
30#include "llvm/IR/GlobalValue.h"
32#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Metadata.h"
36#include "llvm/IR/Type.h"
37#include "llvm/IR/TypeFinder.h"
38#include "llvm/IR/Value.h"
43#include "llvm/Support/Error.h"
45#include "llvm/Support/Path.h"
49#include <cassert>
50#include <cstdint>
51#include <memory>
52#include <optional>
53#include <utility>
54#include <vector>
55
56using namespace llvm;
57
58//===----------------------------------------------------------------------===//
59// Methods to implement the globals and functions lists.
60//
61
62// Explicit instantiations of SymbolTableListTraits since some of the methods
63// are not in the public header file.
68
69//===----------------------------------------------------------------------===//
70// Primitive Module methods.
71//
72
74 : Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
75 ModuleID(std::string(MID)), SourceFileName(std::string(MID)) {
76 Context.addModule(this);
77}
78
80 assert(&Context == &Other.Context && "Module must be in the same Context");
81
82 dropAllReferences();
83
84 ModuleID = std::move(Other.ModuleID);
85 SourceFileName = std::move(Other.SourceFileName);
86
87 GlobalList.clear();
88 GlobalList.splice(GlobalList.begin(), Other.GlobalList);
89
90 FunctionList.clear();
91 FunctionList.splice(FunctionList.begin(), Other.FunctionList);
92
93 AliasList.clear();
94 AliasList.splice(AliasList.begin(), Other.AliasList);
95
96 IFuncList.clear();
97 IFuncList.splice(IFuncList.begin(), Other.IFuncList);
98
99 NamedMDList.clear();
100 NamedMDList.splice(NamedMDList.begin(), Other.NamedMDList);
101 for (NamedMDNode &NMD : NamedMDList)
102 NMD.setParent(this);
103
104 NamedMDSymTab = std::move(Other.NamedMDSymTab);
105 ComdatSymTab = std::move(Other.ComdatSymTab);
106 GlobalScopeAsm = std::move(Other.GlobalScopeAsm);
107 OwnedMemoryBuffer = std::move(Other.OwnedMemoryBuffer);
108 Materializer = std::move(Other.Materializer);
109 TargetTriple = std::move(Other.TargetTriple);
110 DL = std::move(Other.DL);
111 CurrentIntrinsicIds = std::move(Other.CurrentIntrinsicIds);
112 UniquedIntrinsicNames = std::move(Other.UniquedIntrinsicNames);
113 ModuleFlags = std::move(Other.ModuleFlags);
114 Context.addModule(this);
115 return *this;
116}
117
119 Context.removeModule(this);
120 dropAllReferences();
121 GlobalList.clear();
122 FunctionList.clear();
123 AliasList.clear();
124 IFuncList.clear();
125}
126
128 if (auto *DeclareIntrinsicFn =
129 Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_declare)) {
130 assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
131 "Debug declare intrinsic should have had uses removed.");
132 DeclareIntrinsicFn->eraseFromParent();
133 }
134 if (auto *ValueIntrinsicFn =
135 Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_value)) {
136 assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
137 "Debug value intrinsic should have had uses removed.");
138 ValueIntrinsicFn->eraseFromParent();
139 }
140 if (auto *AssignIntrinsicFn =
141 Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_assign)) {
142 assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
143 "Debug assign intrinsic should have had uses removed.");
144 AssignIntrinsicFn->eraseFromParent();
145 }
146 if (auto *LabelntrinsicFn =
147 Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_label)) {
148 assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
149 "Debug label intrinsic should have had uses removed.");
150 LabelntrinsicFn->eraseFromParent();
151 }
152}
153
154std::unique_ptr<RandomNumberGenerator>
155Module::createRNG(const StringRef Name) const {
156 SmallString<32> Salt(Name);
157
158 // This RNG is guaranteed to produce the same random stream only
159 // when the Module ID and thus the input filename is the same. This
160 // might be problematic if the input filename extension changes
161 // (e.g. from .c to .bc or .ll).
162 //
163 // We could store this salt in NamedMetadata, but this would make
164 // the parameter non-const. This would unfortunately make this
165 // interface unusable by any Machine passes, since they only have a
166 // const reference to their IR Module. Alternatively we can always
167 // store salt metadata from the Module constructor.
168 Salt += sys::path::filename(getModuleIdentifier());
169
170 return std::unique_ptr<RandomNumberGenerator>(
171 new RandomNumberGenerator(Salt));
172}
173
174/// getNamedValue - Return the first global value in the module with
175/// the specified name, of arbitrary type. This method returns null
176/// if a global with the specified name is not found.
178 return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
179}
180
181unsigned Module::getNumNamedValues() const {
182 return getValueSymbolTable().size();
183}
184
185/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
186/// This ID is uniqued across modules in the current LLVMContext.
187unsigned Module::getMDKindID(StringRef Name) const {
188 return Context.getMDKindID(Name);
189}
190
191/// getMDKindNames - Populate client supplied SmallVector with the name for
192/// custom metadata IDs registered in this LLVMContext. ID #0 is not used,
193/// so it is filled in as an empty string.
195 return Context.getMDKindNames(Result);
196}
197
199 return Context.getOperandBundleTags(Result);
200}
201
202//===----------------------------------------------------------------------===//
203// Methods for easy access to the functions in the module.
204//
205
206// getOrInsertFunction - Look up the specified function in the module symbol
207// table. If it does not exist, add a prototype for the function and return
208// it. This is nice because it allows most passes to get away with not handling
209// the symbol table directly for this common task.
210//
213 // See if we have a definition for the specified function already.
214 GlobalValue *F = getNamedValue(Name);
215 if (!F) {
216 // Nope, add it
218 DL.getProgramAddressSpace(), Name, this);
219 if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
220 New->setAttributes(AttributeList);
221 return {Ty, New}; // Return the new prototype.
222 }
223
224 // Otherwise, we just found the existing function or a prototype.
225 return {Ty, F};
226}
227
229 return getOrInsertFunction(Name, Ty, AttributeList());
230}
231
232// getFunction - Look up the specified function in the module symbol table.
233// If it does not exist, return null.
234//
236 return dyn_cast_or_null<Function>(getNamedValue(Name));
237}
238
239//===----------------------------------------------------------------------===//
240// Methods for easy access to the global variables in the module.
241//
242
243/// getGlobalVariable - Look up the specified global variable in the module
244/// symbol table. If it does not exist, return null. The type argument
245/// should be the underlying type of the global, i.e., it should not have
246/// the top-level PointerType, which represents the address of the global.
247/// If AllowLocal is set to true, this function will return types that
248/// have an local. By default, these types are not returned.
249///
251 bool AllowLocal) const {
252 if (GlobalVariable *Result =
253 dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
254 if (AllowLocal || !Result->hasLocalLinkage())
255 return Result;
256 return nullptr;
257}
258
259/// getOrInsertGlobal - Look up the specified global in the module symbol table.
260/// If it does not exist, add a declaration of the global and return it.
261/// Otherwise, return the existing global.
263 StringRef Name, Type *Ty,
264 function_ref<GlobalVariable *()> CreateGlobalCallback) {
265 // See if we have a definition for the specified global already.
266 GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
267 if (!GV)
268 GV = CreateGlobalCallback();
269 assert(GV && "The CreateGlobalCallback is expected to create a global");
270
271 // Otherwise, we just found the existing function or a prototype.
272 return GV;
273}
274
275// Overload to construct a global variable using its constructor's defaults.
277 return getOrInsertGlobal(Name, Ty, [&] {
278 return new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
279 nullptr, Name);
280 });
281}
282
283//===----------------------------------------------------------------------===//
284// Methods for easy access to the global variables in the module.
285//
286
287// getNamedAlias - Look up the specified global in the module symbol table.
288// If it does not exist, return null.
289//
291 return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
292}
293
295 return dyn_cast_or_null<GlobalIFunc>(getNamedValue(Name));
296}
297
298/// getNamedMetadata - Return the first NamedMDNode in the module with the
299/// specified name. This method returns null if a NamedMDNode with the
300/// specified name is not found.
302 return NamedMDSymTab.lookup(Name);
303}
304
305/// getOrInsertNamedMetadata - Return the first named MDNode in the module
306/// with the specified name. This method returns a new NamedMDNode if a
307/// NamedMDNode with the specified name is not found.
309 NamedMDNode *&NMD = NamedMDSymTab[Name];
310 if (!NMD) {
311 NMD = new NamedMDNode(Name);
312 NMD->setParent(this);
313 insertNamedMDNode(NMD);
314 if (Name == "llvm.module.flags")
315 ModuleFlags = NMD;
316 }
317 return NMD;
318}
319
320/// eraseNamedMetadata - Remove the given NamedMDNode from this module and
321/// delete it.
323 NamedMDSymTab.erase(NMD->getName());
324 if (NMD == ModuleFlags)
325 ModuleFlags = nullptr;
326 eraseNamedMDNode(NMD);
327}
328
329bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
331 uint64_t Val = Behavior->getLimitedValue();
332 if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
333 MFB = static_cast<ModFlagBehavior>(Val);
334 return true;
335 }
336 }
337 return false;
338}
339
340/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
341void Module::
342getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
343 const NamedMDNode *ModFlags = getModuleFlagsMetadata();
344 if (!ModFlags) return;
345
346 for (const MDNode *Flag : ModFlags->operands()) {
347 // The verifier will catch errors, so no need to check them here.
348 auto *MFBConstant = mdconst::extract<ConstantInt>(Flag->getOperand(0));
349 auto MFB = static_cast<ModFlagBehavior>(MFBConstant->getLimitedValue());
350 MDString *Key = cast<MDString>(Flag->getOperand(1));
351 Metadata *Val = Flag->getOperand(2);
352 Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
353 }
354}
355
356/// Return the corresponding value if Key appears in module flags, otherwise
357/// return null.
359 const NamedMDNode *ModFlags = getModuleFlagsMetadata();
360 if (!ModFlags)
361 return nullptr;
362 for (const MDNode *Flag : ModFlags->operands()) {
363 if (Key == cast<MDString>(Flag->getOperand(1))->getString())
364 return Flag->getOperand(2);
365 }
366 return nullptr;
367}
368
369/// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
370/// represents module-level flags. If module-level flags aren't found, it
371/// creates the named metadata that contains them.
373 if (ModuleFlags)
374 return ModuleFlags;
375 return getOrInsertNamedMetadata("llvm.module.flags");
376}
377
378/// addModuleFlag - Add a module-level flag to the module-level flags
379/// metadata. It will create the module-level flags named metadata if it doesn't
380/// already exist.
381void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
382 Metadata *Val) {
383 Type *Int32Ty = Type::getInt32Ty(Context);
384 Metadata *Ops[3] = {
385 ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
386 MDString::get(Context, Key), Val};
387 getOrInsertModuleFlagsMetadata()->addOperand(MDNode::get(Context, Ops));
388}
389void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
390 Constant *Val) {
391 addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
392}
393void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
394 uint64_t Val) {
395 Type *Int64Ty = Type::getInt64Ty(Context);
396 addModuleFlag(Behavior, Key, ConstantInt::get(Int64Ty, Val));
397}
398void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
399 uint32_t Val) {
400 Type *Int32Ty = Type::getInt32Ty(Context);
401 addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
402}
404 assert(Node->getNumOperands() == 3 &&
405 "Invalid number of operands for module flag!");
406 assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
407 isa<MDString>(Node->getOperand(1)) &&
408 "Invalid operand types for module flag!");
409 getOrInsertModuleFlagsMetadata()->addOperand(Node);
410}
411
412void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
413 Metadata *Val) {
414 NamedMDNode *ModFlags = getOrInsertModuleFlagsMetadata();
415 // Replace the flag if it already exists.
416 for (unsigned i = 0; i < ModFlags->getNumOperands(); ++i) {
417 MDNode *Flag = ModFlags->getOperand(i);
418 if (cast<MDString>(Flag->getOperand(1))->getString() == Key) {
419 Type *Int32Ty = Type::getInt32Ty(Context);
420 Metadata *Ops[3] = {
421 ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
422 MDString::get(Context, Key), Val};
423 ModFlags->setOperand(i, MDNode::get(Context, Ops));
424 return;
425 }
426 }
427 addModuleFlag(Behavior, Key, Val);
428}
429void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
430 Constant *Val) {
431 setModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
432}
433void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
434 uint64_t Val) {
435 Type *Int64Ty = Type::getInt64Ty(Context);
436 setModuleFlag(Behavior, Key, ConstantInt::get(Int64Ty, Val));
437}
438void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
439 uint32_t Val) {
440 Type *Int32Ty = Type::getInt32Ty(Context);
441 setModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
442}
443
445
447
449 return cast<DICompileUnit>(CUs->getOperand(Idx));
450}
452 return cast<DICompileUnit>(CUs->getOperand(Idx));
453}
454
455void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
456 while (CUs && (Idx < CUs->getNumOperands()) &&
457 ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
458 ++Idx;
459}
460
463}
467}
468
470 return concat<GlobalValue>(functions(), globals(), aliases(), ifuncs());
471}
473Module::global_values() const {
474 return concat<const GlobalValue>(functions(), globals(), aliases(), ifuncs());
475}
476
477//===----------------------------------------------------------------------===//
478// Methods to control the materialization of GlobalValues in the Module.
479//
481 assert(!Materializer &&
482 "Module already has a GVMaterializer. Call materializeAll"
483 " to clear it out before setting another one.");
484 Materializer.reset(GVM);
485}
486
488 if (!Materializer)
489 return Error::success();
490
491 return Materializer->materialize(GV);
492}
493
495 if (!Materializer)
496 return Error::success();
497 std::unique_ptr<GVMaterializer> M = std::move(Materializer);
498 return M->materializeModule();
499}
500
502 llvm::TimeTraceScope timeScope("Materialize metadata");
503 if (!Materializer)
504 return Error::success();
505 return Materializer->materializeMetadata();
506}
507
508//===----------------------------------------------------------------------===//
509// Other module related stuff.
510//
511
512std::vector<StructType *> Module::getIdentifiedStructTypes() const {
513 // If we have a materializer, it is possible that some unread function
514 // uses a type that is currently not visible to a TypeFinder, so ask
515 // the materializer which types it created.
516 if (Materializer)
517 return Materializer->getIdentifiedStructTypes();
518
519 std::vector<StructType *> Ret;
520 TypeFinder SrcStructTypes;
521 SrcStructTypes.run(*this, true);
522 Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
523 return Ret;
524}
525
527 const FunctionType *Proto) {
528 auto Encode = [&BaseName](unsigned Suffix) {
529 return (Twine(BaseName) + "." + Twine(Suffix)).str();
530 };
531
532 {
533 // fast path - the prototype is already known
534 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, Proto}, 0});
535 if (!UinItInserted.second)
536 return Encode(UinItInserted.first->second);
537 }
538
539 // Not known yet. A new entry was created with index 0. Check if there already
540 // exists a matching declaration, or select a new entry.
541
542 // Start looking for names with the current known maximum count (or 0).
543 auto NiidItInserted = CurrentIntrinsicIds.insert({BaseName, 0});
544 unsigned Count = NiidItInserted.first->second;
545
546 // This might be slow if a whole population of intrinsics already existed, but
547 // we cache the values for later usage.
548 std::string NewName;
549 while (true) {
550 NewName = Encode(Count);
551 GlobalValue *F = getNamedValue(NewName);
552 if (!F) {
553 // Reserve this entry for the new proto
554 UniquedIntrinsicNames[{Id, Proto}] = Count;
555 break;
556 }
557
558 // A declaration with this name already exists. Remember it.
559 FunctionType *FT = dyn_cast<FunctionType>(F->getValueType());
560 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, FT}, Count});
561 if (FT == Proto) {
562 // It was a declaration for our prototype. This entry was allocated in the
563 // beginning. Update the count to match the existing declaration.
564 UinItInserted.first->second = Count;
565 break;
566 }
567
568 ++Count;
569 }
570
571 NiidItInserted.first->second = Count + 1;
572
573 return NewName;
574}
575
576// dropAllReferences() - This function causes all the subelements to "let go"
577// of all references that they are maintaining. This allows one to 'delete' a
578// whole module at a time, even though there may be circular references... first
579// all references are dropped, and all use counts go to zero. Then everything
580// is deleted for real. Note that no operations are valid on an object that
581// has "dropped all references", except operator delete.
582//
584 for (Function &F : *this)
585 F.dropAllReferences();
586
587 for (GlobalVariable &GV : globals())
589
590 for (GlobalAlias &GA : aliases())
591 GA.dropAllReferences();
592
593 for (GlobalIFunc &GIF : ifuncs())
594 GIF.dropAllReferences();
595}
596
598 auto *Val =
599 cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
600 if (!Val)
601 return 0;
602 return cast<ConstantInt>(Val->getValue())->getZExtValue();
603}
604
605unsigned Module::getDwarfVersion() const {
606 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
607 if (!Val)
608 return 0;
609 return cast<ConstantInt>(Val->getValue())->getZExtValue();
610}
611
612bool Module::isDwarf64() const {
613 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("DWARF64"));
614 return Val && cast<ConstantInt>(Val->getValue())->isOne();
615}
616
617unsigned Module::getCodeViewFlag() const {
618 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
619 if (!Val)
620 return 0;
621 return cast<ConstantInt>(Val->getValue())->getZExtValue();
622}
623
624unsigned Module::getInstructionCount() const {
625 unsigned NumInstrs = 0;
626 for (const Function &F : FunctionList)
627 NumInstrs += F.getInstructionCount();
628 return NumInstrs;
629}
630
632 auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
633 Entry.second.Name = &Entry;
634 return &Entry.second;
635}
636
638 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
639
640 if (!Val)
641 return PICLevel::NotPIC;
642
643 return static_cast<PICLevel::Level>(
644 cast<ConstantInt>(Val->getValue())->getZExtValue());
645}
646
648 // The merge result of a non-PIC object and a PIC object can only be reliably
649 // used as a non-PIC object, so use the Min merge behavior.
650 addModuleFlag(ModFlagBehavior::Min, "PIC Level", PL);
651}
652
654 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
655
656 if (!Val)
657 return PIELevel::Default;
658
659 return static_cast<PIELevel::Level>(
660 cast<ConstantInt>(Val->getValue())->getZExtValue());
661}
662
664 addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
665}
666
667std::optional<CodeModel::Model> Module::getCodeModel() const {
668 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Code Model"));
669
670 if (!Val)
671 return std::nullopt;
672
673 return static_cast<CodeModel::Model>(
674 cast<ConstantInt>(Val->getValue())->getZExtValue());
675}
676
678 // Linking object files with different code models is undefined behavior
679 // because the compiler would have to generate additional code (to span
680 // longer jumps) if a larger code model is used with a smaller one.
681 // Therefore we will treat attempts to mix code models as an error.
682 addModuleFlag(ModFlagBehavior::Error, "Code Model", CL);
683}
684
686 if (auto *Val = cast_or_null<MDString>(getModuleFlag("long-double-type"))) {
687 if (std::optional<LongDoubleFormat> Format =
688 parseLongDoubleFormat(Val->getString()))
689 return *Format;
690 }
691
692 return getTargetTriple().getDefaultLongDoubleFormat();
693}
694
696 addModuleFlag(ModFlagBehavior::Error, "long-double-type",
698}
699
701 if (auto *Val = cast_or_null<MDString>(getModuleFlag("float-abi")))
702 return *FloatABI::parseABIType(Val->getString());
703 // Without an explicit flag, fall back to the ABI implied by the target
704 // triple.
705 return getTargetTriple().getDefaultFloatABI();
706}
707
709 if (auto *Val = cast_or_null<MDString>(getModuleFlag("thread-model")))
710 return *parseThreadModel(Val->getString());
711 return getTargetTriple().getDefaultThreadModel();
712}
713
715 addModuleFlag(ModFlagBehavior::Error, "thread-model",
717}
718
719ExceptionHandling Module::getExceptionModel() const {
720 if (auto *Val = cast_or_null<MDString>(getModuleFlag("exception-model")))
721 return *parseExceptionModel(Val->getString());
722
723 // TODO: Return getDefaultExceptionHandling when TargetOptions field is
724 // deleted.
726}
727
728std::optional<uint64_t> Module::getLargeDataThreshold() const {
729 auto *Val =
730 cast_or_null<ConstantAsMetadata>(getModuleFlag("Large Data Threshold"));
731
732 if (!Val)
733 return std::nullopt;
734
735 return cast<ConstantInt>(Val->getValue())->getZExtValue();
736}
737
739 // Since the large data threshold goes along with the code model, the merge
740 // behavior is the same.
741 addModuleFlag(ModFlagBehavior::Error, "Large Data Threshold",
742 ConstantInt::get(Type::getInt64Ty(Context), Threshold));
743}
744
746 if (Kind == ProfileSummary::PSK_CSInstr)
747 setModuleFlag(ModFlagBehavior::Error, "CSProfileSummary", M);
748 else
749 setModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
750}
751
752Metadata *Module::getProfileSummary(bool IsCS) const {
753 return (IsCS ? getModuleFlag("CSProfileSummary")
754 : getModuleFlag("ProfileSummary"));
755}
756
758 Metadata *MF = getModuleFlag("SemanticInterposition");
759
760 auto *Val = cast_or_null<ConstantAsMetadata>(MF);
761 if (!Val)
762 return false;
763
764 return cast<ConstantInt>(Val->getValue())->getZExtValue();
765}
766
768 addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI);
769}
770
771void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
772 OwnedMemoryBuffer = std::move(MB);
773}
774
775bool Module::getRtLibUseGOT() const {
776 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("RtLibUseGOT"));
777 return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
778}
779
781 addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
782}
783
786 getModuleFlag("direct-access-external-data"));
787 if (Val)
788 return cast<ConstantInt>(Val->getValue())->getZExtValue() > 0;
789 return getPICLevel() == PICLevel::NotPIC;
790}
791
793 addModuleFlag(ModFlagBehavior::Max, "direct-access-external-data", Value);
794}
795
797 if (auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("uwtable")))
798 return UWTableKind(cast<ConstantInt>(Val->getValue())->getZExtValue());
799 return UWTableKind::None;
800}
801
803 addModuleFlag(ModFlagBehavior::Max, "uwtable", uint32_t(Kind));
804}
805
806FramePointerKind Module::getFramePointer() const {
807 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("frame-pointer"));
808 return static_cast<FramePointerKind>(
809 Val ? cast<ConstantInt>(Val->getValue())->getZExtValue() : 0);
810}
811
812void Module::setFramePointer(FramePointerKind Kind) {
813 addModuleFlag(ModFlagBehavior::Max, "frame-pointer", static_cast<int>(Kind));
814}
815
818 getModuleFlag("stack-protector-guard-record"));
819 return Val && cast<ConstantInt>(Val->getValue())->isOne();
820}
821
823 addModuleFlag(ModFlagBehavior::Max, "stack-protector-guard-record",
824 Flag ? 1 : 0);
825}
826
828 Metadata *MD = getModuleFlag("stack-protector-guard");
829 if (auto *MDS = dyn_cast_or_null<MDString>(MD))
830 return MDS->getString();
831 return {};
832}
833
835 MDString *ID = MDString::get(getContext(), Kind);
836 addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard", ID);
837}
838
840 Metadata *MD = getModuleFlag("stack-protector-guard-reg");
841 if (auto *MDS = dyn_cast_or_null<MDString>(MD))
842 return MDS->getString();
843 return {};
844}
845
848 addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-reg", ID);
849}
850
852 Metadata *MD = getModuleFlag("stack-protector-guard-symbol");
853 if (auto *MDS = dyn_cast_or_null<MDString>(MD))
854 return MDS->getString();
855 return {};
856}
857
859 MDString *ID = MDString::get(getContext(), Symbol);
860 addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-symbol", ID);
861}
862
864 Metadata *MD = getModuleFlag("stack-protector-guard-offset");
866 return CI->getSExtValue();
867 return INT_MAX;
868}
869
871 addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-offset", Offset);
872}
873
874std::optional<unsigned> Module::getStackProtectorGuardValueWidth() const {
875 Metadata *MD = getModuleFlag("stack-protector-guard-value-width");
877 return CI->getZExtValue();
878 return std::nullopt;
879}
880
881void Module::setStackProtectorGuardValueWidth(unsigned Width) {
882 addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-value-width",
883 Width);
884}
885
886unsigned Module::getOverrideStackAlignment() const {
887 Metadata *MD = getModuleFlag("override-stack-alignment");
889 return CI->getZExtValue();
890 return 0;
891}
892
893unsigned Module::getMaxTLSAlignment() const {
894 Metadata *MD = getModuleFlag("MaxTLSAlign");
896 return CI->getZExtValue();
897 return 0;
898}
899
901 addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align);
902}
903
904static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name) {
906 Entries.push_back(V.getMajor());
907 if (auto Minor = V.getMinor()) {
908 Entries.push_back(*Minor);
909 if (auto Subminor = V.getSubminor())
910 Entries.push_back(*Subminor);
911 // Ignore the 'build' component as it can't be represented in the object
912 // file.
913 }
914 M.addModuleFlag(Module::ModFlagBehavior::Warning, Name,
915 ConstantDataArray::get(M.getContext(), Entries));
916}
917
918void Module::setSDKVersion(const VersionTuple &V) {
919 addSDKVersionMD(V, *this, "SDK Version");
920}
921
924 if (!CM)
925 return {};
926 auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
927 if (!Arr)
928 return {};
929 auto getVersionComponent = [&](unsigned Index) -> std::optional<unsigned> {
930 if (Index >= Arr->getNumElements())
931 return std::nullopt;
932 return (unsigned)Arr->getElementAsInteger(Index);
933 };
934 auto Major = getVersionComponent(0);
935 if (!Major)
936 return {};
938 if (auto Minor = getVersionComponent(1)) {
939 Result = VersionTuple(*Major, *Minor);
940 if (auto Subminor = getVersionComponent(2)) {
941 Result = VersionTuple(*Major, *Minor, *Subminor);
942 }
943 }
944 return Result;
945}
946
948 return getSDKVersionMD(getModuleFlag("SDK Version"));
949}
950
952 const Module &M, SmallVectorImpl<GlobalValue *> &Vec, bool CompilerUsed) {
953 const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
954 GlobalVariable *GV = M.getGlobalVariable(Name);
955 if (!GV || !GV->hasInitializer())
956 return GV;
957
959 for (Value *Op : Init->operands()) {
960 GlobalValue *G = cast<GlobalValue>(Op->stripPointerCasts());
961 Vec.push_back(G);
962 }
963 return GV;
964}
965
967 if (auto *SummaryMD = getProfileSummary(/*IsCS*/ false)) {
968 std::unique_ptr<ProfileSummary> ProfileSummary(
969 ProfileSummary::getFromMD(SummaryMD));
970 if (ProfileSummary) {
973 return;
974 uint64_t BlockCount = Index.getBlockCount();
975 uint32_t NumCounts = ProfileSummary->getNumCounts();
976 if (!NumCounts)
977 return;
978 double Ratio = (double)BlockCount / NumCounts;
980 setProfileSummary(ProfileSummary->getMD(getContext()),
982 }
983 }
984}
985
987 if (const auto *MD = getModuleFlag("darwin.target_variant.triple"))
988 return cast<MDString>(MD)->getString();
989 return "";
990}
991
993 addModuleFlag(ModFlagBehavior::Warning, "darwin.target_variant.triple",
995}
996
998 return getSDKVersionMD(getModuleFlag("darwin.target_variant.SDK Version"));
999}
1000
1002 addSDKVersionMD(Version, *this, "darwin.target_variant.SDK Version");
1003}
1004
1006 StringRef TargetABI;
1007 if (auto *TargetABIMD = cast_or_null<MDString>(getModuleFlag("target-abi")))
1008 TargetABI = TargetABIMD->getString();
1009 return TargetABI;
1010}
1011
1013 // Check the new unified flag first.
1014 if (Metadata *MD = getModuleFlag("winx64-eh-unwind")) {
1016 return static_cast<WinX64EHUnwindMode>(CI->getZExtValue());
1017 }
1018 // Fall back to the legacy V2 flag.
1019 if (Metadata *MD = getModuleFlag("winx64-eh-unwindv2")) {
1021 return static_cast<WinX64EHUnwindMode>(CI->getZExtValue());
1022 }
1024}
1025
1027 Metadata *MD = getModuleFlag("cfguard");
1029 return static_cast<ControlFlowGuardMode>(CI->getZExtValue());
1031}
1032
1033bool Module::GlobalAsmProperties::set(StringRef Name, std::string Value) {
1034 if (Name == "target_features")
1035 TargetFeatures = std::move(Value);
1036 else if (Name == "target_cpu")
1037 TargetCPU = std::move(Value);
1038 else
1039 return false;
1040 return true;
1041}
1042
1046 if (!TargetFeatures.empty())
1047 Props.emplace_back("target_features", TargetFeatures);
1048 if (!TargetCPU.empty())
1049 Props.emplace_back("target_cpu", TargetCPU);
1050 return Props;
1051}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
unsigned uint64_t
Lower uses of LDS variables from non kernel functions
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_EXPORT_TEMPLATE
Definition Compiler.h:217
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil globals
dxil translate DXIL Translate Metadata
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
Module.h This file contains the declarations for the Module class.
static bool lookup(const GsymReader &GR, GsymDataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define G(x, y, z)
Definition MD5.cpp:55
Machine Check Debug Module
Register Reg
static Constant * getOrInsertGlobal(Module &M, StringRef Name, Type *Ty)
This file contains the declarations for metadata subclasses.
#define T
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static VersionTuple getSDKVersionMD(Metadata *MD)
Definition Module.cpp:922
static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name)
Definition Module.cpp:904
This file defines the SmallString class.
This file defines the SmallVector class.
Defines the llvm::VersionTuple class, which represents a version in the form major[....
ConstantArray - Constant Array Declarations.
Definition Constants.h:590
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:559
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition Constants.h:878
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:169
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1092
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1590
A single uniqued string.
Definition Metadata.h:744
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:602
Class to hold module path string table and global value map, and encapsulate methods for operating on...
LLVM_ABI DICompileUnit * operator*() const
Definition Module.cpp:448
LLVM_ABI DICompileUnit * operator->() const
Definition Module.cpp:451
void setStackProtectorGuardSymbol(StringRef Symbol)
Definition Module.cpp:858
void setSemanticInterposition(bool)
Set whether semantic interposition is to be respected.
Definition Module.cpp:767
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Definition Module.cpp:301
@ Warning
Emits a warning if two values disagree.
Definition Module.h:125
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
Definition Module.cpp:494
void setOverrideStackAlignment(unsigned Align)
Definition Module.cpp:900
void setDirectAccessExternalData(bool Value)
Definition Module.cpp:792
unsigned getMaxTLSAlignment() const
Definition Module.cpp:893
StringRef getTargetABIFromMD()
Returns target-abi from MDString, null if target-abi is absent.
Definition Module.cpp:1005
WinX64EHUnwindMode getWinX64EHUnwindMode() const
Get how unwind information should be generated for x64 Windows.
Definition Module.cpp:1012
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Definition Module.cpp:771
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
Definition Module.cpp:480
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition Module.cpp:487
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition Module.cpp:235
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
Definition Module.cpp:677
LongDoubleFormat getLongDoubleFormat() const
Returns the long double format from the "long-double-type" module flag, or the triple default when th...
Definition Module.cpp:685
StringRef getStackProtectorGuardSymbol() const
Get/set a symbol to use as the stack protector guard.
Definition Module.cpp:851
FloatABI::ABIType getFloatABI() const
Returns the floating-point ABI recorded by the "float-abi" module flag, or the ABI implied by the tar...
Definition Module.cpp:700
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
Definition Module.cpp:757
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
Definition Module.cpp:194
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Definition Module.cpp:73
std::optional< unsigned > getStackProtectorGuardValueWidth() const
Get/set the width in memory of the stack protector guard value.
Definition Module.cpp:874
void removeDebugIntrinsicDeclarations()
Used when printing this module in the new debug info format; removes all declarations of debug intrin...
Definition Module.cpp:127
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
Definition Module.cpp:780
llvm::Error materializeMetadata()
Definition Module.cpp:501
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
Definition Module.cpp:372
ControlFlowGuardMode getControlFlowGuardMode() const
Gets the Control Flow Guard mode.
Definition Module.cpp:1026
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
Definition Module.cpp:322
unsigned getNumNamedValues() const
Return the number of global values in the module.
Definition Module.cpp:181
bool hasStackProtectorGuardRecord() const
Definition Module.cpp:816
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition Module.cpp:187
void setFramePointer(FramePointerKind Kind)
Definition Module.cpp:812
std::optional< uint64_t > getLargeDataThreshold() const
Returns the large data threshold.
Definition Module.cpp:728
StringRef getStackProtectorGuard() const
Get/set what kind of stack protector guard to use.
Definition Module.cpp:827
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
Definition Module.cpp:775
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
Definition Module.cpp:412
UWTableKind getUwtable() const
Get/set whether synthesized functions should get the uwtable attribute.
Definition Module.cpp:796
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining.
Definition Module.cpp:583
void setStackProtectorGuard(StringRef Kind)
Definition Module.cpp:834
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
Definition Module.cpp:745
void setUwtable(UWTableKind Kind)
Definition Module.cpp:802
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Definition Module.cpp:617
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index)
Set the partial sample profile ratio in the profile summary module flag, if applicable.
Definition Module.cpp:966
ExceptionHandling getExceptionModel() const
Returns the exception model recorded by the "exception-model" module flag, or ExceptionHandling::Defa...
Definition Module.cpp:719
Module & operator=(Module &&Other)
Move assignment.
Definition Module.cpp:79
ThreadModel getThreadModel() const
Returns the thread model recorded by the "thread-model" module flag, or the model implied by the targ...
Definition Module.cpp:708
std::string getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id, const FunctionType *Proto)
Return a unique name for an intrinsic whose mangling is based on an unnamed type.
Definition Module.cpp:526
~Module()
The module destructor. This will dropAllReferences.
Definition Module.cpp:118
FramePointerKind getFramePointer() const
Get/set whether synthesized functions should get the "frame-pointer" attribute.
Definition Module.cpp:806
unsigned getOverrideStackAlignment() const
Get/set the stack alignment overridden from the default.
Definition Module.cpp:886
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition Module.cpp:381
void setStackProtectorGuardReg(StringRef Reg)
Definition Module.cpp:846
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition Module.cpp:637
std::unique_ptr< RandomNumberGenerator > createRNG(const StringRef Name) const
Get a RandomNumberGenerator salted for use with this module.
Definition Module.cpp:155
std::vector< StructType * > getIdentifiedStructTypes() const
Definition Module.cpp:512
void setDarwinTargetVariantTriple(StringRef T)
Set the target variant triple which is a string describing a variant of the target host platform.
Definition Module.cpp:992
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
Definition Module.cpp:647
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
Definition Module.cpp:597
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
Definition Module.cpp:294
StringRef getStackProtectorGuardReg() const
Get/set which register to use as the stack protector guard register.
Definition Module.cpp:839
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Definition Module.cpp:605
void setDataLayout(StringRef Desc)
Set the data layout.
Definition Module.cpp:444
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition Module.h:511
void setLargeDataThreshold(uint64_t Threshold)
Set the large data threshold.
Definition Module.cpp:738
bool isDwarf64() const
Returns the DWARF format by checking module flags.
Definition Module.cpp:612
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
Definition Module.cpp:329
void setStackProtectorGuardOffset(int Offset)
Definition Module.cpp:870
iterator_range< global_object_iterator > global_objects()
Definition Module.cpp:461
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition Module.cpp:177
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in the module.
Definition Module.cpp:624
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition Module.cpp:308
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
Definition Module.cpp:198
void setStackProtectorGuardRecord(bool Flag)
Definition Module.cpp:822
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition Module.cpp:631
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition Module.cpp:211
std::optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
Definition Module.cpp:667
VersionTuple getDarwinTargetVariantSDKVersion() const
Get the target variant version build SDK version metadata.
Definition Module.cpp:997
void setThreadModel(ThreadModel Model)
Set the thread model.
Definition Module.cpp:714
void setStackProtectorGuardValueWidth(unsigned Width)
Definition Module.cpp:881
void setLongDoubleFormat(LongDoubleFormat Format)
Set the long double format.
Definition Module.cpp:695
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
Definition Module.cpp:663
GlobalVariable * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
Definition Module.cpp:262
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
Definition Module.cpp:947
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type.
Definition Module.cpp:290
void setDarwinTargetVariantSDKVersion(VersionTuple Version)
Set the target variant version build SDK version metadata.
Definition Module.cpp:1001
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition Module.cpp:653
StringRef getDarwinTargetVariantTriple() const
Get the target variant triple which is a string describing a variant of the target host platform.
Definition Module.cpp:986
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
Definition Module.cpp:918
iterator_range< global_value_iterator > global_values()
Definition Module.cpp:469
int getStackProtectorGuardOffset() const
Get/set what offset from the stack protector to use.
Definition Module.cpp:863
bool getDirectAccessExternalData() const
Get/set whether referencing global variables can use direct access relocations on ELF targets.
Definition Module.cpp:784
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
Definition Module.cpp:752
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition Module.cpp:358
A tuple of MDNodes.
Definition Metadata.h:1808
LLVM_ABI void setOperand(unsigned I, MDNode *New)
LLVM_ABI StringRef getName() const
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
iterator_range< op_iterator > operands()
Definition Metadata.h:1904
void setPartialProfileRatio(double R)
LLVM_ABI Metadata * getMD(LLVMContext &Context, bool AddPartialField=true, bool AddPartialProfileRatioField=true)
Return summary information as metadata.
uint32_t getNumCounts() const
bool isPartialProfile() const
static LLVM_ABI ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
A random number generator.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
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
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
Definition TypeFinder.h:31
iterator end()
Definition TypeFinder.h:52
LLVM_ABI void run(const Module &M, bool onlyNamed)
iterator begin()
Definition TypeFinder.h:51
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
void dropAllReferences()
Drop all references to operands.
Definition User.h:324
This class provides a symbol table of name/value pairs.
Represents a version number in the form major[.minor[.subminor[.build]]].
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
std::optional< ABIType > parseABIType(StringRef S)
Parse the string spelling used by the "float-abi" IR module flag into an ABIType.
Definition CodeGen.h:167
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.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition Metadata.h:731
std::enable_if_t< detail::IsValidPointer< X, Y >::value, bool > hasa(Y &&MD)
Check whether Metadata has a Value.
Definition Metadata.h:673
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:690
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:594
This is an optimization pass for GlobalISel generic memory operations.
std::optional< LongDoubleFormat > parseLongDoubleFormat(StringRef Name)
Parses an IR floating-point type name into a LongDoubleFormat, returning std::nullopt if it does not ...
Definition CodeGen.h:144
@ Offset
Definition DWP.cpp:577
StringRef getLongDoubleFormatName(LongDoubleFormat Format)
Returns the IR floating-point type name for a LongDoubleFormat.
Definition CodeGen.h:126
LongDoubleFormat
The floating-point format used for the target's "long double" type.
Definition CodeGen.h:117
auto cast_or_null(const Y &Val)
Definition Casting.h:714
Op::Description Desc
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1167
std::optional< ExceptionHandling > parseExceptionModel(StringRef Name)
Parses the string spelling used by the "exception-model" IR module flag into an ExceptionHandling val...
Definition CodeGen.h:98
ControlFlowGuardMode
Definition CodeGen.h:322
WinX64EHUnwindMode
Definition CodeGen.h:312
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
UWTableKind
Definition CodeGen.h:299
@ None
No unwind table requested.
Definition CodeGen.h:300
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_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Other
Any other memory.
Definition ModRef.h:68
ThreadModel
The threading model to assume for lowering, e.g. of atomics.
Definition CodeGen.h:191
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
std::optional< ThreadModel > parseThreadModel(StringRef S)
Parse the string spelling used by the "thread-model" IR module flag into a ThreadModel.
Definition CodeGen.h:198
@ Default
Not specified; resolve to the target's default model.
Definition CodeGen.h:55
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
StringRef getThreadModelName(ThreadModel TM)
Returns the string spelling used by the "thread-model" IR module flag for a ThreadModel.
Definition CodeGen.h:208
LLVM_ABI GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition Module.cpp:951
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
LLVM_ABI bool set(StringRef Name, std::string Value)
Set a property using a string name.
Definition Module.cpp:1033
LLVM_ABI SmallVector< std::pair< StringRef, StringRef > > getAsStrings() const
Get a list of set properties as pairs of key and value.
Definition Module.cpp:1044