1 //===-- llvm/ConstantPool.h - Define the constant pool class ------*- C++ -*-=//
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.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_CONSTANTPOOL_H
9 #define LLVM_CONSTANTPOOL_H
12 #include "llvm/ValueHolder.h"
20 typedef ValueHolder<ConstPoolVal, SymTabValue, SymTabValue> PlaneType;
22 typedef vector<PlaneType*> PlanesType;
26 inline void resize(unsigned size);
28 inline ConstantPool(SymTabValue *P) { Parent = P; }
29 inline ~ConstantPool() { delete_all(); }
31 inline SymTabValue *getParent() { return Parent; }
32 inline const SymTabValue *getParent() const { return Parent; }
33 const Value *getParentV() const;
36 void setParent(SymTabValue *STV);
38 void dropAllReferences(); // Drop all references to other constants
40 // Constant getPlane - Returns true if the type plane does not exist,
41 // otherwise updates the pointer to point to the correct plane.
43 bool getPlane(const Type *T, const PlaneType *&Plane) const;
44 bool getPlane(const Type *T, PlaneType *&Plane);
46 // Normal getPlane - Resizes constant pool to contain type even if it doesn't
49 PlaneType &getPlane(const Type *T);
51 // insert - Add constant into the symbol table...
52 void insert(ConstPoolVal *N);
53 bool remove(ConstPoolVal *N); // Returns true on failure
55 // delete_all - Remove all elements from the constant pool
58 // find - Search to see if a constant of the specified value is already in
59 // the constant table.
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) ;
66 // Plane iteration support
68 typedef PlanesType::iterator plane_iterator;
69 typedef PlanesType::const_iterator plane_const_iterator;
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(); }
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
80 const Type *ensureTypeAvailable(const Type *);