[cfe-commits] r99866 - in /cfe/trunk/lib/CodeGen: CGClass.cpp CodeGenFunction.h
Anders Carlsson
andersca at mac.com
Mon Mar 29 20:27:09 PDT 2010
Author: andersca
Date: Mon Mar 29 22:27:09 2010
New Revision: 99866
URL: http://llvm.org/viewvc/llvm-project?rev=99866&view=rev
Log:
Factor emitting a call to a copy constructor out into a separate function.
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=99866&r1=99865&r2=99866&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Mar 29 22:27:09 2010
@@ -308,6 +308,53 @@
return Value;
}
+/// EmitCopyCtorCall - Emit a call to a copy constructor.
+static void
+EmitCopyCtorCall(CodeGenFunction &CGF,
+ const CXXConstructorDecl *CopyCtor, CXXCtorType CopyCtorType,
+ llvm::Value *ThisPtr, llvm::Value *VTT, llvm::Value *Src) {
+ llvm::Value *Callee = CGF.CGM.GetAddrOfCXXConstructor(CopyCtor, CopyCtorType);
+
+ CallArgList CallArgs;
+
+ // Push the this ptr.
+ CallArgs.push_back(std::make_pair(RValue::get(ThisPtr),
+ CopyCtor->getThisType(CGF.getContext())));
+
+ // Push the VTT parameter if necessary.
+ if (VTT) {
+ QualType T = CGF.getContext().getPointerType(CGF.getContext().VoidPtrTy);
+ CallArgs.push_back(std::make_pair(RValue::get(VTT), T));
+ }
+
+ // Push the Src ptr.
+ CallArgs.push_back(std::make_pair(RValue::get(Src),
+ CopyCtor->getParamDecl(0)->getType()));
+
+
+ {
+ CodeGenFunction::CXXTemporariesCleanupScope Scope(CGF);
+
+ // If the copy constructor has default arguments, emit them.
+ for (unsigned I = 1, E = CopyCtor->getNumParams(); I < E; ++I) {
+ const ParmVarDecl *Param = CopyCtor->getParamDecl(I);
+ const Expr *DefaultArgExpr = Param->getDefaultArg();
+
+ assert(DefaultArgExpr && "Ctor parameter must have default arg!");
+
+ QualType ArgType = Param->getType();
+ CallArgs.push_back(std::make_pair(CGF.EmitCallArg(DefaultArgExpr,
+ ArgType),
+ ArgType));
+ }
+
+ const FunctionProtoType *FPT =
+ CopyCtor->getType()->getAs<FunctionProtoType>();
+ CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(CallArgs, FPT),
+ Callee, ReturnValueSlot(), CallArgs, CopyCtor);
+ }
+}
+
/// EmitClassAggrMemberwiseCopy - This routine generates code to copy a class
/// array of objects from SrcValue to DestValue. Copying can be either a bitwise
/// copy or via a copy constructor call.
@@ -531,47 +578,13 @@
return;
}
- if (CXXConstructorDecl *BaseCopyCtor =
- BaseClassDecl->getCopyConstructor(getContext(), 0)) {
- llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(BaseCopyCtor, CtorType);
- CallArgList CallArgs;
- // Push the this (Dest) ptr.
- CallArgs.push_back(std::make_pair(RValue::get(Dest),
- BaseCopyCtor->getThisType(getContext())));
-
- // Push the VTT parameter, if necessary.
- if (llvm::Value *VTT =
- GetVTTParameter(*this, GlobalDecl(BaseCopyCtor, CtorType))) {
- QualType T = getContext().getPointerType(getContext().VoidPtrTy);
- CallArgs.push_back(std::make_pair(RValue::get(VTT), T));
- }
-
- // Push the Src ptr.
- CallArgs.push_back(std::make_pair(RValue::get(Src),
- BaseCopyCtor->getParamDecl(0)->getType()));
-
- {
- CXXTemporariesCleanupScope Scope(*this);
-
- // If the copy constructor has default arguments, emit them.
- for (unsigned I = 1, E = BaseCopyCtor->getNumParams(); I < E; ++I) {
- const ParmVarDecl *Param = BaseCopyCtor->getParamDecl(I);
- const Expr *DefaultArgExpr = Param->getDefaultArg();
-
- assert(DefaultArgExpr && "Ctor parameter must have default arg!");
-
- QualType ArgType = Param->getType();
- CallArgs.push_back(std::make_pair(EmitCallArg(DefaultArgExpr, ArgType),
- ArgType));
-
- }
+ CXXConstructorDecl *BaseCopyCtor =
+ BaseClassDecl->getCopyConstructor(getContext(), 0);
+ if (!BaseCopyCtor)
+ return;
- const FunctionProtoType *FPT =
- BaseCopyCtor->getType()->getAs<FunctionProtoType>();
- EmitCall(CGM.getTypes().getFunctionInfo(CallArgs, FPT),
- Callee, ReturnValueSlot(), CallArgs, BaseCopyCtor);
- }
- }
+ llvm::Value *VTT = GetVTTParameter(*this, GlobalDecl(BaseCopyCtor, CtorType));
+ EmitCopyCtorCall(*this, BaseCopyCtor, CtorType, Dest, VTT, Src);
}
/// EmitClassCopyAssignment - This routine generates code to copy assign a class
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=99866&r1=99865&r2=99866&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Mar 29 22:27:09 2010
@@ -1292,6 +1292,10 @@
/// getTrapBB - Create a basic block that will call the trap intrinsic. We'll
/// generate a branch around the created basic block as necessary.
llvm::BasicBlock* getTrapBB();
+
+ /// EmitCallArg - Emit a single call argument.
+ RValue EmitCallArg(const Expr *E, QualType ArgType);
+
private:
void EmitReturnOfRValue(RValue RV, QualType Ty);
@@ -1323,9 +1327,6 @@
/// current cleanup scope.
void AddBranchFixup(llvm::BranchInst *BI);
- /// EmitCallArg - Emit a single call argument.
- RValue EmitCallArg(const Expr *E, QualType ArgType);
-
/// EmitCallArgs - Emit call arguments for a function.
/// The CallArgTypeInfo parameter is used for iterating over the known
/// argument types of the function being called.
More information about the cfe-commits
mailing list