//
// 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.
//
//===----------------------------------------------------------------------===//
//
}
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: {
ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
NumContainedTys = Params.size() + 1; // + 1 for result type
assert((Result->isFirstClassType() || Result == Type::VoidTy ||
- isa<OpaqueType>(Result)) &&
+ Result->getTypeID() == Type::StructTyID ||
+ isa<OpaqueType>(Result)) &&
"LLVM functions cannot return aggregates");
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;
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.
bool isVarArg;
public:
FunctionValType(const Type *ret, const std::vector<const Type*> &args,
- bool isVA) : RetTy(ret), isVarArg(isVA) {
- 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);
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";