}
}
+/// ContaintsRelocations - Return true if the constant value contains
+/// relocations which cannot be resolved at compile time.
+bool Constant::ContainsRelocations() const {
+ if (isa<GlobalValue>(this))
+ return true;
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+ if (getOperand(i)->ContainsRelocations())
+ return true;
+ return false;
+}
+
// Static constructor to create a '0' constant of arbitrary type...
Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getTypeID()) {
return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
case Type::DoubleTyID:
+ case Type::X86_FP80TyID:
+ case Type::PPC_FP128TyID:
+ case Type::FP128TyID:
return ConstantFP::get(Ty, 0.0);
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
}
}
+Constant *Constant::getAllOnesValue(const Type *Ty) {
+ if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
+ return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
+ return ConstantVector::getAllOnesValue(cast<VectorType>(Ty));
+}
// Static constructor to create an integral constant with all bits set
ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
- return ConstantInt::get(Ty, APInt::getAllOnesValue(ITy->getBitWidth()));
+ return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
return 0;
}
-/// @returns the value for an packed integer constant of the given type that
+/// @returns the value for a vector integer constant of the given type that
/// has all its bits set to true.
/// @brief Get the all ones value
ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
std::vector<Constant*> Elts;
Elts.resize(Ty->getNumElements(),
ConstantInt::getAllOnesValue(Ty->getElementType()));
- assert(Elts[0] && "Not a packed integer type!");
+ assert(Elts[0] && "Not a vector integer type!");
return cast<ConstantVector>(ConstantVector::get(Elts));
}
DenseMapAPIntKeyInfo> IntMapTy;
static ManagedStatic<IntMapTy> IntConstants;
-ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
+ConstantInt *ConstantInt::get(const Type *Ty, uint64_t V, bool isSigned) {
const IntegerType *ITy = cast<IntegerType>(Ty);
- APInt Tmp(ITy->getBitWidth(), V);
- return get(Ty, Tmp);
+ return get(APInt(ITy->getBitWidth(), V, isSigned));
}
-// Get a ConstantInt from a Type and APInt. Note that the value stored in
-// the DenseMap as the key is a DensMapAPIntKeyInfo::KeyTy which has provided
+// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
+// as the key, is a DensMapAPIntKeyInfo::KeyTy which has provided the
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
// compare APInt's of different widths, which would violate an APInt class
// invariant which generates an assertion.
-ConstantInt *ConstantInt::get(const Type *Ty, const APInt& V) {
- const IntegerType *ITy = cast<IntegerType>(Ty);
- assert(ITy->getBitWidth() == V.getBitWidth() && "Invalid type for constant");
+ConstantInt *ConstantInt::get(const APInt& V) {
+ // Get the corresponding integer type for the bit width of the value.
+ const IntegerType *ITy = IntegerType::get(V.getBitWidth());
// get an existing value or the insertion position
- DenseMapAPIntKeyInfo::KeyTy Key(V, Ty);
+ DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
ConstantInt *&Slot = (*IntConstants)[Key];
// if it exists, return it.
if (Slot)
ConstantFP *&Slot = (*FloatConstants)[std::make_pair(IntVal, Ty)];
if (Slot) return Slot;
return Slot = new ConstantFP(Ty, (float)V);
- } else {
- assert(Ty == Type::DoubleTy);
+ } else if (Ty == Type::DoubleTy) {
uint64_t IntVal = DoubleToBits(V);
ConstantFP *&Slot = (*DoubleConstants)[std::make_pair(IntVal, Ty)];
if (Slot) return Slot;
return Slot = new ConstantFP(Ty, V);
+ // FIXME: Make long double constants work.
+ } else if (Ty == Type::X86_FP80Ty ||
+ Ty == Type::PPC_FP128Ty || Ty == Type::FP128Ty) {
+ assert(0 && "Long double constants not handled yet.");
+ } else {
+ assert(0 && "Unknown FP Type!");
}
}
assert((C->getType() == T->getElementType() ||
(T->isAbstract() &&
C->getType()->getTypeID() == T->getElementType()->getTypeID())) &&
- "Initializer for packed element doesn't match packed element type!");
+ "Initializer for vector element doesn't match vector element type!");
OL->init(C, this);
}
}
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!
+ // TODO: Figure out how to test if we can use a shorter type instead!
case Type::FloatTyID:
case Type::DoubleTyID:
- return true; // This is the largest type...
+ case Type::X86_FP80TyID:
+ case Type::PPC_FP128TyID:
+ case Type::FP128TyID:
+ return true;
}
}
Constant *ConstantVector::get(const VectorType *Ty,
const std::vector<Constant*> &V) {
- // If this is an all-zero packed, return a ConstantAggregateZero object
+ // If this is an all-zero vector, return a ConstantAggregateZero object
if (!V.empty()) {
Constant *C = V[0];
if (!C->isNullValue())
destroyConstantImpl();
}
-/// This function will return true iff every element in this packed constant
+/// This function will return true iff every element in this vector constant
/// is set to all ones.
/// @returns true iff this constant's emements are all set to all ones.
/// @brief Determine if the value is all ones.