//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
-#include "llvm/AbstractTypeUser.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/ParameterAttributes.h"
#include "llvm/Constants.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Debug.h"
#include <algorithm>
+#include <cstdarg>
using namespace llvm;
// DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
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;
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";
}
}
if (!Result.empty())
Result += " ";
Result += getTypeDescription(FTy->getReturnType(), TypeStack) + " (";
- unsigned Idx = 1;
- const ParamAttrsList *Attrs = FTy->getParamAttrs();
for (FunctionType::param_iterator I = FTy->param_begin(),
- E = FTy->param_end(); I != E; ++I) {
+ E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
Result += ", ";
- if (Attrs && Attrs->getParamAttrs(Idx) != ParamAttr::None)
- Result += Attrs->getParamAttrsTextByIndex(Idx);
- Idx++;
Result += getTypeDescription(*I, TypeStack);
}
if (FTy->isVarArg()) {
Result += "...";
}
Result += ")";
- if (Attrs && Attrs->getParamAttrs(0) != ParamAttr::None) {
- Result += " " + Attrs->getParamAttrsTextByIndex(0);
- }
break;
}
- case Type::PackedStructTyID:
case Type::StructTyID: {
const StructType *STy = cast<StructType>(Ty);
if (STy->isPacked())
}
case Type::PointerTyID: {
const PointerType *PTy = cast<PointerType>(Ty);
- Result = getTypeDescription(PTy->getElementType(), TypeStack) + " *";
+ Result = getTypeDescription(PTy->getElementType(), TypeStack);
+ if (unsigned AddressSpace = PTy->getAddressSpace())
+ Result += " addrspace(" + utostr(AddressSpace) + ")";
+ Result += " *";
break;
}
case Type::ArrayTyID: {
// Primitive 'Type' data
//===----------------------------------------------------------------------===//
-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);
+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 {
// Derived Type Constructors
//===----------------------------------------------------------------------===//
+/// isValidReturnType - Return true if the specified type is valid as a return
+/// type.
+bool FunctionType::isValidReturnType(const Type *RetTy) {
+ if (RetTy->isFirstClassType())
+ return true;
+ if (RetTy == Type::VoidTy || isa<OpaqueType>(RetTy))
+ return true;
+
+ // If this is a multiple return case, verify that each return is a first class
+ // value and that there is at least one value.
+ const StructType *SRetTy = dyn_cast<StructType>(RetTy);
+ if (SRetTy == 0 || SRetTy->getNumElements() == 0)
+ return false;
+
+ for (unsigned i = 0, e = SRetTy->getNumElements(); i != e; ++i)
+ if (!SRetTy->getElementType(i)->isFirstClassType())
+ return false;
+ return true;
+}
+
FunctionType::FunctionType(const Type *Result,
const std::vector<const Type*> &Params,
- bool IsVarArgs, ParamAttrsList *Attrs)
- : DerivedType(FunctionTyID), isVarArgs(IsVarArgs), ParamAttrs(Attrs) {
+ bool IsVarArgs)
+ : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) {
ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
NumContainedTys = Params.size() + 1; // + 1 for result type
- assert((Result->isFirstClassType() || Result == Type::VoidTy ||
- isa<OpaqueType>(Result)) &&
- "LLVM functions cannot return aggregates");
+ assert(isValidReturnType(Result) && "invalid return type for function");
+
+
bool isAbstract = Result->isAbstract();
new (&ContainedTys[0]) PATypeHandle(Result, this);
}
-PointerType::PointerType(const Type *E) : SequentialType(PointerTyID, E) {
+PointerType::PointerType(const Type *E, unsigned AddrSpace)
+ : SequentialType(PointerTyID, E) {
+ AddressSpace = AddrSpace;
// Calculate whether or not this type is abstract
setAbstract(E->isAbstract());
}
const IntegerType *ITy2 = cast<IntegerType>(Ty2);
return ITy->getBitWidth() == ITy2->getBitWidth();
} else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
- return TypesEqual(PTy->getElementType(),
- cast<PointerType>(Ty2)->getElementType(), EqTypes);
+ const PointerType *PTy2 = cast<PointerType>(Ty2);
+ return PTy->getAddressSpace() == PTy2->getAddressSpace() &&
+ TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
} else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
const StructType *STy2 = cast<StructType>(Ty2);
if (STy->getNumElements() != STy2->getNumElements()) return false;
FTy->getNumParams() != FTy2->getNumParams() ||
!TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
return false;
- const ParamAttrsList *Attrs1 = FTy->getParamAttrs();
- const ParamAttrsList *Attrs2 = FTy2->getParamAttrs();
- if ((!Attrs1 && Attrs2 && !Attrs2->empty()) ||
- (!Attrs2 && Attrs1 && !Attrs1->empty()) ||
- (Attrs1 && Attrs2 && (Attrs1->size() != Attrs2->size() ||
- (Attrs1->size() > 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))
- return false;
if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
return false;
}
case Type::StructTyID:
HashVal ^= cast<StructType>(SubTy)->getNumElements();
break;
+ case Type::PointerTyID:
+ HashVal ^= cast<PointerType>(SubTy)->getAddressSpace();
+ break;
}
}
return HashVal ? HashVal : 1; // Do not return zero unless opaque subty.
class FunctionValType {
const Type *RetTy;
std::vector<const Type*> ArgTypes;
- const ParamAttrsList *ParamAttrs;
bool isVarArg;
public:
FunctionValType(const Type *ret, const std::vector<const Type*> &args,
- bool IVA, const ParamAttrsList *attrs)
- : RetTy(ret), ParamAttrs(attrs), isVarArg(IVA) {
- for (unsigned i = 0; i < args.size(); ++i)
- ArgTypes.push_back(args[i]);
- }
+ bool isVA) : RetTy(ret), ArgTypes(args), isVarArg(isVA) {}
static FunctionValType get(const FunctionType *FT);
static unsigned hashTypeStructure(const FunctionType *FT) {
- unsigned Result = FT->getNumParams()*64 + FT->isVarArg();
- if (FT->getParamAttrs())
- Result += FT->getParamAttrs()->size()*2;
+ unsigned Result = FT->getNumParams()*2 + FT->isVarArg();
return Result;
}
if (isVarArg > MTV.isVarArg) return false;
if (ArgTypes < MTV.ArgTypes) return true;
if (ArgTypes > MTV.ArgTypes) 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 false;
}
};
ParamTypes.reserve(FT->getNumParams());
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
ParamTypes.push_back(FT->getParamType(i));
- return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg(),
- FT->getParamAttrs());
+ return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
}
// FunctionType::get - The factory function for the FunctionType class...
FunctionType *FunctionType::get(const Type *ReturnType,
const std::vector<const Type*> &Params,
- bool isVarArg,
- ParamAttrsList *Attrs) {
-
- FunctionValType VT(ReturnType, Params, isVarArg, Attrs);
- FunctionType *MT = FunctionTypes->get(VT);
- if (MT) {
- delete Attrs; // not needed any more
- return MT;
- }
+ bool isVarArg) {
+ FunctionValType VT(ReturnType, Params, isVarArg);
+ 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);
+ 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;
-}
-
-bool FunctionType::isStructReturn() const {
- if (ParamAttrs)
- return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
- return false;
+ return FT;
}
//===----------------------------------------------------------------------===//
VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
- assert(ElementType && "Can't get packed of null types!");
- assert(isPowerOf2_32(NumElements) && "Vector length should be a power of 2!");
+ assert(ElementType && "Can't get vector of null types!");
VectorValType PVT(ElementType, NumElements);
VectorType *PT = VectorTypes->get(PVT);
return ST;
}
+StructType *StructType::get(const Type *type, ...) {
+ va_list ap;
+ std::vector<const llvm::Type*> StructFields;
+ va_start(ap, type);
+ while (type) {
+ StructFields.push_back(type);
+ type = va_arg(ap, llvm::Type*);
+ }
+ return llvm::StructType::get(StructFields);
+}
+
//===----------------------------------------------------------------------===//
namespace llvm {
class PointerValType {
const Type *ValTy;
+ unsigned AddressSpace;
public:
- PointerValType(const Type *val) : ValTy(val) {}
+ PointerValType(const Type *val, unsigned as) : ValTy(val), AddressSpace(as) {}
static PointerValType get(const PointerType *PT) {
- return PointerValType(PT->getElementType());
+ return PointerValType(PT->getElementType(), PT->getAddressSpace());
}
static unsigned hashTypeStructure(const PointerType *PT) {
}
bool operator<(const PointerValType &MTV) const {
- return ValTy < MTV.ValTy;
+ if (AddressSpace < MTV.AddressSpace) return true;
+ return AddressSpace == MTV.AddressSpace && ValTy < MTV.ValTy;
}
};
}
static ManagedStatic<TypeMap<PointerValType, PointerType> > PointerTypes;
-PointerType *PointerType::get(const Type *ValueType) {
+PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
assert(ValueType && "Can't get a pointer to <null> type!");
assert(ValueType != Type::VoidTy &&
"Pointer to void is not valid, use sbyte* instead!");
assert(ValueType != Type::LabelTy && "Pointer to label is not valid!");
- PointerValType PVT(ValueType);
+ PointerValType PVT(ValueType, AddressSpace);
PointerType *PT = PointerTypes->get(PVT);
if (PT) return PT;
// Value not found. Derive a new type!
- PointerTypes->add(PVT, PT = new PointerType(ValueType));
+ PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *PT << "\n";