[cfe-commits] r94592 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/virt.cpp
Mike Stump
mrs at apple.com
Tue Jan 26 13:35:27 PST 2010
Author: mrs
Date: Tue Jan 26 15:35:27 2010
New Revision: 94592
URL: http://llvm.org/viewvc/llvm-project?rev=94592&view=rev
Log:
Refine the non-virtual this adjustments for thunks by using the offset
to the declaring class from the nearest virtual base class. WIP.
This fixes 40% of all the problems remaining in one of my testcases.
Modified:
cfe/trunk/lib/CodeGen/CGVtable.cpp
cfe/trunk/test/CodeGenCXX/virt.cpp
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=94592&r1=94591&r2=94592&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Tue Jan 26 15:35:27 2010
@@ -634,7 +634,8 @@
// entry.
Methods.AddMethod(GD);
- VCallOffset[GD] = Offset/8;
+ VCallOffset[GD] = Offset/8 - CurrentVBaseOffset/8;
+
if (MorallyVirtual) {
GlobalDecl UGD = getUnique(GD);
const CXXMethodDecl *UMD = cast<CXXMethodDecl>(UGD.getDecl());
@@ -645,7 +646,7 @@
// Allocate the first one, after that, we reuse the previous one.
if (idx == 0) {
VCallOffsetForVCall[UGD] = Offset/8;
- NonVirtualOffset[UMD] = -CurrentVBaseOffset/8 + Offset/8;
+ NonVirtualOffset[UMD] = Offset/8 - CurrentVBaseOffset/8;
idx = VCalls.size()+1;
VCalls.push_back(Offset/8 - CurrentVBaseOffset/8);
D1(printf(" vcall for %s at %d with delta %d\n",
@@ -715,6 +716,9 @@
}
VCalls.clear();
VCall.clear();
+ VCallOffsetForVCall.clear();
+ VCallOffset.clear();
+ NonVirtualOffset.clear();
}
void AddAddressPoints(const CXXRecordDecl *RD, uint64_t Offset,
@@ -1044,6 +1048,7 @@
for (CXXMethodDecl::method_iterator mi = MD->begin_overridden_methods(),
e = MD->end_overridden_methods(); mi != e; ++mi) {
GlobalDecl OGD;
+ GlobalDecl OGD2;
const CXXMethodDecl *OMD = *mi;
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(OMD))
@@ -1057,6 +1062,8 @@
if (!Methods.getIndex(OGD, Index))
continue;
+ OGD2 = OGD;
+
// Get the original method, which we should be computing thunks, etc,
// against.
OGD = Methods.getOrigMethod(Index);
@@ -1087,10 +1094,12 @@
ThisAdjustments.erase(Index);
if (MorallyVirtual || VCall.count(UMD)) {
+
Index_t &idx = VCall[UMD];
if (idx == 0) {
- NonVirtualOffset[UMD] = CurrentVBaseOffset/8 - OverrideOffset/8;
- VCallOffset[GD] = OverrideOffset/8;
+ VCallOffset[GD] = VCallOffset[OGD];
+ // NonVirtualOffset[UMD] = CurrentVBaseOffset/8 - OverrideOffset/8;
+ NonVirtualOffset[UMD] = VCallOffset[OGD];
VCallOffsetForVCall[UMD] = OverrideOffset/8;
idx = VCalls.size()+1;
VCalls.push_back(OverrideOffset/8 - CurrentVBaseOffset/8);
@@ -1098,13 +1107,13 @@
MD->getNameAsString().c_str(), (int)-idx-3,
(int)VCalls[idx-1], MostDerivedClass->getNameAsCString()));
} else {
- VCallOffset[GD] = VCallOffset[OGD];
+ VCallOffset[GD] = NonVirtualOffset[UMD];
VCalls[idx-1] = -VCallOffsetForVCall[UGD] + OverrideOffset/8;
D1(printf(" vcall patch for %s at %d with delta %d most derived %s\n",
MD->getNameAsString().c_str(), (int)-idx-3,
(int)VCalls[idx-1], MostDerivedClass->getNameAsCString()));
}
- int64_t NonVirtualAdjustment = NonVirtualOffset[UMD];
+ int64_t NonVirtualAdjustment = -VCallOffset[OGD];
int64_t VirtualAdjustment =
-((idx + extra + 2) * LLVMPointerWidth / 8);
@@ -1123,8 +1132,16 @@
return true;
}
- int64_t NonVirtualAdjustment = -VCallOffset[OGD] + OverrideOffset/8;
+ VCallOffset[GD] = VCallOffset[OGD2] - OverrideOffset/8;
+ int64_t NonVirtualAdjustment = -VCallOffset[GD];
+ QualType DerivedType = MD->getThisType(CGM.getContext());
+ QualType BaseType = cast<const CXXMethodDecl>(OGD.getDecl())->getThisType(CGM.getContext());
+ int64_t NonVirtualAdjustment2 = -(getNVOffset(BaseType, DerivedType)/8);
+ if (NonVirtualAdjustment2 != NonVirtualAdjustment) {
+ NonVirtualAdjustment = NonVirtualAdjustment2;
+ }
+
if (NonVirtualAdjustment) {
ThunkAdjustment ThisAdjustment(NonVirtualAdjustment, 0);
Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=94592&r1=94591&r2=94592&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Tue Jan 26 15:35:27 2010
@@ -402,8 +402,8 @@
// CHECK-LP64-NEXT: .quad __ZN8test16_B5foo_BEv
// CHECK-LP64-NEXT: .quad -48
// CHECK-LP64-NEXT: .quad __ZTI8test16_D
-// CHECK-LP64-NEXT .quad __ZTcvn16_n40_v16_n32_N8test16_D4foo1Ev
-// CHECK-LP64: .quad __ZN10test16_NV27foo_NV2Ev
+// CHECK-LP64-NEXT: .quad __ZTcvn16_n40_v16_n32_N8test16_D4foo1Ev
+// CHECK-LP64-NEXT: .quad __ZN10test16_NV27foo_NV2Ev
// CHECK-LP64-NEXT: .quad __ZN10test16_NV28foo_NV2bEv
More information about the cfe-commits
mailing list