2002-04-28 19:55:58 +00:00
|
|
|
//===-- Constants.cpp - Implement Constant nodes -----------------*- C++ -*--=//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
// This file implements the Constant* classes...
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define __STDC_LIMIT_MACROS // Get defs for INT64_MAX and friends...
|
2002-04-28 19:55:58 +00:00
|
|
|
#include "llvm/Constants.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/SymbolTable.h"
|
2001-10-13 06:57:33 +00:00
|
|
|
#include "llvm/Module.h"
|
2002-04-07 22:49:37 +00:00
|
|
|
#include "llvm/SlotCalculator.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/StringExtras.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
using std::map;
|
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantBool *ConstantBool::True = new ConstantBool(true);
|
|
|
|
ConstantBool *ConstantBool::False = new ConstantBool(false);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-20 19:16:02 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-12-03 22:26:30 +00:00
|
|
|
// Constant Class
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Specialize setName to take care of symbol table majik
|
2002-01-20 22:54:45 +00:00
|
|
|
void Constant::setName(const std::string &Name, SymbolTable *ST) {
|
2001-09-07 16:46:31 +00:00
|
|
|
assert(ST && "Type::setName - Must provide symbol table argument!");
|
|
|
|
|
|
|
|
if (Name.size()) ST->insert(Name, this);
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Static constructor to create a '0' constant of arbitrary type...
|
2002-04-27 02:25:43 +00:00
|
|
|
Constant *Constant::getNullValue(const Type *Ty) {
|
2001-06-06 20:29:01 +00:00
|
|
|
switch (Ty->getPrimitiveID()) {
|
2001-12-03 22:26:30 +00:00
|
|
|
case Type::BoolTyID: return ConstantBool::get(false);
|
2001-06-06 20:29:01 +00:00
|
|
|
case Type::SByteTyID:
|
|
|
|
case Type::ShortTyID:
|
|
|
|
case Type::IntTyID:
|
2001-12-03 22:26:30 +00:00
|
|
|
case Type::LongTyID: return ConstantSInt::get(Ty, 0);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
case Type::UByteTyID:
|
|
|
|
case Type::UShortTyID:
|
|
|
|
case Type::UIntTyID:
|
2001-12-03 22:26:30 +00:00
|
|
|
case Type::ULongTyID: return ConstantUInt::get(Ty, 0);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
case Type::FloatTyID:
|
2001-12-03 22:26:30 +00:00
|
|
|
case Type::DoubleTyID: return ConstantFP::get(Ty, 0);
|
2001-09-30 20:14:07 +00:00
|
|
|
|
|
|
|
case Type::PointerTyID:
|
2001-12-03 22:26:30 +00:00
|
|
|
return ConstantPointerNull::get(cast<PointerType>(Ty));
|
2001-06-06 20:29:01 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
void Constant::destroyConstantImpl() {
|
|
|
|
// When a Constant is destroyed, there may be lingering
|
2001-10-13 06:57:33 +00:00
|
|
|
// references to the constant by other constants in the constant pool. These
|
|
|
|
// constants are implicitly dependant on the module that is being deleted,
|
|
|
|
// but they don't know that. Because we only find out when the CPV is
|
|
|
|
// deleted, we must now notify all of our users (that should only be
|
2001-12-03 22:26:30 +00:00
|
|
|
// Constants) that they are, in fact, invalid now and should be deleted.
|
2001-10-13 06:57:33 +00:00
|
|
|
//
|
|
|
|
while (!use_empty()) {
|
|
|
|
Value *V = use_back();
|
|
|
|
#ifndef NDEBUG // Only in -g mode...
|
2001-12-03 22:26:30 +00:00
|
|
|
if (!isa<Constant>(V)) {
|
2002-04-07 22:32:25 +00:00
|
|
|
std::cerr << "While deleting: ";
|
|
|
|
dump();
|
|
|
|
std::cerr << "\nUse still stuck around after Def is destroyed: ";
|
|
|
|
V->dump();
|
|
|
|
std::cerr << "\n";
|
2001-10-13 06:57:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-12-03 22:26:30 +00:00
|
|
|
assert(isa<Constant>(V) && "References remain to ConstantPointerRef!");
|
|
|
|
Constant *CPV = cast<Constant>(V);
|
2001-10-13 06:57:33 +00:00
|
|
|
CPV->destroyConstant();
|
|
|
|
|
|
|
|
// The constant should remove itself from our use list...
|
|
|
|
assert((use_empty() || use_back() == V) && "Constant not removed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value has no outstanding references it is safe to delete it now...
|
|
|
|
delete this;
|
2001-10-01 20:11:19 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-12-03 22:26:30 +00:00
|
|
|
// ConstantXXX Classes
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Normal Constructors
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantBool::ConstantBool(bool V) : Constant(Type::BoolTy) {
|
2001-06-06 20:29:01 +00:00
|
|
|
Val = V;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : Constant(Ty) {
|
2001-09-07 16:46:31 +00:00
|
|
|
Val.Unsigned = V;
|
|
|
|
}
|
2001-07-20 19:16:02 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantSInt::ConstantSInt(const Type *Ty, int64_t V) : ConstantInt(Ty, V) {
|
2001-07-20 19:16:02 +00:00
|
|
|
assert(isValueValidForType(Ty, V) && "Value too large for type!");
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantUInt::ConstantUInt(const Type *Ty, uint64_t V) : ConstantInt(Ty, V) {
|
2001-07-20 19:16:02 +00:00
|
|
|
assert(isValueValidForType(Ty, V) && "Value too large for type!");
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) {
|
2001-07-20 19:16:02 +00:00
|
|
|
assert(isValueValidForType(Ty, V) && "Value too large for type!");
|
2001-06-06 20:29:01 +00:00
|
|
|
Val = V;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantArray::ConstantArray(const ArrayType *T,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::vector<Constant*> &V) : Constant(T) {
|
2001-06-06 20:29:01 +00:00
|
|
|
for (unsigned i = 0; i < V.size(); i++) {
|
|
|
|
assert(V[i]->getType() == T->getElementType());
|
2001-07-07 08:36:50 +00:00
|
|
|
Operands.push_back(Use(V[i], this));
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantStruct::ConstantStruct(const StructType *T,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::vector<Constant*> &V) : Constant(T) {
|
2001-06-06 20:29:01 +00:00
|
|
|
const StructType::ElementTypes &ETypes = T->getElementTypes();
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
for (unsigned i = 0; i < V.size(); i++) {
|
|
|
|
assert(V[i]->getType() == ETypes[i]);
|
2001-07-07 08:36:50 +00:00
|
|
|
Operands.push_back(Use(V[i], this));
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantPointerRef::ConstantPointerRef(GlobalValue *GV)
|
|
|
|
: ConstantPointer(GV->getType()) {
|
2001-10-03 06:12:09 +00:00
|
|
|
Operands.push_back(Use(GV, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-13 06:57:33 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// classof implementations
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantInt::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return CPV->getType()->isIntegral();
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantSInt::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return CPV->getType()->isSigned();
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantUInt::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return CPV->getType()->isUnsigned();
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantFP::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
const Type *Ty = CPV->getType();
|
|
|
|
return Ty == Type::FloatTy || Ty == Type::DoubleTy;
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantArray::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return isa<ArrayType>(CPV->getType());
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantStruct::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return isa<StructType>(CPV->getType());
|
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantPointer::classof(const Constant *CPV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
return isa<PointerType>(CPV->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// isValueValidForType implementations
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantSInt::isValueValidForType(const Type *Ty, int64_t Val) {
|
2001-06-06 20:29:01 +00:00
|
|
|
switch (Ty->getPrimitiveID()) {
|
|
|
|
default:
|
|
|
|
return false; // These can't be represented as integers!!!
|
|
|
|
|
|
|
|
// Signed types...
|
|
|
|
case Type::SByteTyID:
|
|
|
|
return (Val <= INT8_MAX && Val >= INT8_MIN);
|
|
|
|
case Type::ShortTyID:
|
|
|
|
return (Val <= INT16_MAX && Val >= INT16_MIN);
|
|
|
|
case Type::IntTyID:
|
|
|
|
return (Val <= INT32_MAX && Val >= INT32_MIN);
|
|
|
|
case Type::LongTyID:
|
|
|
|
return true; // This is the largest type...
|
|
|
|
}
|
|
|
|
assert(0 && "WTF?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantUInt::isValueValidForType(const Type *Ty, uint64_t Val) {
|
2001-06-06 20:29:01 +00:00
|
|
|
switch (Ty->getPrimitiveID()) {
|
|
|
|
default:
|
|
|
|
return false; // These can't be represented as integers!!!
|
|
|
|
|
|
|
|
// Unsigned types...
|
|
|
|
case Type::UByteTyID:
|
|
|
|
return (Val <= UINT8_MAX);
|
|
|
|
case Type::UShortTyID:
|
|
|
|
return (Val <= UINT16_MAX);
|
|
|
|
case Type::UIntTyID:
|
|
|
|
return (Val <= UINT32_MAX);
|
|
|
|
case Type::ULongTyID:
|
|
|
|
return true; // This is the largest type...
|
|
|
|
}
|
|
|
|
assert(0 && "WTF?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
|
2001-06-06 20:29:01 +00:00
|
|
|
switch (Ty->getPrimitiveID()) {
|
|
|
|
default:
|
|
|
|
return false; // These can't be represented as floating point!
|
|
|
|
|
|
|
|
// TODO: Figure out how to test if a double can be cast to a float!
|
|
|
|
case Type::FloatTyID:
|
2001-07-15 00:18:39 +00:00
|
|
|
/*
|
2001-06-06 20:29:01 +00:00
|
|
|
return (Val <= UINT8_MAX);
|
|
|
|
*/
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return true; // This is the largest type...
|
|
|
|
}
|
|
|
|
};
|
2001-07-20 19:16:02 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-07 16:46:31 +00:00
|
|
|
// Factory Function Implementation
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
template<class ValType, class ConstantClass>
|
2001-09-07 16:46:31 +00:00
|
|
|
struct ValueMap {
|
|
|
|
typedef pair<const Type*, ValType> ConstHashKey;
|
2001-12-03 22:26:30 +00:00
|
|
|
map<ConstHashKey, ConstantClass *> Map;
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
inline ConstantClass *get(const Type *Ty, ValType V) {
|
|
|
|
map<ConstHashKey,ConstantClass *>::iterator I =
|
2001-09-07 16:46:31 +00:00
|
|
|
Map.find(ConstHashKey(Ty, V));
|
|
|
|
return (I != Map.end()) ? I->second : 0;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
inline void add(const Type *Ty, ValType V, ConstantClass *CP) {
|
2001-09-07 16:46:31 +00:00
|
|
|
Map.insert(make_pair(ConstHashKey(Ty, V), CP));
|
|
|
|
}
|
2001-10-13 06:57:33 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
inline void remove(ConstantClass *CP) {
|
|
|
|
for (map<ConstHashKey,ConstantClass *>::iterator I = Map.begin(),
|
2001-10-13 06:57:33 +00:00
|
|
|
E = Map.end(); I != E;++I)
|
|
|
|
if (I->second == CP) {
|
|
|
|
Map.erase(I);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-09-07 16:46:31 +00:00
|
|
|
};
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantUInt::get() and ConstantSInt::get() implementations...
|
2001-09-07 16:46:31 +00:00
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
static ValueMap<uint64_t, ConstantInt> IntConstants;
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantSInt *ConstantSInt::get(const Type *Ty, int64_t V) {
|
|
|
|
ConstantSInt *Result = (ConstantSInt*)IntConstants.get(Ty, (uint64_t)V);
|
2001-09-07 16:46:31 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
IntConstants.add(Ty, V, Result = new ConstantSInt(Ty, V));
|
2001-09-07 16:46:31 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantUInt *ConstantUInt::get(const Type *Ty, uint64_t V) {
|
|
|
|
ConstantUInt *Result = (ConstantUInt*)IntConstants.get(Ty, V);
|
2001-09-07 16:46:31 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
IntConstants.add(Ty, V, Result = new ConstantUInt(Ty, V));
|
2001-09-07 16:46:31 +00:00
|
|
|
return Result;
|
|
|
|
}
|
2001-07-20 19:16:02 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantInt *ConstantInt::get(const Type *Ty, unsigned char V) {
|
2001-09-07 16:46:31 +00:00
|
|
|
assert(V <= 127 && "Can only be used with very small positive constants!");
|
2001-12-03 22:26:30 +00:00
|
|
|
if (Ty->isSigned()) return ConstantSInt::get(Ty, V);
|
|
|
|
return ConstantUInt::get(Ty, V);
|
2001-09-07 16:46:31 +00:00
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantFP::get() implementation...
|
2001-09-07 16:46:31 +00:00
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
static ValueMap<double, ConstantFP> FPConstants;
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
|
|
|
|
ConstantFP *Result = FPConstants.get(Ty, V);
|
2001-09-07 16:46:31 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
FPConstants.add(Ty, V, Result = new ConstantFP(Ty, V));
|
2001-09-07 16:46:31 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantArray::get() implementation...
|
2001-09-07 16:46:31 +00:00
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
static ValueMap<std::vector<Constant*>, ConstantArray> ArrayConstants;
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantArray *ConstantArray::get(const ArrayType *Ty,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::vector<Constant*> &V) {
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantArray *Result = ArrayConstants.get(Ty, V);
|
2001-09-07 16:46:31 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
ArrayConstants.add(Ty, V, Result = new ConstantArray(Ty, V));
|
2001-09-07 16:46:31 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
// ConstantArray::get(const string&) - Return an array that is initialized to
|
2001-10-14 23:54:12 +00:00
|
|
|
// contain the specified string. A null terminator is added to the specified
|
|
|
|
// string so that it may be used in a natural way...
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
ConstantArray *ConstantArray::get(const std::string &Str) {
|
|
|
|
std::vector<Constant*> ElementVals;
|
2001-10-14 23:54:12 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < Str.length(); ++i)
|
2001-12-14 16:41:18 +00:00
|
|
|
ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
|
2001-10-14 23:54:12 +00:00
|
|
|
|
|
|
|
// Add a null terminator to the string...
|
2001-12-14 16:41:18 +00:00
|
|
|
ElementVals.push_back(ConstantSInt::get(Type::SByteTy, 0));
|
2001-10-14 23:54:12 +00:00
|
|
|
|
2001-12-14 16:41:18 +00:00
|
|
|
ArrayType *ATy = ArrayType::get(Type::SByteTy, Str.length()+1);
|
2001-12-03 22:26:30 +00:00
|
|
|
return ConstantArray::get(ATy, ElementVals);
|
2001-10-14 23:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-13 06:57:33 +00:00
|
|
|
// destroyConstant - Remove the constant from the constant table...
|
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
void ConstantArray::destroyConstant() {
|
2001-10-13 06:57:33 +00:00
|
|
|
ArrayConstants.remove(this);
|
|
|
|
destroyConstantImpl();
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantStruct::get() implementation...
|
2001-09-07 16:46:31 +00:00
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
static ValueMap<std::vector<Constant*>, ConstantStruct> StructConstants;
|
2001-09-07 16:46:31 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantStruct *ConstantStruct::get(const StructType *Ty,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::vector<Constant*> &V) {
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantStruct *Result = StructConstants.get(Ty, V);
|
2001-09-07 16:46:31 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
StructConstants.add(Ty, V, Result = new ConstantStruct(Ty, V));
|
2001-09-07 16:46:31 +00:00
|
|
|
return Result;
|
|
|
|
}
|
2001-10-03 15:39:36 +00:00
|
|
|
|
2001-10-13 06:57:33 +00:00
|
|
|
// destroyConstant - Remove the constant from the constant table...
|
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
void ConstantStruct::destroyConstant() {
|
2001-10-13 06:57:33 +00:00
|
|
|
StructConstants.remove(this);
|
|
|
|
destroyConstantImpl();
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantPointerNull::get() implementation...
|
2001-10-03 15:39:36 +00:00
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
static ValueMap<char, ConstantPointerNull> NullPtrConstants;
|
2001-10-03 15:39:36 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
|
|
|
|
ConstantPointerNull *Result = NullPtrConstants.get(Ty, 0);
|
2001-10-03 15:39:36 +00:00
|
|
|
if (!Result) // If no preexisting value, create one now...
|
2001-12-03 22:26:30 +00:00
|
|
|
NullPtrConstants.add(Ty, 0, Result = new ConstantPointerNull(Ty));
|
2001-10-03 15:39:36 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
//---- ConstantPointerRef::get() implementation...
|
2001-10-03 19:28:15 +00:00
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) {
|
2001-10-13 06:57:33 +00:00
|
|
|
assert(GV->getParent() && "Global Value must be attached to a module!");
|
|
|
|
|
|
|
|
// The Module handles the pointer reference sharing...
|
2001-12-03 22:26:30 +00:00
|
|
|
return GV->getParent()->getConstantPointerRef(GV);
|
2001-10-13 06:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
void ConstantPointerRef::mutateReference(GlobalValue *NewGV) {
|
|
|
|
getValue()->getParent()->mutateConstantPointerRef(getValue(), NewGV);
|
2001-10-13 06:57:33 +00:00
|
|
|
Operands[0] = NewGV;
|
2001-10-03 19:28:15 +00:00
|
|
|
}
|