Rename ConstPoolVal -> Constant
[oota-llvm.git] / include / llvm / Module.h
1 //===-- llvm/Module.h - C++ class to represent a VM module -------*- C++ -*--=//
2 //
3 // This file contains the declarations for the Module class that is used to 
4 // maintain all the information related to a VM module.
5 //
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.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_MODULE_H
13 #define LLVM_MODULE_H
14
15 #include "llvm/Value.h"
16 #include "llvm/SymTabValue.h"
17 #include "llvm/ValueHolder.h"
18 class Method;
19 class GlobalVariable;
20 class GlobalValueRefMap;   // Used by ConstantVals.cpp
21 class ConstantPointerRef;
22
23 class Module : public Value, public SymTabValue {
24 public:
25   typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType;
26   typedef ValueHolder<Method, Module, Module> MethodListType;
27
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;
33
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;
39
40 private:
41   GlobalListType GlobalList;     // The Global Variables
42   MethodListType MethodList;     // The Methods
43
44   GlobalValueRefMap *GVRefMap;
45
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);
51
52 public:
53   Module();
54   ~Module();
55
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.
58   //
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;
63
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; }
69
70   //===--------------------------------------------------------------------===//
71   // Module iterator forwarding functions
72   //
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();   }
77
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();   }
82
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(); }
89
90
91
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();   }
96
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();   }
101
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(); }
108
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;
113   }
114
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 
121   // delete.
122   //
123   void dropAllReferences();
124 };
125
126 #endif