OSDN Git Service

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