Use CharUnits in the EmptyClassOffsets map.

llvm-svn: 117873
This commit is contained in:
Anders Carlsson 2010-10-31 21:22:43 +00:00
parent 5fd3e86cce
commit f8f756d1d5
1 changed files with 12 additions and 3 deletions

View File

@ -63,7 +63,7 @@ class EmptySubobjectMap {
/// EmptyClassOffsets - A map from offsets to empty record decls.
typedef llvm::SmallVector<const CXXRecordDecl *, 1> ClassVectorTy;
typedef llvm::DenseMap<uint64_t, ClassVectorTy> EmptyClassOffsetsMapTy;
typedef llvm::DenseMap<CharUnits, ClassVectorTy> EmptyClassOffsetsMapTy;
EmptyClassOffsetsMapTy EmptyClassOffsets;
/// MaxEmptyClassOffset - The highest offset known to contain an empty
@ -90,6 +90,14 @@ class EmptySubobjectMap {
return Offset <= MaxEmptyClassOffset;
}
// FIXME: Remove these.
CharUnits toCharUnits(uint64_t Offset) const {
return CharUnits::fromQuantity(Offset / Context.getCharWidth());
}
uint64_t toOffset(CharUnits Offset) const {
return Offset.getQuantity() * Context.getCharWidth();
}
protected:
bool CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
uint64_t Offset) const;
@ -183,7 +191,8 @@ EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
if (!RD->isEmpty())
return true;
EmptyClassOffsetsMapTy::const_iterator I = EmptyClassOffsets.find(Offset);
EmptyClassOffsetsMapTy::const_iterator I =
EmptyClassOffsets.find(toCharUnits(Offset));
if (I == EmptyClassOffsets.end())
return true;
@ -201,7 +210,7 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const CXXRecordDecl *RD,
if (!RD->isEmpty())
return;
ClassVectorTy& Classes = EmptyClassOffsets[Offset];
ClassVectorTy& Classes = EmptyClassOffsets[toCharUnits(Offset)];
assert(std::find(Classes.begin(), Classes.end(), RD) == Classes.end() &&
"Duplicate empty class detected!");