1 //===-- Internal/SlotTable.h - Type/Value Slot Holder -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SlotTable class for type plane numbering.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_INTERNAL_SLOTTABLE_H
15 #define LLVM_INTERNAL_SLOTTABLE_H
22 // Forward declarations
30 /// This class is the common abstract data type for both the SlotMachine and
31 /// the SlotCalculator. It provides the two-way mapping between Values and
32 /// Slots as well as the two-way mapping between Types and Slots. For Values,
33 /// the slot number can be extracted by simply using the getSlot()
34 /// method and passing in the Value. For Types, it is the same.
35 /// @brief Abstract data type for slot numbers.
42 /// This type is used throughout the code to make it clear that
43 /// an unsigned value refers to a Slot number and not something else.
44 /// @brief Type slot number identification type.
45 typedef unsigned SlotNum;
47 /// This type is used throughout the code to make it clear that an
48 /// unsigned value refers to a type plane number and not something else.
49 /// @brief The type of a plane number (corresponds to Type::PrimitiveID).
50 typedef unsigned PlaneNum;
52 /// @brief Some constants used as flags instead of actual slot numbers
54 MAX_SLOT = 4294967294U,
55 BAD_SLOT = 4294967295U
58 /// @brief A single plane of Values. Intended index is slot number.
59 typedef std::vector<const Value*> ValuePlane;
61 /// @brief A table of Values. Intended index is Type::PrimitiveID.
62 typedef std::vector<ValuePlane> ValueTable;
64 /// @brief A map of values to slot numbers.
65 typedef std::map<const Value*,SlotNum> ValueMap;
67 /// @brief A single plane of Types. Intended index is slot number.
68 typedef std::vector<const Type*> TypePlane;
70 /// @brief A map of types to slot numbers.
71 typedef std::map<const Type*,SlotNum> TypeMap;
74 /// @name Constructors
77 /// This constructor initializes all the containers in the SlotTable
78 /// to empty and then inserts all the primitive types into the type plane
79 /// by default. This is done as a convenience since most uses of the
80 /// SlotTable will need the primitive types. If you don't need them, pass
82 /// @brief Default Constructor
84 bool dont_insert_primitives = false ///< Control insertion of primitives.
91 /// @brief Get the number of planes of values.
92 size_t value_size() const { return vTable.size(); }
94 /// @brief Get the number of types.
95 size_t type_size() const { return tPlane.size(); }
97 /// @brief Determine if a specific type plane in the value table exists
98 bool plane_exists(PlaneNum plane) const {
99 return vTable.size() > plane;
102 /// @brief Determine if a specific type plane in the value table is empty
103 bool plane_empty(PlaneNum plane) const {
104 return (plane_exists(plane) ? vTable[plane].empty() : true);
107 /// @brief Get the number of entries in a specific plane of the value table
108 size_t plane_size(PlaneNum plane) const {
109 return (plane_exists(plane) ? vTable[plane].size() : 0 );
112 /// @returns true if the slot table is completely empty.
113 /// @brief Determine if the SlotTable is empty.
116 /// @returns the slot number or BAD_SLOT if Val is not in table.
117 /// @brief Get a slot number for a Value.
118 SlotNum getSlot(const Value* Val) const;
120 /// @returns the slot number or BAD_SLOT if Type is not in the table.
121 /// @brief Get a slot number for a Type.
122 SlotNum getSlot(const Type* Typ) const;
124 /// @returns true iff the Value is in the table.
125 /// @brief Determine if a Value has a slot number.
126 bool hasSlot(const Value* Val) { return getSlot(Val) != BAD_SLOT; }
128 /// @returns true iff the Type is in the table.
129 /// @brief Determine if a Type has a slot number.
130 bool hasSlot(const Type* Typ) { return getSlot(Typ) != BAD_SLOT; }
136 /// @brief Completely clear the SlotTable;
139 /// @brief Resize the table to incorporate at least \p new_size planes
140 void resize( size_t new_size );
142 /// @returns the slot number of the newly inserted value in its plane
143 /// @brief Add a Value to the SlotTable
144 SlotNum insert(const Value* Val, PlaneNum plane );
146 /// @returns the slot number of the newly inserted type
147 /// @brief Add a Type to the SlotTable
148 SlotNum insert( const Type* Typ );
150 /// @returns the slot number that \p Val had when it was in the table
151 /// @brief Remove a Value from the SlotTable
152 SlotNum remove( const Value* Val, PlaneNum plane );
154 /// @returns the slot number that \p Typ had when it was in the table
155 /// @brief Remove a Type from the SlotTable
156 SlotNum remove( const Type* Typ );
159 /// @name Implementation Details
162 /// Insert the primitive types into the type plane. This is called
163 /// by the constructor to initialize the type plane.
164 void insertPrimitives();
170 /// A two dimensional table of Values indexed by type and slot number. This
171 /// allows for efficient lookup of a Value by its type and slot number.
174 /// A map of Values to unsigned integer. This allows for efficient lookup of
175 /// A Value's slot number in its type plane.
178 /// A one dimensional vector of Types indexed by slot number. Types are
179 /// handled separately because they are not Values.
182 /// A map of Types to unsigned integer. This allows for efficient lookup of
183 /// a Type's slot number in the type plane.
190 } // End llvm namespace