IntervalPartition & IntervalIterator classes have been split out into
[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
14 class ConstPoolVal;
15 class SymTabValue;
16 class Type;
17
18 class ConstantPool {
19 public:
20   typedef ValueHolder<ConstPoolVal, 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
34   void setParent(SymTabValue *STV);
35
36   void dropAllReferences();  // Drop all references to other constants
37
38   // Constant getPlane - Returns true if the type plane does not exist, 
39   // otherwise updates the pointer to point to the correct plane.
40   //
41   bool getPlane(const Type *T, const PlaneType *&Plane) const;
42   bool getPlane(const Type *T,       PlaneType *&Plane);
43
44   // Normal getPlane - Resizes constant pool to contain type even if it doesn't
45   // already have it.
46   //
47   PlaneType &getPlane(const Type *T);
48
49   // insert - Add constant into the symbol table...
50   void insert(ConstPoolVal *N);
51   bool remove(ConstPoolVal *N);   // Returns true on failure 
52
53   void delete_all();
54
55   // find - Search to see if a constant of the specified value is already in
56   // the constant table.
57   //
58   const ConstPoolVal *find(const ConstPoolVal *V) const;
59         ConstPoolVal *find(const ConstPoolVal *V)      ;
60   const ConstPoolVal *find(const Type *Ty) const;
61         ConstPoolVal *find(const Type *Ty)      ;
62
63   // Plane iteration support
64   //
65   typedef PlanesType::iterator       plane_iterator;
66   typedef PlanesType::const_iterator plane_const_iterator;
67
68   inline plane_iterator       begin()       { return Planes.begin(); }
69   inline plane_const_iterator begin() const { return Planes.begin(); }
70   inline plane_iterator       end()         { return Planes.end(); }
71   inline plane_const_iterator end()   const { return Planes.end(); }
72 };
73
74 #endif