Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===-- iConstPool.cpp - Implement ConstPool instructions --------*- C++ -*--=// |
| 2 | // |
| 3 | // This file implements the ConstPool* classes... |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | #define __STDC_LIMIT_MACROS // Get defs for INT64_MAX and friends... |
| 8 | #include "llvm/ConstPoolVals.h" |
Chris Lattner | e2472bb | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 9 | #include "llvm/Support/StringExtras.h" // itostr |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 10 | #include "llvm/DerivedTypes.h" |
| 11 | #include "llvm/SymbolTable.h" |
Chris Lattner | 60e0dd7 | 2001-10-03 06:12:09 +0000 | [diff] [blame] | 12 | #include "llvm/GlobalVariable.h" // TODO make this GlobalValue.h |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <assert.h> |
| 15 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 16 | ConstPoolBool *ConstPoolBool::True = new ConstPoolBool(true); |
| 17 | ConstPoolBool *ConstPoolBool::False = new ConstPoolBool(false); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
| 21 | // ConstPoolVal Class |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
| 24 | // Specialize setName to take care of symbol table majik |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 25 | void ConstPoolVal::setName(const string &Name, SymbolTable *ST) { |
| 26 | assert(ST && "Type::setName - Must provide symbol table argument!"); |
| 27 | |
| 28 | if (Name.size()) ST->insert(Name, this); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // Static constructor to create a '0' constant of arbitrary type... |
| 32 | ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) { |
| 33 | switch (Ty->getPrimitiveID()) { |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 34 | case Type::BoolTyID: return ConstPoolBool::get(false); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 35 | case Type::SByteTyID: |
| 36 | case Type::ShortTyID: |
| 37 | case Type::IntTyID: |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 38 | case Type::LongTyID: return ConstPoolSInt::get(Ty, 0); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 39 | |
| 40 | case Type::UByteTyID: |
| 41 | case Type::UShortTyID: |
| 42 | case Type::UIntTyID: |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 43 | case Type::ULongTyID: return ConstPoolUInt::get(Ty, 0); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 | |
| 45 | case Type::FloatTyID: |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 46 | case Type::DoubleTyID: return ConstPoolFP::get(Ty, 0); |
Chris Lattner | 436248f | 2001-09-30 20:14:07 +0000 | [diff] [blame] | 47 | |
| 48 | case Type::PointerTyID: |
Chris Lattner | 883ad0b | 2001-10-03 15:39:36 +0000 | [diff] [blame] | 49 | return ConstPoolPointer::getNull(cast<PointerType>(Ty)); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 50 | default: |
| 51 | return 0; |
| 52 | } |
| 53 | } |
| 54 | |
Chris Lattner | da55810 | 2001-10-02 03:41:24 +0000 | [diff] [blame] | 55 | bool ConstPoolInt::classof(const ConstPoolVal *CPV) { |
Chris Lattner | 3856934 | 2001-10-01 20:11:19 +0000 | [diff] [blame] | 56 | return CPV->getType()->isIntegral(); |
| 57 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 58 | |
| 59 | //===----------------------------------------------------------------------===// |
| 60 | // ConstPoolXXX Classes |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | |
| 63 | //===----------------------------------------------------------------------===// |
| 64 | // Normal Constructors |
| 65 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 66 | ConstPoolBool::ConstPoolBool(bool V) : ConstPoolVal(Type::BoolTy) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 67 | Val = V; |
| 68 | } |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 69 | |
| 70 | ConstPoolInt::ConstPoolInt(const Type *Ty, uint64_t V) : ConstPoolVal(Ty) { |
| 71 | Val.Unsigned = V; |
Chris Lattner | 7309d66 | 2001-07-21 19:16:08 +0000 | [diff] [blame] | 72 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 73 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 74 | ConstPoolSInt::ConstPoolSInt(const Type *Ty, int64_t V) : ConstPoolInt(Ty, V) { |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 75 | assert(isValueValidForType(Ty, V) && "Value too large for type!"); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 78 | ConstPoolUInt::ConstPoolUInt(const Type *Ty, uint64_t V) : ConstPoolInt(Ty, V) { |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 79 | assert(isValueValidForType(Ty, V) && "Value too large for type!"); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 82 | ConstPoolFP::ConstPoolFP(const Type *Ty, double V) : ConstPoolVal(Ty) { |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 83 | assert(isValueValidForType(Ty, V) && "Value too large for type!"); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 84 | Val = V; |
| 85 | } |
| 86 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 87 | ConstPoolArray::ConstPoolArray(const ArrayType *T, |
| 88 | const vector<ConstPoolVal*> &V) |
| 89 | : ConstPoolVal(T) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 90 | for (unsigned i = 0; i < V.size(); i++) { |
| 91 | assert(V[i]->getType() == T->getElementType()); |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 92 | Operands.push_back(Use(V[i], this)); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 96 | ConstPoolStruct::ConstPoolStruct(const StructType *T, |
| 97 | const vector<ConstPoolVal*> &V) |
| 98 | : ConstPoolVal(T) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 99 | const StructType::ElementTypes &ETypes = T->getElementTypes(); |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 101 | for (unsigned i = 0; i < V.size(); i++) { |
| 102 | assert(V[i]->getType() == ETypes[i]); |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 103 | Operands.push_back(Use(V[i], this)); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Chris Lattner | 436248f | 2001-09-30 20:14:07 +0000 | [diff] [blame] | 107 | ConstPoolPointer::ConstPoolPointer(const PointerType *T) : ConstPoolVal(T) {} |
| 108 | |
Chris Lattner | 7fac070 | 2001-10-03 14:53:21 +0000 | [diff] [blame] | 109 | ConstPoolPointerReference::ConstPoolPointerReference(GlobalValue *GV) |
Chris Lattner | 60e0dd7 | 2001-10-03 06:12:09 +0000 | [diff] [blame] | 110 | : ConstPoolPointer(GV->getType()) { |
| 111 | Operands.push_back(Use(GV, this)); |
| 112 | } |
| 113 | |
| 114 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 115 | |
| 116 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 117 | // getStrValue implementations |
| 118 | |
| 119 | string ConstPoolBool::getStrValue() const { |
Chris Lattner | 4cee8d8 | 2001-06-27 23:41:11 +0000 | [diff] [blame] | 120 | return Val ? "true" : "false"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | string ConstPoolSInt::getStrValue() const { |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 124 | return itostr(Val.Signed); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | string ConstPoolUInt::getStrValue() const { |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 128 | return utostr(Val.Unsigned); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | string ConstPoolFP::getStrValue() const { |
Chris Lattner | d06dd69 | 2001-07-15 00:18:39 +0000 | [diff] [blame] | 132 | return ftostr(Val); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 135 | string ConstPoolArray::getStrValue() const { |
| 136 | string Result = "["; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 137 | if (Operands.size()) { |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 138 | Result += " " + Operands[0]->getType()->getDescription() + |
Chris Lattner | 8f19112 | 2001-10-01 18:26:53 +0000 | [diff] [blame] | 139 | " " + cast<ConstPoolVal>(Operands[0])->getStrValue(); |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 140 | for (unsigned i = 1; i < Operands.size(); i++) |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 141 | Result += ", " + Operands[i]->getType()->getDescription() + |
Chris Lattner | 8f19112 | 2001-10-01 18:26:53 +0000 | [diff] [blame] | 142 | " " + cast<ConstPoolVal>(Operands[i])->getStrValue(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return Result + " ]"; |
| 146 | } |
| 147 | |
| 148 | string ConstPoolStruct::getStrValue() const { |
| 149 | string Result = "{"; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 150 | if (Operands.size()) { |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 151 | Result += " " + Operands[0]->getType()->getDescription() + |
Chris Lattner | 8f19112 | 2001-10-01 18:26:53 +0000 | [diff] [blame] | 152 | " " + cast<ConstPoolVal>(Operands[0])->getStrValue(); |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 153 | for (unsigned i = 1; i < Operands.size(); i++) |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 154 | Result += ", " + Operands[i]->getType()->getDescription() + |
Chris Lattner | 8f19112 | 2001-10-01 18:26:53 +0000 | [diff] [blame] | 155 | " " + cast<ConstPoolVal>(Operands[i])->getStrValue(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | return Result + " }"; |
| 159 | } |
| 160 | |
Chris Lattner | 436248f | 2001-09-30 20:14:07 +0000 | [diff] [blame] | 161 | string ConstPoolPointer::getStrValue() const { |
| 162 | return "null"; |
| 163 | } |
| 164 | |
Chris Lattner | 60e0dd7 | 2001-10-03 06:12:09 +0000 | [diff] [blame] | 165 | string ConstPoolPointerReference::getStrValue() const { |
| 166 | return "<pointer reference>"; |
| 167 | } |
| 168 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 169 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 170 | // isValueValidForType implementations |
| 171 | |
| 172 | bool ConstPoolSInt::isValueValidForType(const Type *Ty, int64_t Val) { |
| 173 | switch (Ty->getPrimitiveID()) { |
| 174 | default: |
| 175 | return false; // These can't be represented as integers!!! |
| 176 | |
| 177 | // Signed types... |
| 178 | case Type::SByteTyID: |
| 179 | return (Val <= INT8_MAX && Val >= INT8_MIN); |
| 180 | case Type::ShortTyID: |
| 181 | return (Val <= INT16_MAX && Val >= INT16_MIN); |
| 182 | case Type::IntTyID: |
| 183 | return (Val <= INT32_MAX && Val >= INT32_MIN); |
| 184 | case Type::LongTyID: |
| 185 | return true; // This is the largest type... |
| 186 | } |
| 187 | assert(0 && "WTF?"); |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | bool ConstPoolUInt::isValueValidForType(const Type *Ty, uint64_t Val) { |
| 192 | switch (Ty->getPrimitiveID()) { |
| 193 | default: |
| 194 | return false; // These can't be represented as integers!!! |
| 195 | |
| 196 | // Unsigned types... |
| 197 | case Type::UByteTyID: |
| 198 | return (Val <= UINT8_MAX); |
| 199 | case Type::UShortTyID: |
| 200 | return (Val <= UINT16_MAX); |
| 201 | case Type::UIntTyID: |
| 202 | return (Val <= UINT32_MAX); |
| 203 | case Type::ULongTyID: |
| 204 | return true; // This is the largest type... |
| 205 | } |
| 206 | assert(0 && "WTF?"); |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | bool ConstPoolFP::isValueValidForType(const Type *Ty, double Val) { |
| 211 | switch (Ty->getPrimitiveID()) { |
| 212 | default: |
| 213 | return false; // These can't be represented as floating point! |
| 214 | |
| 215 | // TODO: Figure out how to test if a double can be cast to a float! |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 216 | case Type::FloatTyID: |
Chris Lattner | d06dd69 | 2001-07-15 00:18:39 +0000 | [diff] [blame] | 217 | /* |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 218 | return (Val <= UINT8_MAX); |
| 219 | */ |
| 220 | case Type::DoubleTyID: |
| 221 | return true; // This is the largest type... |
| 222 | } |
| 223 | }; |
Chris Lattner | 9655e54 | 2001-07-20 19:16:02 +0000 | [diff] [blame] | 224 | |
Chris Lattner | 49d855c | 2001-09-07 16:46:31 +0000 | [diff] [blame] | 225 | //===----------------------------------------------------------------------===// |
| 226 | // Hash Function Implementations |
| 227 | #if 0 |
| 228 | unsigned ConstPoolSInt::hash(const Type *Ty, int64_t V) { |
| 229 | return unsigned(Ty->getPrimitiveID() ^ V); |
| 230 | } |
| 231 | |
| 232 | unsigned ConstPoolUInt::hash(const Type *Ty, uint64_t V) { |
| 233 | return unsigned(Ty->getPrimitiveID() ^ V); |
| 234 | } |
| 235 | |
| 236 | unsigned ConstPoolFP::hash(const Type *Ty, double V) { |
| 237 | return Ty->getPrimitiveID() ^ unsigned(V); |
| 238 | } |
| 239 | |
| 240 | unsigned ConstPoolArray::hash(const ArrayType *Ty, |
| 241 | const vector<ConstPoolVal*> &V) { |
| 242 | unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); |
| 243 | for (unsigned i = 0; i < V.size(); ++i) |
| 244 | Result ^= V[i]->getHash() << (i & 7); |
| 245 | return Result; |
| 246 | } |
| 247 | |
| 248 | unsigned ConstPoolStruct::hash(const StructType *Ty, |
| 249 | const vector<ConstPoolVal*> &V) { |
| 250 | unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); |
| 251 | for (unsigned i = 0; i < V.size(); ++i) |
| 252 | Result ^= V[i]->getHash() << (i & 7); |
| 253 | return Result; |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | //===----------------------------------------------------------------------===// |
| 258 | // Factory Function Implementation |
| 259 | |
| 260 | template<class ValType, class ConstPoolClass> |
| 261 | struct ValueMap { |
| 262 | typedef pair<const Type*, ValType> ConstHashKey; |
| 263 | map<ConstHashKey, ConstPoolClass *> Map; |
| 264 | |
| 265 | inline ConstPoolClass *get(const Type *Ty, ValType V) { |
| 266 | map<ConstHashKey,ConstPoolClass *>::iterator I = |
| 267 | Map.find(ConstHashKey(Ty, V)); |
| 268 | return (I != Map.end()) ? I->second : 0; |
| 269 | } |
| 270 | |
| 271 | inline void add(const Type *Ty, ValType V, ConstPoolClass *CP) { |
| 272 | Map.insert(make_pair(ConstHashKey(Ty, V), CP)); |
| 273 | } |
| 274 | }; |
| 275 | |
| 276 | //---- ConstPoolUInt::get() and ConstPoolSInt::get() implementations... |
| 277 | // |
| 278 | static ValueMap<uint64_t, ConstPoolInt> IntConstants; |
| 279 | |
| 280 | ConstPoolSInt *ConstPoolSInt::get(const Type *Ty, int64_t V) { |
| 281 | ConstPoolSInt *Result = (ConstPoolSInt*)IntConstants.get(Ty, (uint64_t)V); |
| 282 | if (!Result) // If no preexisting value, create one now... |
| 283 | IntConstants.add(Ty, V, Result = new ConstPoolSInt(Ty, V)); |
| 284 | return Result; |
| 285 | } |
| 286 | |
| 287 | ConstPoolUInt *ConstPoolUInt::get(const Type *Ty, uint64_t V) { |
| 288 | ConstPoolUInt *Result = (ConstPoolUInt*)IntConstants.get(Ty, V); |
| 289 | if (!Result) // If no preexisting value, create one now... |
| 290 | IntConstants.add(Ty, V, Result = new ConstPoolUInt(Ty, V)); |
| 291 | return Result; |
| 292 | } |
| 293 | |
| 294 | ConstPoolInt *ConstPoolInt::get(const Type *Ty, unsigned char V) { |
| 295 | assert(V <= 127 && "Can only be used with very small positive constants!"); |
| 296 | if (Ty->isSigned()) return ConstPoolSInt::get(Ty, V); |
| 297 | return ConstPoolUInt::get(Ty, V); |
| 298 | } |
| 299 | |
| 300 | //---- ConstPoolFP::get() implementation... |
| 301 | // |
| 302 | static ValueMap<double, ConstPoolFP> FPConstants; |
| 303 | |
| 304 | ConstPoolFP *ConstPoolFP::get(const Type *Ty, double V) { |
| 305 | ConstPoolFP *Result = FPConstants.get(Ty, V); |
| 306 | if (!Result) // If no preexisting value, create one now... |
| 307 | FPConstants.add(Ty, V, Result = new ConstPoolFP(Ty, V)); |
| 308 | return Result; |
| 309 | } |
| 310 | |
| 311 | //---- ConstPoolArray::get() implementation... |
| 312 | // |
| 313 | static ValueMap<vector<ConstPoolVal*>, ConstPoolArray> ArrayConstants; |
| 314 | |
| 315 | ConstPoolArray *ConstPoolArray::get(const ArrayType *Ty, |
| 316 | const vector<ConstPoolVal*> &V) { |
| 317 | ConstPoolArray *Result = ArrayConstants.get(Ty, V); |
| 318 | if (!Result) // If no preexisting value, create one now... |
| 319 | ArrayConstants.add(Ty, V, Result = new ConstPoolArray(Ty, V)); |
| 320 | return Result; |
| 321 | } |
| 322 | |
| 323 | //---- ConstPoolStruct::get() implementation... |
| 324 | // |
| 325 | static ValueMap<vector<ConstPoolVal*>, ConstPoolStruct> StructConstants; |
| 326 | |
| 327 | ConstPoolStruct *ConstPoolStruct::get(const StructType *Ty, |
| 328 | const vector<ConstPoolVal*> &V) { |
| 329 | ConstPoolStruct *Result = StructConstants.get(Ty, V); |
| 330 | if (!Result) // If no preexisting value, create one now... |
| 331 | StructConstants.add(Ty, V, Result = new ConstPoolStruct(Ty, V)); |
| 332 | return Result; |
| 333 | } |
Chris Lattner | 883ad0b | 2001-10-03 15:39:36 +0000 | [diff] [blame] | 334 | |
| 335 | //---- ConstPoolPointer::get() implementation... |
| 336 | // |
| 337 | static ValueMap<char, ConstPoolPointer> NullPtrConstants; |
| 338 | |
| 339 | ConstPoolPointer *ConstPoolPointer::getNull(const PointerType *Ty) { |
| 340 | ConstPoolPointer *Result = NullPtrConstants.get(Ty, 0); |
| 341 | if (!Result) // If no preexisting value, create one now... |
| 342 | NullPtrConstants.add(Ty, 0, Result = new ConstPoolPointer(Ty)); |
| 343 | return Result; |
| 344 | } |
| 345 | |
Chris Lattner | 2503325 | 2001-10-03 19:28:15 +0000 | [diff] [blame^] | 346 | //---- ConstPoolPointerReference::get() implementation... |
| 347 | // |
| 348 | ConstPoolPointerReference *ConstPoolPointerReference::get(GlobalValue *GV) { |
| 349 | assert(GV->getParent()); |
| 350 | // FIXME: These should all be shared! |
| 351 | return new ConstPoolPointerReference(GV); |
| 352 | } |