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"
20 class GlobalValueRefMap; // Used by ConstPoolVals.cpp
21 class ConstPoolPointerRef;
23 class Module : public Value, public SymTabValue {
25 typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType;
26 typedef ValueHolder<Method, Module, Module> MethodListType;
28 // Global Variable iterators...
29 typedef GlobalListType::iterator giterator;
30 typedef GlobalListType::const_iterator const_giterator;
31 typedef reverse_iterator<giterator> reverse_giterator;
32 typedef reverse_iterator<const_giterator> const_reverse_giterator;
34 // Method iterators...
35 typedef MethodListType::iterator iterator;
36 typedef MethodListType::const_iterator const_iterator;
37 typedef reverse_iterator<const_iterator> const_reverse_iterator;
38 typedef reverse_iterator<iterator> reverse_iterator;
41 GlobalListType GlobalList; // The Global Variables
42 MethodListType MethodList; // The Methods
44 GlobalValueRefMap *GVRefMap;
46 // Accessor for the underlying GlobalValRefMap... only through the
47 // ConstPoolPointerRef class...
48 friend class ConstPoolPointerRef;
49 void mutateConstPoolPointerRef(GlobalValue *OldGV, GlobalValue *NewGV);
50 ConstPoolPointerRef *getConstPoolPointerRef(GlobalValue *GV);
56 // reduceApply - Apply the specified function to all of the methods in this
57 // module. The result values are or'd together and the result is returned.
59 bool reduceApply(bool (*Func)(GlobalVariable*));
60 bool reduceApply(bool (*Func)(const GlobalVariable*)) const;
61 bool reduceApply(bool (*Func)(Method*));
62 bool reduceApply(bool (*Func)(const Method*)) const;
64 // Get the underlying elements of the Module...
65 inline const GlobalListType &getGlobalList() const { return GlobalList; }
66 inline GlobalListType &getGlobalList() { return GlobalList; }
67 inline const MethodListType &getMethodList() const { return MethodList; }
68 inline MethodListType &getMethodList() { return MethodList; }
70 //===--------------------------------------------------------------------===//
71 // Module iterator forwarding functions
73 inline giterator gbegin() { return GlobalList.begin(); }
74 inline const_giterator gbegin() const { return GlobalList.begin(); }
75 inline giterator gend () { return GlobalList.end(); }
76 inline const_giterator gend () const { return GlobalList.end(); }
78 inline reverse_giterator grbegin() { return GlobalList.rbegin(); }
79 inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); }
80 inline reverse_giterator grend () { return GlobalList.rend(); }
81 inline const_reverse_giterator grend () const { return GlobalList.rend(); }
83 inline unsigned gsize() const { return GlobalList.size(); }
84 inline bool gempty() const { return GlobalList.empty(); }
85 inline const GlobalVariable *gfront() const { return GlobalList.front(); }
86 inline GlobalVariable *gfront() { return GlobalList.front(); }
87 inline const GlobalVariable *gback() const { return GlobalList.back(); }
88 inline GlobalVariable *gback() { return GlobalList.back(); }
92 inline iterator begin() { return MethodList.begin(); }
93 inline const_iterator begin() const { return MethodList.begin(); }
94 inline iterator end () { return MethodList.end(); }
95 inline const_iterator end () const { return MethodList.end(); }
97 inline reverse_iterator rbegin() { return MethodList.rbegin(); }
98 inline const_reverse_iterator rbegin() const { return MethodList.rbegin(); }
99 inline reverse_iterator rend () { return MethodList.rend(); }
100 inline const_reverse_iterator rend () const { return MethodList.rend(); }
102 inline unsigned size() const { return MethodList.size(); }
103 inline bool empty() const { return MethodList.empty(); }
104 inline const Method *front() const { return MethodList.front(); }
105 inline Method *front() { return MethodList.front(); }
106 inline const Method *back() const { return MethodList.back(); }
107 inline Method *back() { return MethodList.back(); }
109 // Methods for support type inquiry through isa, cast, and dyn_cast:
110 static inline bool classof(const Module *T) { return true; }
111 static inline bool classof(const Value *V) {
112 return V->getValueType() == Value::ModuleVal;
115 // dropAllReferences() - This function causes all the subinstructions to "let
116 // go" of all references that they are maintaining. This allows one to
117 // 'delete' a whole class at a time, even though there may be circular
118 // references... first all references are dropped, and all use counts go to
119 // zero. Then everything is delete'd for real. Note that no operations are
120 // valid on an object that has "dropped all references", except operator
123 void dropAllReferences();