blob: c9b37c633214ce3a382efbeb71ae074b5440eb01 [file] [log] [blame]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001//===-- 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 Lattnere2472bb2001-07-23 17:46:59 +00009#include "llvm/Support/StringExtras.h" // itostr
Chris Lattner2f7c9632001-06-06 20:29:01 +000010#include "llvm/DerivedTypes.h"
11#include "llvm/SymbolTable.h"
Chris Lattnerd7a73302001-10-13 06:57:33 +000012#include "llvm/GlobalValue.h"
13#include "llvm/Module.h"
14#include "llvm/Analysis/SlotCalculator.h"
Chris Lattner2f7c9632001-06-06 20:29:01 +000015#include <algorithm>
Vikram S. Adve34410432001-10-14 23:17:20 +000016#include <hash_map>
17#include <strstream.h>
Chris Lattner2f7c9632001-06-06 20:29:01 +000018#include <assert.h>
19
Chris Lattner49d855c2001-09-07 16:46:31 +000020ConstPoolBool *ConstPoolBool::True = new ConstPoolBool(true);
21ConstPoolBool *ConstPoolBool::False = new ConstPoolBool(false);
Chris Lattner2f7c9632001-06-06 20:29:01 +000022
Chris Lattner9655e542001-07-20 19:16:02 +000023
Chris Lattner2f7c9632001-06-06 20:29:01 +000024//===----------------------------------------------------------------------===//
25// ConstPoolVal Class
26//===----------------------------------------------------------------------===//
27
28// Specialize setName to take care of symbol table majik
Chris Lattner49d855c2001-09-07 16:46:31 +000029void ConstPoolVal::setName(const string &Name, SymbolTable *ST) {
30 assert(ST && "Type::setName - Must provide symbol table argument!");
31
32 if (Name.size()) ST->insert(Name, this);
Chris Lattner2f7c9632001-06-06 20:29:01 +000033}
34
35// Static constructor to create a '0' constant of arbitrary type...
36ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {
37 switch (Ty->getPrimitiveID()) {
Chris Lattner49d855c2001-09-07 16:46:31 +000038 case Type::BoolTyID: return ConstPoolBool::get(false);
Chris Lattner2f7c9632001-06-06 20:29:01 +000039 case Type::SByteTyID:
40 case Type::ShortTyID:
41 case Type::IntTyID:
Chris Lattner49d855c2001-09-07 16:46:31 +000042 case Type::LongTyID: return ConstPoolSInt::get(Ty, 0);
Chris Lattner2f7c9632001-06-06 20:29:01 +000043
44 case Type::UByteTyID:
45 case Type::UShortTyID:
46 case Type::UIntTyID:
Chris Lattner49d855c2001-09-07 16:46:31 +000047 case Type::ULongTyID: return ConstPoolUInt::get(Ty, 0);
Chris Lattner2f7c9632001-06-06 20:29:01 +000048
49 case Type::FloatTyID:
Chris Lattner49d855c2001-09-07 16:46:31 +000050 case Type::DoubleTyID: return ConstPoolFP::get(Ty, 0);
Chris Lattner436248f2001-09-30 20:14:07 +000051
52 case Type::PointerTyID:
Chris Lattnerd7a73302001-10-13 06:57:33 +000053 return ConstPoolPointerNull::get(cast<PointerType>(Ty));
Chris Lattner2f7c9632001-06-06 20:29:01 +000054 default:
55 return 0;
56 }
57}
58
Chris Lattnerd7a73302001-10-13 06:57:33 +000059#ifndef NDEBUG
60#include "llvm/Assembly/Writer.h"
61#endif
62
63void ConstPoolVal::destroyConstantImpl() {
64 // When a ConstPoolVal is destroyed, there may be lingering
65 // references to the constant by other constants in the constant pool. These
66 // constants are implicitly dependant on the module that is being deleted,
67 // but they don't know that. Because we only find out when the CPV is
68 // deleted, we must now notify all of our users (that should only be
69 // ConstPoolVals) that they are, in fact, invalid now and should be deleted.
70 //
71 while (!use_empty()) {
72 Value *V = use_back();
73#ifndef NDEBUG // Only in -g mode...
74 if (!isa<ConstPoolVal>(V)) {
75 cerr << "While deleting: " << this << endl;
76 cerr << "Use still stuck around after Def is destroyed: " << V << endl;
77 }
78#endif
79 assert(isa<ConstPoolVal>(V) && "References remain to ConstPoolPointerRef!");
80 ConstPoolVal *CPV = cast<ConstPoolVal>(V);
81 CPV->destroyConstant();
82
83 // The constant should remove itself from our use list...
84 assert((use_empty() || use_back() == V) && "Constant not removed!");
85 }
86
87 // Value has no outstanding references it is safe to delete it now...
88 delete this;
Chris Lattner38569342001-10-01 20:11:19 +000089}
Chris Lattner2f7c9632001-06-06 20:29:01 +000090
91//===----------------------------------------------------------------------===//
92// ConstPoolXXX Classes
93//===----------------------------------------------------------------------===//
94
95//===----------------------------------------------------------------------===//
96// Normal Constructors
97
Chris Lattner49d855c2001-09-07 16:46:31 +000098ConstPoolBool::ConstPoolBool(bool V) : ConstPoolVal(Type::BoolTy) {
Chris Lattner2f7c9632001-06-06 20:29:01 +000099 Val = V;
100}
Chris Lattner49d855c2001-09-07 16:46:31 +0000101
102ConstPoolInt::ConstPoolInt(const Type *Ty, uint64_t V) : ConstPoolVal(Ty) {
103 Val.Unsigned = V;
Chris Lattner7309d662001-07-21 19:16:08 +0000104}
Chris Lattner2f7c9632001-06-06 20:29:01 +0000105
Chris Lattner49d855c2001-09-07 16:46:31 +0000106ConstPoolSInt::ConstPoolSInt(const Type *Ty, int64_t V) : ConstPoolInt(Ty, V) {
Chris Lattner9655e542001-07-20 19:16:02 +0000107 assert(isValueValidForType(Ty, V) && "Value too large for type!");
Chris Lattner2f7c9632001-06-06 20:29:01 +0000108}
109
Chris Lattner49d855c2001-09-07 16:46:31 +0000110ConstPoolUInt::ConstPoolUInt(const Type *Ty, uint64_t V) : ConstPoolInt(Ty, V) {
Chris Lattner9655e542001-07-20 19:16:02 +0000111 assert(isValueValidForType(Ty, V) && "Value too large for type!");
Chris Lattner2f7c9632001-06-06 20:29:01 +0000112}
113
Chris Lattner49d855c2001-09-07 16:46:31 +0000114ConstPoolFP::ConstPoolFP(const Type *Ty, double V) : ConstPoolVal(Ty) {
Chris Lattner9655e542001-07-20 19:16:02 +0000115 assert(isValueValidForType(Ty, V) && "Value too large for type!");
Chris Lattner2f7c9632001-06-06 20:29:01 +0000116 Val = V;
117}
118
Chris Lattner49d855c2001-09-07 16:46:31 +0000119ConstPoolArray::ConstPoolArray(const ArrayType *T,
120 const vector<ConstPoolVal*> &V)
121 : ConstPoolVal(T) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000122 for (unsigned i = 0; i < V.size(); i++) {
123 assert(V[i]->getType() == T->getElementType());
Chris Lattnera073acb2001-07-07 08:36:50 +0000124 Operands.push_back(Use(V[i], this));
Chris Lattner2f7c9632001-06-06 20:29:01 +0000125 }
126}
127
Chris Lattner49d855c2001-09-07 16:46:31 +0000128ConstPoolStruct::ConstPoolStruct(const StructType *T,
129 const vector<ConstPoolVal*> &V)
130 : ConstPoolVal(T) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000131 const StructType::ElementTypes &ETypes = T->getElementTypes();
Chris Lattner49d855c2001-09-07 16:46:31 +0000132
Chris Lattner2f7c9632001-06-06 20:29:01 +0000133 for (unsigned i = 0; i < V.size(); i++) {
134 assert(V[i]->getType() == ETypes[i]);
Chris Lattnera073acb2001-07-07 08:36:50 +0000135 Operands.push_back(Use(V[i], this));
Chris Lattner2f7c9632001-06-06 20:29:01 +0000136 }
137}
138
Chris Lattner7fac0702001-10-03 14:53:21 +0000139ConstPoolPointerReference::ConstPoolPointerReference(GlobalValue *GV)
Chris Lattner60e0dd72001-10-03 06:12:09 +0000140 : ConstPoolPointer(GV->getType()) {
141 Operands.push_back(Use(GV, this));
142}
143
144
Chris Lattner2f7c9632001-06-06 20:29:01 +0000145
146//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +0000147// getStrValue implementations
148
149string ConstPoolBool::getStrValue() const {
Chris Lattner4cee8d82001-06-27 23:41:11 +0000150 return Val ? "true" : "false";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000151}
152
153string ConstPoolSInt::getStrValue() const {
Chris Lattner9655e542001-07-20 19:16:02 +0000154 return itostr(Val.Signed);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000155}
156
157string ConstPoolUInt::getStrValue() const {
Chris Lattner9655e542001-07-20 19:16:02 +0000158 return utostr(Val.Unsigned);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000159}
160
161string ConstPoolFP::getStrValue() const {
Chris Lattnerd06dd692001-07-15 00:18:39 +0000162 return ftostr(Val);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000163}
164
Chris Lattner2f7c9632001-06-06 20:29:01 +0000165string ConstPoolArray::getStrValue() const {
Vikram S. Adve34410432001-10-14 23:17:20 +0000166 string Result;
167 strstream makeString;
168
169 // As a special case, print the array as a string if it is an array of
170 // ubytes or an array of sbytes with positive values.
171 //
172 const Type* elType = cast<ArrayType>(this->getType())->getElementType();
173 bool isString = (elType == Type::SByteTy || elType == Type::UByteTy)
174 && Operands.size() > 0;
175 if (isString) {
176 for (unsigned i = 0; i < Operands.size(); i++) {
177 if (elType == Type::SByteTy && cast<ConstPoolSInt>(Operands[i]) < 0)
178 {
179 isString = false;
180 break;
181 }
182 // else it is a legal char and is safe to cast to an unsigned int
183 uint64_t c = ((elType == Type::SByteTy)
184 ? (uint64_t) cast<ConstPoolSInt>(Operands[i])->getValue()
185 : cast<ConstPoolUInt>(Operands[i])->getValue());
186 makeString << (char) c;
187 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000188 }
Vikram S. Adve34410432001-10-14 23:17:20 +0000189
190 if (isString) {
191 makeString << ends;
192 Result = "c\"";
193 Result += makeString.str();
194 Result += "\"";
195 free(makeString.str());
196 } else {
197 Result = "[";
198 if (Operands.size()) {
199 Result += " " + Operands[0]->getType()->getDescription() +
200 " " + cast<ConstPoolVal>(Operands[0])->getStrValue();
201 for (unsigned i = 1; i < Operands.size(); i++)
202 Result += ", " + Operands[i]->getType()->getDescription() +
203 " " + cast<ConstPoolVal>(Operands[i])->getStrValue();
204 }
205 Result += " ]";
206 }
207
208 return Result;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000209}
210
211string ConstPoolStruct::getStrValue() const {
212 string Result = "{";
Chris Lattnera073acb2001-07-07 08:36:50 +0000213 if (Operands.size()) {
Chris Lattner49d855c2001-09-07 16:46:31 +0000214 Result += " " + Operands[0]->getType()->getDescription() +
Chris Lattner8f191122001-10-01 18:26:53 +0000215 " " + cast<ConstPoolVal>(Operands[0])->getStrValue();
Chris Lattnera073acb2001-07-07 08:36:50 +0000216 for (unsigned i = 1; i < Operands.size(); i++)
Chris Lattner49d855c2001-09-07 16:46:31 +0000217 Result += ", " + Operands[i]->getType()->getDescription() +
Chris Lattner8f191122001-10-01 18:26:53 +0000218 " " + cast<ConstPoolVal>(Operands[i])->getStrValue();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000219 }
220
221 return Result + " }";
222}
223
Chris Lattnerd7a73302001-10-13 06:57:33 +0000224string ConstPoolPointerNull::getStrValue() const {
Chris Lattner436248f2001-09-30 20:14:07 +0000225 return "null";
226}
227
Chris Lattner60e0dd72001-10-03 06:12:09 +0000228string ConstPoolPointerReference::getStrValue() const {
Chris Lattnerd7a73302001-10-13 06:57:33 +0000229 const GlobalValue *V = getValue();
230 if (V->hasName()) return "%" + V->getName();
231
232 SlotCalculator *Table = new SlotCalculator(V->getParent(), true);
233 int Slot = Table->getValSlot(V);
234 delete Table;
235
236 if (Slot >= 0) return string(" %") + itostr(Slot);
237 else return "<pointer reference badref>";
Chris Lattner60e0dd72001-10-03 06:12:09 +0000238}
239
Chris Lattnerd7a73302001-10-13 06:57:33 +0000240
241//===----------------------------------------------------------------------===//
242// classof implementations
243
244bool ConstPoolInt::classof(const ConstPoolVal *CPV) {
245 return CPV->getType()->isIntegral();
246}
247bool ConstPoolSInt::classof(const ConstPoolVal *CPV) {
248 return CPV->getType()->isSigned();
249}
250bool ConstPoolUInt::classof(const ConstPoolVal *CPV) {
251 return CPV->getType()->isUnsigned();
252}
253bool ConstPoolFP::classof(const ConstPoolVal *CPV) {
254 const Type *Ty = CPV->getType();
255 return Ty == Type::FloatTy || Ty == Type::DoubleTy;
256}
257bool ConstPoolArray::classof(const ConstPoolVal *CPV) {
258 return isa<ArrayType>(CPV->getType());
259}
260bool ConstPoolStruct::classof(const ConstPoolVal *CPV) {
261 return isa<StructType>(CPV->getType());
262}
263bool ConstPoolPointer::classof(const ConstPoolVal *CPV) {
264 return isa<PointerType>(CPV->getType());
265}
266
267
Chris Lattner2f7c9632001-06-06 20:29:01 +0000268//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +0000269// isValueValidForType implementations
270
271bool ConstPoolSInt::isValueValidForType(const Type *Ty, int64_t Val) {
272 switch (Ty->getPrimitiveID()) {
273 default:
274 return false; // These can't be represented as integers!!!
275
276 // Signed types...
277 case Type::SByteTyID:
278 return (Val <= INT8_MAX && Val >= INT8_MIN);
279 case Type::ShortTyID:
280 return (Val <= INT16_MAX && Val >= INT16_MIN);
281 case Type::IntTyID:
282 return (Val <= INT32_MAX && Val >= INT32_MIN);
283 case Type::LongTyID:
284 return true; // This is the largest type...
285 }
286 assert(0 && "WTF?");
287 return false;
288}
289
290bool ConstPoolUInt::isValueValidForType(const Type *Ty, uint64_t Val) {
291 switch (Ty->getPrimitiveID()) {
292 default:
293 return false; // These can't be represented as integers!!!
294
295 // Unsigned types...
296 case Type::UByteTyID:
297 return (Val <= UINT8_MAX);
298 case Type::UShortTyID:
299 return (Val <= UINT16_MAX);
300 case Type::UIntTyID:
301 return (Val <= UINT32_MAX);
302 case Type::ULongTyID:
303 return true; // This is the largest type...
304 }
305 assert(0 && "WTF?");
306 return false;
307}
308
309bool ConstPoolFP::isValueValidForType(const Type *Ty, double Val) {
310 switch (Ty->getPrimitiveID()) {
311 default:
312 return false; // These can't be represented as floating point!
313
314 // TODO: Figure out how to test if a double can be cast to a float!
Chris Lattner2f7c9632001-06-06 20:29:01 +0000315 case Type::FloatTyID:
Chris Lattnerd06dd692001-07-15 00:18:39 +0000316 /*
Chris Lattner2f7c9632001-06-06 20:29:01 +0000317 return (Val <= UINT8_MAX);
318 */
319 case Type::DoubleTyID:
320 return true; // This is the largest type...
321 }
322};
Chris Lattner9655e542001-07-20 19:16:02 +0000323
Chris Lattner49d855c2001-09-07 16:46:31 +0000324//===----------------------------------------------------------------------===//
325// Hash Function Implementations
326#if 0
327unsigned ConstPoolSInt::hash(const Type *Ty, int64_t V) {
328 return unsigned(Ty->getPrimitiveID() ^ V);
329}
330
331unsigned ConstPoolUInt::hash(const Type *Ty, uint64_t V) {
332 return unsigned(Ty->getPrimitiveID() ^ V);
333}
334
335unsigned ConstPoolFP::hash(const Type *Ty, double V) {
336 return Ty->getPrimitiveID() ^ unsigned(V);
337}
338
339unsigned ConstPoolArray::hash(const ArrayType *Ty,
340 const vector<ConstPoolVal*> &V) {
341 unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
342 for (unsigned i = 0; i < V.size(); ++i)
343 Result ^= V[i]->getHash() << (i & 7);
344 return Result;
345}
346
347unsigned ConstPoolStruct::hash(const StructType *Ty,
348 const vector<ConstPoolVal*> &V) {
349 unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
350 for (unsigned i = 0; i < V.size(); ++i)
351 Result ^= V[i]->getHash() << (i & 7);
352 return Result;
353}
354#endif
355
356//===----------------------------------------------------------------------===//
357// Factory Function Implementation
358
359template<class ValType, class ConstPoolClass>
360struct ValueMap {
361 typedef pair<const Type*, ValType> ConstHashKey;
362 map<ConstHashKey, ConstPoolClass *> Map;
363
364 inline ConstPoolClass *get(const Type *Ty, ValType V) {
365 map<ConstHashKey,ConstPoolClass *>::iterator I =
366 Map.find(ConstHashKey(Ty, V));
367 return (I != Map.end()) ? I->second : 0;
368 }
369
370 inline void add(const Type *Ty, ValType V, ConstPoolClass *CP) {
371 Map.insert(make_pair(ConstHashKey(Ty, V), CP));
372 }
Chris Lattnerd7a73302001-10-13 06:57:33 +0000373
374 inline void remove(ConstPoolClass *CP) {
375 for (map<ConstHashKey,ConstPoolClass *>::iterator I = Map.begin(),
376 E = Map.end(); I != E;++I)
377 if (I->second == CP) {
378 Map.erase(I);
379 return;
380 }
381 }
Chris Lattner49d855c2001-09-07 16:46:31 +0000382};
383
384//---- ConstPoolUInt::get() and ConstPoolSInt::get() implementations...
385//
386static ValueMap<uint64_t, ConstPoolInt> IntConstants;
387
388ConstPoolSInt *ConstPoolSInt::get(const Type *Ty, int64_t V) {
389 ConstPoolSInt *Result = (ConstPoolSInt*)IntConstants.get(Ty, (uint64_t)V);
390 if (!Result) // If no preexisting value, create one now...
391 IntConstants.add(Ty, V, Result = new ConstPoolSInt(Ty, V));
392 return Result;
393}
394
395ConstPoolUInt *ConstPoolUInt::get(const Type *Ty, uint64_t V) {
396 ConstPoolUInt *Result = (ConstPoolUInt*)IntConstants.get(Ty, V);
397 if (!Result) // If no preexisting value, create one now...
398 IntConstants.add(Ty, V, Result = new ConstPoolUInt(Ty, V));
399 return Result;
400}
401
402ConstPoolInt *ConstPoolInt::get(const Type *Ty, unsigned char V) {
403 assert(V <= 127 && "Can only be used with very small positive constants!");
404 if (Ty->isSigned()) return ConstPoolSInt::get(Ty, V);
405 return ConstPoolUInt::get(Ty, V);
406}
407
408//---- ConstPoolFP::get() implementation...
409//
410static ValueMap<double, ConstPoolFP> FPConstants;
411
412ConstPoolFP *ConstPoolFP::get(const Type *Ty, double V) {
413 ConstPoolFP *Result = FPConstants.get(Ty, V);
414 if (!Result) // If no preexisting value, create one now...
415 FPConstants.add(Ty, V, Result = new ConstPoolFP(Ty, V));
416 return Result;
417}
418
419//---- ConstPoolArray::get() implementation...
420//
421static ValueMap<vector<ConstPoolVal*>, ConstPoolArray> ArrayConstants;
Vikram S. Adve34410432001-10-14 23:17:20 +0000422static hash_map<const char*, ConstPoolArray*> StringConstants;
Chris Lattner49d855c2001-09-07 16:46:31 +0000423
424ConstPoolArray *ConstPoolArray::get(const ArrayType *Ty,
425 const vector<ConstPoolVal*> &V) {
426 ConstPoolArray *Result = ArrayConstants.get(Ty, V);
427 if (!Result) // If no preexisting value, create one now...
428 ArrayConstants.add(Ty, V, Result = new ConstPoolArray(Ty, V));
429 return Result;
430}
431
Vikram S. Adve34410432001-10-14 23:17:20 +0000432ConstPoolArray *ConstPoolArray::get(const string& stringConstant) {
433 ConstPoolArray *Result = StringConstants[stringConstant.c_str()];
434 if (Result == NULL) {
435 ArrayType *aty = ArrayType::get(Type::UByteTy/*,stringConstant.length()*/);
436 vector<ConstPoolVal*> charVals;
437 for (const char *c = stringConstant.c_str(); *c; ++c) {
438 if (isprint(*c))
439 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, *c));
440 else {
441 char charString[3];
442 sprintf(charString, "\\%02X", *c);
443 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, charString[0]));
444 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, charString[1]));
445 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, charString[2]));
446 }
447 }
448
449 // Append "\00" which is the null character in LLVM
450 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, '\\'));
451 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, '0'));
452 charVals.push_back(ConstPoolUInt::get(Type::UByteTy, '0'));
453
454 Result = ConstPoolArray::get(aty, charVals);
455 StringConstants[stringConstant.c_str()] = Result;
456 }
457 return Result;
458}
459
460
Chris Lattnerd7a73302001-10-13 06:57:33 +0000461// destroyConstant - Remove the constant from the constant table...
462//
463void ConstPoolArray::destroyConstant() {
464 ArrayConstants.remove(this);
465 destroyConstantImpl();
466}
467
Chris Lattner49d855c2001-09-07 16:46:31 +0000468//---- ConstPoolStruct::get() implementation...
469//
470static ValueMap<vector<ConstPoolVal*>, ConstPoolStruct> StructConstants;
471
472ConstPoolStruct *ConstPoolStruct::get(const StructType *Ty,
473 const vector<ConstPoolVal*> &V) {
474 ConstPoolStruct *Result = StructConstants.get(Ty, V);
475 if (!Result) // If no preexisting value, create one now...
476 StructConstants.add(Ty, V, Result = new ConstPoolStruct(Ty, V));
477 return Result;
478}
Chris Lattner883ad0b2001-10-03 15:39:36 +0000479
Chris Lattnerd7a73302001-10-13 06:57:33 +0000480// destroyConstant - Remove the constant from the constant table...
Chris Lattner883ad0b2001-10-03 15:39:36 +0000481//
Chris Lattnerd7a73302001-10-13 06:57:33 +0000482void ConstPoolStruct::destroyConstant() {
483 StructConstants.remove(this);
484 destroyConstantImpl();
485}
Chris Lattner883ad0b2001-10-03 15:39:36 +0000486
Chris Lattnerd7a73302001-10-13 06:57:33 +0000487//---- ConstPoolPointerNull::get() implementation...
488//
489static ValueMap<char, ConstPoolPointerNull> NullPtrConstants;
490
491ConstPoolPointerNull *ConstPoolPointerNull::get(const PointerType *Ty) {
492 ConstPoolPointerNull *Result = NullPtrConstants.get(Ty, 0);
Chris Lattner883ad0b2001-10-03 15:39:36 +0000493 if (!Result) // If no preexisting value, create one now...
Chris Lattnerd7a73302001-10-13 06:57:33 +0000494 NullPtrConstants.add(Ty, 0, Result = new ConstPoolPointerNull(Ty));
Chris Lattner883ad0b2001-10-03 15:39:36 +0000495 return Result;
496}
497
Chris Lattner25033252001-10-03 19:28:15 +0000498//---- ConstPoolPointerReference::get() implementation...
499//
500ConstPoolPointerReference *ConstPoolPointerReference::get(GlobalValue *GV) {
Chris Lattnerd7a73302001-10-13 06:57:33 +0000501 assert(GV->getParent() && "Global Value must be attached to a module!");
502
503 // The Module handles the pointer reference sharing...
504 return GV->getParent()->getConstPoolPointerReference(GV);
505}
506
507
508void ConstPoolPointerReference::mutateReference(GlobalValue *NewGV) {
509 getValue()->getParent()->mutateConstPoolPointerReference(getValue(), NewGV);
510 Operands[0] = NewGV;
Chris Lattner25033252001-10-03 19:28:15 +0000511}