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