X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FType.cpp;h=889705e95fc25aea1bb4411810565cc495cd476d;hb=2c22f8dc09b638a375f671b81027f242a9775558;hp=13424562757acb002b7785db9fc58fcc6a0e739e;hpb=24623bab81ae6dde6d58fdd041d73c67f8dd98cf;p=oota-llvm.git diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 13424562757..889705e95fc 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -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 } @@ -155,7 +159,7 @@ 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(SmallPtrSet *Visited) const { +bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { if (const ArrayType *ATy = dyn_cast(this)) return ATy->getElementType()->isSized(Visited); @@ -356,8 +360,7 @@ FunctionType *FunctionType::get(Type *ReturnType, ArrayRef Params, bool isVarArg) { LLVMContextImpl *pImpl = ReturnType->getContext().pImpl; FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg); - LLVMContextImpl::FunctionTypeMap::iterator I = - pImpl->FunctionTypes.find_as(Key); + auto I = pImpl->FunctionTypes.find_as(Key); FunctionType *FT; if (I == pImpl->FunctionTypes.end()) { @@ -365,9 +368,9 @@ FunctionType *FunctionType::get(Type *ReturnType, Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1), AlignOf::Alignment); new (FT) FunctionType(ReturnType, Params, isVarArg); - pImpl->FunctionTypes[FT] = true; + pImpl->FunctionTypes.insert(FT); } else { - FT = I->first; + FT = *I; } return FT; @@ -400,8 +403,7 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef ETypes, bool isPacked) { LLVMContextImpl *pImpl = Context.pImpl; AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked); - LLVMContextImpl::StructTypeMap::iterator I = - pImpl->AnonStructTypes.find_as(Key); + auto I = pImpl->AnonStructTypes.find_as(Key); StructType *ST; if (I == pImpl->AnonStructTypes.end()) { @@ -409,9 +411,9 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef ETypes, ST = new (Context.pImpl->TypeAllocator) StructType(Context); ST->setSubclassData(SCDB_IsLiteral); // Literal struct. ST->setBody(ETypes, isPacked); - Context.pImpl->AnonStructTypes[ST] = true; + Context.pImpl->AnonStructTypes.insert(ST); } else { - ST = I->first; + ST = *I; } return ST; @@ -454,10 +456,11 @@ void StructType::setName(StringRef Name) { } // Look up the entry for the name. - EntryTy *Entry = &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name); - + auto IterBool = + getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this)); + // While we have a name collision, try a random rename. - if (Entry->getValue()) { + if (!IterBool.second) { SmallString<64> TempStr(Name); TempStr.push_back('.'); raw_svector_ostream TmpStream(TempStr); @@ -467,19 +470,16 @@ void StructType::setName(StringRef Name) { TempStr.resize(NameSize + 1); TmpStream.resync(); TmpStream << getContext().pImpl->NamedStructTypesUniqueID++; - - Entry = &getContext().pImpl-> - NamedStructTypes.GetOrCreateValue(TmpStream.str()); - } while (Entry->getValue()); - } - // Okay, we found an entry that isn't used. It's us! - Entry->setValue(this); + IterBool = getContext().pImpl->NamedStructTypes.insert( + std::make_pair(TmpStream.str(), this)); + } while (!IterBool.second); + } // Delete the old string data. if (SymbolTableEntry) ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator()); - SymbolTableEntry = Entry; + SymbolTableEntry = &*IterBool.first; } //===----------------------------------------------------------------------===// @@ -554,13 +554,13 @@ StructType *StructType::create(StringRef Name, Type *type, ...) { return Ret; } -bool StructType::isSized(SmallPtrSet *Visited) const { +bool StructType::isSized(SmallPtrSetImpl *Visited) const { if ((getSubclassData() & SCDB_IsSized) != 0) return true; if (isOpaque()) return false; - if (Visited && !Visited->insert(this)) + if (Visited && !Visited->insert(this).second) return false; // Okay, our struct is sized if all of the elements are, but if one of the