[cfe-commits] r90561 - /cfe/trunk/lib/CodeGen/CGVtable.cpp
Eli Friedman
eli.friedman at gmail.com
Fri Dec 4 00:34:14 PST 2009
Author: efriedma
Date: Fri Dec 4 02:34:14 2009
New Revision: 90561
URL: http://llvm.org/viewvc/llvm-project?rev=90561&view=rev
Log:
Eliminate the inner loop in VtableBuilder::OverrideMethod.
Modified:
cfe/trunk/lib/CodeGen/CGVtable.cpp
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=90561&r1=90560&r2=90561&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Fri Dec 4 02:34:14 2009
@@ -92,6 +92,10 @@
MethodToIndexMap[GD] = Index;
}
+ bool hasIndex(GlobalDecl GD) const {
+ return MethodToIndexMap.count(GD);
+ }
+
/// getIndex - Returns the index of the given method.
uint64_t getIndex(GlobalDecl GD) const {
assert(MethodToIndexMap.count(GD) && "Did not find method!");
@@ -747,90 +751,82 @@
OGD = GlobalDecl(DD, GD.getDtorType());
else
OGD = OMD;
-
- llvm::Constant *om;
- om = WrapAddrOf(OGD);
- om = llvm::ConstantExpr::getBitCast(om, Ptr8Ty);
-
- for (Index_t i = 0, e = submethods.size();
- i != e; ++i) {
- if (submethods[i] != om)
- continue;
- uint64_t Index = Methods.getIndex(OGD);
+ // FIXME: Explain why this is necessary!
+ if (!Methods.hasIndex(OGD))
+ continue;
- assert(i == Index);
-
- QualType ReturnType =
- MD->getType()->getAs<FunctionType>()->getResultType();
- QualType OverriddenReturnType =
- OMD->getType()->getAs<FunctionType>()->getResultType();
+ uint64_t Index = Methods.getIndex(OGD);
- // Check if we need a return type adjustment.
- if (TypeConversionRequiresAdjustment(CGM.getContext(), ReturnType,
- OverriddenReturnType)) {
- CanQualType &BaseReturnType = BaseReturnTypes[i];
-
- // Get the canonical return type.
- CanQualType CanReturnType =
- CGM.getContext().getCanonicalType(ReturnType);
-
- // Insert the base return type.
- if (BaseReturnType.isNull())
- BaseReturnType =
- CGM.getContext().getCanonicalType(OverriddenReturnType);
+ QualType ReturnType =
+ MD->getType()->getAs<FunctionType>()->getResultType();
+ QualType OverriddenReturnType =
+ OMD->getType()->getAs<FunctionType>()->getResultType();
+
+ // Check if we need a return type adjustment.
+ if (TypeConversionRequiresAdjustment(CGM.getContext(), ReturnType,
+ OverriddenReturnType)) {
+ CanQualType &BaseReturnType = BaseReturnTypes[Index];
+
+ // Get the canonical return type.
+ CanQualType CanReturnType =
+ CGM.getContext().getCanonicalType(ReturnType);
+
+ // Insert the base return type.
+ if (BaseReturnType.isNull())
+ BaseReturnType =
+ CGM.getContext().getCanonicalType(OverriddenReturnType);
+ }
+
+ Methods.OverrideMethod(OGD, GD);
+
+ submethods[Index] = m;
+ ThisAdjustments.erase(Index);
+ if (MorallyVirtual || VCall.count(OGD)) {
+ Index_t &idx = VCall[OGD];
+ if (idx == 0) {
+ NonVirtualOffset[GD] = -OverrideOffset/8 + CurrentVBaseOffset/8;
+ VCallOffset[GD] = OverrideOffset/8;
+ idx = VCalls.size()+1;
+ VCalls.push_back(0);
+ D1(printf(" vcall for %s at %d with delta %d most derived %s\n",
+ MD->getNameAsString().c_str(), (int)-idx-3,
+ (int)VCalls[idx-1], Class->getNameAsCString()));
+ } else {
+ NonVirtualOffset[GD] = NonVirtualOffset[OGD];
+ VCallOffset[GD] = VCallOffset[OGD];
+ VCalls[idx-1] = -VCallOffset[OGD] + 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], Class->getNameAsCString()));
}
+ VCall[GD] = idx;
+ int64_t NonVirtualAdjustment = NonVirtualOffset[GD];
+ int64_t VirtualAdjustment =
+ -((idx + extra + 2) * LLVMPointerWidth / 8);
+
+ // Optimize out virtual adjustments of 0.
+ if (VCalls[idx-1] == 0)
+ VirtualAdjustment = 0;
+
+ ThunkAdjustment ThisAdjustment(NonVirtualAdjustment,
+ VirtualAdjustment);
- Methods.OverrideMethod(OGD, GD);
-
- submethods[Index] = m;
- ThisAdjustments.erase(i);
- if (MorallyVirtual || VCall.count(OGD)) {
- Index_t &idx = VCall[OGD];
- if (idx == 0) {
- NonVirtualOffset[GD] = -OverrideOffset/8 + CurrentVBaseOffset/8;
- VCallOffset[GD] = OverrideOffset/8;
- idx = VCalls.size()+1;
- VCalls.push_back(0);
- D1(printf(" vcall for %s at %d with delta %d most derived %s\n",
- MD->getNameAsString().c_str(), (int)-idx-3,
- (int)VCalls[idx-1], Class->getNameAsCString()));
- } else {
- NonVirtualOffset[GD] = NonVirtualOffset[OGD];
- VCallOffset[GD] = VCallOffset[OGD];
- VCalls[idx-1] = -VCallOffset[OGD] + 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], Class->getNameAsCString()));
- }
- VCall[GD] = idx;
- int64_t NonVirtualAdjustment = NonVirtualOffset[GD];
- int64_t VirtualAdjustment =
- -((idx + extra + 2) * LLVMPointerWidth / 8);
-
- // Optimize out virtual adjustments of 0.
- if (VCalls[idx-1] == 0)
- VirtualAdjustment = 0;
-
- ThunkAdjustment ThisAdjustment(NonVirtualAdjustment,
- VirtualAdjustment);
-
- if (!isPure && !ThisAdjustment.isEmpty())
- ThisAdjustments[Index] = ThisAdjustment;
- return true;
- }
+ if (!isPure && !ThisAdjustment.isEmpty())
+ ThisAdjustments[Index] = ThisAdjustment;
+ return true;
+ }
- // FIXME: finish off
- int64_t NonVirtualAdjustment = VCallOffset[OGD] - OverrideOffset/8;
+ // FIXME: finish off
+ int64_t NonVirtualAdjustment = VCallOffset[OGD] - OverrideOffset/8;
- if (NonVirtualAdjustment) {
- ThunkAdjustment ThisAdjustment(NonVirtualAdjustment, 0);
-
- if (!isPure)
- ThisAdjustments[Index] = ThisAdjustment;
- }
- return true;
+ if (NonVirtualAdjustment) {
+ ThunkAdjustment ThisAdjustment(NonVirtualAdjustment, 0);
+
+ if (!isPure)
+ ThisAdjustments[Index] = ThisAdjustment;
}
+ return true;
}
return false;
More information about the cfe-commits
mailing list