aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGVtable.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-13 21:33:22 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-13 21:33:22 +0000
commita4699882abd8bedd159fa979508f8f6deb64a121 (patch)
tree9361ab1fa80db3c32278550805b2f080583713aa /lib/CodeGen/CGVtable.cpp
parent1d05be51b09ae1ce65b1ecd6220bade12908586d (diff)
Merge base offsets and dump them.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96121 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGVtable.cpp')
-rw-r--r--lib/CodeGen/CGVtable.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index f16f66af2a..8bdb713f6c 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -264,6 +264,18 @@ FinalOverriders::FinalOverriders(const CXXRecordDecl *MostDerivedClass)
// And dump them (for now).
dump();
+
+ // Also dump the base offsets (for now).
+ for (SubobjectOffsetsMapTy::const_iterator I = Offsets.begin(),
+ E = Offsets.end(); I != E; ++I) {
+ const OffsetVectorTy& OffsetVector = I->second;
+
+ llvm::errs() << "Base offsets for ";
+ llvm::errs() << I->first->getQualifiedNameAsString() << '\n';
+
+ for (unsigned I = 0, E = OffsetVector.size(); I != E; ++I)
+ llvm::errs() << " " << I << " - " << OffsetVector[I] << '\n';
+ }
}
void FinalOverriders::AddOverriders(BaseSubobject Base,
@@ -452,17 +464,41 @@ FinalOverriders::MergeSubobjectOffsets(const SubobjectOffsetsMapTy &NewOffsets,
for (SubobjectOffsetsMapTy::const_iterator I = NewOffsets.begin(),
E = NewOffsets.end(); I != E; ++I) {
const CXXRecordDecl *NewRD = I->first;
- const OffsetVectorTy& NewOffsetsVector = I->second;
+ const OffsetVectorTy& NewOffsetVector = I->second;
- OffsetVectorTy &OffsetsVector = Offsets[NewRD];
- if (OffsetsVector.empty()) {
+ OffsetVectorTy &OffsetVector = Offsets[NewRD];
+ if (OffsetVector.empty()) {
// There were no previous offsets in this vector, just insert all entries
- // from the new offsets vector.
- OffsetsVector.append(NewOffsetsVector.begin(), NewOffsetsVector.end());
+ // from the new offset vector.
+ OffsetVector.append(NewOffsetVector.begin(), NewOffsetVector.end());
continue;
}
- assert(false && "FIXME: Handle merging the subobject offsets!");
+ // We need to merge the new offsets vector into the old, but we don't want
+ // to have duplicate entries. Do this by inserting the old offsets in a set
+ // so they'll be unique. After this, we iterate over the new offset vector
+ // and only append elements that aren't in the set.
+
+ // First, add the existing offsets to the set.
+ llvm::SmallSet<uint64_t, 4> OffsetSet;
+ for (unsigned I = 0, E = OffsetVector.size(); I != E; ++I) {
+ bool Inserted = OffsetSet.insert(OffsetVector[I]);
+ if (!Inserted)
+ assert(false && "Set of offsets should be unique!");
+ }
+
+ // Next, only add the new offsets if they are not already in the set.
+ for (unsigned I = 0, E = NewOffsetVector.size(); I != E; ++I) {
+ uint64_t Offset = NewOffsetVector[I];
+
+ if (OffsetSet.count(Offset)) {
+ // Ignore the offset.
+ continue;
+ }
+
+ // Otherwise, add it to the offsets vector.
+ OffsetVector.push_back(Offset);
+ }
}
}