Make ObjectFile and BitcodeReader always own the MemoryBuffer.
[oota-llvm.git] / include / llvm / IR / Module.h
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
18 #include "llvm/ADT/iterator_range.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/GlobalAlias.h"
22 #include "llvm/IR/GlobalVariable.h"
23 #include "llvm/IR/Metadata.h"
24 #include "llvm/Support/CBindingWrapping.h"
25 #include "llvm/Support/DataTypes.h"
26 #include <system_error>
27
28 namespace llvm {
29 class FunctionType;
30 class GVMaterializer;
31 class LLVMContext;
32 class StructType;
33 template<typename T> struct DenseMapInfo;
34 template<typename KeyT, typename ValueT, typename KeyInfoT> class DenseMap;
35
36 template<> struct ilist_traits<Function>
37   : public SymbolTableListTraits<Function, Module> {
38
39   // createSentinel is used to get hold of the node that marks the end of the
40   // list... (same trick used here as in ilist_traits<Instruction>)
41   Function *createSentinel() const {
42     return static_cast<Function*>(&Sentinel);
43   }
44   static void destroySentinel(Function*) {}
45
46   Function *provideInitialHead() const { return createSentinel(); }
47   Function *ensureHead(Function*) const { return createSentinel(); }
48   static void noteHead(Function*, Function*) {}
49
50 private:
51   mutable ilist_node<Function> Sentinel;
52 };
53
54 template<> struct ilist_traits<GlobalVariable>
55   : public SymbolTableListTraits<GlobalVariable, Module> {
56   // createSentinel is used to create a node that marks the end of the list.
57   GlobalVariable *createSentinel() const {
58     return static_cast<GlobalVariable*>(&Sentinel);
59   }
60   static void destroySentinel(GlobalVariable*) {}
61
62   GlobalVariable *provideInitialHead() const { return createSentinel(); }
63   GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); }
64   static void noteHead(GlobalVariable*, GlobalVariable*) {}
65 private:
66   mutable ilist_node<GlobalVariable> Sentinel;
67 };
68
69 template<> struct ilist_traits<GlobalAlias>
70   : public SymbolTableListTraits<GlobalAlias, Module> {
71   // createSentinel is used to create a node that marks the end of the list.
72   GlobalAlias *createSentinel() const {
73     return static_cast<GlobalAlias*>(&Sentinel);
74   }
75   static void destroySentinel(GlobalAlias*) {}
76
77   GlobalAlias *provideInitialHead() const { return createSentinel(); }
78   GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); }
79   static void noteHead(GlobalAlias*, GlobalAlias*) {}
80 private:
81   mutable ilist_node<GlobalAlias> Sentinel;
82 };
83
84 template<> struct ilist_traits<NamedMDNode>
85   : public ilist_default_traits<NamedMDNode> {
86   // createSentinel is used to get hold of a node that marks the end of
87   // the list...
88   NamedMDNode *createSentinel() const {
89     return static_cast<NamedMDNode*>(&Sentinel);
90   }
91   static void destroySentinel(NamedMDNode*) {}
92
93   NamedMDNode *provideInitialHead() const { return createSentinel(); }
94   NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); }
95   static void noteHead(NamedMDNode*, NamedMDNode*) {}
96   void addNodeToList(NamedMDNode *) {}
97   void removeNodeFromList(NamedMDNode *) {}
98 private:
99   mutable ilist_node<NamedMDNode> Sentinel;
100 };
101
102 /// A Module instance is used to store all the information related to an
103 /// LLVM module. Modules are the top level container of all other LLVM
104 /// Intermediate Representation (IR) objects. Each module directly contains a
105 /// list of globals variables, a list of functions, a list of libraries (or
106 /// other modules) this module depends on, a symbol table, and various data
107 /// about the target's characteristics.
108 ///
109 /// A module maintains a GlobalValRefMap object that is used to hold all
110 /// constant references to global variables in the module.  When a global
111 /// variable is destroyed, it should have no entries in the GlobalValueRefMap.
112 /// @brief The main container class for the LLVM Intermediate Representation.
113 class Module {
114 /// @name Types And Enumerations
115 /// @{
116 public:
117   /// The type for the list of global variables.
118   typedef iplist<GlobalVariable> GlobalListType;
119   /// The type for the list of functions.
120   typedef iplist<Function> FunctionListType;
121   /// The type for the list of aliases.
122   typedef iplist<GlobalAlias> AliasListType;
123   /// The type for the list of named metadata.
124   typedef ilist<NamedMDNode> NamedMDListType;
125
126   /// The Global Variable iterator.
127   typedef GlobalListType::iterator                      global_iterator;
128   /// The Global Variable constant iterator.
129   typedef GlobalListType::const_iterator          const_global_iterator;
130
131   /// The Function iterators.
132   typedef FunctionListType::iterator                           iterator;
133   /// The Function constant iterator
134   typedef FunctionListType::const_iterator               const_iterator;
135
136   /// The Global Alias iterators.
137   typedef AliasListType::iterator                        alias_iterator;
138   /// The Global Alias constant iterator
139   typedef AliasListType::const_iterator            const_alias_iterator;
140
141   /// The named metadata iterators.
142   typedef NamedMDListType::iterator             named_metadata_iterator;
143   /// The named metadata constant interators.
144   typedef NamedMDListType::const_iterator const_named_metadata_iterator;
145
146   /// This enumeration defines the supported behaviors of module flags.
147   enum ModFlagBehavior {
148     /// Emits an error if two values disagree, otherwise the resulting value is
149     /// that of the operands.
150     Error = 1,
151
152     /// Emits a warning if two values disagree. The result value will be the
153     /// operand for the flag from the first module being linked.
154     Warning = 2,
155
156     /// Adds a requirement that another module flag be present and have a
157     /// specified value after linking is performed. The value must be a metadata
158     /// pair, where the first element of the pair is the ID of the module flag
159     /// to be restricted, and the second element of the pair is the value the
160     /// module flag should be restricted to. This behavior can be used to
161     /// restrict the allowable results (via triggering of an error) of linking
162     /// IDs with the **Override** behavior.
163     Require = 3,
164
165     /// Uses the specified value, regardless of the behavior or value of the
166     /// other module. If both modules specify **Override**, but the values
167     /// differ, an error will be emitted.
168     Override = 4,
169
170     /// Appends the two values, which are required to be metadata nodes.
171     Append = 5,
172
173     /// Appends the two values, which are required to be metadata
174     /// nodes. However, duplicate entries in the second list are dropped
175     /// during the append operation.
176     AppendUnique = 6
177   };
178
179   struct ModuleFlagEntry {
180     ModFlagBehavior Behavior;
181     MDString *Key;
182     Value *Val;
183     ModuleFlagEntry(ModFlagBehavior B, MDString *K, Value *V)
184       : Behavior(B), Key(K), Val(V) {}
185   };
186
187 /// @}
188 /// @name Member Variables
189 /// @{
190 private:
191   LLVMContext &Context;           ///< The LLVMContext from which types and
192                                   ///< constants are allocated.
193   GlobalListType GlobalList;      ///< The Global Variables in the module
194   FunctionListType FunctionList;  ///< The Functions in the module
195   AliasListType AliasList;        ///< The Aliases in the module
196   NamedMDListType NamedMDList;    ///< The named metadata in the module
197   std::string GlobalScopeAsm;     ///< Inline Asm at global scope.
198   ValueSymbolTable *ValSymTab;    ///< Symbol table for values
199   std::unique_ptr<GVMaterializer>
200   Materializer;                   ///< Used to materialize GlobalValues
201   std::string ModuleID;           ///< Human readable identifier for the module
202   std::string TargetTriple;       ///< Platform target triple Module compiled on
203   void *NamedMDSymTab;            ///< NamedMDNode names.
204
205   // We need to keep the string because the C API expects us to own the string
206   // representation.
207   // Since we have it, we also use an empty string to represent a module without
208   // a DataLayout. If it has a DataLayout, these variables are in sync and the
209   // string is just a cache of getDataLayout()->getStringRepresentation().
210   std::string DataLayoutStr;
211   DataLayout DL;
212
213   friend class Constant;
214
215 /// @}
216 /// @name Constructors
217 /// @{
218 public:
219   /// The Module constructor. Note that there is no default constructor. You
220   /// must provide a name for the module upon construction.
221   explicit Module(StringRef ModuleID, LLVMContext& C);
222   /// The module destructor. This will dropAllReferences.
223   ~Module();
224
225 /// @}
226 /// @name Module Level Accessors
227 /// @{
228
229   /// Get the module identifier which is, essentially, the name of the module.
230   /// @returns the module identifier as a string
231   const std::string &getModuleIdentifier() const { return ModuleID; }
232
233   /// Get the data layout string for the module's target platform. This is
234   /// equivalent to getDataLayout()->getStringRepresentation().
235   const std::string &getDataLayoutStr() const { return DataLayoutStr; }
236
237   /// Get the data layout for the module's target platform.
238   const DataLayout *getDataLayout() const;
239
240   /// Get the target triple which is a string describing the target host.
241   /// @returns a string containing the target triple.
242   const std::string &getTargetTriple() const { return TargetTriple; }
243
244   /// Get the global data context.
245   /// @returns LLVMContext - a container for LLVM's global information
246   LLVMContext &getContext() const { return Context; }
247
248   /// Get any module-scope inline assembly blocks.
249   /// @returns a string containing the module-scope inline assembly blocks.
250   const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
251
252 /// @}
253 /// @name Module Level Mutators
254 /// @{
255
256   /// Set the module identifier.
257   void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
258
259   /// Set the data layout
260   void setDataLayout(StringRef Desc);
261   void setDataLayout(const DataLayout *Other);
262
263   /// Set the target triple.
264   void setTargetTriple(StringRef T) { TargetTriple = T; }
265
266   /// Set the module-scope inline assembly blocks.
267   void setModuleInlineAsm(StringRef Asm) {
268     GlobalScopeAsm = Asm;
269     if (!GlobalScopeAsm.empty() &&
270         GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
271       GlobalScopeAsm += '\n';
272   }
273
274   /// Append to the module-scope inline assembly blocks, automatically inserting
275   /// a separating newline if necessary.
276   void appendModuleInlineAsm(StringRef Asm) {
277     GlobalScopeAsm += Asm;
278     if (!GlobalScopeAsm.empty() &&
279         GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
280       GlobalScopeAsm += '\n';
281   }
282
283 /// @}
284 /// @name Generic Value Accessors
285 /// @{
286
287   /// Return the global value in the module with the specified name, of
288   /// arbitrary type. This method returns null if a global with the specified
289   /// name is not found.
290   GlobalValue *getNamedValue(StringRef Name) const;
291
292   /// Return a unique non-zero ID for the specified metadata kind. This ID is
293   /// uniqued across modules in the current LLVMContext.
294   unsigned getMDKindID(StringRef Name) const;
295
296   /// Populate client supplied SmallVector with the name for custom metadata IDs
297   /// registered in this LLVMContext.
298   void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
299
300   /// Return the type with the specified name, or null if there is none by that
301   /// name.
302   StructType *getTypeByName(StringRef Name) const;
303
304 /// @}
305 /// @name Function Accessors
306 /// @{
307
308   /// Look up the specified function in the module symbol table. Four
309   /// possibilities:
310   ///   1. If it does not exist, add a prototype for the function and return it.
311   ///   2. If it exists, and has a local linkage, the existing function is
312   ///      renamed and a new one is inserted.
313   ///   3. Otherwise, if the existing function has the correct prototype, return
314   ///      the existing function.
315   ///   4. Finally, the function exists but has the wrong prototype: return the
316   ///      function with a constantexpr cast to the right prototype.
317   Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
318                                 AttributeSet AttributeList);
319
320   Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
321
322   /// Look up the specified function in the module symbol table. If it does not
323   /// exist, add a prototype for the function and return it. This function
324   /// guarantees to return a constant of pointer to the specified function type
325   /// or a ConstantExpr BitCast of that type if the named function has a
326   /// different type. This version of the method takes a null terminated list of
327   /// function arguments, which makes it easier for clients to use.
328   Constant *getOrInsertFunction(StringRef Name,
329                                 AttributeSet AttributeList,
330                                 Type *RetTy, ...)  END_WITH_NULL;
331
332   /// Same as above, but without the attributes.
333   Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
334     END_WITH_NULL;
335
336   /// Look up the specified function in the module symbol table. If it does not
337   /// exist, return null.
338   Function *getFunction(StringRef Name) const;
339
340 /// @}
341 /// @name Global Variable Accessors
342 /// @{
343
344   /// Look up the specified global variable in the module symbol table. If it
345   /// does not exist, return null. If AllowInternal is set to true, this
346   /// function will return types that have InternalLinkage. By default, these
347   /// types are not returned.
348   const GlobalVariable *getGlobalVariable(StringRef Name,
349                                           bool AllowInternal = false) const {
350     return const_cast<Module *>(this)->getGlobalVariable(Name, AllowInternal);
351   }
352
353   GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal = false);
354
355   /// Return the global variable in the module with the specified name, of
356   /// arbitrary type. This method returns null if a global with the specified
357   /// name is not found.
358   GlobalVariable *getNamedGlobal(StringRef Name) {
359     return getGlobalVariable(Name, true);
360   }
361   const GlobalVariable *getNamedGlobal(StringRef Name) const {
362     return const_cast<Module *>(this)->getNamedGlobal(Name);
363   }
364
365   /// Look up the specified global in the module symbol table.
366   ///   1. If it does not exist, add a declaration of the global and return it.
367   ///   2. Else, the global exists but has the wrong type: return the function
368   ///      with a constantexpr cast to the right type.
369   ///   3. Finally, if the existing global is the correct declaration, return
370   ///      the existing global.
371   Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
372
373 /// @}
374 /// @name Global Alias Accessors
375 /// @{
376
377   /// Return the global alias in the module with the specified name, of
378   /// arbitrary type. This method returns null if a global with the specified
379   /// name is not found.
380   GlobalAlias *getNamedAlias(StringRef Name) const;
381
382 /// @}
383 /// @name Named Metadata Accessors
384 /// @{
385
386   /// Return the first NamedMDNode in the module with the specified name. This
387   /// method returns null if a NamedMDNode with the specified name is not found.
388   NamedMDNode *getNamedMetadata(const Twine &Name) const;
389
390   /// Return the named MDNode in the module with the specified name. This method
391   /// returns a new NamedMDNode if a NamedMDNode with the specified name is not
392   /// found.
393   NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
394
395   /// Remove the given NamedMDNode from this module and delete it.
396   void eraseNamedMetadata(NamedMDNode *NMD);
397
398 /// @}
399 /// @name Module Flags Accessors
400 /// @{
401
402   /// Returns the module flags in the provided vector.
403   void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
404
405   /// Return the corresponding value if Key appears in module flags, otherwise
406   /// return null.
407   Value *getModuleFlag(StringRef Key) const;
408
409   /// Returns the NamedMDNode in the module that represents module-level flags.
410   /// This method returns null if there are no module-level flags.
411   NamedMDNode *getModuleFlagsMetadata() const;
412
413   /// Returns the NamedMDNode in the module that represents module-level flags.
414   /// If module-level flags aren't found, it creates the named metadata that
415   /// contains them.
416   NamedMDNode *getOrInsertModuleFlagsMetadata();
417
418   /// Add a module-level flag to the module-level flags metadata. It will create
419   /// the module-level flags named metadata if it doesn't already exist.
420   void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Value *Val);
421   void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
422   void addModuleFlag(MDNode *Node);
423
424 /// @}
425 /// @name Materialization
426 /// @{
427
428   /// Sets the GVMaterializer to GVM. This module must not yet have a
429   /// Materializer. To reset the materializer for a module that already has one,
430   /// call MaterializeAllPermanently first. Destroying this module will destroy
431   /// its materializer without materializing any more GlobalValues. Without
432   /// destroying the Module, there is no way to detach or destroy a materializer
433   /// without materializing all the GVs it controls, to avoid leaving orphan
434   /// unmaterialized GVs.
435   void setMaterializer(GVMaterializer *GVM);
436   /// Retrieves the GVMaterializer, if any, for this Module.
437   GVMaterializer *getMaterializer() const { return Materializer.get(); }
438
439   /// True if the definition of GV has yet to be materializedfrom the
440   /// GVMaterializer.
441   bool isMaterializable(const GlobalValue *GV) const;
442   /// Returns true if this GV was loaded from this Module's GVMaterializer and
443   /// the GVMaterializer knows how to dematerialize the GV.
444   bool isDematerializable(const GlobalValue *GV) const;
445
446   /// Make sure the GlobalValue is fully read. If the module is corrupt, this
447   /// returns true and fills in the optional string with information about the
448   /// problem. If successful, this returns false.
449   bool Materialize(GlobalValue *GV, std::string *ErrInfo = nullptr);
450   /// If the GlobalValue is read in, and if the GVMaterializer supports it,
451   /// release the memory for the function, and set it up to be materialized
452   /// lazily. If !isDematerializable(), this method is a noop.
453   void Dematerialize(GlobalValue *GV);
454
455   /// Make sure all GlobalValues in this Module are fully read.
456   std::error_code materializeAll();
457
458   /// Make sure all GlobalValues in this Module are fully read and clear the
459   /// Materializer. If the module is corrupt, this DOES NOT clear the old
460   /// Materializer.
461   std::error_code materializeAllPermanently(bool ReleaseBuffer = false);
462
463 /// @}
464 /// @name Direct access to the globals list, functions list, and symbol table
465 /// @{
466
467   /// Get the Module's list of global variables (constant).
468   const GlobalListType   &getGlobalList() const       { return GlobalList; }
469   /// Get the Module's list of global variables.
470   GlobalListType         &getGlobalList()             { return GlobalList; }
471   static iplist<GlobalVariable> Module::*getSublistAccess(GlobalVariable*) {
472     return &Module::GlobalList;
473   }
474   /// Get the Module's list of functions (constant).
475   const FunctionListType &getFunctionList() const     { return FunctionList; }
476   /// Get the Module's list of functions.
477   FunctionListType       &getFunctionList()           { return FunctionList; }
478   static iplist<Function> Module::*getSublistAccess(Function*) {
479     return &Module::FunctionList;
480   }
481   /// Get the Module's list of aliases (constant).
482   const AliasListType    &getAliasList() const        { return AliasList; }
483   /// Get the Module's list of aliases.
484   AliasListType          &getAliasList()              { return AliasList; }
485   static iplist<GlobalAlias> Module::*getSublistAccess(GlobalAlias*) {
486     return &Module::AliasList;
487   }
488   /// Get the Module's list of named metadata (constant).
489   const NamedMDListType  &getNamedMDList() const      { return NamedMDList; }
490   /// Get the Module's list of named metadata.
491   NamedMDListType        &getNamedMDList()            { return NamedMDList; }
492   static ilist<NamedMDNode> Module::*getSublistAccess(NamedMDNode*) {
493     return &Module::NamedMDList;
494   }
495   /// Get the symbol table of global variable and function identifiers
496   const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
497   /// Get the Module's symbol table of global variable and function identifiers.
498   ValueSymbolTable       &getValueSymbolTable()       { return *ValSymTab; }
499
500 /// @}
501 /// @name Global Variable Iteration
502 /// @{
503
504   global_iterator       global_begin()       { return GlobalList.begin(); }
505   const_global_iterator global_begin() const { return GlobalList.begin(); }
506   global_iterator       global_end  ()       { return GlobalList.end(); }
507   const_global_iterator global_end  () const { return GlobalList.end(); }
508   bool                  global_empty() const { return GlobalList.empty(); }
509
510   iterator_range<global_iterator> globals() {
511     return iterator_range<global_iterator>(global_begin(), global_end());
512   }
513   iterator_range<const_global_iterator> globals() const {
514     return iterator_range<const_global_iterator>(global_begin(), global_end());
515   }
516
517 /// @}
518 /// @name Function Iteration
519 /// @{
520
521   iterator                begin()       { return FunctionList.begin(); }
522   const_iterator          begin() const { return FunctionList.begin(); }
523   iterator                end  ()       { return FunctionList.end();   }
524   const_iterator          end  () const { return FunctionList.end();   }
525   size_t                  size() const  { return FunctionList.size(); }
526   bool                    empty() const { return FunctionList.empty(); }
527
528 /// @}
529 /// @name Alias Iteration
530 /// @{
531
532   alias_iterator       alias_begin()            { return AliasList.begin(); }
533   const_alias_iterator alias_begin() const      { return AliasList.begin(); }
534   alias_iterator       alias_end  ()            { return AliasList.end();   }
535   const_alias_iterator alias_end  () const      { return AliasList.end();   }
536   size_t               alias_size () const      { return AliasList.size();  }
537   bool                 alias_empty() const      { return AliasList.empty(); }
538
539   iterator_range<alias_iterator> aliases() {
540     return iterator_range<alias_iterator>(alias_begin(), alias_end());
541   }
542   iterator_range<const_alias_iterator> aliases() const {
543     return iterator_range<const_alias_iterator>(alias_begin(), alias_end());
544   }
545
546 /// @}
547 /// @name Named Metadata Iteration
548 /// @{
549
550   named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
551   const_named_metadata_iterator named_metadata_begin() const {
552     return NamedMDList.begin();
553   }
554
555   named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
556   const_named_metadata_iterator named_metadata_end() const {
557     return NamedMDList.end();
558   }
559
560   size_t named_metadata_size() const { return NamedMDList.size();  }
561   bool named_metadata_empty() const { return NamedMDList.empty(); }
562
563   iterator_range<named_metadata_iterator> named_metadata() {
564     return iterator_range<named_metadata_iterator>(named_metadata_begin(),
565                                                    named_metadata_end());
566   }
567   iterator_range<const_named_metadata_iterator> named_metadata() const {
568     return iterator_range<const_named_metadata_iterator>(named_metadata_begin(),
569                                                          named_metadata_end());
570   }
571
572 /// @}
573 /// @name Utility functions for printing and dumping Module objects
574 /// @{
575
576   /// Print the module to an output stream with an optional
577   /// AssemblyAnnotationWriter.
578   void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
579
580   /// Dump the module to stderr (for debugging).
581   void dump() const;
582   
583   /// This function causes all the subinstructions to "let go" of all references
584   /// that they are maintaining.  This allows one to 'delete' a whole class at
585   /// a time, even though there may be circular references... first all
586   /// references are dropped, and all use counts go to zero.  Then everything
587   /// is delete'd for real.  Note that no operations are valid on an object
588   /// that has "dropped all references", except operator delete.
589   void dropAllReferences();
590
591 /// @}
592 /// @name Utility functions for querying Debug information.
593 /// @{
594
595   /// \brief Returns the Dwarf Version by checking module flags.
596   unsigned getDwarfVersion() const;
597
598 /// @}
599 };
600
601 /// An raw_ostream inserter for modules.
602 inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
603   M.print(O, nullptr);
604   return O;
605 }
606
607 // Create wrappers for C Binding types (see CBindingWrapping.h).
608 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef)
609
610 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
611  * Module.
612  */
613 inline Module *unwrap(LLVMModuleProviderRef MP) {
614   return reinterpret_cast<Module*>(MP);
615 }
616   
617 } // End llvm namespace
618
619 #endif