//
//===----------------------------------------------------------------------===//
-#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
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::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::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
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);