X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FType.cpp;h=90fde4db19242d1d0b8b255889ccc182f9d8ff7d;hb=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;hp=432cbc99f5e66197626c5d6f1502edee3757eca2;hpb=877ca3418f8fcd8e966e80b7e7f1dcb944dbed59;p=oota-llvm.git diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 432cbc99f5e..90fde4db192 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -36,7 +36,7 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) { case MetadataTyID : return getMetadataTy(C); case X86_MMXTyID : return getX86_MMXTy(C); default: - return 0; + return nullptr; } } @@ -89,9 +89,13 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { // At this point we have only various mismatches of the first class types // remaining and ptr->ptr. Just select the lossless conversions. Everything - // else is not lossless. - if (this->isPointerTy()) - return Ty->isPointerTy(); + // 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)) + return PTy->getAddressSpace() == OtherPTy->getAddressSpace(); + return false; + } return false; // Other types have no identity values } @@ -132,7 +136,7 @@ unsigned Type::getPrimitiveSizeInBits() const { /// getScalarSizeInBits - If this is a vector type, return the /// getPrimitiveSizeInBits value for the element type. Otherwise return the /// getPrimitiveSizeInBits value for this type. -unsigned Type::getScalarSizeInBits() { +unsigned Type::getScalarSizeInBits() const { return getScalarType()->getPrimitiveSizeInBits(); } @@ -155,20 +159,14 @@ 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() const { - if (this->isIntegerTy()) - return true; - +bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { if (const ArrayType *ATy = dyn_cast(this)) - return ATy->getElementType()->isSized(); + return ATy->getElementType()->isSized(Visited); if (const VectorType *VTy = dyn_cast(this)) - return VTy->getElementType()->isSized(); + return VTy->getElementType()->isSized(Visited); - if (!this->isStructTy()) - return false; - - return cast(this)->isSized(); + return cast(this)->isSized(Visited); } //===----------------------------------------------------------------------===// @@ -318,8 +316,8 @@ IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) { } IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits]; - - if (Entry == 0) + + if (!Entry) Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits); return Entry; @@ -454,7 +452,7 @@ void StructType::setName(StringRef Name) { if (SymbolTableEntry) { // Delete the old string data. ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator()); - SymbolTableEntry = 0; + SymbolTableEntry = nullptr; } return; } @@ -503,7 +501,7 @@ StructType *StructType::get(LLVMContext &Context, bool isPacked) { } StructType *StructType::get(Type *type, ...) { - assert(type != 0 && "Cannot create a struct type with no elements with this"); + assert(type && "Cannot create a struct type with no elements with this"); LLVMContext &Ctx = type->getContext(); va_list ap; SmallVector StructFields; @@ -512,7 +510,9 @@ StructType *StructType::get(Type *type, ...) { StructFields.push_back(type); type = va_arg(ap, llvm::Type*); } - return llvm::StructType::get(Ctx, StructFields); + auto *Ret = llvm::StructType::get(Ctx, StructFields); + va_end(ap); + return Ret; } StructType *StructType::create(LLVMContext &Context, ArrayRef Elements, @@ -544,7 +544,7 @@ StructType *StructType::create(ArrayRef Elements) { } StructType *StructType::create(StringRef Name, Type *type, ...) { - assert(type != 0 && "Cannot create a struct type with no elements with this"); + assert(type && "Cannot create a struct type with no elements with this"); LLVMContext &Ctx = type->getContext(); va_list ap; SmallVector StructFields; @@ -553,20 +553,25 @@ StructType *StructType::create(StringRef Name, Type *type, ...) { StructFields.push_back(type); type = va_arg(ap, llvm::Type*); } - return llvm::StructType::create(Ctx, StructFields, Name); + auto *Ret = llvm::StructType::create(Ctx, StructFields, Name); + va_end(ap); + return Ret; } -bool StructType::isSized() const { +bool StructType::isSized(SmallPtrSetImpl *Visited) const { if ((getSubclassData() & SCDB_IsSized) != 0) return true; if (isOpaque()) return false; + if (Visited && !Visited->insert(this)) + return false; + // Okay, our struct is sized if all of the elements are, but if one of the // elements is opaque, the struct isn't sized *yet*, but may become sized in // the future, so just bail out without caching. for (element_iterator I = element_begin(), E = element_end(); I != E; ++I) - if (!(*I)->isSized()) + if (!(*I)->isSized(Visited)) return false; // Here we cheat a bit and cast away const-ness. The goal is to memoize when @@ -579,13 +584,13 @@ bool StructType::isSized() const { StringRef StructType::getName() const { assert(!isLiteral() && "Literal structs never have names"); - if (SymbolTableEntry == 0) return StringRef(); - + if (!SymbolTableEntry) return StringRef(); + return ((StringMapEntry *)SymbolTableEntry)->getKey(); } void StructType::setBody(Type *type, ...) { - assert(type != 0 && "Cannot create a struct type with no elements with this"); + assert(type && "Cannot create a struct type with no elements with this"); va_list ap; SmallVector StructFields; va_start(ap, type); @@ -594,6 +599,7 @@ void StructType::setBody(Type *type, ...) { type = va_arg(ap, llvm::Type*); } setBody(StructFields); + va_end(ap); } bool StructType::isValidElementType(Type *ElemTy) { @@ -683,8 +689,8 @@ ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) { LLVMContextImpl *pImpl = ElementType->getContext().pImpl; ArrayType *&Entry = pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)]; - - if (Entry == 0) + + if (!Entry) Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements); return Entry; } @@ -712,8 +718,8 @@ VectorType *VectorType::get(Type *elementType, unsigned NumElements) { LLVMContextImpl *pImpl = ElementType->getContext().pImpl; VectorType *&Entry = ElementType->getContext().pImpl ->VectorTypes[std::make_pair(ElementType, NumElements)]; - - if (Entry == 0) + + if (!Entry) Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements); return Entry; } @@ -737,7 +743,7 @@ PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) { PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy] : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)]; - if (Entry == 0) + if (!Entry) Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace); return Entry; }