1 //===-- llvm/Module.h - C++ class to represent a VM module -------*- C++ -*--=//
3 // This file contains the declarations for the Module class that is used to
4 // maintain all the information related to a VM module.
6 // A module also maintains a GlobalValRefMap object that is used to hold all
7 // constant references to global variables in the module. When a global
8 // variable is destroyed, it should have no entries in the GlobalValueRefMap.
10 //===----------------------------------------------------------------------===//
15 #include "llvm/Value.h"
16 #include "llvm/SymTabValue.h"
17 #include "llvm/ValueHolder.h"
19 class GlobalValueRefMap; // Used by ConstantVals.cpp
20 class ConstantPointerRef;
23 class Module : public Value, public SymTabValue {
25 typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType;
26 typedef ValueHolder<Function, Module, Module> FunctionListType;
28 // Global Variable iterators...
29 typedef GlobalListType::iterator giterator;
30 typedef GlobalListType::const_iterator const_giterator;
31 typedef std::reverse_iterator<giterator> reverse_giterator;
32 typedef std::reverse_iterator<const_giterator> const_reverse_giterator;
34 // Function iterators...
35 typedef FunctionListType::iterator iterator;
36 typedef FunctionListType::const_iterator const_iterator;
37 typedef std::reverse_iterator<iterator> reverse_iterator;
38 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
41 GlobalListType GlobalList; // The Global Variables
42 FunctionListType FunctionList; // The Functions
44 GlobalValueRefMap *GVRefMap;
46 // Accessor for the underlying GlobalValRefMap... only through the
47 // ConstantPointerRef class...
48 friend class ConstantPointerRef;
49 void mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV);
50 ConstantPointerRef *getConstantPointerRef(GlobalValue *GV);
56 // getOrInsertFunction - Look up the specified function in the module symbol
57 // table. If it does not exist, add a prototype for the function and return
59 Function *getOrInsertFunction(const std::string &Name, const FunctionType *T);
61 // getFunction - Look up the specified function in the module symbol table.
62 // If it does not exist, return null.
64 Function *getFunction(const std::string &Name, const FunctionType *Ty);
66 // addTypeName - Insert an entry in the symbol table mapping Str to Type. If
67 // there is already an entry for this name, true is returned and the symbol
68 // table is not modified.
70 bool addTypeName(const std::string &Name, const Type *Ty);
72 // Get the underlying elements of the Module...
73 inline const GlobalListType &getGlobalList() const { return GlobalList; }
74 inline GlobalListType &getGlobalList() { return GlobalList; }
75 inline const FunctionListType &getFunctionList() const { return FunctionList;}
76 inline FunctionListType &getFunctionList() { return FunctionList;}
78 //===--------------------------------------------------------------------===//
79 // Module iterator forwarding functions
81 inline giterator gbegin() { return GlobalList.begin(); }
82 inline const_giterator gbegin() const { return GlobalList.begin(); }
83 inline giterator gend () { return GlobalList.end(); }
84 inline const_giterator gend () const { return GlobalList.end(); }
86 inline reverse_giterator grbegin() { return GlobalList.rbegin(); }
87 inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); }
88 inline reverse_giterator grend () { return GlobalList.rend(); }
89 inline const_reverse_giterator grend () const { return GlobalList.rend(); }
91 inline unsigned gsize() const { return GlobalList.size(); }
92 inline bool gempty() const { return GlobalList.empty(); }
93 inline const GlobalVariable *gfront() const { return GlobalList.front(); }
94 inline GlobalVariable *gfront() { return GlobalList.front(); }
95 inline const GlobalVariable *gback() const { return GlobalList.back(); }
96 inline GlobalVariable *gback() { return GlobalList.back(); }
100 inline iterator begin() { return FunctionList.begin(); }
101 inline const_iterator begin() const { return FunctionList.begin(); }
102 inline iterator end () { return FunctionList.end(); }
103 inline const_iterator end () const { return FunctionList.end(); }
105 inline reverse_iterator rbegin() { return FunctionList.rbegin(); }
106 inline const_reverse_iterator rbegin() const { return FunctionList.rbegin(); }
107 inline reverse_iterator rend () { return FunctionList.rend(); }
108 inline const_reverse_iterator rend () const { return FunctionList.rend(); }
110 inline unsigned size() const { return FunctionList.size(); }
111 inline bool empty() const { return FunctionList.empty(); }
112 inline const Function *front() const { return FunctionList.front(); }
113 inline Function *front() { return FunctionList.front(); }
114 inline const Function *back() const { return FunctionList.back(); }
115 inline Function *back() { return FunctionList.back(); }
117 // Methods for support type inquiry through isa, cast, and dyn_cast:
118 static inline bool classof(const Module *T) { return true; }
119 static inline bool classof(const Value *V) {
120 return V->getValueType() == Value::ModuleVal;
123 // dropAllReferences() - This function causes all the subinstructions to "let
124 // go" of all references that they are maintaining. This allows one to
125 // 'delete' a whole class at a time, even though there may be circular
126 // references... first all references are dropped, and all use counts go to
127 // zero. Then everything is delete'd for real. Note that no operations are
128 // valid on an object that has "dropped all references", except operator
131 void dropAllReferences();