LLVM 24.0.0git
Module.h
Go to the documentation of this file.
1//===- llvm/Module.h - C++ class to represent a VM module -------*- C++ -*-===//
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/// @file
10/// Module.h This file contains the declarations for the Module class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_MODULE_H
15#define LLVM_IR_MODULE_H
16
17#include "llvm-c/Types.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/Attributes.h"
23#include "llvm/IR/Comdat.h"
24#include "llvm/IR/DataLayout.h"
25#include "llvm/IR/Function.h"
26#include "llvm/IR/GlobalAlias.h"
27#include "llvm/IR/GlobalIFunc.h"
29#include "llvm/IR/Metadata.h"
32#include "llvm/IR/ValueMap.h"
37#include <cstddef>
38#include <cstdint>
39#include <iterator>
40#include <memory>
41#include <optional>
42#include <string>
43#include <vector>
44
45namespace llvm {
46
47class Error;
48class FunctionType;
49class GVMaterializer;
50class LLVMContext;
51class MemoryBuffer;
54class StructType;
55class VersionTuple;
56
57/// A Module instance is used to store all the information related to an
58/// LLVM module. Modules are the top level container of all other LLVM
59/// Intermediate Representation (IR) objects. Each module directly contains a
60/// list of globals variables, a list of functions, a list of libraries (or
61/// other modules) this module depends on, a symbol table, and various data
62/// about the target's characteristics.
63///
64/// A module maintains a GlobalList object that is used to hold all
65/// constant references to global variables in the module. When a global
66/// variable is destroyed, it should have no entries in the GlobalList.
67/// The main container class for the LLVM Intermediate Representation.
69 /// @name Types And Enumerations
70 /// @{
71public:
72 /// The type for the list of global variables.
74 /// The type for the list of functions.
76 /// The type for the list of aliases.
78 /// The type for the list of ifuncs.
80 /// The type for the list of named metadata.
82 /// The type of the comdat "symbol" table.
84 /// The type for mapping names to named metadata.
86
87 /// The Global Variable iterator.
89 /// The Global Variable constant iterator.
91
92 /// The Function iterators.
94 /// The Function constant iterator
96
97 /// The Function reverse iterator.
99 /// The Function constant reverse iterator.
101
102 /// The Global Alias iterators.
104 /// The Global Alias constant iterator
106
107 /// The Global IFunc iterators.
109 /// The Global IFunc constant iterator
111
112 /// The named metadata iterators.
114 /// The named metadata constant iterators.
116
117 /// This enumeration defines the supported behaviors of module flags.
119 /// Emits an error if two values disagree, otherwise the resulting value is
120 /// that of the operands.
121 Error = 1,
122
123 /// Emits a warning if two values disagree. The result value will be the
124 /// operand for the flag from the first module being linked.
126
127 /// Adds a requirement that another module flag be present and have a
128 /// specified value after linking is performed. The value must be a metadata
129 /// pair, where the first element of the pair is the ID of the module flag
130 /// to be restricted, and the second element of the pair is the value the
131 /// module flag should be restricted to. This behavior can be used to
132 /// restrict the allowable results (via triggering of an error) of linking
133 /// IDs with the **Override** behavior.
135
136 /// Uses the specified value, regardless of the behavior or value of the
137 /// other module. If both modules specify **Override**, but the values
138 /// differ, an error will be emitted.
140
141 /// Appends the two values, which are required to be metadata nodes.
143
144 /// Appends the two values, which are required to be metadata
145 /// nodes. However, duplicate entries in the second list are dropped
146 /// during the append operation.
148
149 /// Takes the max of the two values, which are required to be integers.
150 Max = 7,
151
152 /// Takes the min of the two values, which are required to be integers.
153 Min = 8,
154
155 // Markers:
158 };
159
160 /// Checks if Metadata represents a valid ModFlagBehavior, and stores the
161 /// converted result in MFB.
162 static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB);
163
172
174 std::string TargetFeatures;
175 std::string TargetCPU;
176
177 /// Set a property using a string name.
178 /// Returns whether the property name was valid.
179 LLVM_ABI bool set(StringRef Name, std::string Value);
180
181 /// Get a list of set properties as pairs of key and value.
183
185 return TargetFeatures == Other.TargetFeatures &&
186 TargetCPU == Other.TargetCPU;
187 }
188
190 return !(*this == Other);
191 }
192 };
193
195 std::string Asm;
197
200 : Asm(std::move(AsmArg)), Props(std::move(Props)) {
201 if (!Asm.empty() && Asm.back() != '\n')
202 Asm += '\n';
203 }
204
205 bool empty() const { return Asm.empty(); }
206
208 return Props == Other.Props;
209 }
210 };
211
212/// @}
213/// @name Member Variables
214/// @{
215private:
216 LLVMContext &Context; ///< The LLVMContext from which types and
217 ///< constants are allocated.
218 GlobalListType GlobalList; ///< The Global Variables in the module
219 FunctionListType FunctionList; ///< The Functions in the module
220 AliasListType AliasList; ///< The Aliases in the module
221 IFuncListType IFuncList; ///< The IFuncs in the module
222 NamedMDListType NamedMDList; ///< The named metadata in the module
223 /// Inline Asm at the global scope.
225 std::unique_ptr<ValueSymbolTable> ValSymTab; ///< Symbol table for values
226 ComdatSymTabType ComdatSymTab; ///< Symbol table for COMDATs
227 std::unique_ptr<MemoryBuffer>
228 OwnedMemoryBuffer; ///< Memory buffer directly owned by this
229 ///< module, for legacy clients only.
230 std::unique_ptr<GVMaterializer>
231 Materializer; ///< Used to materialize GlobalValues
232 std::string ModuleID; ///< Human readable identifier for the module
233 std::string SourceFileName; ///< Original source file name for module,
234 ///< recorded in bitcode.
235 /// Platform target triple Module compiled on
236 /// Format: (arch)(sub)-(vendor)-(sys)-(abi)
237 // FIXME: Default construction is not the same as empty triple :(
238 Triple TargetTriple = Triple("");
239 NamedMDSymTabType NamedMDSymTab; ///< NamedMDNode names.
240 DataLayout DL; ///< DataLayout associated with the module
242 CurrentIntrinsicIds; ///< Keep track of the current unique id count for
243 ///< the specified intrinsic basename.
245 UniquedIntrinsicNames; ///< Keep track of uniqued names of intrinsics
246 ///< based on unnamed types. The combination of
247 ///< ID and FunctionType maps to the extension that
248 ///< is used to make the intrinsic name unique.
249
250 /// llvm.module.flags metadata
251 NamedMDNode *ModuleFlags = nullptr;
252
253 friend class Constant;
254
255/// @}
256/// @name Constructors
257/// @{
258public:
259 /// Used when printing this module in the new debug info format; removes all
260 /// declarations of debug intrinsics that are replaced by non-intrinsic
261 /// records in the new format.
263
264 /// \see BasicBlock::convertToNewDbgValues.
266 for (auto &F : *this) {
267 F.convertToNewDbgValues();
268 }
269
271 }
272
273 /// \see BasicBlock::convertFromNewDbgValues.
274 /// Returns true if any function's conversion modified the module.
276 bool Modified = false;
277 for (auto &F : *this) {
278 if (F.convertFromNewDbgValues())
279 Modified = true;
280 }
281 return Modified;
282 }
283
284 /// The Module constructor. Note that there is no default constructor. You
285 /// must provide a name for the module upon construction.
286 explicit Module(StringRef ModuleID, LLVMContext& C);
287 /// The module destructor. This will dropAllReferences.
288 ~Module();
289
290 /// Move assignment.
291 Module &operator=(Module &&Other);
292
293 /// @}
294 /// @name Module Level Accessors
295 /// @{
296
297 /// Get the module identifier which is, essentially, the name of the module.
298 /// @returns the module identifier as a string
299 const std::string &getModuleIdentifier() const { return ModuleID; }
300
301 /// Returns the number of non-debug IR instructions in the module.
302 /// This is equivalent to the sum of the IR instruction counts of each
303 /// function contained in the module.
304 unsigned getInstructionCount() const;
305
306 /// Get the module's original source file name. When compiling from
307 /// bitcode, this is taken from a bitcode record where it was recorded.
308 /// For other compiles it is the same as the ModuleID, which would
309 /// contain the source file name.
310 const std::string &getSourceFileName() const { return SourceFileName; }
311
312 /// Get a short "name" for the module.
313 ///
314 /// This is useful for debugging or logging. It is essentially a convenience
315 /// wrapper around getModuleIdentifier().
316 StringRef getName() const { return ModuleID; }
317
318 /// Get the data layout string for the module's target platform. This is
319 /// equivalent to getDataLayout()->getStringRepresentation().
320 const std::string &getDataLayoutStr() const {
321 return DL.getStringRepresentation();
322 }
323
324 /// Get the data layout for the module's target platform.
325 const DataLayout &getDataLayout() const { return DL; }
326
327 /// Get the target triple which is a string describing the target host.
328 const Triple &getTargetTriple() const { return TargetTriple; }
329
330 /// Get the global data context.
331 /// @returns LLVMContext - a container for LLVM's global information
332 LLVMContext &getContext() const { return Context; }
333
334 /// Get any module-scope inline assembly blocks.
336 return GlobalScopeAsm;
337 }
338
339 /// Get any module-scope inline assembly blocks.
341 return GlobalScopeAsm;
342 }
343
344 /// Return whether there is any module-scope inline assembly.
345 bool hasModuleInlineAsm() const { return !GlobalScopeAsm.empty(); }
346
347 /// Get a RandomNumberGenerator salted for use with this module. The
348 /// RNG can be seeded via -rng-seed=<uint64> and is salted with the
349 /// ModuleID and the provided pass salt. The returned RNG should not
350 /// be shared across threads or passes.
351 ///
352 /// A unique RNG per pass ensures a reproducible random stream even
353 /// when other randomness consuming passes are added or removed. In
354 /// addition, the random stream will be reproducible across LLVM
355 /// versions when the pass does not change.
356 std::unique_ptr<RandomNumberGenerator> createRNG(const StringRef Name) const;
357
358 /// Return true if size-info optimization remark is enabled, false
359 /// otherwise.
361 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
362 "size-info");
363 }
364
365 /// @}
366 /// @name Module Level Mutators
367 /// @{
368
369 /// Set the module identifier.
370 void setModuleIdentifier(StringRef ID) { ModuleID = std::string(ID); }
371
372 /// Set the module's original source file name.
373 void setSourceFileName(StringRef Name) { SourceFileName = std::string(Name); }
374
375 /// Set the data layout
376 void setDataLayout(StringRef Desc);
377 void setDataLayout(const DataLayout &Other);
378
379 /// Set the target triple.
380 void setTargetTriple(Triple T) { TargetTriple = std::move(T); }
381
382 void removeModuleInlineAsm() { GlobalScopeAsm.clear(); }
383
384 /// Set the module-scope inline assembly blocks.
385 /// A trailing newline is added if the input doesn't have one.
387 GlobalScopeAsm.clear();
388 appendModuleInlineAsm(std::move(Fragment));
389 }
390
392 GlobalScopeAsm.clear();
393 append_range(GlobalScopeAsm, Fragments);
394 }
395
396 /// Append to the module-scope inline assembly blocks.
397 /// A trailing newline is added if the input doesn't have one.
399 if (Fragment.empty())
400 return;
401
402 if (!GlobalScopeAsm.empty() &&
403 GlobalScopeAsm.back().hasSameProperties(Fragment)) {
404 GlobalScopeAsm.back().Asm += Fragment.Asm;
405 } else {
406 GlobalScopeAsm.emplace_back(std::move(Fragment));
407 }
408 }
409
410 /// Prepend to the module-scope inline assembly blocks.
412 if (Fragment.empty())
413 return;
414
415 if (!GlobalScopeAsm.empty() &&
416 GlobalScopeAsm.front().hasSameProperties(Fragment)) {
417 GlobalScopeAsm.front().Asm.insert(0, Fragment.Asm);
418 } else {
419 GlobalScopeAsm.insert(GlobalScopeAsm.begin(), std::move(Fragment));
420 }
421 }
422
423/// @}
424/// @name Generic Value Accessors
425/// @{
426
427 /// Return the global value in the module with the specified name, of
428 /// arbitrary type. This method returns null if a global with the specified
429 /// name is not found.
430 GlobalValue *getNamedValue(StringRef Name) const;
431
432 /// Return the number of global values in the module.
433 unsigned getNumNamedValues() const;
434
435 /// Return a unique non-zero ID for the specified metadata kind. This ID is
436 /// uniqued across modules in the current LLVMContext.
437 unsigned getMDKindID(StringRef Name) const;
438
439 /// Populate client supplied SmallVector with the name for custom metadata IDs
440 /// registered in this LLVMContext.
441 void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
442
443 /// Populate client supplied SmallVector with the bundle tags registered in
444 /// this LLVMContext. The bundle tags are ordered by increasing bundle IDs.
445 /// \see LLVMContext::getOperandBundleTagID
446 void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const;
447
448 std::vector<StructType *> getIdentifiedStructTypes() const;
449
450 /// Return a unique name for an intrinsic whose mangling is based on an
451 /// unnamed type. The Proto represents the function prototype.
452 std::string getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id,
453 const FunctionType *Proto);
454
455/// @}
456/// @name Function Accessors
457/// @{
458
459 /// Look up the specified function in the module symbol table. If it does not
460 /// exist, add a prototype for the function and return it. Otherwise, return
461 /// the existing function.
462 ///
463 /// In all cases, the returned value is a FunctionCallee wrapper around the
464 /// 'FunctionType *T' passed in, as well as the 'Value*' of the Function. The
465 /// function type of the function may differ from the function type stored in
466 /// FunctionCallee if it was previously created with a different type.
467 ///
468 /// Note: For library calls getOrInsertLibFunc() should be used instead.
469 FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T,
470 AttributeList AttributeList);
471
472 FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T);
473
474 /// Same as above, but takes a list of function arguments, which makes it
475 /// easier for clients to use.
476 template <typename... ArgsTy>
478 AttributeList AttributeList, Type *RetTy,
479 ArgsTy... Args) {
480 SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
481 return getOrInsertFunction(Name,
482 FunctionType::get(RetTy, ArgTys, false),
483 AttributeList);
484 }
485
486 /// Same as above, but without the attributes.
487 template <typename... ArgsTy>
489 ArgsTy... Args) {
490 return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
491 }
492
493 // Avoid an incorrect ordering that'd otherwise compile incorrectly.
494 template <typename... ArgsTy>
496 getOrInsertFunction(StringRef Name, AttributeList AttributeList,
497 FunctionType *Invalid, ArgsTy... Args) = delete;
498
499 /// Look up the specified function in the module symbol table. If it does not
500 /// exist, return null.
501 Function *getFunction(StringRef Name) const;
502
503/// @}
504/// @name Global Variable Accessors
505/// @{
506
507 /// Look up the specified global variable in the module symbol table. If it
508 /// does not exist, return null. If AllowInternal is set to true, this
509 /// function will return types that have InternalLinkage. By default, these
510 /// types are not returned.
512 return getGlobalVariable(Name, false);
513 }
514
515 GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
516
518 bool AllowInternal = false) {
519 return static_cast<const Module *>(this)->getGlobalVariable(Name,
520 AllowInternal);
521 }
522
523 /// Return the global variable in the module with the specified name, of
524 /// arbitrary type. This method returns null if a global with the specified
525 /// name is not found.
527 return getGlobalVariable(Name, true);
528 }
530 return const_cast<GlobalVariable *>(
531 static_cast<const Module *>(this)->getNamedGlobal(Name));
532 }
533
534 /// Look up the specified global in the module symbol table.
535 /// If it does not exist, invoke a callback to create a declaration of the
536 /// global and return it.
539 function_ref<GlobalVariable *()> CreateGlobalCallback);
540
541 /// Look up the specified global in the module symbol table. If required, this
542 /// overload constructs the global variable using its constructor's defaults.
544
545/// @}
546/// @name Global Alias Accessors
547/// @{
548
549 /// Return the global alias in the module with the specified name, of
550 /// arbitrary type. This method returns null if a global with the specified
551 /// name is not found.
552 GlobalAlias *getNamedAlias(StringRef Name) const;
553
554/// @}
555/// @name Global IFunc Accessors
556/// @{
557
558 /// Return the global ifunc in the module with the specified name, of
559 /// arbitrary type. This method returns null if a global with the specified
560 /// name is not found.
561 GlobalIFunc *getNamedIFunc(StringRef Name) const;
562
563/// @}
564/// @name Named Metadata Accessors
565/// @{
566
567 /// Return the first NamedMDNode in the module with the specified name. This
568 /// method returns null if a NamedMDNode with the specified name is not found.
569 NamedMDNode *getNamedMetadata(StringRef Name) const;
570
571 /// Return the named MDNode in the module with the specified name. This method
572 /// returns a new NamedMDNode if a NamedMDNode with the specified name is not
573 /// found.
574 NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
575
576 /// Remove the given NamedMDNode from this module and delete it.
577 void eraseNamedMetadata(NamedMDNode *NMD);
578
579/// @}
580/// @name Comdat Accessors
581/// @{
582
583 /// Return the Comdat in the module with the specified name. It is created
584 /// if it didn't already exist.
585 Comdat *getOrInsertComdat(StringRef Name);
586
587/// @}
588/// @name Module Flags Accessors
589/// @{
590
591 /// Returns the module flags in the provided vector.
592 void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
593
594 /// Return the corresponding value if Key appears in module flags, otherwise
595 /// return null.
596 Metadata *getModuleFlag(StringRef Key) const;
597
598 /// Returns the NamedMDNode in the module that represents module-level flags.
599 /// This method returns null if there are no module-level flags.
600 NamedMDNode *getModuleFlagsMetadata() const { return ModuleFlags; }
601
602 /// Returns the NamedMDNode in the module that represents module-level flags.
603 /// If module-level flags aren't found, it creates the named metadata that
604 /// contains them.
605 NamedMDNode *getOrInsertModuleFlagsMetadata();
606
607 /// Add a module-level flag to the module-level flags metadata. It will create
608 /// the module-level flags named metadata if it doesn't already exist.
609 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
610 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
611 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint64_t Val);
612 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
613 inline void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val) {
614 addModuleFlag(Behavior, Key, static_cast<uint32_t>(Val));
615 }
616 void addModuleFlag(MDNode *Node);
617 /// Like addModuleFlag but replaces the old module flag if it already exists.
618 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
619 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
620 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint64_t Val);
621 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
622 inline void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val) {
623 setModuleFlag(Behavior, Key, static_cast<uint32_t>(Val));
624 }
625
626 /// @}
627 /// @name Materialization
628 /// @{
629
630 /// Sets the GVMaterializer to GVM. This module must not yet have a
631 /// Materializer. To reset the materializer for a module that already has one,
632 /// call materializeAll first. Destroying this module will destroy
633 /// its materializer without materializing any more GlobalValues. Without
634 /// destroying the Module, there is no way to detach or destroy a materializer
635 /// without materializing all the GVs it controls, to avoid leaving orphan
636 /// unmaterialized GVs.
637 void setMaterializer(GVMaterializer *GVM);
638 /// Retrieves the GVMaterializer, if any, for this Module.
639 GVMaterializer *getMaterializer() const { return Materializer.get(); }
640 bool isMaterialized() const { return !getMaterializer(); }
641
642 /// Make sure the GlobalValue is fully read.
643 llvm::Error materialize(GlobalValue *GV);
644
645 /// Make sure all GlobalValues in this Module are fully read and clear the
646 /// Materializer.
647 llvm::Error materializeAll();
648
649 llvm::Error materializeMetadata();
650
651 /// Detach global variable \p GV from the list but don't delete it.
652 void removeGlobalVariable(GlobalVariable *GV) { GlobalList.remove(GV); }
653 /// Remove global variable \p GV from the list and delete it.
654 void eraseGlobalVariable(GlobalVariable *GV) { GlobalList.erase(GV); }
655 /// Insert global variable \p GV at the end of the global variable list and
656 /// take ownership.
658 insertGlobalVariable(GlobalList.end(), GV);
659 }
660 /// Insert global variable \p GV into the global variable list before \p
661 /// Where and take ownership.
663 GlobalList.insert(Where, GV);
664 }
665 // Use global_size() to get the total number of global variables.
666 // Use globals() to get the range of all global variables.
667
668 std::optional<GlobalValue::GUID> getGUID(const Value *V) const {
669 const auto It = ValueToGUIDMap.find(V);
670 if (It == ValueToGUIDMap.end())
671 return std::nullopt;
672
673 return It->second;
674 }
675
676 void insertGUID(const Value *V, GlobalValue::GUID GUID) {
677 const auto [It, WasInserted] = ValueToGUIDMap.insert({V, GUID});
678
679 (void)It, (void)WasInserted;
680#ifndef NDEBUG
681 if (!WasInserted) {
682 assert((It->second == GUID) && "insertGUID called with different value");
683 }
684#endif
685 }
686
687private:
688 /// Do not transfer GUID of a value to the value it is being RAUWed with.
689 struct GUIDMapConfig : ValueMapConfig<const Value *> {
690 enum { FollowRAUW = false };
691 };
692
693 /// A mapping directly from Value to GUID. Populated from bitcode
694 /// (MODULE_CODE_GUIDLIST). Necessary for lazy-loading modules, where we
695 /// don't load metadata.
696 ValueMap<const Value *, GlobalValue::GUID, GUIDMapConfig> ValueToGUIDMap;
697
698 /// @}
699 /// @name Direct access to the globals list, functions list, and symbol table
700 /// @{
701
702 /// Get the Module's list of global variables (constant).
703 const GlobalListType &getGlobalList() const { return GlobalList; }
704 /// Get the Module's list of global variables.
705 GlobalListType &getGlobalList() { return GlobalList; }
706
707 static GlobalListType Module::*getSublistAccess(GlobalVariable*) {
708 return &Module::GlobalList;
709 }
711
712public:
713 /// Get the Module's list of functions (constant).
714 const FunctionListType &getFunctionList() const { return FunctionList; }
715 /// Get the Module's list of functions.
716 FunctionListType &getFunctionList() { return FunctionList; }
718 return &Module::FunctionList;
719 }
720
721 /// Detach \p Alias from the list but don't delete it.
722 void removeAlias(GlobalAlias *Alias) { AliasList.remove(Alias); }
723 /// Remove \p Alias from the list and delete it.
724 void eraseAlias(GlobalAlias *Alias) { AliasList.erase(Alias); }
725 /// Insert \p Alias at the end of the alias list and take ownership.
726 void insertAlias(GlobalAlias *Alias) { AliasList.insert(AliasList.end(), Alias); }
727 // Use alias_size() to get the size of AliasList.
728 // Use aliases() to get a range of all Alias objects in AliasList.
729
730 /// Detach \p IFunc from the list but don't delete it.
731 void removeIFunc(GlobalIFunc *IFunc) { IFuncList.remove(IFunc); }
732 /// Remove \p IFunc from the list and delete it.
733 void eraseIFunc(GlobalIFunc *IFunc) { IFuncList.erase(IFunc); }
734 /// Insert \p IFunc at the end of the alias list and take ownership.
735 void insertIFunc(GlobalIFunc *IFunc) { IFuncList.push_back(IFunc); }
736 // Use ifunc_size() to get the number of functions in IFuncList.
737 // Use ifuncs() to get the range of all IFuncs.
738
739 /// Detach \p MDNode from the list but don't delete it.
740 void removeNamedMDNode(NamedMDNode *MDNode) { NamedMDList.remove(MDNode); }
741 /// Remove \p MDNode from the list and delete it.
742 void eraseNamedMDNode(NamedMDNode *MDNode) { NamedMDList.erase(MDNode); }
743 /// Insert \p MDNode at the end of the alias list and take ownership.
745 NamedMDList.push_back(MDNode);
746 }
747 // Use named_metadata_size() to get the size of the named meatadata list.
748 // Use named_metadata() to get the range of all named metadata.
749
750private: // Please use functions like insertAlias(), removeAlias() etc.
751 /// Get the Module's list of aliases (constant).
752 const AliasListType &getAliasList() const { return AliasList; }
753 /// Get the Module's list of aliases.
754 AliasListType &getAliasList() { return AliasList; }
755
756 static AliasListType Module::*getSublistAccess(GlobalAlias*) {
757 return &Module::AliasList;
758 }
760
761 /// Get the Module's list of ifuncs (constant).
762 const IFuncListType &getIFuncList() const { return IFuncList; }
763 /// Get the Module's list of ifuncs.
764 IFuncListType &getIFuncList() { return IFuncList; }
765
766 static IFuncListType Module::*getSublistAccess(GlobalIFunc*) {
767 return &Module::IFuncList;
768 }
770
771 /// Get the Module's list of named metadata (constant).
772 const NamedMDListType &getNamedMDList() const { return NamedMDList; }
773 /// Get the Module's list of named metadata.
774 NamedMDListType &getNamedMDList() { return NamedMDList; }
775
776 static NamedMDListType Module::*getSublistAccess(NamedMDNode*) {
777 return &Module::NamedMDList;
778 }
779
780public:
781 /// Get the symbol table of global variable and function identifiers
782 const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
783 /// Get the Module's symbol table of global variable and function identifiers.
784 ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
785
786 /// Get the Module's symbol table for COMDATs (constant).
787 const ComdatSymTabType &getComdatSymbolTable() const { return ComdatSymTab; }
788 /// Get the Module's symbol table for COMDATs.
789 ComdatSymTabType &getComdatSymbolTable() { return ComdatSymTab; }
790
791/// @}
792/// @name Global Variable Iteration
793/// @{
794
795 global_iterator global_begin() { return GlobalList.begin(); }
796 const_global_iterator global_begin() const { return GlobalList.begin(); }
797 global_iterator global_end () { return GlobalList.end(); }
798 const_global_iterator global_end () const { return GlobalList.end(); }
799 size_t global_size () const { return GlobalList.size(); }
800 bool global_empty() const { return GlobalList.empty(); }
801
808
809/// @}
810/// @name Function Iteration
811/// @{
812
813 iterator begin() { return FunctionList.begin(); }
814 const_iterator begin() const { return FunctionList.begin(); }
815 iterator end () { return FunctionList.end(); }
816 const_iterator end () const { return FunctionList.end(); }
817 reverse_iterator rbegin() { return FunctionList.rbegin(); }
818 const_reverse_iterator rbegin() const{ return FunctionList.rbegin(); }
819 reverse_iterator rend() { return FunctionList.rend(); }
820 const_reverse_iterator rend() const { return FunctionList.rend(); }
821 size_t size() const { return FunctionList.size(); }
822 bool empty() const { return FunctionList.empty(); }
823
830
831 /// Get an iterator range over all function definitions (excluding
832 /// declarations).
835 [](Function &F) { return !F.isDeclaration(); });
836 }
837 auto getFunctionDefs() const {
838 return make_filter_range(
839 functions(), [](const Function &F) { return !F.isDeclaration(); });
840 }
841
842/// @}
843/// @name Alias Iteration
844/// @{
845
846 alias_iterator alias_begin() { return AliasList.begin(); }
847 const_alias_iterator alias_begin() const { return AliasList.begin(); }
848 alias_iterator alias_end () { return AliasList.end(); }
849 const_alias_iterator alias_end () const { return AliasList.end(); }
850 size_t alias_size () const { return AliasList.size(); }
851 bool alias_empty() const { return AliasList.empty(); }
852
859
860/// @}
861/// @name IFunc Iteration
862/// @{
863
864 ifunc_iterator ifunc_begin() { return IFuncList.begin(); }
865 const_ifunc_iterator ifunc_begin() const { return IFuncList.begin(); }
866 ifunc_iterator ifunc_end () { return IFuncList.end(); }
867 const_ifunc_iterator ifunc_end () const { return IFuncList.end(); }
868 size_t ifunc_size () const { return IFuncList.size(); }
869 bool ifunc_empty() const { return IFuncList.empty(); }
870
877
878 /// @}
879 /// @name Convenience iterators
880 /// @{
881
887
890
897
900
901 /// @}
902 /// @name Named Metadata Iteration
903 /// @{
904
905 named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
907 return NamedMDList.begin();
908 }
909
910 named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
912 return NamedMDList.end();
913 }
914
915 size_t named_metadata_size() const { return NamedMDList.size(); }
916 bool named_metadata_empty() const { return NamedMDList.empty(); }
917
924
925 /// An iterator for DICompileUnits that skips those marked NoDebug.
927 NamedMDNode *CUs;
928 unsigned Idx;
929
930 LLVM_ABI void SkipNoDebugCUs();
931
932 public:
933 using iterator_category = std::input_iterator_tag;
935 using difference_type = std::ptrdiff_t;
938
939 explicit debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
940 : CUs(CUs), Idx(Idx) {
941 SkipNoDebugCUs();
942 }
943
945 ++Idx;
946 SkipNoDebugCUs();
947 return *this;
948 }
949
952 ++Idx;
953 return T;
954 }
955
957 return Idx == I.Idx;
958 }
959
961 return Idx != I.Idx;
962 }
963
965 LLVM_ABI DICompileUnit *operator->() const;
966 };
967
969 auto *CUs = getNamedMetadata("llvm.dbg.cu");
970 return debug_compile_units_iterator(CUs, 0);
971 }
972
974 auto *CUs = getNamedMetadata("llvm.dbg.cu");
975 return debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0);
976 }
977
978 /// Return an iterator for all DICompileUnits listed in this Module's
979 /// llvm.dbg.cu named metadata node and aren't explicitly marked as
980 /// NoDebug.
982 auto *CUs = getNamedMetadata("llvm.dbg.cu");
983 return make_range(
985 debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0));
986 }
987/// @}
988
989/// @name Utility functions for printing and dumping Module objects
990/// @{
991
992 /// Print the module to an output stream with an optional
993 /// AssemblyAnnotationWriter. If \c ShouldPreserveUseListOrder, then include
994 /// uselistorder directives so that use-lists can be recreated when reading
995 /// the assembly.
997 bool ShouldPreserveUseListOrder = false,
998 bool IsForDebug = false) const;
999
1000 /// Renumber the IDs stored in metadata nodes into canonical assembly order.
1001 /// This mutates the IDs and should only be used immediately before final
1002 /// assembly output.
1003 void renumberMetadataForAssembly();
1004
1005 /// Dump the module to stderr (for debugging).
1006 void dump() const;
1007
1008 /// This function causes all the subinstructions to "let go" of all references
1009 /// that they are maintaining. This allows one to 'delete' a whole class at
1010 /// a time, even though there may be circular references... first all
1011 /// references are dropped, and all use counts go to zero. Then everything
1012 /// is delete'd for real. Note that no operations are valid on an object
1013 /// that has "dropped all references", except operator delete.
1014 void dropAllReferences();
1015
1016/// @}
1017/// @name Utility functions for querying Debug information.
1018/// @{
1019
1020 /// Returns the Number of Register ParametersDwarf Version by checking
1021 /// module flags.
1022 unsigned getNumberRegisterParameters() const;
1023
1024 /// Returns the Dwarf Version by checking module flags.
1025 unsigned getDwarfVersion() const;
1026
1027 /// Returns the DWARF format by checking module flags.
1028 bool isDwarf64() const;
1029
1030 /// Returns the CodeView Version by checking module flags.
1031 /// Returns zero if not present in module.
1032 unsigned getCodeViewFlag() const;
1033
1034/// @}
1035/// @name Utility functions for querying and setting PIC level
1036/// @{
1037
1038 /// Returns the PIC level (small or large model)
1039 PICLevel::Level getPICLevel() const;
1040
1041 /// Set the PIC level (small or large model)
1042 void setPICLevel(PICLevel::Level PL);
1043/// @}
1044
1045/// @}
1046/// @name Utility functions for querying and setting PIE level
1047/// @{
1048
1049 /// Returns the PIE level (small or large model)
1050 PIELevel::Level getPIELevel() const;
1051
1052 /// Set the PIE level (small or large model)
1053 void setPIELevel(PIELevel::Level PL);
1054/// @}
1055
1056 /// @}
1057 /// @name Utility function for querying and setting code model
1058 /// @{
1059
1060 /// Returns the code model (tiny, small, kernel, medium or large model)
1061 std::optional<CodeModel::Model> getCodeModel() const;
1062
1063 /// Set the code model (tiny, small, kernel, medium or large)
1064 void setCodeModel(CodeModel::Model CL);
1065 /// @}
1066
1067 /// @}
1068 /// @name Utility functions for querying the long double format
1069 /// @{
1070
1071 /// Returns the long double format from the "long-double-type" module flag,
1072 /// or the triple default when the flag is absent.
1073 LongDoubleFormat getLongDoubleFormat() const;
1074
1075 /// Set the long double format.
1076 void setLongDoubleFormat(LongDoubleFormat Format);
1077 /// @}
1078
1079 /// @}
1080 /// @name Utility function for querying the floating-point ABI
1081 /// @{
1082
1083 /// Returns the floating-point ABI recorded by the "float-abi" module flag, or
1084 /// the ABI implied by the target triple when the flag is absent.
1085 FloatABI::ABIType getFloatABI() const;
1086 /// @}
1087
1088 /// @}
1089 /// @name Utility function for querying and setting the large data threshold
1090 /// @{
1091
1092 /// Returns the large data threshold.
1093 std::optional<uint64_t> getLargeDataThreshold() const;
1094
1095 /// Set the large data threshold.
1096 void setLargeDataThreshold(uint64_t Threshold);
1097 /// @}
1098
1099 /// @name Utility functions for querying and setting PGO summary
1100 /// @{
1101
1102 /// Attach profile summary metadata to this module.
1103 void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind);
1104
1105 /// Returns profile summary metadata. When IsCS is true, use the context
1106 /// sensitive profile summary.
1107 Metadata *getProfileSummary(bool IsCS) const;
1108 /// @}
1109
1110 /// Returns whether semantic interposition is to be respected.
1111 bool getSemanticInterposition() const;
1112
1113 /// Set whether semantic interposition is to be respected.
1114 void setSemanticInterposition(bool);
1115
1116 /// Returns true if PLT should be avoided for RTLib calls.
1117 bool getRtLibUseGOT() const;
1118
1119 /// Set that PLT should be avoid for RTLib calls.
1120 void setRtLibUseGOT();
1121
1122 /// Get/set whether referencing global variables can use direct access
1123 /// relocations on ELF targets.
1124 bool getDirectAccessExternalData() const;
1125 void setDirectAccessExternalData(bool Value);
1126
1127 /// Get/set whether synthesized functions should get the uwtable attribute.
1128 UWTableKind getUwtable() const;
1129 void setUwtable(UWTableKind Kind);
1130
1131 /// Get/set whether synthesized functions should get the "frame-pointer"
1132 /// attribute.
1133 FramePointerKind getFramePointer() const;
1134 void setFramePointer(FramePointerKind Kind);
1135
1136 /// Get/set what kind of stack protector guard to use.
1137 StringRef getStackProtectorGuard() const;
1138 void setStackProtectorGuard(StringRef Kind);
1139
1140 /// Get/set which register to use as the stack protector guard register. The
1141 /// empty string is equivalent to "global". Other values may be "tls" or
1142 /// "sysreg".
1143 StringRef getStackProtectorGuardReg() const;
1144 void setStackProtectorGuardReg(StringRef Reg);
1145
1146 /// Get/set a symbol to use as the stack protector guard.
1147 StringRef getStackProtectorGuardSymbol() const;
1148 void setStackProtectorGuardSymbol(StringRef Symbol);
1149
1150 /// Get/set what offset from the stack protector to use.
1151 int getStackProtectorGuardOffset() const;
1152 void setStackProtectorGuardOffset(int Offset);
1153
1154 /// Get/set the width in memory of the stack protector guard value.
1155 std::optional<unsigned> getStackProtectorGuardValueWidth() const;
1156 void setStackProtectorGuardValueWidth(unsigned Width);
1157
1158 // Get/set flag indicating whether to emit a __stack_protector_loc section.
1159 bool hasStackProtectorGuardRecord() const;
1160 void setStackProtectorGuardRecord(bool Flag);
1161
1162 /// Get/set the stack alignment overridden from the default.
1163 unsigned getOverrideStackAlignment() const;
1164 void setOverrideStackAlignment(unsigned Align);
1165
1166 unsigned getMaxTLSAlignment() const;
1167
1168 /// @name Utility functions for querying and setting the build SDK version
1169 /// @{
1170
1171 /// Attach a build SDK version metadata to this module.
1172 void setSDKVersion(const VersionTuple &V);
1173
1174 /// Get the build SDK version metadata.
1175 ///
1176 /// An empty version is returned if no such metadata is attached.
1177 VersionTuple getSDKVersion() const;
1178 /// @}
1179
1180 /// Take ownership of the given memory buffer.
1181 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1182
1183 /// Set the partial sample profile ratio in the profile summary module flag,
1184 /// if applicable.
1185 void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index);
1186
1187 /// Get the target variant triple which is a string describing a variant of
1188 /// the target host platform. For example, Mac Catalyst can be a variant
1189 /// target triple for a macOS target.
1190 /// @returns a string containing the target variant triple.
1191 StringRef getDarwinTargetVariantTriple() const;
1192
1193 /// Set the target variant triple which is a string describing a variant of
1194 /// the target host platform.
1195 void setDarwinTargetVariantTriple(StringRef T);
1196
1197 /// Get the target variant version build SDK version metadata.
1198 ///
1199 /// An empty version is returned if no such metadata is attached.
1200 VersionTuple getDarwinTargetVariantSDKVersion() const;
1201
1202 /// Set the target variant version build SDK version metadata.
1203 void setDarwinTargetVariantSDKVersion(VersionTuple Version);
1204
1205 /// Returns target-abi from MDString, null if target-abi is absent.
1206 StringRef getTargetABIFromMD();
1207
1208 /// Get how unwind information should be generated for x64 Windows.
1209 WinX64EHUnwindMode getWinX64EHUnwindMode() const;
1210
1211 /// Gets the Control Flow Guard mode.
1212 ControlFlowGuardMode getControlFlowGuardMode() const;
1213};
1214
1215/// Given "llvm.used" or "llvm.compiler.used" as a global name, collect the
1216/// initializer elements of that global in a SmallVector and return the global
1217/// itself.
1218LLVM_ABI GlobalVariable *
1219collectUsedGlobalVariables(const Module &M, SmallVectorImpl<GlobalValue *> &Vec,
1220 bool CompilerUsed);
1221
1222/// An raw_ostream inserter for modules.
1224 M.print(O, nullptr);
1225 return O;
1226}
1227
1228// Create wrappers for C Binding types (see CBindingWrapping.h).
1230
1231/* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1232 * Module.
1233 */
1235 return reinterpret_cast<Module*>(MP);
1236}
1237
1238} // end namespace llvm
1239
1240#endif // LLVM_IR_MODULE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
This file defines the StringMap class.
unsigned uint64_t
Lower uses of LDS variables from non kernel functions
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
always inline
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
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")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_ABI
Definition Compiler.h:215
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
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
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file contains some templates that are useful if you are working with the STL at all.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static GlobalVariable * getGlobalVariable(Module &M, Type *Ty, const char *Name)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1069
A single uniqued string.
Definition Metadata.h:722
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Root of the metadata hierarchy.
Definition Metadata.h:64
Class to hold module path string table and global value map, and encapsulate methods for operating on...
An iterator for DICompileUnits that skips those marked NoDebug.
Definition Module.h:926
debug_compile_units_iterator & operator++()
Definition Module.h:944
bool operator==(const debug_compile_units_iterator &I) const
Definition Module.h:956
debug_compile_units_iterator operator++(int)
Definition Module.h:950
std::input_iterator_tag iterator_category
Definition Module.h:933
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
Definition Module.h:939
bool operator!=(const debug_compile_units_iterator &I) const
Definition Module.h:960
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition Module.h:328
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
Definition Module.h:83
global_iterator global_begin()
Definition Module.h:795
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition Module.h:731
const_global_iterator global_begin() const
Definition Module.h:796
const_iterator begin() const
Definition Module.h:814
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Definition Module.cpp:301
ifunc_iterator ifunc_begin()
Definition Module.h:864
void eraseNamedMDNode(NamedMDNode *MDNode)
Remove MDNode from the list and delete it.
Definition Module.h:742
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition Module.h:118
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
Definition Module.h:147
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
Definition Module.h:139
@ Warning
Emits a warning if two values disagree.
Definition Module.h:125
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition Module.h:121
@ ModFlagBehaviorFirstVal
Definition Module.h:156
@ Min
Takes the min of the two values, which are required to be integers.
Definition Module.h:153
@ Append
Appends the two values, which are required to be metadata nodes.
Definition Module.h:142
@ Max
Takes the max of the two values, which are required to be integers.
Definition Module.h:150
@ ModFlagBehaviorLastVal
Definition Module.h:157
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition Module.h:134
LLVMContext & getContext() const
Get the global data context.
Definition Module.h:332
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition Module.h:735
iterator_range< const_alias_iterator > aliases() const
Definition Module.h:856
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Definition Module.h:787
global_iterator global_end()
Definition Module.h:797
GlobalVariable * getNamedGlobal(StringRef Name)
Definition Module.h:529
void setTargetTriple(Triple T)
Set the target triple.
Definition Module.h:380
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
Definition Module.h:113
size_t alias_size() const
Definition Module.h:850
const_global_iterator global_end() const
Definition Module.h:798
bool global_empty() const
Definition Module.h:800
iterator begin()
Definition Module.h:813
void convertToNewDbgValues()
Definition Module.h:265
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)
Same as above, but takes a list of function arguments, which makes it easier for clients to use.
Definition Module.h:477
const_ifunc_iterator ifunc_end() const
Definition Module.h:867
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
Definition Module.h:622
iterator_range< ifunc_iterator > ifuncs()
Definition Module.h:871
bool named_metadata_empty() const
Definition Module.h:916
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Definition Module.cpp:73
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
Definition Module.h:81
SymbolTableList< Function > FunctionListType
The type for the list of functions.
Definition Module.h:75
void removeDebugIntrinsicDeclarations()
Used when printing this module in the new debug info format; removes all declarations of debug intrin...
Definition Module.cpp:127
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
Definition Module.h:784
NamedMDListType::const_iterator const_named_metadata_iterator
The named metadata constant iterators.
Definition Module.h:115
const_named_metadata_iterator named_metadata_begin() const
Definition Module.h:906
size_t global_size() const
Definition Module.h:799
iterator_range< debug_compile_units_iterator > debug_compile_units() const
Return an iterator for all DICompileUnits listed in this Module's llvm.dbg.cu named metadata node and...
Definition Module.h:981
iterator_range< iterator > functions()
Definition Module.h:824
StringRef getName() const
Get a short "name" for the module.
Definition Module.h:316
void prependModuleInlineAsm(GlobalAsmFragment Fragment)
Prepend to the module-scope inline assembly blocks.
Definition Module.h:411
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
Definition Module.h:639
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition Module.h:310
IFuncListType::iterator ifunc_iterator
The Global IFunc iterators.
Definition Module.h:108
const_alias_iterator alias_end() const
Definition Module.h:849
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition Module.h:722
iterator_range< named_metadata_iterator > named_metadata()
Definition Module.h:918
friend class Constant
Definition Module.h:253
named_metadata_iterator named_metadata_begin()
Definition Module.h:905
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
Definition Module.cpp:412
ifunc_iterator ifunc_end()
Definition Module.h:866
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
Definition Module.h:90
void appendModuleInlineAsm(GlobalAsmFragment Fragment)
Append to the module-scope inline assembly blocks.
Definition Module.h:398
iterator_range< alias_iterator > aliases()
Definition Module.h:853
void removeModuleInlineAsm()
Definition Module.h:382
void insertGlobalVariable(GlobalListType::iterator Where, GlobalVariable *GV)
Insert global variable GV into the global variable list before Where and take ownership.
Definition Module.h:662
alias_iterator alias_end()
Definition Module.h:848
const_alias_iterator alias_begin() const
Definition Module.h:847
const_reverse_iterator rbegin() const
Definition Module.h:818
alias_iterator alias_begin()
Definition Module.h:846
reverse_iterator rend()
Definition Module.h:819
bool convertFromNewDbgValues()
Definition Module.h:275
FunctionListType::iterator iterator
The Function iterators.
Definition Module.h:93
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)
Definition Module.h:517
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition Module.h:733
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
Definition Module.h:360
StringMap< NamedMDNode * > NamedMDSymTabType
The type for mapping names to named metadata.
Definition Module.h:85
auto getFunctionDefs()
Get an iterator range over all function definitions (excluding declarations).
Definition Module.h:833
GlobalListType::iterator global_iterator
The Global Variable iterator.
Definition Module.h:88
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition Module.cpp:381
size_t size() const
Definition Module.h:821
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
Definition Module.h:613
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
Definition Module.h:100
bool alias_empty() const
Definition Module.h:851
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, FunctionType *Invalid, ArgsTy... Args)=delete
void insertGUID(const Value *V, GlobalValue::GUID GUID)
Definition Module.h:676
iterator_range< global_iterator > globals()
Definition Module.h:802
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition Module.h:714
const_reverse_iterator rend() const
Definition Module.h:820
iterator_range< const_named_metadata_iterator > named_metadata() const
Definition Module.h:921
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
Definition Module.h:882
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
Definition Module.h:110
size_t ifunc_size() const
Definition Module.h:868
SymbolTableList< GlobalVariable > GlobalListType
The type for the list of global variables.
Definition Module.h:73
FunctionListType & getFunctionList()
Get the Module's list of functions.
Definition Module.h:716
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition Module.h:724
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition Module.h:299
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition Module.h:654
std::optional< GlobalValue::GUID > getGUID(const Value *V) const
Definition Module.h:668
reverse_iterator rbegin()
Definition Module.h:817
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
Definition Module.h:488
void insertNamedMDNode(NamedMDNode *MDNode)
Insert MDNode at the end of the alias list and take ownership.
Definition Module.h:744
const_named_metadata_iterator named_metadata_end() const
Definition Module.h:911
bool empty() const
Definition Module.h:822
void removeNamedMDNode(NamedMDNode *MDNode)
Detach MDNode from the list but don't delete it.
Definition Module.h:740
AliasListType::iterator alias_iterator
The Global Alias iterators.
Definition Module.h:103
iterator end()
Definition Module.h:815
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition Module.h:511
bool hasModuleInlineAsm() const
Return whether there is any module-scope inline assembly.
Definition Module.h:345
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
Definition Module.h:657
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
Definition Module.h:782
size_t named_metadata_size() const
Definition Module.h:915
iterator_range< global_object_iterator > global_objects()
Definition Module.cpp:461
named_metadata_iterator named_metadata_end()
Definition Module.h:910
bool isMaterialized() const
Definition Module.h:640
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Definition Module.h:526
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
Definition Module.h:105
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition Module.cpp:211
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
Definition Module.h:789
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
Definition Module.h:98
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:325
iterator_range< const_iterator > functions() const
Definition Module.h:827
concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator > global_value_iterator
Definition Module.h:891
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
Definition Module.h:600
iterator_range< const_global_iterator > globals() const
Definition Module.h:805
void setModuleIdentifier(StringRef ID)
Set the module identifier.
Definition Module.h:370
iterator_range< const_ifunc_iterator > ifuncs() const
Definition Module.h:874
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
Definition Module.h:77
const_iterator end() const
Definition Module.h:816
void setSourceFileName(StringRef Name)
Set the module's original source file name.
Definition Module.h:373
void setModuleInlineAsm(GlobalAsmFragment Fragment)
Set the module-scope inline assembly blocks.
Definition Module.h:386
void setModuleInlineAsm(ArrayRef< GlobalAsmFragment > Fragments)
Definition Module.h:391
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
Definition Module.h:79
auto getFunctionDefs() const
Definition Module.h:837
ArrayRef< GlobalAsmFragment > getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition Module.h:335
MutableArrayRef< GlobalAsmFragment > getModuleInlineAsm()
Get any module-scope inline assembly blocks.
Definition Module.h:340
const_ifunc_iterator ifunc_begin() const
Definition Module.h:865
concat_iterator< const GlobalObject, const_iterator, const_global_iterator > const_global_object_iterator
Definition Module.h:884
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
Definition Module.h:320
static FunctionListType Module::* getSublistAccess(Function *)
Definition Module.h:717
FunctionListType::const_iterator const_iterator
The Function constant iterator.
Definition Module.h:95
concat_iterator< const GlobalValue, const_iterator, const_global_iterator, const_alias_iterator, const_ifunc_iterator > const_global_value_iterator
Definition Module.h:894
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition Module.h:726
debug_compile_units_iterator debug_compile_units_begin() const
Definition Module.h:968
bool ifunc_empty() const
Definition Module.h:869
iterator_range< global_value_iterator > global_values()
Definition Module.cpp:469
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition Module.h:652
debug_compile_units_iterator debug_compile_units_end() const
Definition Module.h:973
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
A tuple of MDNodes.
Definition Metadata.h:1755
A random number generator.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
List that automatically updates parent links and symbol tables.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Definition Value.h:75
Represents a version number in the form major[.minor[.subminor[.build]]].
Iterator wrapper that concatenates sequences together.
Definition STLExtras.h:1000
An efficient, type-erasing, non-owning reference to a callable.
typename base_list_type::const_reverse_iterator const_reverse_iterator
Definition ilist.h:124
typename base_list_type::reverse_iterator reverse_iterator
Definition ilist.h:123
typename base_list_type::iterator iterator
Definition ilist.h:121
typename base_list_type::const_iterator const_iterator
Definition ilist.h:122
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition Types.h:61
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Definition Types.h:124
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition DWP.cpp:577
FramePointerKind
Definition CodeGen.h:185
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2262
LongDoubleFormat
The floating-point format used for the target's "long double" type.
Definition CodeGen.h:67
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
Op::Description Desc
ControlFlowGuardMode
Definition CodeGen.h:244
WinX64EHUnwindMode
Definition CodeGen.h:234
iplist< T, Options... > ilist
Definition ilist.h:344
UWTableKind
Definition CodeGen.h:221
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:551
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Other
Any other memory.
Definition ModRef.h:68
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:397
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
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:932
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
GlobalAsmFragment(StringRef Asm)
Definition Module.h:198
GlobalAsmProperties Props
Definition Module.h:196
GlobalAsmFragment(std::string AsmArg, GlobalAsmProperties Props={})
Definition Module.h:199
bool hasSameProperties(const GlobalAsmFragment &Other) const
Definition Module.h:207
LLVM_ABI bool set(StringRef Name, std::string Value)
Set a property using a string name.
Definition Module.cpp:1015
bool operator==(const GlobalAsmProperties &Other) const
Definition Module.h:184
LLVM_ABI SmallVector< std::pair< StringRef, StringRef > > getAsStrings() const
Get a list of set properties as pairs of key and value.
Definition Module.cpp:1026
bool operator!=(const GlobalAsmProperties &Other) const
Definition Module.h:189
ModFlagBehavior Behavior
Definition Module.h:165
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
Definition Module.h:169
This class defines the default behavior for configurable aspects of ValueMap<>.
Definition ValueMap.h:53