[cfe-commits] r117869 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/RecordLayoutBuilder.cpp
Anders Carlsson
andersca at mac.com
Sun Oct 31 14:01:46 PDT 2010
Author: andersca
Date: Sun Oct 31 16:01:46 2010
New Revision: 117869
URL: http://llvm.org/viewvc/llvm-project?rev=117869&view=rev
Log:
Baby steps towards using only CharUnits for base class offsets in ASTRecordLayout. Start by storing the offsets in CharUnits in the ASTRecordLayout object.
Modified:
cfe/trunk/include/clang/AST/RecordLayout.h
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=117869&r1=117868&r2=117869&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Sun Oct 31 16:01:46 2010
@@ -119,7 +119,7 @@
PrimaryBaseInfo PrimaryBase;
/// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
- typedef llvm::DenseMap<const CXXRecordDecl *, uint64_t> BaseOffsetsMapTy;
+ typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
/// BaseOffsets - Contains a map from base classes to their offset.
BaseOffsetsMapTy BaseOffsets;
@@ -153,7 +153,7 @@
~ASTRecordLayout() {}
void Destroy(ASTContext &Ctx);
-
+
ASTRecordLayout(const ASTRecordLayout&); // DO NOT IMPLEMENT
void operator=(const ASTRecordLayout&); // DO NOT IMPLEMENT
public:
@@ -218,7 +218,8 @@
assert(CXXInfo && "Record layout does not have C++ specific info!");
assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");
- return CXXInfo->BaseOffsets[Base];
+ return CXXInfo->BaseOffsets[Base].getQuantity() *
+ Base->getASTContext().getCharWidth();
}
/// getVBaseClassOffset - Get the offset, in bits, for the given base class.
@@ -226,9 +227,10 @@
assert(CXXInfo && "Record layout does not have C++ specific info!");
assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
- return CXXInfo->VBaseOffsets[VBase];
+ return CXXInfo->VBaseOffsets[VBase].getQuantity() *
+ VBase->getASTContext().getCharWidth();
}
-
+
uint64_t getSizeOfLargestEmptySubobject() const {
assert(CXXInfo && "Record layout does not have C++ specific info!");
return CXXInfo->SizeOfLargestEmptySubobject;
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=117869&r1=117868&r2=117869&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sun Oct 31 16:01:46 2010
@@ -565,7 +565,7 @@
/// out is virtual.
bool PrimaryBaseIsVirtual;
- typedef llvm::DenseMap<const CXXRecordDecl *, uint64_t> BaseOffsetsMapTy;
+ typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
/// Bases - base classes and their offsets in the record.
BaseOffsetsMapTy Bases;
@@ -992,10 +992,12 @@
void RecordLayoutBuilder::LayoutNonVirtualBase(const BaseSubobjectInfo *Base) {
// Layout the base.
uint64_t Offset = LayoutBase(Base);
+ CharUnits OffsetInChars =
+ CharUnits::fromQuantity(Offset / Context.getCharWidth());
// Add its base class offset.
assert(!Bases.count(Base->Class) && "base offset already exists!");
- Bases.insert(std::make_pair(Base->Class, Offset));
+ Bases.insert(std::make_pair(Base->Class, OffsetInChars));
AddPrimaryVirtualBaseOffsets(Base, Offset);
}
@@ -1015,8 +1017,10 @@
// Add the offset.
assert(!VBases.count(Info->PrimaryVirtualBaseInfo->Class) &&
"primary vbase offset already exists!");
+ CharUnits OffsetInChars =
+ CharUnits::fromQuantity(Offset / Context.getCharWidth());
VBases.insert(std::make_pair(Info->PrimaryVirtualBaseInfo->Class,
- Offset));
+ OffsetInChars));
// Traverse the primary virtual base.
AddPrimaryVirtualBaseOffsets(Info->PrimaryVirtualBaseInfo, Offset);
@@ -1089,10 +1093,12 @@
// Layout the base.
uint64_t Offset = LayoutBase(Base);
+ CharUnits OffsetInChars =
+ CharUnits::fromQuantity(Offset / Context.getCharWidth());
// Add its base class offset.
assert(!VBases.count(Base->Class) && "vbase offset already exists!");
- VBases.insert(std::make_pair(Base->Class, Offset));
+ VBases.insert(std::make_pair(Base->Class, OffsetInChars));
AddPrimaryVirtualBaseOffsets(Base, Offset);
}
More information about the cfe-commits
mailing list