Add support for iteration through type graphs
[oota-llvm.git] / include / llvm / ConstantPool.h
1 //===-- llvm/ConstantPool.h - Define the constant pool class ------*- C++ -*-=//
2 //
3 // This file implements a constant pool that is split into different type 
4 // planes.  This allows searching for a typed object to go a little faster.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_CONSTANTPOOL_H
9 #define LLVM_CONSTANTPOOL_H
10
11 #include <vector>
12 #include "llvm/ValueHolder.h"
13 class SymTabValue;
14 class ConstPoolVal;
15 class Type;
16 class Value;
17
18 class ConstantPool {
19 public:
20   typedef ValueHolder<ConstPoolVal, SymTabValue, SymTabValue> PlaneType;
21 private:
22   typedef vector<PlaneType*> PlanesType;
23   PlanesType Planes;
24   SymTabValue *Parent;
25
26   inline void resize(unsigned size);
27 public:
28   inline ConstantPool(SymTabValue *P) { Parent = P; }
29   inline ~ConstantPool() { delete_all(); }
30
31   inline       SymTabValue *getParent()       { return Parent; }
32   inline const SymTabValue *getParent() const { return Parent; }
33   const Value *getParentV() const;
34         Value *getParentV()      ;
35
36   void setParent(SymTabValue *STV);
37
38   void dropAllReferences();  // Drop all references to other constants
39
40   // Constant getPlane - Returns true if the type plane does not exist, 
41   // otherwise updates the pointer to point to the correct plane.
42   //
43   bool getPlane(const Type *T, const PlaneType *&Plane) const;
44   bool getPlane(const Type *T,       PlaneType *&Plane);
45
46   // Normal getPlane - Resizes constant pool to contain type even if it doesn't
47   // already have it.
48   //
49   PlaneType &getPlane(const Type *T);
50
51   // insert - Add constant into the symbol table...
52   void insert(ConstPoolVal *N);
53   bool remove(ConstPoolVal *N);   // Returns true on failure 
54
55   // delete_all - Remove all elements from the constant pool
56   void delete_all();
57
58   // find - Search to see if a constant of the specified value is already in
59   // the constant table.
60   //
61   const ConstPoolVal *find(const ConstPoolVal *V) const;
62         ConstPoolVal *find(const ConstPoolVal *V)      ;
63   const ConstPoolVal *find(const Type *Ty) const;
64         ConstPoolVal *find(const Type *Ty)      ;
65
66   // Plane iteration support
67   //
68   typedef PlanesType::iterator       plane_iterator;
69   typedef PlanesType::const_iterator plane_const_iterator;
70
71   inline plane_iterator       begin()       { return Planes.begin(); }
72   inline plane_const_iterator begin() const { return Planes.begin(); }
73   inline plane_iterator       end()         { return Planes.end(); }
74   inline plane_const_iterator end()   const { return Planes.end(); }
75
76   // ensureTypeAvailable - This is used to make sure that the specified type is
77   // in the constant pool.  If it is not already in the constant pool, it is
78   // added.
79   //
80   const Type *ensureTypeAvailable(const Type *);
81 };
82
83 #endif