//
//===----------------------------------------------------------------------===//
-#include "llvm/AbstractTypeUser.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ParameterAttributes.h"
#include "llvm/Constants.h"
static ManagedStatic<std::map<const Type*,
std::string> > AbstractTypeDescriptions;
-Type::Type(const char *Name, TypeID id)
- : ID(id), Abstract(false), SubclassData(0), RefCount(0), ForwardType(0),
- NumContainedTys(0), ContainedTys(0) {
- assert(Name && Name[0] && "Should use other ctor if no name!");
- (*ConcreteTypeDescriptions)[this] = Name;
-}
-
/// Because of the way Type subclasses are allocated, this function is necessary
/// to use the correct kind of "delete" operator to deallocate the Type object.
/// Some type objects (FunctionTy, StructTy) allocate additional space after
const Type *Type::getPrimitiveType(TypeID IDNumber) {
switch (IDNumber) {
- case VoidTyID : return VoidTy;
- case FloatTyID : return FloatTy;
- case DoubleTyID: return DoubleTy;
- case LabelTyID : return LabelTy;
+ case VoidTyID : return VoidTy;
+ case FloatTyID : return FloatTy;
+ case DoubleTyID : return DoubleTy;
+ case X86_FP80TyID : return X86_FP80Ty;
+ case FP128TyID : return FP128Ty;
+ case PPC_FP128TyID : return PPC_FP128Ty;
+ case LabelTyID : return LabelTy;
default:
return 0;
}
return this;
}
+/// isIntOrIntVector - Return true if this is an integer type or a vector of
+/// integer types.
+///
+bool Type::isIntOrIntVector() const {
+ if (isInteger())
+ return true;
+ if (ID != Type::VectorTyID) return false;
+
+ return cast<VectorType>(this)->getElementType()->isInteger();
+}
+
/// isFPOrFPVector - Return true if this is a FP type or a vector of FP types.
///
bool Type::isFPOrFPVector() const {
- if (ID == Type::FloatTyID || ID == Type::DoubleTyID) return true;
+ if (ID == Type::FloatTyID || ID == Type::DoubleTyID ||
+ ID == Type::FP128TyID || ID == Type::X86_FP80TyID ||
+ ID == Type::PPC_FP128TyID)
+ return true;
if (ID != Type::VectorTyID) return false;
return cast<VectorType>(this)->getElementType()->isFloatingPoint();
switch (getTypeID()) {
case Type::FloatTyID: return 32;
case Type::DoubleTyID: return 64;
+ case Type::X86_FP80TyID: return 80;
+ case Type::FP128TyID: return 128;
+ case Type::PPC_FP128TyID: return 128;
case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
default: return 0;
if (!Ty->isAbstract()) { // Base case for the recursion
std::map<const Type*, std::string>::iterator I =
ConcreteTypeDescriptions->find(Ty);
- if (I != ConcreteTypeDescriptions->end()) return I->second;
+ if (I != ConcreteTypeDescriptions->end())
+ return I->second;
+
+ if (Ty->isPrimitiveType()) {
+ switch (Ty->getTypeID()) {
+ default: assert(0 && "Unknown prim type!");
+ case Type::VoidTyID: return (*ConcreteTypeDescriptions)[Ty] = "void";
+ case Type::FloatTyID: return (*ConcreteTypeDescriptions)[Ty] = "float";
+ case Type::DoubleTyID: return (*ConcreteTypeDescriptions)[Ty] = "double";
+ case Type::X86_FP80TyID:
+ return (*ConcreteTypeDescriptions)[Ty] = "x86_fp80";
+ case Type::FP128TyID: return (*ConcreteTypeDescriptions)[Ty] = "fp128";
+ case Type::PPC_FP128TyID:
+ return (*ConcreteTypeDescriptions)[Ty] = "ppc_fp128";
+ case Type::LabelTyID: return (*ConcreteTypeDescriptions)[Ty] = "label";
+ }
+ }
}
// Check to see if the Type is already on the stack...
}
break;
}
- case Type::PackedStructTyID:
case Type::StructTyID: {
const StructType *STy = cast<StructType>(Ty);
if (STy->isPacked())
// Primitive 'Type' data
//===----------------------------------------------------------------------===//
-const Type *Type::VoidTy = new Type("void", Type::VoidTyID);
-const Type *Type::FloatTy = new Type("float", Type::FloatTyID);
-const Type *Type::DoubleTy = new Type("double", Type::DoubleTyID);
-const Type *Type::LabelTy = new Type("label", Type::LabelTyID);
+const Type *Type::VoidTy = new Type(Type::VoidTyID);
+const Type *Type::FloatTy = new Type(Type::FloatTyID);
+const Type *Type::DoubleTy = new Type(Type::DoubleTyID);
+const Type *Type::X86_FP80Ty = new Type(Type::X86_FP80TyID);
+const Type *Type::FP128Ty = new Type(Type::FP128TyID);
+const Type *Type::PPC_FP128Ty = new Type(Type::PPC_FP128TyID);
+const Type *Type::LabelTy = new Type(Type::LabelTyID);
namespace {
struct BuiltinIntegerType : public IntegerType {
FunctionType::FunctionType(const Type *Result,
const std::vector<const Type*> &Params,
- bool IsVarArgs, ParamAttrsList *Attrs)
+ bool IsVarArgs, const ParamAttrsList *Attrs)
: DerivedType(FunctionTyID), isVarArgs(IsVarArgs), ParamAttrs(Attrs) {
ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
NumContainedTys = Params.size() + 1; // + 1 for result type
// Calculate whether or not this type is abstract
setAbstract(isAbstract);
-
}
StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
return false;
const ParamAttrsList *Attrs1 = FTy->getParamAttrs();
const ParamAttrsList *Attrs2 = FTy2->getParamAttrs();
- if ((!Attrs1 && Attrs2 && !Attrs2->empty()) ||
- (!Attrs2 && Attrs1 && !Attrs1->empty()) ||
+ if ((!Attrs1 && Attrs2) || (!Attrs2 && Attrs1) ||
(Attrs1 && Attrs2 && (Attrs1->size() != Attrs2->size() ||
- (Attrs1->size() > 0 &&
- Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0)))))
+ (Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0)))))
return false;
- ParamAttrsList PAL1;
- if (Attrs1)
- PAL1 = *Attrs1;
- ParamAttrsList PAL2;
- if (Attrs2)
- PAL2 = *Attrs2;
+
for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
- if (PAL1.getParamAttrs(i+1) != PAL2.getParamAttrs(i+1))
+ if (Attrs1 && Attrs1->getParamAttrs(i+1) != Attrs2->getParamAttrs(i+1))
return false;
if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
return false;
if (ParamAttrs)
if (MTV.ParamAttrs)
return *ParamAttrs < *MTV.ParamAttrs;
- else if (ParamAttrs->empty())
- return true;
else
return false;
else if (MTV.ParamAttrs)
- if (MTV.ParamAttrs->empty())
- return false;
- else
- return true;
+ return true;
return false;
}
};
FunctionType *FunctionType::get(const Type *ReturnType,
const std::vector<const Type*> &Params,
bool isVarArg,
- ParamAttrsList *Attrs) {
+ const ParamAttrsList *Attrs) {
FunctionValType VT(ReturnType, Params, isVarArg, Attrs);
- FunctionType *MT = FunctionTypes->get(VT);
- if (MT) {
- delete Attrs; // not needed any more
- return MT;
+ FunctionType *FT = FunctionTypes->get(VT);
+ if (FT) {
+ return FT;
}
-
- MT = (FunctionType*) new char[sizeof(FunctionType) +
+ FT = (FunctionType*) new char[sizeof(FunctionType) +
sizeof(PATypeHandle)*(Params.size()+1)];
- new (MT) FunctionType(ReturnType, Params, isVarArg, Attrs);
- FunctionTypes->add(VT, MT);
+ new (FT) FunctionType(ReturnType, Params, isVarArg, Attrs);
+ FunctionTypes->add(VT, FT);
#ifdef DEBUG_MERGE_TYPES
- DOUT << "Derived new type: " << MT << "\n";
+ DOUT << "Derived new type: " << FT << "\n";
#endif
- return MT;
-}
-
-FunctionType::~FunctionType() {
- delete ParamAttrs;
+ return FT;
}
bool FunctionType::isStructReturn() const {
VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
- assert(ElementType && "Can't get packed of null types!");
+ assert(ElementType && "Can't get vector of null types!");
assert(isPowerOf2_32(NumElements) && "Vector length should be a power of 2!");
VectorValType PVT(ElementType, NumElements);