add Value::getNameStart/getNameLen() accessors.
[oota-llvm.git] / lib / VMCore / Constants.cpp
index e5417f524564d25043711b4896a423fb20633d7b..eadfe39afa6a4c59d6c30a710ec18ccafe2e6822 100644 (file)
@@ -108,6 +108,9 @@ Constant *Constant::getNullValue(const Type *Ty) {
     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));
@@ -122,6 +125,11 @@ Constant *Constant::getNullValue(const Type *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) {
@@ -130,14 +138,14 @@ ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
   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));
 }
 
@@ -283,12 +291,17 @@ ConstantFP *ConstantFP::get(const Type *Ty, double V) {
     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!");
   }
 }
 
@@ -353,7 +366,7 @@ ConstantVector::ConstantVector(const VectorType *T,
       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);
   }
 }
@@ -691,10 +704,13 @@ bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
   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;
   }
 }
 
@@ -1185,7 +1201,7 @@ static ManagedStatic<ValueMap<std::vector<Constant*>, VectorType,
 
 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())
@@ -1209,7 +1225,7 @@ void ConstantVector::destroyConstant() {
   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.