LLVM  3.7.0
Module.h
Go to the documentation of this file.
1 //===-- llvm/Module.h - C++ class to represent a VM module ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// Module.h This file contains the declarations for the Module class.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_MODULE_H
16 #define LLVM_IR_MODULE_H
17 
19 #include "llvm/IR/Comdat.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/GlobalAlias.h"
23 #include "llvm/IR/GlobalVariable.h"
24 #include "llvm/IR/Metadata.h"
26 #include "llvm/Support/CodeGen.h"
27 #include "llvm/Support/DataTypes.h"
28 #include <system_error>
29 
30 namespace llvm {
31 class FunctionType;
32 class GVMaterializer;
33 class LLVMContext;
34 class RandomNumberGenerator;
35 class StructType;
36 
37 template<> struct ilist_traits<Function>
38  : public SymbolTableListTraits<Function, Module> {
39 
40  // createSentinel is used to get hold of the node that marks the end of the
41  // list... (same trick used here as in ilist_traits<Instruction>)
43  return static_cast<Function*>(&Sentinel);
44  }
45  static void destroySentinel(Function*) {}
46 
48  Function *ensureHead(Function*) const { return createSentinel(); }
49  static void noteHead(Function*, Function*) {}
50 
51 private:
52  mutable ilist_node<Function> Sentinel;
53 };
54 
55 template<> struct ilist_traits<GlobalVariable>
56  : public SymbolTableListTraits<GlobalVariable, Module> {
57  // createSentinel is used to create a node that marks the end of the list.
59  return static_cast<GlobalVariable*>(&Sentinel);
60  }
62 
66 private:
67  mutable ilist_node<GlobalVariable> Sentinel;
68 };
69 
70 template<> struct ilist_traits<GlobalAlias>
71  : public SymbolTableListTraits<GlobalAlias, Module> {
72  // createSentinel is used to create a node that marks the end of the list.
74  return static_cast<GlobalAlias*>(&Sentinel);
75  }
76  static void destroySentinel(GlobalAlias*) {}
77 
80  static void noteHead(GlobalAlias*, GlobalAlias*) {}
81 private:
82  mutable ilist_node<GlobalAlias> Sentinel;
83 };
84 
85 template<> struct ilist_traits<NamedMDNode>
86  : public ilist_default_traits<NamedMDNode> {
87  // createSentinel is used to get hold of a node that marks the end of
88  // the list...
90  return static_cast<NamedMDNode*>(&Sentinel);
91  }
92  static void destroySentinel(NamedMDNode*) {}
93 
96  static void noteHead(NamedMDNode*, NamedMDNode*) {}
99 private:
100  mutable ilist_node<NamedMDNode> Sentinel;
101 };
102 
103 /// A Module instance is used to store all the information related to an
104 /// LLVM module. Modules are the top level container of all other LLVM
105 /// Intermediate Representation (IR) objects. Each module directly contains a
106 /// list of globals variables, a list of functions, a list of libraries (or
107 /// other modules) this module depends on, a symbol table, and various data
108 /// about the target's characteristics.
109 ///
110 /// A module maintains a GlobalValRefMap object that is used to hold all
111 /// constant references to global variables in the module. When a global
112 /// variable is destroyed, it should have no entries in the GlobalValueRefMap.
113 /// @brief The main container class for the LLVM Intermediate Representation.
114 class Module {
115 /// @name Types And Enumerations
116 /// @{
117 public:
118  /// The type for the list of global variables.
120  /// The type for the list of functions.
122  /// The type for the list of aliases.
124  /// The type for the list of named metadata.
126  /// The type of the comdat "symbol" table.
128 
129  /// The Global Variable iterator.
131  /// The Global Variable constant iterator.
133 
134  /// The Function iterators.
136  /// The Function constant iterator
138 
139  /// The Function reverse iterator.
141  /// The Function constant reverse iterator.
143 
144  /// The Global Alias iterators.
146  /// The Global Alias constant iterator
148 
149  /// The named metadata iterators.
151  /// The named metadata constant iterators.
153 
154  /// This enumeration defines the supported behaviors of module flags.
156  /// Emits an error if two values disagree, otherwise the resulting value is
157  /// that of the operands.
158  Error = 1,
159 
160  /// Emits a warning if two values disagree. The result value will be the
161  /// operand for the flag from the first module being linked.
162  Warning = 2,
163 
164  /// Adds a requirement that another module flag be present and have a
165  /// specified value after linking is performed. The value must be a metadata
166  /// pair, where the first element of the pair is the ID of the module flag
167  /// to be restricted, and the second element of the pair is the value the
168  /// module flag should be restricted to. This behavior can be used to
169  /// restrict the allowable results (via triggering of an error) of linking
170  /// IDs with the **Override** behavior.
171  Require = 3,
172 
173  /// Uses the specified value, regardless of the behavior or value of the
174  /// other module. If both modules specify **Override**, but the values
175  /// differ, an error will be emitted.
176  Override = 4,
177 
178  /// Appends the two values, which are required to be metadata nodes.
179  Append = 5,
180 
181  /// Appends the two values, which are required to be metadata
182  /// nodes. However, duplicate entries in the second list are dropped
183  /// during the append operation.
185 
186  // Markers:
189  };
190 
191  /// Checks if Metadata represents a valid ModFlagBehavior, and stores the
192  /// converted result in MFB.
193  static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB);
194 
200  : Behavior(B), Key(K), Val(V) {}
201  };
202 
203 /// @}
204 /// @name Member Variables
205 /// @{
206 private:
207  LLVMContext &Context; ///< The LLVMContext from which types and
208  ///< constants are allocated.
209  GlobalListType GlobalList; ///< The Global Variables in the module
210  FunctionListType FunctionList; ///< The Functions in the module
211  AliasListType AliasList; ///< The Aliases in the module
212  NamedMDListType NamedMDList; ///< The named metadata in the module
213  std::string GlobalScopeAsm; ///< Inline Asm at global scope.
214  ValueSymbolTable *ValSymTab; ///< Symbol table for values
215  ComdatSymTabType ComdatSymTab; ///< Symbol table for COMDATs
216  std::unique_ptr<GVMaterializer>
217  Materializer; ///< Used to materialize GlobalValues
218  std::string ModuleID; ///< Human readable identifier for the module
219  std::string TargetTriple; ///< Platform target triple Module compiled on
220  ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
221  void *NamedMDSymTab; ///< NamedMDNode names.
222  DataLayout DL; ///< DataLayout associated with the module
223 
224  friend class Constant;
225 
226 /// @}
227 /// @name Constructors
228 /// @{
229 public:
230  /// The Module constructor. Note that there is no default constructor. You
231  /// must provide a name for the module upon construction.
232  explicit Module(StringRef ModuleID, LLVMContext& C);
233  /// The module destructor. This will dropAllReferences.
234  ~Module();
235 
236 /// @}
237 /// @name Module Level Accessors
238 /// @{
239 
240  /// Get the module identifier which is, essentially, the name of the module.
241  /// @returns the module identifier as a string
242  const std::string &getModuleIdentifier() const { return ModuleID; }
243 
244  /// \brief Get a short "name" for the module.
245  ///
246  /// This is useful for debugging or logging. It is essentially a convenience
247  /// wrapper around getModuleIdentifier().
248  StringRef getName() const { return ModuleID; }
249 
250  /// Get the data layout string for the module's target platform. This is
251  /// equivalent to getDataLayout()->getStringRepresentation().
252  const std::string &getDataLayoutStr() const {
253  return DL.getStringRepresentation();
254  }
255 
256  /// Get the data layout for the module's target platform.
257  const DataLayout &getDataLayout() const;
258 
259  /// Get the target triple which is a string describing the target host.
260  /// @returns a string containing the target triple.
261  const std::string &getTargetTriple() const { return TargetTriple; }
262 
263  /// Get the global data context.
264  /// @returns LLVMContext - a container for LLVM's global information
265  LLVMContext &getContext() const { return Context; }
266 
267  /// Get any module-scope inline assembly blocks.
268  /// @returns a string containing the module-scope inline assembly blocks.
269  const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
270 
271  /// Get a RandomNumberGenerator salted for use with this module. The
272  /// RNG can be seeded via -rng-seed=<uint64> and is salted with the
273  /// ModuleID and the provided pass salt. The returned RNG should not
274  /// be shared across threads or passes.
275  ///
276  /// A unique RNG per pass ensures a reproducible random stream even
277  /// when other randomness consuming passes are added or removed. In
278  /// addition, the random stream will be reproducible across LLVM
279  /// versions when the pass does not change.
280  RandomNumberGenerator *createRNG(const Pass* P) const;
281 
282 /// @}
283 /// @name Module Level Mutators
284 /// @{
285 
286  /// Set the module identifier.
287  void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
288 
289  /// Set the data layout
290  void setDataLayout(StringRef Desc);
291  void setDataLayout(const DataLayout &Other);
292 
293  /// Set the target triple.
294  void setTargetTriple(StringRef T) { TargetTriple = T; }
295 
296  /// Set the module-scope inline assembly blocks.
297  /// A trailing newline is added if the input doesn't have one.
299  GlobalScopeAsm = Asm;
300  if (!GlobalScopeAsm.empty() &&
301  GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
302  GlobalScopeAsm += '\n';
303  }
304 
305  /// Append to the module-scope inline assembly blocks.
306  /// A trailing newline is added if the input doesn't have one.
308  GlobalScopeAsm += Asm;
309  if (!GlobalScopeAsm.empty() &&
310  GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
311  GlobalScopeAsm += '\n';
312  }
313 
314 /// @}
315 /// @name Generic Value Accessors
316 /// @{
317 
318  /// Return the global value in the module with the specified name, of
319  /// arbitrary type. This method returns null if a global with the specified
320  /// name is not found.
322 
323  /// Return a unique non-zero ID for the specified metadata kind. This ID is
324  /// uniqued across modules in the current LLVMContext.
325  unsigned getMDKindID(StringRef Name) const;
326 
327  /// Populate client supplied SmallVector with the name for custom metadata IDs
328  /// registered in this LLVMContext.
329  void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
330 
331  /// Return the type with the specified name, or null if there is none by that
332  /// name.
334 
335  std::vector<StructType *> getIdentifiedStructTypes() const;
336 
337 /// @}
338 /// @name Function Accessors
339 /// @{
340 
341  /// Look up the specified function in the module symbol table. Four
342  /// possibilities:
343  /// 1. If it does not exist, add a prototype for the function and return it.
344  /// 2. If it exists, and has a local linkage, the existing function is
345  /// renamed and a new one is inserted.
346  /// 3. Otherwise, if the existing function has the correct prototype, return
347  /// the existing function.
348  /// 4. Finally, the function exists but has the wrong prototype: return the
349  /// function with a constantexpr cast to the right prototype.
351  AttributeSet AttributeList);
352 
354 
355  /// Look up the specified function in the module symbol table. If it does not
356  /// exist, add a prototype for the function and return it. This function
357  /// guarantees to return a constant of pointer to the specified function type
358  /// or a ConstantExpr BitCast of that type if the named function has a
359  /// different type. This version of the method takes a null terminated list of
360  /// function arguments, which makes it easier for clients to use.
362  AttributeSet AttributeList,
363  Type *RetTy, ...) LLVM_END_WITH_NULL;
364 
365  /// Same as above, but without the attributes.
366  Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
368 
369  /// Look up the specified function in the module symbol table. If it does not
370  /// exist, return null.
372 
373 /// @}
374 /// @name Global Variable Accessors
375 /// @{
376 
377  /// Look up the specified global variable in the module symbol table. If it
378  /// does not exist, return null. If AllowInternal is set to true, this
379  /// function will return types that have InternalLinkage. By default, these
380  /// types are not returned.
382  return getGlobalVariable(Name, false);
383  }
384 
385  GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const {
386  return const_cast<Module *>(this)->getGlobalVariable(Name, AllowInternal);
387  }
388 
389  GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal = false);
390 
391  /// Return the global variable in the module with the specified name, of
392  /// arbitrary type. This method returns null if a global with the specified
393  /// name is not found.
395  return getGlobalVariable(Name, true);
396  }
398  return const_cast<Module *>(this)->getNamedGlobal(Name);
399  }
400 
401  /// Look up the specified global in the module symbol table.
402  /// 1. If it does not exist, add a declaration of the global and return it.
403  /// 2. Else, the global exists but has the wrong type: return the function
404  /// with a constantexpr cast to the right type.
405  /// 3. Finally, if the existing global is the correct declaration, return
406  /// the existing global.
408 
409 /// @}
410 /// @name Global Alias Accessors
411 /// @{
412 
413  /// Return the global alias in the module with the specified name, of
414  /// arbitrary type. This method returns null if a global with the specified
415  /// name is not found.
417 
418 /// @}
419 /// @name Named Metadata Accessors
420 /// @{
421 
422  /// Return the first NamedMDNode in the module with the specified name. This
423  /// method returns null if a NamedMDNode with the specified name is not found.
424  NamedMDNode *getNamedMetadata(const Twine &Name) const;
425 
426  /// Return the named MDNode in the module with the specified name. This method
427  /// returns a new NamedMDNode if a NamedMDNode with the specified name is not
428  /// found.
430 
431  /// Remove the given NamedMDNode from this module and delete it.
432  void eraseNamedMetadata(NamedMDNode *NMD);
433 
434 /// @}
435 /// @name Comdat Accessors
436 /// @{
437 
438  /// Return the Comdat in the module with the specified name. It is created
439  /// if it didn't already exist.
441 
442 /// @}
443 /// @name Module Flags Accessors
444 /// @{
445 
446  /// Returns the module flags in the provided vector.
448 
449  /// Return the corresponding value if Key appears in module flags, otherwise
450  /// return null.
451  Metadata *getModuleFlag(StringRef Key) const;
452 
453  /// Returns the NamedMDNode in the module that represents module-level flags.
454  /// This method returns null if there are no module-level flags.
456 
457  /// Returns the NamedMDNode in the module that represents module-level flags.
458  /// If module-level flags aren't found, it creates the named metadata that
459  /// contains them.
461 
462  /// Add a module-level flag to the module-level flags metadata. It will create
463  /// the module-level flags named metadata if it doesn't already exist.
464  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
465  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
466  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
467  void addModuleFlag(MDNode *Node);
468 
469 /// @}
470 /// @name Materialization
471 /// @{
472 
473  /// Sets the GVMaterializer to GVM. This module must not yet have a
474  /// Materializer. To reset the materializer for a module that already has one,
475  /// call MaterializeAllPermanently first. Destroying this module will destroy
476  /// its materializer without materializing any more GlobalValues. Without
477  /// destroying the Module, there is no way to detach or destroy a materializer
478  /// without materializing all the GVs it controls, to avoid leaving orphan
479  /// unmaterialized GVs.
480  void setMaterializer(GVMaterializer *GVM);
481  /// Retrieves the GVMaterializer, if any, for this Module.
482  GVMaterializer *getMaterializer() const { return Materializer.get(); }
483 
484  /// Returns true if this GV was loaded from this Module's GVMaterializer and
485  /// the GVMaterializer knows how to dematerialize the GV.
486  bool isDematerializable(const GlobalValue *GV) const;
487 
488  /// Make sure the GlobalValue is fully read. If the module is corrupt, this
489  /// returns true and fills in the optional string with information about the
490  /// problem. If successful, this returns false.
491  std::error_code materialize(GlobalValue *GV);
492  /// If the GlobalValue is read in, and if the GVMaterializer supports it,
493  /// release the memory for the function, and set it up to be materialized
494  /// lazily. If !isDematerializable(), this method is a no-op.
495  void dematerialize(GlobalValue *GV);
496 
497  /// Make sure all GlobalValues in this Module are fully read.
498  std::error_code materializeAll();
499 
500  /// Make sure all GlobalValues in this Module are fully read and clear the
501  /// Materializer. If the module is corrupt, this DOES NOT clear the old
502  /// Materializer.
503  std::error_code materializeAllPermanently();
504 
505  std::error_code materializeMetadata();
506 
507 /// @}
508 /// @name Direct access to the globals list, functions list, and symbol table
509 /// @{
510 
511  /// Get the Module's list of global variables (constant).
512  const GlobalListType &getGlobalList() const { return GlobalList; }
513  /// Get the Module's list of global variables.
514  GlobalListType &getGlobalList() { return GlobalList; }
516  return &Module::GlobalList;
517  }
518  /// Get the Module's list of functions (constant).
519  const FunctionListType &getFunctionList() const { return FunctionList; }
520  /// Get the Module's list of functions.
521  FunctionListType &getFunctionList() { return FunctionList; }
523  return &Module::FunctionList;
524  }
525  /// Get the Module's list of aliases (constant).
526  const AliasListType &getAliasList() const { return AliasList; }
527  /// Get the Module's list of aliases.
528  AliasListType &getAliasList() { return AliasList; }
530  return &Module::AliasList;
531  }
532  /// Get the Module's list of named metadata (constant).
533  const NamedMDListType &getNamedMDList() const { return NamedMDList; }
534  /// Get the Module's list of named metadata.
535  NamedMDListType &getNamedMDList() { return NamedMDList; }
537  return &Module::NamedMDList;
538  }
539  /// Get the symbol table of global variable and function identifiers
540  const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
541  /// Get the Module's symbol table of global variable and function identifiers.
542  ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
543  /// Get the Module's symbol table for COMDATs (constant).
544  const ComdatSymTabType &getComdatSymbolTable() const { return ComdatSymTab; }
545  /// Get the Module's symbol table for COMDATs.
546  ComdatSymTabType &getComdatSymbolTable() { return ComdatSymTab; }
547 
548 /// @}
549 /// @name Global Variable Iteration
550 /// @{
551 
552  global_iterator global_begin() { return GlobalList.begin(); }
553  const_global_iterator global_begin() const { return GlobalList.begin(); }
554  global_iterator global_end () { return GlobalList.end(); }
555  const_global_iterator global_end () const { return GlobalList.end(); }
556  bool global_empty() const { return GlobalList.empty(); }
557 
560  }
563  }
564 
565 /// @}
566 /// @name Function Iteration
567 /// @{
568 
569  iterator begin() { return FunctionList.begin(); }
570  const_iterator begin() const { return FunctionList.begin(); }
571  iterator end () { return FunctionList.end(); }
572  const_iterator end () const { return FunctionList.end(); }
573  reverse_iterator rbegin() { return FunctionList.rbegin(); }
574  const_reverse_iterator rbegin() const{ return FunctionList.rbegin(); }
575  reverse_iterator rend() { return FunctionList.rend(); }
576  const_reverse_iterator rend() const { return FunctionList.rend(); }
577  size_t size() const { return FunctionList.size(); }
578  bool empty() const { return FunctionList.empty(); }
579 
581  return iterator_range<iterator>(begin(), end());
582  }
585  }
586 
587 /// @}
588 /// @name Alias Iteration
589 /// @{
590 
591  alias_iterator alias_begin() { return AliasList.begin(); }
592  const_alias_iterator alias_begin() const { return AliasList.begin(); }
593  alias_iterator alias_end () { return AliasList.end(); }
594  const_alias_iterator alias_end () const { return AliasList.end(); }
595  size_t alias_size () const { return AliasList.size(); }
596  bool alias_empty() const { return AliasList.empty(); }
597 
600  }
603  }
604 
605 /// @}
606 /// @name Named Metadata Iteration
607 /// @{
608 
611  return NamedMDList.begin();
612  }
613 
614  named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
616  return NamedMDList.end();
617  }
618 
619  size_t named_metadata_size() const { return NamedMDList.size(); }
620  bool named_metadata_empty() const { return NamedMDList.empty(); }
621 
625  }
629  }
630 
631  /// Destroy ConstantArrays in LLVMContext if they are not used.
632  /// ConstantArrays constructed during linking can cause quadratic memory
633  /// explosion. Releasing all unused constants can cause a 20% LTO compile-time
634  /// slowdown for a large application.
635  ///
636  /// NOTE: Constants are currently owned by LLVMContext. This can then only
637  /// be called where all uses of the LLVMContext are understood.
639 
640 /// @}
641 /// @name Utility functions for printing and dumping Module objects
642 /// @{
643 
644  /// Print the module to an output stream with an optional
645  /// AssemblyAnnotationWriter. If \c ShouldPreserveUseListOrder, then include
646  /// uselistorder directives so that use-lists can be recreated when reading
647  /// the assembly.
649  bool ShouldPreserveUseListOrder = false) const;
650 
651  /// Dump the module to stderr (for debugging).
652  void dump() const;
653 
654  /// This function causes all the subinstructions to "let go" of all references
655  /// that they are maintaining. This allows one to 'delete' a whole class at
656  /// a time, even though there may be circular references... first all
657  /// references are dropped, and all use counts go to zero. Then everything
658  /// is delete'd for real. Note that no operations are valid on an object
659  /// that has "dropped all references", except operator delete.
660  void dropAllReferences();
661 
662 /// @}
663 /// @name Utility functions for querying Debug information.
664 /// @{
665 
666  /// \brief Returns the Dwarf Version by checking module flags.
667  unsigned getDwarfVersion() const;
668 
669 /// @}
670 /// @name Utility functions for querying and setting PIC level
671 /// @{
672 
673  /// \brief Returns the PIC level (small or large model)
675 
676  /// \brief Set the PIC level (small or large model)
678 /// @}
679 };
680 
681 /// An raw_ostream inserter for modules.
682 inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
683  M.print(O, nullptr);
684  return O;
685 }
686 
687 // Create wrappers for C Binding types (see CBindingWrapping.h).
689 
690 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
691  * Module.
692  */
694  return reinterpret_cast<Module*>(MP);
695 }
696 
697 } // End llvm namespace
698 
699 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:82
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
This class provides a symbol table of name/value pairs.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
Definition: Module.h:540
iterator_range< const_named_metadata_iterator > named_metadata() const
Definition: Module.h:626
NamedMDNode * createSentinel() const
Definition: Module.h:89
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
Definition: Module.h:542
const_alias_iterator alias_begin() const
Definition: Module.h:592
Function * provideInitialHead() const
Definition: Module.h:47
std::error_code materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:390
iplist< NamedMDNode >::iterator iterator
Definition: ilist.h:588
RandomNumberGenerator * createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
Definition: Module.cpp:66
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
void dematerialize(GlobalValue *GV)
If the GlobalValue is read in, and if the GVMaterializer supports it, release the memory for the func...
Definition: Module.cpp:397
reverse_iterator rend()
Definition: ilist.h:379
void setModuleIdentifier(StringRef ID)
Set the module identifier.
Definition: Module.h:287
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
Definition: Module.h:142
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
Definition: Module.h:512
static void noteHead(Function *, Function *)
Definition: Module.h:49
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
Definition: Module.cpp:377
named_metadata_iterator named_metadata_end()
Definition: Module.h:614
static void destroySentinel(NamedMDNode *)
Definition: Module.h:92
This file contains the declarations for metadata subclasses.
bool alias_empty() const
Definition: Module.h:596
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:262
void setDataLayout(StringRef Desc)
Set the data layout.
Definition: Module.cpp:366
FunctionListType::const_iterator const_iterator
The Function constant iterator.
Definition: Module.h:137
bool empty() const
Definition: Module.h:578
Metadata node.
Definition: Metadata.h:740
std::vector< StructType * > getIdentifiedStructTypes() const
Definition: Module.cpp:426
iterator begin()
Definition: ilist.h:359
void addNodeToList(NamedMDNode *)
Definition: Module.h:97
const_reverse_iterator rend() const
Definition: Module.h:576
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
Definition: Module.h:526
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:261
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
Definition: Type.cpp:625
static void destroySentinel(Function *)
Definition: Module.h:45
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
Definition: AsmWriter.cpp:3146
reverse_iterator rbegin()
Definition: ilist.h:377
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Module.h:171
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
Definition: Module.h:546
ModFlagBehavior Behavior
Definition: Module.h:196
Appends the two values, which are required to be metadata nodes.
Definition: Module.h:179
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
Definition: Module.cpp:101
GlobalVariable * createSentinel() const
Definition: Module.h:58
iterator_range< const_iterator > functions() const
Definition: Module.h:583
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
Definition: Module.h:147
A tuple of MDNodes.
Definition: Metadata.h:1127
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
StringRef getName() const
Get a short "name" for the module.
Definition: Module.h:248
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
Definition: Module.cpp:275
const GlobalVariable * getNamedGlobal(StringRef Name) const
Definition: Module.h:397
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:225
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
iplist< GlobalAlias > AliasListType
The type for the list of aliases.
Definition: Module.h:123
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
Definition: Module.h:482
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
Definition: Module.h:125
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
Definition: Module.h:533
ilist_default_traits - Default template traits for intrusive list.
Definition: ilist.h:127
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
Definition: Module.h:298
const_alias_iterator alias_end() const
Definition: Module.h:594
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:242
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:591
void removeNodeFromList(NamedMDNode *)
Definition: Module.h:98
global_iterator global_begin()
Definition: Module.h:552
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Definition: Core.h:113
std::error_code materializeAllPermanently()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
Definition: Module.cpp:408
std::error_code materializeAll()
Make sure all GlobalValues in this Module are fully read.
Definition: Module.cpp:402
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
reverse_iterator rend()
Definition: Module.h:575
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
Definition: Module.h:535
#define T
iplist< Function > FunctionListType
The type for the list of functions.
Definition: Module.h:121
bool named_metadata_empty() const
Definition: Module.h:620
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
Definition: Module.cpp:447
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal) const
Definition: Module.h:385
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:188
bool global_empty() const
Definition: Module.h:556
static AliasListType Module::* getSublistAccess(GlobalAlias *)
Definition: Module.h:529
const_reverse_iterator rbegin() const
Definition: Module.h:574
const_global_iterator global_end() const
Definition: Module.h:555
#define P(N)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Definition: Module.cpp:48
const_named_metadata_iterator named_metadata_begin() const
Definition: Module.h:610
always inline
DataLayout * unwrap(LLVMTargetDataRef P)
Definition: DataLayout.h:465
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
Definition: Module.h:140
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Definition: Module.h:158
iterator_range< iterator > functions()
Definition: Module.h:580
GlobalVariable * ensureHead(GlobalVariable *) const
Definition: Module.h:64
alias_iterator alias_end()
Definition: Module.h:593
Function * createSentinel() const
Definition: Module.h:42
bool isDematerializable(const GlobalValue *GV) const
Returns true if this GV was loaded from this Module's GVMaterializer and the GVMaterializer knows how...
Definition: Module.cpp:384
void dump() const
Dump the module to stderr (for debugging).
Definition: AsmWriter.cpp:3361
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:115
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
AliasListType & getAliasList()
Get the Module's list of aliases.
Definition: Module.h:528
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
Definition: Module.cpp:217
GlobalAlias * ensureHead(GlobalAlias *) const
Definition: Module.h:79
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const
Definition: ilist.h:539
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:326
This is an important base class in LLVM.
Definition: Constant.h:41
std::error_code materializeMetadata()
Definition: Module.cpp:416
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
Definition: Module.h:132
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
Definition: Module.h:515
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition: Module.h:155
iterator_range< named_metadata_iterator > named_metadata()
Definition: Module.h:622
const_iterator begin() const
Definition: Module.h:570
static FunctionListType Module::* getSublistAccess(Function *)
Definition: Module.h:522
const_global_iterator global_begin() const
Definition: Module.h:553
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:340
NamedMDNode * ensureHead(NamedMDNode *) const
Definition: Module.h:95
const_iterator end() const
Definition: Module.h:572
GlobalAlias * createSentinel() const
Definition: Module.h:73
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:465
static void noteHead(GlobalVariable *, GlobalVariable *)
Definition: Module.h:65
static void destroySentinel(GlobalVariable *)
Definition: Module.h:61
#define LLVM_END_WITH_NULL
Definition: Compiler.h:116
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Definition: Module.cpp:458
AliasListType::iterator alias_iterator
The Global Alias iterators.
Definition: Module.h:145
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition: Module.h:269
reverse_iterator rbegin()
Definition: Module.h:573
global_iterator global_end()
Definition: Module.h:554
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition: Module.h:519
GlobalListType::iterator global_iterator
The Global Variable iterator.
Definition: Module.h:130
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:313
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
Definition: Module.h:199
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition: Module.cpp:471
GlobalListType & getGlobalList()
Get the Module's list of global variables.
Definition: Module.h:514
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
Function * ensureHead(Function *) const
Definition: Module.h:48
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
Definition: Module.cpp:280
GlobalVariable * getNamedGlobal(StringRef Name)
Return the global variable in the module with the specified name, of arbitrary type.
Definition: Module.h:394
size_t named_metadata_size() const
Definition: Module.h:619
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: ilist.h:385
NamedMDNode * provideInitialHead() const
Definition: Module.h:94
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:333
alias_iterator alias_begin()
Definition: Module.h:591
std::reverse_iterator< iterator > reverse_iterator
Definition: ilist.h:349
static void destroySentinel(GlobalAlias *)
Definition: Module.h:76
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
Definition: Module.h:536
Uses the specified value, regardless of the behavior or value of the other module.
Definition: Module.h:176
NamedMDListType::const_iterator const_named_metadata_iterator
The named metadata constant iterators.
Definition: Module.h:152
A range adaptor for a pair of iterators.
iplist< GlobalVariable > GlobalListType
The type for the list of global variables.
Definition: Module.h:119
Emits a warning if two values disagree.
Definition: Module.h:162
size_t size() const
Definition: Module.h:577
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:246
FunctionListType & getFunctionList()
Get the Module's list of functions.
Definition: Module.h:521
A random number generator.
static void noteHead(GlobalAlias *, GlobalAlias *)
Definition: Module.h:80
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:372
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:253
static void noteHead(NamedMDNode *, NamedMDNode *)
Definition: Module.h:96
iterator end()
Definition: Module.h:571
Appends the two values, which are required to be metadata nodes.
Definition: Module.h:184
iterator_range< const_global_iterator > globals() const
Definition: Module.h:561
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Definition: Module.h:544
iterator begin()
Definition: Module.h:569
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Definition: Module.h:307
size_t alias_size() const
Definition: Module.h:595
FunctionListType::iterator iterator
The Function iterators.
Definition: Module.h:135
void setTargetTriple(StringRef T)
Set the target triple.
Definition: Module.h:294
~Module()
The module destructor. This will dropAllReferences.
Definition: Module.cpp:55
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1738
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Core.h:78
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
Definition: ilist.h:78
GlobalVariable * provideInitialHead() const
Definition: Module.h:63
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
Definition: Module.h:127
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
Definition: Module.h:150
GlobalAlias * provideInitialHead() const
Definition: Module.h:78
iterator end()
Definition: ilist.h:367
aarch64 promote const
iterator_range< const_alias_iterator > aliases() const
Definition: Module.h:601
const_named_metadata_iterator named_metadata_end() const
Definition: Module.h:615
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ilist.h:348
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
Definition: Module.cpp:481
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
iterator_range< global_iterator > globals()
Definition: Module.h:558
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
A single uniqued string.
Definition: Metadata.h:508
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
Definition: Module.h:252
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition: Module.cpp:94
Root of the metadata hierarchy.
Definition: Metadata.h:45
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:88
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition: Module.h:381
named_metadata_iterator named_metadata_begin()
Definition: Module.h:609
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:265
iterator_range< alias_iterator > aliases()
Definition: Module.h:598