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();
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,
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>
479 ArgsTy... Args) {
480 SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
481 return getOrInsertFunction(Name,
482 FunctionType::get(RetTy, ArgTys, false),
484 }
485
486 /// Same as above, but without the attributes.
487 template <typename... ArgsTy, typename = std::enable_if_t<std::conjunction_v<
488 std::is_convertible<ArgsTy, Type *>...>>>
490 ArgsTy... Args) {
491 return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
492 }
493
494 /// Look up the specified function in the module symbol table. If it does not
495 /// exist, insert a declaration of the function and invoke a callback to
496 /// initialize it. \p Name must not be empty or start with "llvm.".
498 getOrInsertFunction(StringRef Name, FunctionType *T,
499 function_ref<void(Function &)> InitCallback);
500
501 // Avoid an incorrect ordering that'd otherwise compile incorrectly.
502 template <typename... ArgsTy>
505 FunctionType *Invalid, ArgsTy... Args) = delete;
506
507 /// Look up the specified function in the module symbol table. If it does not
508 /// exist, return null.
509 Function *getFunction(StringRef Name) const;
510
511/// @}
512/// @name Global Variable Accessors
513/// @{
514
515 /// Look up the specified global variable in the module symbol table. If it
516 /// does not exist, return null. If AllowInternal is set to true, this
517 /// function will return types that have InternalLinkage. By default, these
518 /// types are not returned.
520 return getGlobalVariable(Name, false);
521 }
522
523 GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
524
526 bool AllowInternal = false) {
527 return static_cast<const Module *>(this)->getGlobalVariable(Name,
528 AllowInternal);
529 }
530
531 /// Return the global variable in the module with the specified name, of
532 /// arbitrary type. This method returns null if a global with the specified
533 /// name is not found.
535 return getGlobalVariable(Name, true);
536 }
538 return const_cast<GlobalVariable *>(
539 static_cast<const Module *>(this)->getNamedGlobal(Name));
540 }
541
542 /// Look up the specified global in the module symbol table.
543 /// If it does not exist, invoke a callback to create a declaration of the
544 /// global and return it.
547 function_ref<GlobalVariable *()> CreateGlobalCallback);
548
549 /// Look up the specified global in the module symbol table. If required, this
550 /// overload constructs the global variable using its constructor's defaults.
552
553/// @}
554/// @name Global Alias Accessors
555/// @{
556
557 /// Return the global alias 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 GlobalAlias *getNamedAlias(StringRef Name) const;
561
562/// @}
563/// @name Global IFunc Accessors
564/// @{
565
566 /// Return the global ifunc in the module with the specified name, of
567 /// arbitrary type. This method returns null if a global with the specified
568 /// name is not found.
569 GlobalIFunc *getNamedIFunc(StringRef Name) const;
570
571/// @}
572/// @name Named Metadata Accessors
573/// @{
574
575 /// Return the first NamedMDNode in the module with the specified name. This
576 /// method returns null if a NamedMDNode with the specified name is not found.
577 NamedMDNode *getNamedMetadata(StringRef Name) const;
578
579 /// Return the named MDNode in the module with the specified name. This method
580 /// returns a new NamedMDNode if a NamedMDNode with the specified name is not
581 /// found.
582 NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
583
584 /// Remove the given NamedMDNode from this module and delete it.
585 void eraseNamedMetadata(NamedMDNode *NMD);
586
587/// @}
588/// @name Comdat Accessors
589/// @{
590
591 /// Return the Comdat in the module with the specified name. It is created
592 /// if it didn't already exist.
593 Comdat *getOrInsertComdat(StringRef Name);
594
595/// @}
596/// @name Module Flags Accessors
597/// @{
598
599 /// Returns the module flags in the provided vector.
600 void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
601
602 /// Return the corresponding value if Key appears in module flags, otherwise
603 /// return null.
604 Metadata *getModuleFlag(StringRef Key) const;
605
606 /// Returns the NamedMDNode in the module that represents module-level flags.
607 /// This method returns null if there are no module-level flags.
608 NamedMDNode *getModuleFlagsMetadata() const { return ModuleFlags; }
609
610 /// Returns the NamedMDNode in the module that represents module-level flags.
611 /// If module-level flags aren't found, it creates the named metadata that
612 /// contains them.
613 NamedMDNode *getOrInsertModuleFlagsMetadata();
614
615 /// Add a module-level flag to the module-level flags metadata. It will create
616 /// the module-level flags named metadata if it doesn't already exist.
617 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
618 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
619 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint64_t Val);
620 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
621 inline void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val) {
622 addModuleFlag(Behavior, Key, static_cast<uint32_t>(Val));
623 }
624 void addModuleFlag(MDNode *Node);
625 /// Like addModuleFlag but replaces the old module flag if it already exists.
626 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
627 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
628 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint64_t Val);
629 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
630 inline void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val) {
631 setModuleFlag(Behavior, Key, static_cast<uint32_t>(Val));
632 }
633
634 /// @}
635 /// @name Materialization
636 /// @{
637
638 /// Sets the GVMaterializer to GVM. This module must not yet have a
639 /// Materializer. To reset the materializer for a module that already has one,
640 /// call materializeAll first. Destroying this module will destroy
641 /// its materializer without materializing any more GlobalValues. Without
642 /// destroying the Module, there is no way to detach or destroy a materializer
643 /// without materializing all the GVs it controls, to avoid leaving orphan
644 /// unmaterialized GVs.
645 void setMaterializer(GVMaterializer *GVM);
646 /// Retrieves the GVMaterializer, if any, for this Module.
647 GVMaterializer *getMaterializer() const { return Materializer.get(); }
648 bool isMaterialized() const { return !getMaterializer(); }
649
650 /// Make sure the GlobalValue is fully read.
651 llvm::Error materialize(GlobalValue *GV);
652
653 /// Make sure all GlobalValues in this Module are fully read and clear the
654 /// Materializer.
655 llvm::Error materializeAll();
656
657 llvm::Error materializeMetadata();
658
659 /// Detach global variable \p GV from the list but don't delete it.
660 void removeGlobalVariable(GlobalVariable *GV) { GlobalList.remove(GV); }
661 /// Remove global variable \p GV from the list and delete it.
662 void eraseGlobalVariable(GlobalVariable *GV) { GlobalList.erase(GV); }
663 /// Insert global variable \p GV at the end of the global variable list and
664 /// take ownership.
666 insertGlobalVariable(GlobalList.end(), GV);
667 }
668 /// Insert global variable \p GV into the global variable list before \p
669 /// Where and take ownership.
671 GlobalList.insert(Where, GV);
672 }
673 // Use global_size() to get the total number of global variables.
674 // Use globals() to get the range of all global variables.
675
676 std::optional<GlobalValue::GUID> getGUID(const Value *V) const {
677 const auto It = ValueToGUIDMap.find(V);
678 if (It == ValueToGUIDMap.end())
679 return std::nullopt;
680
681 return It->second;
682 }
683
684 void insertGUID(const Value *V, GlobalValue::GUID GUID) {
685 const auto [It, WasInserted] = ValueToGUIDMap.insert({V, GUID});
686
687 (void)It, (void)WasInserted;
688#ifndef NDEBUG
689 if (!WasInserted) {
690 assert((It->second == GUID) && "insertGUID called with different value");
691 }
692#endif
693 }
694
695private:
696 /// Do not transfer GUID of a value to the value it is being RAUWed with.
697 struct GUIDMapConfig : ValueMapConfig<const Value *> {
698 enum { FollowRAUW = false };
699 };
700
701 /// A mapping directly from Value to GUID. Populated from bitcode
702 /// (MODULE_CODE_GUIDLIST). Necessary for lazy-loading modules, where we
703 /// don't load metadata.
704 ValueMap<const Value *, GlobalValue::GUID, GUIDMapConfig> ValueToGUIDMap;
705
706 /// @}
707 /// @name Direct access to the globals list, functions list, and symbol table
708 /// @{
709
710 /// Get the Module's list of global variables (constant).
711 const GlobalListType &getGlobalList() const { return GlobalList; }
712 /// Get the Module's list of global variables.
713 GlobalListType &getGlobalList() { return GlobalList; }
714
715 static GlobalListType Module::*getSublistAccess(GlobalVariable*) {
716 return &Module::GlobalList;
717 }
719
720public:
721 /// Get the Module's list of functions (constant).
722 const FunctionListType &getFunctionList() const { return FunctionList; }
723 /// Get the Module's list of functions.
724 FunctionListType &getFunctionList() { return FunctionList; }
726 return &Module::FunctionList;
727 }
728
729 /// Detach \p Alias from the list but don't delete it.
730 void removeAlias(GlobalAlias *Alias) { AliasList.remove(Alias); }
731 /// Remove \p Alias from the list and delete it.
732 void eraseAlias(GlobalAlias *Alias) { AliasList.erase(Alias); }
733 /// Insert \p Alias at the end of the alias list and take ownership.
734 void insertAlias(GlobalAlias *Alias) { AliasList.insert(AliasList.end(), Alias); }
735 // Use alias_size() to get the size of AliasList.
736 // Use aliases() to get a range of all Alias objects in AliasList.
737
738 /// Detach \p IFunc from the list but don't delete it.
739 void removeIFunc(GlobalIFunc *IFunc) { IFuncList.remove(IFunc); }
740 /// Remove \p IFunc from the list and delete it.
741 void eraseIFunc(GlobalIFunc *IFunc) { IFuncList.erase(IFunc); }
742 /// Insert \p IFunc at the end of the alias list and take ownership.
743 void insertIFunc(GlobalIFunc *IFunc) { IFuncList.push_back(IFunc); }
744 // Use ifunc_size() to get the number of functions in IFuncList.
745 // Use ifuncs() to get the range of all IFuncs.
746
747 /// Detach \p MDNode from the list but don't delete it.
748 void removeNamedMDNode(NamedMDNode *MDNode) { NamedMDList.remove(MDNode); }
749 /// Remove \p MDNode from the list and delete it.
750 void eraseNamedMDNode(NamedMDNode *MDNode) { NamedMDList.erase(MDNode); }
751 /// Insert \p MDNode at the end of the alias list and take ownership.
753 NamedMDList.push_back(MDNode);
754 }
755 // Use named_metadata_size() to get the size of the named meatadata list.
756 // Use named_metadata() to get the range of all named metadata.
757
758private: // Please use functions like insertAlias(), removeAlias() etc.
759 /// Get the Module's list of aliases (constant).
760 const AliasListType &getAliasList() const { return AliasList; }
761 /// Get the Module's list of aliases.
762 AliasListType &getAliasList() { return AliasList; }
763
764 static AliasListType Module::*getSublistAccess(GlobalAlias*) {
765 return &Module::AliasList;
766 }
768
769 /// Get the Module's list of ifuncs (constant).
770 const IFuncListType &getIFuncList() const { return IFuncList; }
771 /// Get the Module's list of ifuncs.
772 IFuncListType &getIFuncList() { return IFuncList; }
773
774 static IFuncListType Module::*getSublistAccess(GlobalIFunc*) {
775 return &Module::IFuncList;
776 }
778
779 /// Get the Module's list of named metadata (constant).
780 const NamedMDListType &getNamedMDList() const { return NamedMDList; }
781 /// Get the Module's list of named metadata.
782 NamedMDListType &getNamedMDList() { return NamedMDList; }
783
784 static NamedMDListType Module::*getSublistAccess(NamedMDNode*) {
785 return &Module::NamedMDList;
786 }
787
788public:
789 /// Get the symbol table of global variable and function identifiers
790 const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
791 /// Get the Module's symbol table of global variable and function identifiers.
792 ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
793
794 /// Get the Module's symbol table for COMDATs (constant).
795 const ComdatSymTabType &getComdatSymbolTable() const { return ComdatSymTab; }
796 /// Get the Module's symbol table for COMDATs.
797 ComdatSymTabType &getComdatSymbolTable() { return ComdatSymTab; }
798
799/// @}
800/// @name Global Variable Iteration
801/// @{
802
803 global_iterator global_begin() { return GlobalList.begin(); }
804 const_global_iterator global_begin() const { return GlobalList.begin(); }
805 global_iterator global_end () { return GlobalList.end(); }
806 const_global_iterator global_end () const { return GlobalList.end(); }
807 size_t global_size () const { return GlobalList.size(); }
808 bool global_empty() const { return GlobalList.empty(); }
809
816
817/// @}
818/// @name Function Iteration
819/// @{
820
821 iterator begin() { return FunctionList.begin(); }
822 const_iterator begin() const { return FunctionList.begin(); }
823 iterator end () { return FunctionList.end(); }
824 const_iterator end () const { return FunctionList.end(); }
825 reverse_iterator rbegin() { return FunctionList.rbegin(); }
826 const_reverse_iterator rbegin() const{ return FunctionList.rbegin(); }
827 reverse_iterator rend() { return FunctionList.rend(); }
828 const_reverse_iterator rend() const { return FunctionList.rend(); }
829 size_t size() const { return FunctionList.size(); }
830 bool empty() const { return FunctionList.empty(); }
831
838
839 /// Get an iterator range over all function definitions (excluding
840 /// declarations).
843 [](Function &F) { return !F.isDeclaration(); });
844 }
845 auto getFunctionDefs() const {
846 return make_filter_range(
847 functions(), [](const Function &F) { return !F.isDeclaration(); });
848 }
849
850/// @}
851/// @name Alias Iteration
852/// @{
853
854 alias_iterator alias_begin() { return AliasList.begin(); }
855 const_alias_iterator alias_begin() const { return AliasList.begin(); }
856 alias_iterator alias_end () { return AliasList.end(); }
857 const_alias_iterator alias_end () const { return AliasList.end(); }
858 size_t alias_size () const { return AliasList.size(); }
859 bool alias_empty() const { return AliasList.empty(); }
860
867
868/// @}
869/// @name IFunc Iteration
870/// @{
871
872 ifunc_iterator ifunc_begin() { return IFuncList.begin(); }
873 const_ifunc_iterator ifunc_begin() const { return IFuncList.begin(); }
874 ifunc_iterator ifunc_end () { return IFuncList.end(); }
875 const_ifunc_iterator ifunc_end () const { return IFuncList.end(); }
876 size_t ifunc_size () const { return IFuncList.size(); }
877 bool ifunc_empty() const { return IFuncList.empty(); }
878
885
886 /// @}
887 /// @name Convenience iterators
888 /// @{
889
895
898
905
908
909 /// @}
910 /// @name Named Metadata Iteration
911 /// @{
912
913 named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
915 return NamedMDList.begin();
916 }
917
918 named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
920 return NamedMDList.end();
921 }
922
923 size_t named_metadata_size() const { return NamedMDList.size(); }
924 bool named_metadata_empty() const { return NamedMDList.empty(); }
925
932
933 /// An iterator for DICompileUnits that skips those marked NoDebug.
935 NamedMDNode *CUs;
936 unsigned Idx;
937
938 LLVM_ABI void SkipNoDebugCUs();
939
940 public:
941 using iterator_category = std::input_iterator_tag;
943 using difference_type = std::ptrdiff_t;
946
947 explicit debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
948 : CUs(CUs), Idx(Idx) {
949 SkipNoDebugCUs();
950 }
951
953 ++Idx;
954 SkipNoDebugCUs();
955 return *this;
956 }
957
960 ++Idx;
961 return T;
962 }
963
965 return Idx == I.Idx;
966 }
967
969 return Idx != I.Idx;
970 }
971
973 LLVM_ABI DICompileUnit *operator->() const;
974 };
975
977 auto *CUs = getNamedMetadata("llvm.dbg.cu");
978 return debug_compile_units_iterator(CUs, 0);
979 }
980
982 auto *CUs = getNamedMetadata("llvm.dbg.cu");
983 return debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0);
984 }
985
986 /// Return an iterator for all DICompileUnits listed in this Module's
987 /// llvm.dbg.cu named metadata node and aren't explicitly marked as
988 /// NoDebug.
990 auto *CUs = getNamedMetadata("llvm.dbg.cu");
991 return make_range(
993 debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0));
994 }
995/// @}
996
997/// @name Utility functions for printing and dumping Module objects
998/// @{
999
1000 /// Print the module to an output stream with an optional
1001 /// AssemblyAnnotationWriter. If \c ShouldPreserveUseListOrder, then include
1002 /// uselistorder directives so that use-lists can be recreated when reading
1003 /// the assembly.
1005 bool ShouldPreserveUseListOrder = false,
1006 bool IsForDebug = false) const;
1007
1008 /// Renumber the IDs stored in metadata nodes into canonical assembly order.
1009 /// This mutates the IDs and should only be used immediately before final
1010 /// assembly output.
1011 void renumberMetadataForAssembly();
1012
1013 /// Dump the module to stderr (for debugging).
1014 void dump() const;
1015
1016 /// This function causes all the subinstructions to "let go" of all references
1017 /// that they are maintaining. This allows one to 'delete' a whole class at
1018 /// a time, even though there may be circular references... first all
1019 /// references are dropped, and all use counts go to zero. Then everything
1020 /// is delete'd for real. Note that no operations are valid on an object
1021 /// that has "dropped all references", except operator delete.
1022 void dropAllReferences();
1023
1024/// @}
1025/// @name Utility functions for querying Debug information.
1026/// @{
1027
1028 /// Returns the Number of Register ParametersDwarf Version by checking
1029 /// module flags.
1030 unsigned getNumberRegisterParameters() const;
1031
1032 /// Returns the Dwarf Version by checking module flags.
1033 unsigned getDwarfVersion() const;
1034
1035 /// Returns the DWARF format by checking module flags.
1036 bool isDwarf64() const;
1037
1038 /// Returns the CodeView Version by checking module flags.
1039 /// Returns zero if not present in module.
1040 unsigned getCodeViewFlag() const;
1041
1042/// @}
1043/// @name Utility functions for querying and setting PIC level
1044/// @{
1045
1046 /// Returns the PIC level (small or large model)
1047 PICLevel::Level getPICLevel() const;
1048
1049 /// Set the PIC level (small or large model)
1050 void setPICLevel(PICLevel::Level PL);
1051/// @}
1052
1053/// @}
1054/// @name Utility functions for querying and setting PIE level
1055/// @{
1056
1057 /// Returns the PIE level (small or large model)
1058 PIELevel::Level getPIELevel() const;
1059
1060 /// Set the PIE level (small or large model)
1061 void setPIELevel(PIELevel::Level PL);
1062/// @}
1063
1064 /// @}
1065 /// @name Utility function for querying and setting code model
1066 /// @{
1067
1068 /// Returns the code model (tiny, small, kernel, medium or large model)
1069 std::optional<CodeModel::Model> getCodeModel() const;
1070
1071 /// Set the code model (tiny, small, kernel, medium or large)
1072 void setCodeModel(CodeModel::Model CL);
1073
1074 /// @}
1075 /// @name Utility functions for querying the size of wchar_t
1076 /// @{
1077
1078 /// Returns the size of the wchar_t type from the "wchar_size" module flag,
1079 /// or the triple default when the flag is absent.
1080 unsigned getWCharSize() const;
1081
1082 /// @}
1083 /// @name Utility functions for querying the long double format
1084 /// @{
1085
1086 /// Returns the long double format from the "long-double-type" module flag,
1087 /// or the triple default when the flag is absent.
1088 LongDoubleFormat getLongDoubleFormat() const;
1089
1090 /// Set the long double format.
1091 void setLongDoubleFormat(LongDoubleFormat Format);
1092 /// @}
1093
1094 /// @}
1095 /// @name Utility function for querying the floating-point ABI
1096 /// @{
1097
1098 /// Returns the floating-point ABI recorded by the "float-abi" module flag, or
1099 /// the ABI implied by the target triple when the flag is absent.
1100 FloatABI::ABIType getFloatABI() const;
1101 /// @}
1102
1103 /// @}
1104 /// @name Utility function for querying and setting the thread model
1105 /// @{
1106
1107 /// Returns the thread model recorded by the "thread-model" module flag, or
1108 /// the model implied by the target triple when the flag is absent.
1109 ThreadModel getThreadModel() const;
1110
1111 /// Set the thread model.
1112 void setThreadModel(ThreadModel Model);
1113
1114 /// @name Utility function for querying the exception model
1115 /// @{
1116
1117 /// Returns the exception model recorded by the "exception-model" module flag,
1118 /// or the target's default exception model (from the target triple) when the
1119 /// flag is absent. Never returns ExceptionHandling::Default.
1120 ExceptionHandling getExceptionModel() const;
1121 /// @}
1122
1123 /// @}
1124 /// @name Utility function for querying and setting the debugger tuning
1125 /// @{
1126
1127 /// Returns the debugger tuning recorded by the "debugger-tuning" module flag,
1128 /// or the target's default debugger tuning (from the target triple) when the
1129 /// flag is absent. Never returns DebuggerKind::Default.
1130 DebuggerKind getDebuggerTuning() const;
1131
1132 /// Set the debugger tuning.
1133 void setDebuggerTuning(DebuggerKind Tuning);
1134 /// @}
1135
1136 /// @}
1137 /// @name Utility function for querying and setting the large data threshold
1138 /// @{
1139
1140 /// Returns the large data threshold.
1141 std::optional<uint64_t> getLargeDataThreshold() const;
1142
1143 /// Set the large data threshold.
1144 void setLargeDataThreshold(uint64_t Threshold);
1145 /// @}
1146
1147 /// @name Utility functions for querying and setting PGO summary
1148 /// @{
1149
1150 /// Attach profile summary metadata to this module.
1151 void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind);
1152
1153 /// Returns profile summary metadata. When IsCS is true, use the context
1154 /// sensitive profile summary.
1155 Metadata *getProfileSummary(bool IsCS) const;
1156 /// @}
1157
1158 /// Returns whether semantic interposition is to be respected.
1159 bool getSemanticInterposition() const;
1160
1161 /// Set whether semantic interposition is to be respected.
1162 void setSemanticInterposition(bool);
1163
1164 /// Returns true if PLT should be avoided for RTLib calls.
1165 bool getRtLibUseGOT() const;
1166
1167 /// Set that PLT should be avoid for RTLib calls.
1168 void setRtLibUseGOT();
1169
1170 /// Get/set whether referencing global variables can use direct access
1171 /// relocations on ELF targets.
1172 bool getDirectAccessExternalData() const;
1173 void setDirectAccessExternalData(bool Value);
1174
1175 /// Get/set whether synthesized functions should get the uwtable attribute.
1176 UWTableKind getUwtable() const;
1177 void setUwtable(UWTableKind Kind);
1178
1179 /// Get/set whether synthesized functions should get the "frame-pointer"
1180 /// attribute.
1181 FramePointerKind getFramePointer() const;
1182 void setFramePointer(FramePointerKind Kind);
1183
1184 /// Get/set what kind of stack protector guard to use.
1185 StringRef getStackProtectorGuard() const;
1186 void setStackProtectorGuard(StringRef Kind);
1187
1188 /// Get/set which register to use as the stack protector guard register. The
1189 /// empty string is equivalent to "global". Other values may be "tls" or
1190 /// "sysreg".
1191 StringRef getStackProtectorGuardReg() const;
1192 void setStackProtectorGuardReg(StringRef Reg);
1193
1194 /// Get/set a symbol to use as the stack protector guard.
1195 StringRef getStackProtectorGuardSymbol() const;
1196 void setStackProtectorGuardSymbol(StringRef Symbol);
1197
1198 /// Get/set what offset from the stack protector to use.
1199 int getStackProtectorGuardOffset() const;
1200 void setStackProtectorGuardOffset(int Offset);
1201
1202 /// Get/set the width in memory of the stack protector guard value.
1203 std::optional<unsigned> getStackProtectorGuardValueWidth() const;
1204 void setStackProtectorGuardValueWidth(unsigned Width);
1205
1206 // Get/set flag indicating whether to emit a __stack_protector_loc section.
1207 bool hasStackProtectorGuardRecord() const;
1208 void setStackProtectorGuardRecord(bool Flag);
1209
1210 /// Get/set the stack alignment overridden from the default.
1211 unsigned getOverrideStackAlignment() const;
1212 void setOverrideStackAlignment(unsigned Align);
1213
1214 unsigned getMaxTLSAlignment() const;
1215
1216 /// @name Utility functions for querying and setting the build SDK version
1217 /// @{
1218
1219 /// Attach a build SDK version metadata to this module.
1220 void setSDKVersion(const VersionTuple &V);
1221
1222 /// Get the build SDK version metadata.
1223 ///
1224 /// An empty version is returned if no such metadata is attached.
1225 VersionTuple getSDKVersion() const;
1226 /// @}
1227
1228 /// Take ownership of the given memory buffer.
1229 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1230
1231 /// Set the partial sample profile ratio in the profile summary module flag,
1232 /// if applicable.
1233 void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index);
1234
1235 /// Get the target variant triple which is a string describing a variant of
1236 /// the target host platform. For example, Mac Catalyst can be a variant
1237 /// target triple for a macOS target.
1238 /// @returns a string containing the target variant triple.
1239 StringRef getDarwinTargetVariantTriple() const;
1240
1241 /// Set the target variant triple which is a string describing a variant of
1242 /// the target host platform.
1243 void setDarwinTargetVariantTriple(StringRef T);
1244
1245 /// Get the target variant version build SDK version metadata.
1246 ///
1247 /// An empty version is returned if no such metadata is attached.
1248 VersionTuple getDarwinTargetVariantSDKVersion() const;
1249
1250 /// Set the target variant version build SDK version metadata.
1251 void setDarwinTargetVariantSDKVersion(VersionTuple Version);
1252
1253 /// Returns target-abi from MDString, null if target-abi is absent.
1254 StringRef getTargetABIFromMD();
1255
1256 /// Get how unwind information should be generated for x64 Windows.
1257 WinX64EHUnwindMode getWinX64EHUnwindMode() const;
1258
1259 /// Gets the Control Flow Guard mode.
1260 ControlFlowGuardMode getControlFlowGuardMode() const;
1261};
1262
1263/// Given "llvm.used" or "llvm.compiler.used" as a global name, collect the
1264/// initializer elements of that global in a SmallVector and return the global
1265/// itself.
1266LLVM_ABI GlobalVariable *
1267collectUsedGlobalVariables(const Module &M, SmallVectorImpl<GlobalValue *> &Vec,
1268 bool CompilerUsed);
1269
1270/// An raw_ostream inserter for modules.
1272 M.print(O, nullptr);
1273 return O;
1274}
1275
1276// Create wrappers for C Binding types (see CBindingWrapping.h).
1278
1279/* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1280 * Module.
1281 */
1283 return reinterpret_cast<Module*>(MP);
1284}
1285
1286} // end namespace llvm
1287
1288#endif // LLVM_IR_MODULE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
This file defines the StringMap class.
uint64_t 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)
static unsigned getDwarfVersion(const MachineFunction &MF)
Resolve the DWARF version the way DwarfDebug does.
Definition Analysis.cpp:545
#define LLVM_ABI
Definition Compiler.h:211
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:44
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:76
Metadata node.
Definition Metadata.h:1081
A single uniqued string.
Definition Metadata.h:733
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:934
debug_compile_units_iterator & operator++()
Definition Module.h:952
bool operator==(const debug_compile_units_iterator &I) const
Definition Module.h:964
debug_compile_units_iterator operator++(int)
Definition Module.h:958
std::input_iterator_tag iterator_category
Definition Module.h:941
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
Definition Module.h:947
bool operator!=(const debug_compile_units_iterator &I) const
Definition Module.h:968
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:803
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition Module.h:739
const_global_iterator global_begin() const
Definition Module.h:804
const_iterator begin() const
Definition Module.h:822
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Definition Module.cpp:320
ifunc_iterator ifunc_begin()
Definition Module.h:872
void eraseNamedMDNode(NamedMDNode *MDNode)
Remove MDNode from the list and delete it.
Definition Module.h:750
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:743
iterator_range< const_alias_iterator > aliases() const
Definition Module.h:864
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Definition Module.h:795
global_iterator global_end()
Definition Module.h:805
GlobalVariable * getNamedGlobal(StringRef Name)
Definition Module.h:537
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:858
const_global_iterator global_end() const
Definition Module.h:806
bool global_empty() const
Definition Module.h:808
iterator begin()
Definition Module.h:821
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:875
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
Definition Module.h:630
iterator_range< ifunc_iterator > ifuncs()
Definition Module.h:879
bool named_metadata_empty() const
Definition Module.h:924
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:792
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:914
size_t global_size() const
Definition Module.h:807
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:989
iterator_range< iterator > functions()
Definition Module.h:832
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:647
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:857
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition Module.h:730
iterator_range< named_metadata_iterator > named_metadata()
Definition Module.h:926
friend class Constant
Definition Module.h:253
named_metadata_iterator named_metadata_begin()
Definition Module.h:913
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
Definition Module.cpp:431
ifunc_iterator ifunc_end()
Definition Module.h:874
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:861
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:670
alias_iterator alias_end()
Definition Module.h:856
const_alias_iterator alias_begin() const
Definition Module.h:855
const_reverse_iterator rbegin() const
Definition Module.h:826
alias_iterator alias_begin()
Definition Module.h:854
reverse_iterator rend()
Definition Module.h:827
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:525
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition Module.h:741
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:841
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:400
size_t size() const
Definition Module.h:829
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
Definition Module.h:621
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
Definition Module.h:100
bool alias_empty() const
Definition Module.h:859
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, FunctionType *Invalid, ArgsTy... Args)=delete
void insertGUID(const Value *V, GlobalValue::GUID GUID)
Definition Module.h:684
iterator_range< global_iterator > globals()
Definition Module.h:810
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition Module.h:722
const_reverse_iterator rend() const
Definition Module.h:828
iterator_range< const_named_metadata_iterator > named_metadata() const
Definition Module.h:929
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
Definition Module.h:890
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
Definition Module.h:110
size_t ifunc_size() const
Definition Module.h:876
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:724
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition Module.h:732
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:662
std::optional< GlobalValue::GUID > getGUID(const Value *V) const
Definition Module.h:676
reverse_iterator rbegin()
Definition Module.h:825
void insertNamedMDNode(NamedMDNode *MDNode)
Insert MDNode at the end of the alias list and take ownership.
Definition Module.h:752
const_named_metadata_iterator named_metadata_end() const
Definition Module.h:919
bool empty() const
Definition Module.h:830
void removeNamedMDNode(NamedMDNode *MDNode)
Detach MDNode from the list but don't delete it.
Definition Module.h:748
AliasListType::iterator alias_iterator
The Global Alias iterators.
Definition Module.h:103
iterator end()
Definition Module.h:823
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition Module.h:519
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:665
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
Definition Module.h:790
size_t named_metadata_size() const
Definition Module.h:923
iterator_range< global_object_iterator > global_objects()
Definition Module.cpp:480
named_metadata_iterator named_metadata_end()
Definition Module.h:918
bool isMaterialized() const
Definition Module.h:648
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Definition Module.h:534
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:229
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
Definition Module.h:797
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:835
concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator > global_value_iterator
Definition Module.h:899
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
Definition Module.h:608
iterator_range< const_global_iterator > globals() const
Definition Module.h:813
void setModuleIdentifier(StringRef ID)
Set the module identifier.
Definition Module.h:370
iterator_range< const_ifunc_iterator > ifuncs() const
Definition Module.h:882
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
Definition Module.h:77
const_iterator end() const
Definition Module.h:824
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
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
Definition Module.h:489
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
Definition Module.h:79
auto getFunctionDefs() const
Definition Module.h:845
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:873
concat_iterator< const GlobalObject, const_iterator, const_global_iterator > const_global_object_iterator
Definition Module.h:892
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:725
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:902
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition Module.h:734
debug_compile_units_iterator debug_compile_units_begin() const
Definition Module.h:976
bool ifunc_empty() const
Definition Module.h:877
iterator_range< global_value_iterator > global_values()
Definition Module.cpp:488
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition Module.h:660
debug_compile_units_iterator debug_compile_units_end() const
Definition Module.h:981
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:1797
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:1016
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:326
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2261
LongDoubleFormat
The floating-point format used for the target's "long double" type.
Definition CodeGen.h:117
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:2224
Op::Description Desc
ControlFlowGuardMode
Definition CodeGen.h:385
WinX64EHUnwindMode
Definition CodeGen.h:375
iplist< T, Options... > ilist
Definition ilist.h:344
UWTableKind
Definition CodeGen.h:362
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:552
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Other
Any other memory.
Definition ModRef.h:68
ThreadModel
The threading model to assume for lowering, e.g. of atomics.
Definition CodeGen.h:191
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:1933
ExceptionHandling
Definition CodeGen.h:54
DebuggerKind
Identify a debugger for "tuning" the debug info.
Definition CodeGen.h:231
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:991
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
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:1073
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:1084
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