148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- llvm/Module.h - C++ class to represent a VM module ------*- C++ -*-===// 29769ab22265b313171d201b5928688524a01bd87Misha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 79769ab22265b313171d201b5928688524a01bd87Misha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 100f8b53f19d29013ab18f3d444cea1e6305405611Dan Gohman/// @file 110f8b53f19d29013ab18f3d444cea1e6305405611Dan Gohman/// Module.h This file contains the declarations for the Module class. 127502f635c650a535d5ae57f047627cd1b6df3216Chris Lattner// 13009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//===----------------------------------------------------------------------===// 14009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 15009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#ifndef LLVM_MODULE_H 16009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#define LLVM_MODULE_H 17009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 1818961504fc2b299578dba817900a0696cf3ccc4dChris Lattner#include "llvm/Function.h" 1918961504fc2b299578dba817900a0696cf3ccc4dChris Lattner#include "llvm/GlobalVariable.h" 208b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov#include "llvm/GlobalAlias.h" 2128bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel#include "llvm/Metadata.h" 22f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin#include "llvm/ADT/OwningPtr.h" 231f6efa3996dd1929fbc129203ce5009b620e6969Michael J. Spencer#include "llvm/Support/DataTypes.h" 2436f78c8935da34074ccd06d5674e45b9cd45da8bChris Lattner#include <vector> 25d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 28db70a8eff3e738a6c3317d06aa56ea7a63b26387Chris Lattnerclass FunctionType; 29f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskinclass GVMaterializer; 3012ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext; 311afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattnerclass StructType; 321afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattnertemplate<typename T> struct DenseMapInfo; 334e58263459d7f9ae862b52adafe585b66411272fBenjamin Kramertemplate<typename KeyT, typename ValueT, typename KeyInfoT> class DenseMap; 34009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 3518961504fc2b299578dba817900a0696cf3ccc4dChris Lattnertemplate<> struct ilist_traits<Function> 3617fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattner : public SymbolTableListTraits<Function, Module> { 37d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif 38d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif // createSentinel is used to get hold of the node that marks the end of the 39d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif // list... (same trick used here as in ilist_traits<Instruction>) 40d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif Function *createSentinel() const { 41d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif return static_cast<Function*>(&Sentinel); 42d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif } 43d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif static void destroySentinel(Function*) {} 44d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif 45d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif Function *provideInitialHead() const { return createSentinel(); } 46d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif Function *ensureHead(Function*) const { return createSentinel(); } 47d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif static void noteHead(Function*, Function*) {} 48d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif 49d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greifprivate: 50d257f7d96b414682834f1eb5aa4d9ea00f6761beGabor Greif mutable ilist_node<Function> Sentinel; 5118961504fc2b299578dba817900a0696cf3ccc4dChris Lattner}; 5253b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky 5318961504fc2b299578dba817900a0696cf3ccc4dChris Lattnertemplate<> struct ilist_traits<GlobalVariable> 5417fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattner : public SymbolTableListTraits<GlobalVariable, Module> { 55bca81448ac8e19c588c9a4ad16fc70732b76327cChris Lattner // createSentinel is used to create a node that marks the end of the list. 5653b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalVariable *createSentinel() const { 5753b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky return static_cast<GlobalVariable*>(&Sentinel); 5853b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky } 5953b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky static void destroySentinel(GlobalVariable*) {} 6053b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky 6153b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalVariable *provideInitialHead() const { return createSentinel(); } 6253b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); } 6353b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky static void noteHead(GlobalVariable*, GlobalVariable*) {} 6453b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewyckyprivate: 6553b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky mutable ilist_node<GlobalVariable> Sentinel; 6618961504fc2b299578dba817900a0696cf3ccc4dChris Lattner}; 6753b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky 688b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikovtemplate<> struct ilist_traits<GlobalAlias> 698b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov : public SymbolTableListTraits<GlobalAlias, Module> { 708b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov // createSentinel is used to create a node that marks the end of the list. 7153b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalAlias *createSentinel() const { 7253b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky return static_cast<GlobalAlias*>(&Sentinel); 7353b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky } 7453b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky static void destroySentinel(GlobalAlias*) {} 7553b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky 7653b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalAlias *provideInitialHead() const { return createSentinel(); } 7753b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); } 7853b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky static void noteHead(GlobalAlias*, GlobalAlias*) {} 7953b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewyckyprivate: 8053b2b7364385b2f2d98c0052df73a637a81c2288Nick Lewycky mutable ilist_node<GlobalAlias> Sentinel; 818b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov}; 8226028f27ddd132b3284943e11aca130c2911abc4Devang Patel 8328bc9d88260a3e153ead4311c9129e3d3ad07736Devang Pateltemplate<> struct ilist_traits<NamedMDNode> 8417aa92c92a925b4a674440c7ef088c223990e854Dan Gohman : public ilist_default_traits<NamedMDNode> { 8528bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel // createSentinel is used to get hold of a node that marks the end of 8628bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel // the list... 8728bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel NamedMDNode *createSentinel() const { 8828bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel return static_cast<NamedMDNode*>(&Sentinel); 8928bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel } 9028bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel static void destroySentinel(NamedMDNode*) {} 9128bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel 9228bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel NamedMDNode *provideInitialHead() const { return createSentinel(); } 9328bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); } 9428bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel static void noteHead(NamedMDNode*, NamedMDNode*) {} 95ed2b84087f4ff1df77b73afaf2003c97816fe7ecEric Christopher void addNodeToList(NamedMDNode *) {} 96ed2b84087f4ff1df77b73afaf2003c97816fe7ecEric Christopher void removeNodeFromList(NamedMDNode *) {} 9728bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patelprivate: 9828bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel mutable ilist_node<NamedMDNode> Sentinel; 9928bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel}; 10018961504fc2b299578dba817900a0696cf3ccc4dChris Lattner 1016413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// A Module instance is used to store all the information related to an 102e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher/// LLVM module. Modules are the top level container of all other LLVM 1036413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// Intermediate Representation (IR) objects. Each module directly contains a 104e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher/// list of globals variables, a list of functions, a list of libraries (or 1056413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// other modules) this module depends on, a symbol table, and various data 1066413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// about the target's characteristics. 1076413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// 1086413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// A module maintains a GlobalValRefMap object that is used to hold all 1096413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// constant references to global variables in the module. When a global 1106413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// variable is destroyed, it should have no entries in the GlobalValueRefMap. 1116413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @brief The main container class for the LLVM Intermediate Representation. 11285b0195f0e619d7151824a08f33e6754a451e7fcChris Lattnerclass Module { 1136413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Types And Enumerations 1146413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 11585b0195f0e619d7151824a08f33e6754a451e7fcChris Lattnerpublic: 1166413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The type for the list of global variables. 11718961504fc2b299578dba817900a0696cf3ccc4dChris Lattner typedef iplist<GlobalVariable> GlobalListType; 1186413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The type for the list of functions. 11918961504fc2b299578dba817900a0696cf3ccc4dChris Lattner typedef iplist<Function> FunctionListType; 1208b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// The type for the list of aliases. 1218b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov typedef iplist<GlobalAlias> AliasListType; 12228bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel /// The type for the list of named metadata. 12317aa92c92a925b4a674440c7ef088c223990e854Dan Gohman typedef ilist<NamedMDNode> NamedMDListType; 1246413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer 1256413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The type for the list of dependent libraries. 1266734b57d1bcd743491b627979f7801f94c97a970Reid Spencer typedef std::vector<std::string> LibraryListType; 1271020b3982c9eae15844c5612b0cf251917931b1dChris Lattner 1286413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Global Variable iterator. 12928bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef GlobalListType::iterator global_iterator; 1306413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Global Variable constant iterator. 13128bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef GlobalListType::const_iterator const_global_iterator; 13270cc3397f84c2e1fd69c059a0ef89e398e847b00Chris Lattner 1336413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Function iterators. 13428bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef FunctionListType::iterator iterator; 1356413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Function constant iterator 13628bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef FunctionListType::const_iterator const_iterator; 13770cc3397f84c2e1fd69c059a0ef89e398e847b00Chris Lattner 1388b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// The Global Alias iterators. 13928bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef AliasListType::iterator alias_iterator; 1408b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// The Global Alias constant iterator 14128bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef AliasListType::const_iterator const_alias_iterator; 1428b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov 14328bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel /// The named metadata iterators. 14428bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef NamedMDListType::iterator named_metadata_iterator; 14528bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel /// The named metadata constant interators. 14628bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel typedef NamedMDListType::const_iterator const_named_metadata_iterator; 1476413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Library list iterator. 148641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer typedef LibraryListType::const_iterator lib_iterator; 149af8ea13dd63601034c2d9178dd8e391cafe600ddReid Spencer 1506413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// An enumeration for describing the endianess of the target machine. 151a7a35a831bf7aaa63287824645bb71937652e1b9Chris Lattner enum Endianness { AnyEndianness, LittleEndian, BigEndian }; 1526413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer 1536413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// An enumeration for describing the size of a pointer on the target machine. 154a7a35a831bf7aaa63287824645bb71937652e1b9Chris Lattner enum PointerSize { AnyPointerSize, Pointer32, Pointer64 }; 155009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 156d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// An enumeration for the supported behaviors of module flags. The following 157d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// module flags behavior values are supported: 158d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 159d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// Value Behavior 160d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// ----- -------- 161d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 1 Error 162d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// Emits an error if two values disagree. 163d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 164d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 2 Warning 165d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// Emits a warning if two values disagree. 166d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 167d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 3 Require 168d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// Emits an error when the specified value is not present 169d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// or doesn't have the specified value. It is an error for 170d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// two (or more) llvm.module.flags with the same ID to have 171d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// the Require behavior but different values. There may be 172d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// multiple Require flags per ID. 173d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 174d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// 4 Override 175d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// Uses the specified value if the two values disagree. It 176d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// is an error for two (or more) llvm.module.flags with the 177d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// same ID to have the Override behavior but different 178d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// values. 179e6bd7a805808a05e9869fbf067581855a8b2a2c2Bill Wendling enum ModFlagBehavior { Error = 1, Warning = 2, Require = 3, Override = 4 }; 180d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling 181f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling struct ModuleFlagEntry { 182e6bd7a805808a05e9869fbf067581855a8b2a2c2Bill Wendling ModFlagBehavior Behavior; 183f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling MDString *Key; 184f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling Value *Val; 185e6bd7a805808a05e9869fbf067581855a8b2a2c2Bill Wendling ModuleFlagEntry(ModFlagBehavior B, MDString *K, Value *V) 186f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling : Behavior(B), Key(K), Val(V) {} 187f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling }; 188f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling 1896413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 1906413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Member Variables 1916413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 192678c6a089da468bc20661922cf63deedef2d9b7aChris Lattnerprivate: 1930386f01e061513094504bc11f8352a40173cada7Devang Patel LLVMContext &Context; ///< The LLVMContext from which types and 1940386f01e061513094504bc11f8352a40173cada7Devang Patel ///< constants are allocated. 1950386f01e061513094504bc11f8352a40173cada7Devang Patel GlobalListType GlobalList; ///< The Global Variables in the module 1960386f01e061513094504bc11f8352a40173cada7Devang Patel FunctionListType FunctionList; ///< The Functions in the module 1970386f01e061513094504bc11f8352a40173cada7Devang Patel AliasListType AliasList; ///< The Aliases in the module 1980386f01e061513094504bc11f8352a40173cada7Devang Patel LibraryListType LibraryList; ///< The Libraries needed by the module 1990386f01e061513094504bc11f8352a40173cada7Devang Patel NamedMDListType NamedMDList; ///< The named metadata in the module 2000386f01e061513094504bc11f8352a40173cada7Devang Patel std::string GlobalScopeAsm; ///< Inline Asm at global scope. 2010386f01e061513094504bc11f8352a40173cada7Devang Patel ValueSymbolTable *ValSymTab; ///< Symbol table for values 202f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin OwningPtr<GVMaterializer> Materializer; ///< Used to materialize GlobalValues 2030386f01e061513094504bc11f8352a40173cada7Devang Patel std::string ModuleID; ///< Human readable identifier for the module 2040386f01e061513094504bc11f8352a40173cada7Devang Patel std::string TargetTriple; ///< Platform target triple Module compiled on 2050386f01e061513094504bc11f8352a40173cada7Devang Patel std::string DataLayout; ///< Target data description 20617aa92c92a925b4a674440c7ef088c223990e854Dan Gohman void *NamedMDSymTab; ///< NamedMDNode names. 2076b5689ed55bef1a6cf358dbb1016871d2237e1e6Chris Lattner 20834048e2ace447e5bdbd386d599ce768e19e6b18bChris Lattner friend class Constant; 2097502f635c650a535d5ae57f047627cd1b6df3216Chris Lattner 2106413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 2116413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Constructors 2126413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 213009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 2146413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The Module constructor. Note that there is no default constructor. You 2156413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// must provide a name for the module upon construction. 2162928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar explicit Module(StringRef ModuleID, LLVMContext& C); 2176413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// The module destructor. This will dropAllReferences. 218009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner ~Module(); 219009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 2206413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 2216413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Module Level Accessors 2226413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 223e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 2246413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the module identifier which is, essentially, the name of the module. 2256413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// @returns the module identifier as a string 226304a564c1f84eaaee8dc218a2eb57443c370e12fChris Lattner const std::string &getModuleIdentifier() const { return ModuleID; } 227304a564c1f84eaaee8dc218a2eb57443c370e12fChris Lattner 228cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson /// Get the data layout string for the module's target platform. This encodes 229cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson /// the type sizes and alignments expected by this module. 230cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson /// @returns the data layout as a string 23192ccf70ad448eb02f9f273d2c70ae4708b3bd0f2Daniel Dunbar const std::string &getDataLayout() const { return DataLayout; } 232cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson 2336413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the target triple which is a string describing the target host. 2346413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// @returns a string containing the target triple. 235304a564c1f84eaaee8dc218a2eb57443c370e12fChris Lattner const std::string &getTargetTriple() const { return TargetTriple; } 236678c6a089da468bc20661922cf63deedef2d9b7aChris Lattner 2376413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the target endian information. 2386413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// @returns Endianess - an enumeration for the endianess of the target 2391d8b8535ec6ccbf07b0e83c5be6aec51feed1d45Owen Anderson Endianness getEndianness() const; 240678c6a089da468bc20661922cf63deedef2d9b7aChris Lattner 2416413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the target pointer size. 2426413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// @returns PointerSize - an enumeration for the size of the target's pointer 2431d8b8535ec6ccbf07b0e83c5be6aec51feed1d45Owen Anderson PointerSize getPointerSize() const; 244678c6a089da468bc20661922cf63deedef2d9b7aChris Lattner 2458b477ed579794ba6d76915d56b3f448a7dd20120Owen Anderson /// Get the global data context. 2468b477ed579794ba6d76915d56b3f448a7dd20120Owen Anderson /// @returns LLVMContext - a container for LLVM's global information 247081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner LLVMContext &getContext() const { return Context; } 2488b477ed579794ba6d76915d56b3f448a7dd20120Owen Anderson 2496413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get any module-scope inline assembly blocks. 2506413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// @returns a string containing the module-scope inline assembly blocks. 251cc041ba03aed685400197fb938b7a583713d25afChris Lattner const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; } 252ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 2536413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 2546413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Module Level Mutators 2556413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 256ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 2576413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Set the module identifier. 2582928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void setModuleIdentifier(StringRef ID) { ModuleID = ID; } 2596413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer 260cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson /// Set the data layout 2612928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void setDataLayout(StringRef DL) { DataLayout = DL; } 262cf7ff2b4c8c18d67aced9d7ba84482819b38a84bOwen Anderson 2636413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Set the target triple. 2642928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void setTargetTriple(StringRef T) { TargetTriple = T; } 2656413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer 2666413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Set the module-scope inline assembly blocks. 26738c4e535493363b96eac47af9e7c056530137beaRafael Espindola void setModuleInlineAsm(StringRef Asm) { 26838c4e535493363b96eac47af9e7c056530137beaRafael Espindola GlobalScopeAsm = Asm; 26938c4e535493363b96eac47af9e7c056530137beaRafael Espindola if (!GlobalScopeAsm.empty() && 27038c4e535493363b96eac47af9e7c056530137beaRafael Espindola GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n') 27138c4e535493363b96eac47af9e7c056530137beaRafael Espindola GlobalScopeAsm += '\n'; 27238c4e535493363b96eac47af9e7c056530137beaRafael Espindola } 273e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher 274b06f3ad5f99b3ce05a5d39c04cb4d0cbb6d98db4Duncan Sands /// Append to the module-scope inline assembly blocks, automatically inserting 275b06f3ad5f99b3ce05a5d39c04cb4d0cbb6d98db4Duncan Sands /// a separating newline if necessary. 2762928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void appendModuleInlineAsm(StringRef Asm) { 27738c4e535493363b96eac47af9e7c056530137beaRafael Espindola GlobalScopeAsm += Asm; 278b06f3ad5f99b3ce05a5d39c04cb4d0cbb6d98db4Duncan Sands if (!GlobalScopeAsm.empty() && 279b06f3ad5f99b3ce05a5d39c04cb4d0cbb6d98db4Duncan Sands GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n') 280b06f3ad5f99b3ce05a5d39c04cb4d0cbb6d98db4Duncan Sands GlobalScopeAsm += '\n'; 281bc9d89e6a2d685de7db90013a37e1a60a4ef38deDan Gohman } 282e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher 2836413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 284f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar/// @name Generic Value Accessors 285f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar/// @{ 286f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar 2871afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getNamedValue - Return the global value in the module with 288f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar /// the specified name, of arbitrary type. This method returns null 289f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar /// if a global with the specified name is not found. 2902928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar GlobalValue *getNamedValue(StringRef Name) const; 291f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar 292081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// getMDKindID - Return a unique non-zero ID for the specified metadata kind. 293081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// This ID is uniqued across modules in the current LLVMContext. 294081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner unsigned getMDKindID(StringRef Name) const; 295ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 296081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// getMDKindNames - Populate client supplied SmallVector with the name for 29745953215210ad06a3901b026bdee1d4352294407Dan Gohman /// custom metadata IDs registered in this LLVMContext. 298081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner void getMDKindNames(SmallVectorImpl<StringRef> &Result) const; 299ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 3001afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 3014e58263459d7f9ae862b52adafe585b66411272fBenjamin Kramer typedef DenseMap<StructType*, unsigned, DenseMapInfo<StructType*> > 3024e58263459d7f9ae862b52adafe585b66411272fBenjamin Kramer NumeredTypesMapTy; 3031afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 3041afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getTypeByName - Return the type with the specified name, or null if there 3051afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// is none by that name. 3061afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner StructType *getTypeByName(StringRef Name) const; 3071afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 308f56ec6423cc8116136cfef314b9f3a519e37d3f9Daniel Dunbar/// @} 3096413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Function Accessors 3106413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 311e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 31226199059268a05739c84ebf465fcdbf7ded861dfChris Lattner /// getOrInsertFunction - Look up the specified function in the module symbol 31370d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// table. Four possibilities: 31470d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// 1. If it does not exist, add a prototype for the function and return it. 315bb46f52027416598a662dc1c58f48d9d56b1a65bRafael Espindola /// 2. If it exists, and has a local linkage, the existing function is 31670d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// renamed and a new one is inserted. 31770d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// 3. Otherwise, if the existing function has the correct prototype, return 31870d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// the existing function. 31970d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// 4. Finally, the function exists but has the wrong prototype: return the 32070d130516a38013ef6262dd2da5accbea7932e30Chris Lattner /// function with a constantexpr cast to the right prototype. 321db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Constant *getOrInsertFunction(StringRef Name, FunctionType *T, 3221186bf1350145474bb7f0ab4d38ec33dae5c79d2Nick Lewycky AttrListPtr AttributeList); 3231186bf1350145474bb7f0ab4d38ec33dae5c79d2Nick Lewycky 324db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Constant *getOrInsertFunction(StringRef Name, FunctionType *T); 325db70a8eff3e738a6c3317d06aa56ea7a63b26387Chris Lattner 32612d40d2926776b490aed29bce56536aa17415365Chris Lattner /// getOrInsertFunction - Look up the specified function in the module symbol 32712d40d2926776b490aed29bce56536aa17415365Chris Lattner /// table. If it does not exist, add a prototype for the function and return 32860ea274c706b6be9fb587d5f7c69405bef468b8cReid Spencer /// it. This function guarantees to return a constant of pointer to the 3298b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// specified function type or a ConstantExpr BitCast of that type if the 3308b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// named function has a different type. This version of the method takes a 3318b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// null terminated list of function arguments, which makes it easier for 3328b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// clients to use. 3332928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar Constant *getOrInsertFunction(StringRef Name, 3341186bf1350145474bb7f0ab4d38ec33dae5c79d2Nick Lewycky AttrListPtr AttributeList, 335db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *RetTy, ...) END_WITH_NULL; 3361186bf1350145474bb7f0ab4d38ec33dae5c79d2Nick Lewycky 3377febee2a86d0e7eac45477c1529ed09e8b9a0491Kenneth Uildriks /// getOrInsertFunction - Same as above, but without the attributes. 338db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...) 33966c5fd6c537269eaef0f630fa14360dcaff6a295Jeff Cohen END_WITH_NULL; 34012d40d2926776b490aed29bce56536aa17415365Chris Lattner 3412928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar Constant *getOrInsertTargetIntrinsic(StringRef Name, 342db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner FunctionType *Ty, 34349de98214b82fefeb8f16efbf8cdd8813a85469bDale Johannesen AttrListPtr AttributeList); 344ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 34526199059268a05739c84ebf465fcdbf7ded861dfChris Lattner /// getFunction - Look up the specified function in the module symbol table. 34626199059268a05739c84ebf465fcdbf7ded861dfChris Lattner /// If it does not exist, return null. 3472928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar Function *getFunction(StringRef Name) const; 348db70a8eff3e738a6c3317d06aa56ea7a63b26387Chris Lattner 3496413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 350e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher/// @name Global Variable Accessors 3516413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 352e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 3533f804530c737b74a7417c215ac32f76c4672e370Chris Lattner /// getGlobalVariable - Look up the specified global variable in the module 35404bdf20ec1da00891e9903847613574c6f0505d2Gordon Henriksen /// symbol table. If it does not exist, return null. If AllowInternal is set 35504bdf20ec1da00891e9903847613574c6f0505d2Gordon Henriksen /// to true, this function will return types that have InternalLinkage. By 35604bdf20ec1da00891e9903847613574c6f0505d2Gordon Henriksen /// default, these types are not returned. 3572928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar GlobalVariable *getGlobalVariable(StringRef Name, 358ef9b9a793949469cdaa4ab6d0173136229dcab7bReid Spencer bool AllowInternal = false) const; 3593f804530c737b74a7417c215ac32f76c4672e370Chris Lattner 3601afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getNamedGlobal - Return the global variable in the module with the 3616665b97ae99d03cf85da54253c12dec6f1a227b2Chris Lattner /// specified name, of arbitrary type. This method returns null if a global 3626665b97ae99d03cf85da54253c12dec6f1a227b2Chris Lattner /// with the specified name is not found. 3632928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar GlobalVariable *getNamedGlobal(StringRef Name) const { 364ef9b9a793949469cdaa4ab6d0173136229dcab7bReid Spencer return getGlobalVariable(Name, true); 365ef9b9a793949469cdaa4ab6d0173136229dcab7bReid Spencer } 3668b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov 367b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// getOrInsertGlobal - Look up the specified global in the module symbol 368b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// table. 369b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// 1. If it does not exist, add a declaration of the global and return it. 370b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// 2. Else, the global exists but has the wrong type: return the function 371b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// with a constantexpr cast to the right type. 372b0923771c90070d91d685a20f2e774754365a27cNick Lewycky /// 3. Finally, if the existing global is the correct declaration, return 373b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling /// the existing global. 374db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Constant *getOrInsertGlobal(StringRef Name, Type *Ty); 375b7c2c1246f10972d5a8f55499226872608eb10f9Bill Wendling 3768b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov/// @} 377e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher/// @name Global Alias Accessors 3788b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov/// @{ 379e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 3801afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getNamedAlias - Return the global alias in the module with the 3818b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// specified name, of arbitrary type. This method returns null if a global 3828b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// with the specified name is not found. 3832928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar GlobalAlias *getNamedAlias(StringRef Name) const; 384e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher 3856413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 38628bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @name Named Metadata Accessors 38728bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @{ 388ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 3891afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getNamedMetadata - Return the NamedMDNode in the module with the 390ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach /// specified name. This method returns null if a NamedMDNode with the 39149fe6c914c5f356a97619046384d7ceb2cb5187eDevang Patel /// specified name is not found. 392a762b093107ac3aa438815627006425d0b13a236Devang Patel NamedMDNode *getNamedMetadata(const Twine &Name) const; 39328bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel 3941afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getOrInsertNamedMetadata - Return the named MDNode in the module 395ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach /// with the specified name. This method returns a new NamedMDNode if a 39649fe6c914c5f356a97619046384d7ceb2cb5187eDevang Patel /// NamedMDNode with the specified name is not found. 3972928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar NamedMDNode *getOrInsertNamedMetadata(StringRef Name); 39849fe6c914c5f356a97619046384d7ceb2cb5187eDevang Patel 39917aa92c92a925b4a674440c7ef088c223990e854Dan Gohman /// eraseNamedMetadata - Remove the given NamedMDNode from this module 40017aa92c92a925b4a674440c7ef088c223990e854Dan Gohman /// and delete it. 40117aa92c92a925b4a674440c7ef088c223990e854Dan Gohman void eraseNamedMetadata(NamedMDNode *NMD); 40217aa92c92a925b4a674440c7ef088c223990e854Dan Gohman 40328bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @} 404d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling/// @name Module Flags Accessors 405d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling/// @{ 406d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling 407f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling /// getModuleFlagsMetadata - Returns the module flags in the provided vector. 408f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const; 409f20f281368f75239c852fe99c3b3a19278ba38fdBill Wendling 410d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that 411d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// represents module-level flags. This method returns null if there are no 412d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// module-level flags. 413d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling NamedMDNode *getModuleFlagsMetadata() const; 414d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling 415d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module 416d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// that represents module-level flags. If module-level flags aren't found, 417d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// it creates the named metadata that contains them. 418d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling NamedMDNode *getOrInsertModuleFlagsMetadata(); 419d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling 420d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// addModuleFlag - Add a module-level flag to the module-level flags 421d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// metadata. It will create the module-level flags named metadata if it 422d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling /// doesn't already exist. 423e6bd7a805808a05e9869fbf067581855a8b2a2c2Bill Wendling void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Value *Val); 424e6bd7a805808a05e9869fbf067581855a8b2a2c2Bill Wendling void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val); 425d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling void addModuleFlag(MDNode *Node); 426d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling 427d34cb1e09f5e4b3feb7305346655b83ad2f67773Bill Wendling/// @} 428f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin/// @name Materialization 429f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin/// @{ 430f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 431f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// setMaterializer - Sets the GVMaterializer to GVM. This module must not 432f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// yet have a Materializer. To reset the materializer for a module that 433f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// already has one, call MaterializeAllPermanently first. Destroying this 434f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// module will destroy its materializer without materializing any more 435f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// GlobalValues. Without destroying the Module, there is no way to detach or 436f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// destroy a materializer without materializing all the GVs it controls, to 437f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// avoid leaving orphan unmaterialized GVs. 438f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin void setMaterializer(GVMaterializer *GVM); 439f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// getMaterializer - Retrieves the GVMaterializer, if any, for this Module. 440f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin GVMaterializer *getMaterializer() const { return Materializer.get(); } 441f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 442f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// isMaterializable - True if the definition of GV has yet to be materialized 443f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// from the GVMaterializer. 444f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool isMaterializable(const GlobalValue *GV) const; 445f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// isDematerializable - Returns true if this GV was loaded from this Module's 446f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// GVMaterializer and the GVMaterializer knows how to dematerialize the GV. 447f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool isDematerializable(const GlobalValue *GV) const; 448f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 449f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// Materialize - Make sure the GlobalValue is fully read. If the module is 450f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// corrupt, this returns true and fills in the optional string with 451f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// information about the problem. If successful, this returns false. 452f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0); 453f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// Dematerialize - If the GlobalValue is read in, and if the GVMaterializer 454f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// supports it, release the memory for the function, and set it up to be 455f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// materialized lazily. If !isDematerializable(), this method is a noop. 456f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin void Dematerialize(GlobalValue *GV); 457f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 458f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// MaterializeAll - Make sure all GlobalValues in this Module are fully read. 459f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// If the module is corrupt, this returns true and fills in the optional 460f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// string with information about the problem. If successful, this returns 461f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// false. 462f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool MaterializeAll(std::string *ErrInfo = 0); 463f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 464f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are 465f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// fully read and clear the Materializer. If the module is corrupt, this 466f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// returns true, fills in the optional string with information about the 467f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// problem, and DOES NOT clear the old Materializer. If successful, this 468f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// returns false. 469f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool MaterializeAllPermanently(std::string *ErrInfo = 0); 470f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin 471f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin/// @} 4726413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Direct access to the globals list, functions list, and symbol table 4736413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 474e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 4756413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the Module's list of global variables (constant). 4766413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer const GlobalListType &getGlobalList() const { return GlobalList; } 4776413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the Module's list of global variables. 4786413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer GlobalListType &getGlobalList() { return GlobalList; } 479b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif static iplist<GlobalVariable> Module::*getSublistAccess(GlobalVariable*) { 480b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif return &Module::GlobalList; 481b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif } 4826413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the Module's list of functions (constant). 4836413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer const FunctionListType &getFunctionList() const { return FunctionList; } 4846413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the Module's list of functions. 4856413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer FunctionListType &getFunctionList() { return FunctionList; } 486b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif static iplist<Function> Module::*getSublistAccess(Function*) { 487b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif return &Module::FunctionList; 488b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif } 4898b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// Get the Module's list of aliases (constant). 4908b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov const AliasListType &getAliasList() const { return AliasList; } 4918b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov /// Get the Module's list of aliases. 4928b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov AliasListType &getAliasList() { return AliasList; } 493b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif static iplist<GlobalAlias> Module::*getSublistAccess(GlobalAlias*) { 494b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif return &Module::AliasList; 495b547a181005cc255fa57c61c1c0dbafca5375fb4Gabor Greif } 496abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands /// Get the Module's list of named metadata (constant). 497abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands const NamedMDListType &getNamedMDList() const { return NamedMDList; } 498abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands /// Get the Module's list of named metadata. 499abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands NamedMDListType &getNamedMDList() { return NamedMDList; } 500abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands static ilist<NamedMDNode> Module::*getSublistAccess(NamedMDNode*) { 501abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands return &Module::NamedMDList; 502abaf91557fbcba7868068c13afc798e7898a3325Duncan Sands } 5036413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the symbol table of global variable and function identifiers 504ef9b9a793949469cdaa4ab6d0173136229dcab7bReid Spencer const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; } 5056413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// Get the Module's symbol table of global variable and function identifiers. 506ef9b9a793949469cdaa4ab6d0173136229dcab7bReid Spencer ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; } 5076413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer 5086413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 5096413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Global Variable Iteration 5106413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 511e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 5121a4dff011844d2b6daca8fc9dad6964191824dd7Chris Lattner global_iterator global_begin() { return GlobalList.begin(); } 5131a4dff011844d2b6daca8fc9dad6964191824dd7Chris Lattner const_global_iterator global_begin() const { return GlobalList.begin(); } 5141a4dff011844d2b6daca8fc9dad6964191824dd7Chris Lattner global_iterator global_end () { return GlobalList.end(); } 5151a4dff011844d2b6daca8fc9dad6964191824dd7Chris Lattner const_global_iterator global_end () const { return GlobalList.end(); } 5161a4dff011844d2b6daca8fc9dad6964191824dd7Chris Lattner bool global_empty() const { return GlobalList.empty(); } 51770cc3397f84c2e1fd69c059a0ef89e398e847b00Chris Lattner 5186413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 5196413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Function Iteration 5206413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 521e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 522cc041ba03aed685400197fb938b7a583713d25afChris Lattner iterator begin() { return FunctionList.begin(); } 523cc041ba03aed685400197fb938b7a583713d25afChris Lattner const_iterator begin() const { return FunctionList.begin(); } 524cc041ba03aed685400197fb938b7a583713d25afChris Lattner iterator end () { return FunctionList.end(); } 525cc041ba03aed685400197fb938b7a583713d25afChris Lattner const_iterator end () const { return FunctionList.end(); } 5268b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov size_t size() const { return FunctionList.size(); } 527cc041ba03aed685400197fb938b7a583713d25afChris Lattner bool empty() const { return FunctionList.empty(); } 528cc041ba03aed685400197fb938b7a583713d25afChris Lattner 5296413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 530e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher/// @name Dependent Library Iteration 5316413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 532e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 533641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer /// @brief Get a constant iterator to beginning of dependent library list. 534641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer inline lib_iterator lib_begin() const { return LibraryList.begin(); } 535641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer /// @brief Get a constant iterator to end of dependent library list. 5368b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov inline lib_iterator lib_end() const { return LibraryList.end(); } 537641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer /// @brief Returns the number of items in the list of libraries. 5388b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov inline size_t lib_size() const { return LibraryList.size(); } 539641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer /// @brief Add a library to the list of dependent libraries 5402928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void addLibrary(StringRef Lib); 541641588bb3e7d77a88624d5df10709a07745f1238Reid Spencer /// @brief Remove a library from the list of dependent libraries 5422928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar void removeLibrary(StringRef Lib); 5439769ab22265b313171d201b5928688524a01bd87Misha Brukman /// @brief Get all the libraries 54444407c4503a7f00535106eaf7b5932668343f754Reid Spencer inline const LibraryListType& getLibraries() const { return LibraryList; } 54544407c4503a7f00535106eaf7b5932668343f754Reid Spencer 5466413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 5478b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov/// @name Alias Iteration 5488b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov/// @{ 549e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 5508b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov alias_iterator alias_begin() { return AliasList.begin(); } 5518b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov const_alias_iterator alias_begin() const { return AliasList.begin(); } 5528b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov alias_iterator alias_end () { return AliasList.end(); } 5538b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov const_alias_iterator alias_end () const { return AliasList.end(); } 5548b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov size_t alias_size () const { return AliasList.size(); } 5558b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov bool alias_empty() const { return AliasList.empty(); } 5568b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov 55728bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel 55828bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @} 55928bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @name Named Metadata Iteration 56028bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel/// @{ 561e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 562e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); } 563e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner const_named_metadata_iterator named_metadata_begin() const { 564e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner return NamedMDList.begin(); 565e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner } 566ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 567e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner named_metadata_iterator named_metadata_end() { return NamedMDList.end(); } 568e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner const_named_metadata_iterator named_metadata_end() const { 569e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner return NamedMDList.end(); 570e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner } 571ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 572e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner size_t named_metadata_size() const { return NamedMDList.size(); } 573e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner bool named_metadata_empty() const { return NamedMDList.empty(); } 57428bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel 57528bc9d88260a3e153ead4311c9129e3d3ad07736Devang Patel 5768b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov/// @} 5776413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @name Utility functions for printing and dumping Module objects 5786413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @{ 579e3e38ea9fb70cbd8cc33111589c92c0a61674679Chris Lattner 5801afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// Print the module to an output stream with an optional 5811afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// AssemblyAnnotationWriter. 582944fac71e082cc2664cc71b4d3f6c72bab7143fbChris Lattner void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const; 583ee278437e6cc7a6e3afeddfc947ab68558a9860eJim Grosbach 584944fac71e082cc2664cc71b4d3f6c72bab7143fbChris Lattner /// Dump the module to stderr (for debugging). 58558dda9a8f2ad7056cddc389a1d730b732b7ab6f1Chris Lattner void dump() const; 5861afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 5876413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// This function causes all the subinstructions to "let go" of all references 588e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher /// that they are maintaining. This allows one to 'delete' a whole class at 589e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher /// a time, even though there may be circular references... first all 590e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher /// references are dropped, and all use counts go to zero. Then everything 591e20bbc81012e636cb59bbbe3a114895a2f7fa0daEric Christopher /// is delete'd for real. Note that no operations are valid on an object 5926413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer /// that has "dropped all references", except operator delete. 593009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner void dropAllReferences(); 5946413fb78ab0663d2fae0ac2f8615f80f12f4767aReid Spencer/// @} 595009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 596009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 59779c5d3f9717756dc3ff56cfcaa3ae1a5930c457aChris Lattner/// An raw_ostream inserter for modules. 598944fac71e082cc2664cc71b4d3f6c72bab7143fbChris Lattnerinline raw_ostream &operator<<(raw_ostream &O, const Module &M) { 599944fac71e082cc2664cc71b4d3f6c72bab7143fbChris Lattner M.print(O, 0); 6004b244ac1b4599c97183f184362adf5a67729912eAnand Shukla return O; 6014b244ac1b4599c97183f184362adf5a67729912eAnand Shukla} 6028b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov 603d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 604d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 605009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 606