X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FType.cpp;h=c3c3f492b5bbdf545ff5369d384cfdda6d90d5d5;hb=2dacece9e2c9db49f31a1e1432604f0411018290;hp=889705e95fc25aea1bb4411810565cc495cd476d;hpb=2991725fe2982e0fc2c28e9f53cd9a2bec90a9d9;p=oota-llvm.git diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 889705e95fc..c3c3f492b5b 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -35,6 +35,7 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) { case LabelTyID : return getLabelTy(C); case MetadataTyID : return getMetadataTy(C); case X86_MMXTyID : return getX86_MMXTy(C); + case TokenTyID : return getTokenTy(C); default: return nullptr; } @@ -42,16 +43,10 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) { /// getScalarType - If this is a vector type, return the element type, /// otherwise return this. -Type *Type::getScalarType() { - if (VectorType *VTy = dyn_cast(this)) +Type *Type::getScalarType() const { + if (auto *VTy = dyn_cast(this)) return VTy->getElementType(); - return this; -} - -const Type *Type::getScalarType() const { - if (const VectorType *VTy = dyn_cast(this)) - return VTy->getElementType(); - return this; + return const_cast(this); } /// isIntegerTy - Return true if this is an IntegerType of the specified width. @@ -74,8 +69,8 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { // Vector -> Vector conversions are always lossless if the two vector types // have the same size, otherwise not. Also, 64-bit vector types can be // converted to x86mmx. - if (const VectorType *thisPTy = dyn_cast(this)) { - if (const VectorType *thatPTy = dyn_cast(Ty)) + if (auto *thisPTy = dyn_cast(this)) { + if (auto *thatPTy = dyn_cast(Ty)) return thisPTy->getBitWidth() == thatPTy->getBitWidth(); if (Ty->getTypeID() == Type::X86_MMXTyID && thisPTy->getBitWidth() == 64) @@ -83,7 +78,7 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { } if (this->getTypeID() == Type::X86_MMXTyID) - if (const VectorType *thatPTy = dyn_cast(Ty)) + if (auto *thatPTy = dyn_cast(Ty)) if (thatPTy->getBitWidth() == 64) return true; @@ -91,8 +86,8 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { // remaining and ptr->ptr. Just select the lossless conversions. Everything // else is not lossless. Conservatively assume we can't losslessly convert // between pointers with different address spaces. - if (const PointerType *PTy = dyn_cast(this)) { - if (const PointerType *OtherPTy = dyn_cast(Ty)) + if (auto *PTy = dyn_cast(this)) { + if (auto *OtherPTy = dyn_cast(Ty)) return PTy->getAddressSpace() == OtherPTy->getAddressSpace(); return false; } @@ -100,14 +95,12 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { } bool Type::isEmptyTy() const { - const ArrayType *ATy = dyn_cast(this); - if (ATy) { + if (auto *ATy = dyn_cast(this)) { unsigned NumElements = ATy->getNumElements(); return NumElements == 0 || ATy->getElementType()->isEmptyTy(); } - const StructType *STy = dyn_cast(this); - if (STy) { + if (auto *STy = dyn_cast(this)) { unsigned NumElements = STy->getNumElements(); for (unsigned i = 0; i < NumElements; ++i) if (!STy->getElementType(i)->isEmptyTy()) @@ -144,7 +137,7 @@ unsigned Type::getScalarSizeInBits() const { /// is only valid on floating point types. If the FP type does not /// have a stable mantissa (e.g. ppc long double), this method returns -1. int Type::getFPMantissaWidth() const { - if (const VectorType *VTy = dyn_cast(this)) + if (auto *VTy = dyn_cast(this)) return VTy->getElementType()->getFPMantissaWidth(); assert(isFloatingPointTy() && "Not a floating point type!"); if (getTypeID() == HalfTyID) return 11; @@ -159,11 +152,11 @@ int Type::getFPMantissaWidth() const { /// isSizedDerivedType - Derived types like structures and arrays are sized /// iff all of the members of the type are sized as well. Since asking for /// their size is relatively uncommon, move this operation out of line. -bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { - if (const ArrayType *ATy = dyn_cast(this)) +bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { + if (auto *ATy = dyn_cast(this)) return ATy->getElementType()->isSized(Visited); - if (const VectorType *VTy = dyn_cast(this)) + if (auto *VTy = dyn_cast(this)) return VTy->getElementType()->isSized(Visited); return cast(this)->isSized(Visited); @@ -228,6 +221,7 @@ Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; } Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; } Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; } Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; } +Type *Type::getTokenTy(LLVMContext &C) { return &C.pImpl->TokenTy; } Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; } Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; } Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; } @@ -238,6 +232,7 @@ IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; } IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; } IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; } IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; } +IntegerType *Type::getInt128Ty(LLVMContext &C) { return &C.pImpl->Int128Ty; } IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) { return IntegerType::get(C, N); @@ -306,12 +301,13 @@ IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) { // Check for the built-in integer types switch (NumBits) { - case 1: return cast(Type::getInt1Ty(C)); - case 8: return cast(Type::getInt8Ty(C)); - case 16: return cast(Type::getInt16Ty(C)); - case 32: return cast(Type::getInt32Ty(C)); - case 64: return cast(Type::getInt64Ty(C)); - default: + case 1: return cast(Type::getInt1Ty(C)); + case 8: return cast(Type::getInt8Ty(C)); + case 16: return cast(Type::getInt16Ty(C)); + case 32: return cast(Type::getInt32Ty(C)); + case 64: return cast(Type::getInt64Ty(C)); + case 128: return cast(Type::getInt128Ty(C)); + default: break; } @@ -343,7 +339,7 @@ FunctionType::FunctionType(Type *Result, ArrayRef Params, assert(isValidReturnType(Result) && "invalid return type for function"); setSubclassData(IsVarArgs); - SubTys[0] = const_cast(Result); + SubTys[0] = Result; for (unsigned i = 0, e = Params.size(); i != e; ++i) { assert(isValidArgumentType(Params[i]) && @@ -426,12 +422,14 @@ void StructType::setBody(ArrayRef Elements, bool isPacked) { if (isPacked) setSubclassData(getSubclassData() | SCDB_Packed); - unsigned NumElements = Elements.size(); - Type **Elts = getContext().pImpl->TypeAllocator.Allocate(NumElements); - memcpy(Elts, Elements.data(), sizeof(Elements[0]) * NumElements); - - ContainedTys = Elts; - NumContainedTys = NumElements; + NumContainedTys = Elements.size(); + + if (Elements.empty()) { + ContainedTys = nullptr; + return; + } + + ContainedTys = Elements.copy(getContext().pImpl->TypeAllocator).data(); } void StructType::setName(StringRef Name) { @@ -468,7 +466,6 @@ void StructType::setName(StringRef Name) { do { TempStr.resize(NameSize + 1); - TmpStream.resync(); TmpStream << getContext().pImpl->NamedStructTypesUniqueID++; IterBool = getContext().pImpl->NamedStructTypes.insert( @@ -554,13 +551,13 @@ StructType *StructType::create(StringRef Name, Type *type, ...) { return Ret; } -bool StructType::isSized(SmallPtrSetImpl *Visited) const { +bool StructType::isSized(SmallPtrSetImpl *Visited) const { if ((getSubclassData() & SCDB_IsSized) != 0) return true; if (isOpaque()) return false; - if (Visited && !Visited->insert(this).second) + if (Visited && !Visited->insert(const_cast(this)).second) return false; // Okay, our struct is sized if all of the elements are, but if one of the @@ -600,7 +597,8 @@ void StructType::setBody(Type *type, ...) { bool StructType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy(); + !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() && + !ElemTy->isTokenTy(); } /// isLayoutIdentical - Return true if this is layout identical to the @@ -612,7 +610,8 @@ bool StructType::isLayoutIdentical(StructType *Other) const { getNumElements() != Other->getNumElements()) return false; - return std::equal(element_begin(), element_end(), Other->element_begin()); + return element_begin() && + std::equal(element_begin(), element_end(), Other->element_begin()); } /// getTypeByName - Return the type with the specified name, or null if there @@ -626,8 +625,8 @@ StructType *Module::getTypeByName(StringRef Name) const { // CompositeType Implementation //===----------------------------------------------------------------------===// -Type *CompositeType::getTypeAtIndex(const Value *V) { - if (StructType *STy = dyn_cast(this)) { +Type *CompositeType::getTypeAtIndex(const Value *V) const { + if (auto *STy = dyn_cast(this)) { unsigned Idx = (unsigned)cast(V)->getUniqueInteger().getZExtValue(); assert(indexValid(Idx) && "Invalid structure index!"); @@ -636,16 +635,18 @@ Type *CompositeType::getTypeAtIndex(const Value *V) { return cast(this)->getElementType(); } -Type *CompositeType::getTypeAtIndex(unsigned Idx) { - if (StructType *STy = dyn_cast(this)) { + +Type *CompositeType::getTypeAtIndex(unsigned Idx) const{ + if (auto *STy = dyn_cast(this)) { assert(indexValid(Idx) && "Invalid structure index!"); return STy->getElementType(Idx); } - + return cast(this)->getElementType(); } + bool CompositeType::indexValid(const Value *V) const { - if (const StructType *STy = dyn_cast(this)) { + if (auto *STy = dyn_cast(this)) { // Structure indexes require (vectors of) 32-bit integer constants. In the // vector case all of the indices must be equal. if (!V->getType()->getScalarType()->isIntegerTy(32)) @@ -662,7 +663,7 @@ bool CompositeType::indexValid(const Value *V) const { } bool CompositeType::indexValid(unsigned Idx) const { - if (const StructType *STy = dyn_cast(this)) + if (auto *STy = dyn_cast(this)) return Idx < STy->getNumElements(); // Sequential types can be indexed by any integer. return true; @@ -678,10 +679,9 @@ ArrayType::ArrayType(Type *ElType, uint64_t NumEl) NumElements = NumEl; } -ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) { - Type *ElementType = const_cast(elementType); +ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) { assert(isValidElementType(ElementType) && "Invalid type for array element!"); - + LLVMContextImpl *pImpl = ElementType->getContext().pImpl; ArrayType *&Entry = pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)]; @@ -693,7 +693,8 @@ ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) { bool ArrayType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy(); + !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() && + !ElemTy->isTokenTy(); } //===----------------------------------------------------------------------===// @@ -705,12 +706,12 @@ VectorType::VectorType(Type *ElType, unsigned NumEl) NumElements = NumEl; } -VectorType *VectorType::get(Type *elementType, unsigned NumElements) { - Type *ElementType = const_cast(elementType); +VectorType *VectorType::get(Type *ElementType, unsigned NumElements) { assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0"); - assert(isValidElementType(ElementType) && - "Elements of a VectorType must be a primitive type"); - + assert(isValidElementType(ElementType) && "Element type of a VectorType must " + "be an integer, floating point, or " + "pointer type."); + LLVMContextImpl *pImpl = ElementType->getContext().pImpl; VectorType *&Entry = ElementType->getContext().pImpl ->VectorTypes[std::make_pair(ElementType, NumElements)]; @@ -755,11 +756,15 @@ PointerType::PointerType(Type *E, unsigned AddrSpace) assert(oldNCT == NumContainedTys && "bitfield written out of bounds?"); } -PointerType *Type::getPointerTo(unsigned addrs) { - return PointerType::get(this, addrs); +PointerType *Type::getPointerTo(unsigned addrs) const { + return PointerType::get(const_cast(this), addrs); } bool PointerType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy(); + !ElemTy->isMetadataTy() && !ElemTy->isTokenTy(); +} + +bool PointerType::isLoadableOrStorableType(Type *ElemTy) { + return isValidElementType(ElemTy) && !ElemTy->isFunctionTy(); }