diff options
author | John McCall <rjmccall@apple.com> | 2010-08-31 07:33:07 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-08-31 07:33:07 +0000 |
commit | 4c40d98ab7acf5f27fa89b17bd8fc0ef7683df37 (patch) | |
tree | d4d40dc8719612b86724f6df0f0850057ec3b843 /lib/CodeGen/CodeGenFunction.cpp | |
parent | 1baf2f778c26a71d1353ff2cc1701fcd1dbeaf76 (diff) |
Teach IR generation to return 'this' from constructors and destructors
under the ARM ABI.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112588 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 13ad034a0d..51d084e1d3 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -13,6 +13,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "CGCXXABI.h" #include "CGDebugInfo.h" #include "CGException.h" #include "clang/Basic/TargetInfo.h" @@ -48,7 +49,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) Exceptions = getContext().getLangOptions().Exceptions; CatchUndefined = getContext().getLangOptions().CatchUndefined; - CGM.getMangleContext().startNewFunction(); + CGM.getCXXABI().getMangleContext().startNewFunction(); } ASTContext &CodeGenFunction::getContext() const { @@ -56,17 +57,6 @@ ASTContext &CodeGenFunction::getContext() const { } -llvm::Value *CodeGenFunction::GetAddrOfLocalVar(const VarDecl *VD) { - llvm::Value *Res = LocalDeclMap[VD]; - assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!"); - return Res; -} - -llvm::Constant * -CodeGenFunction::GetAddrOfStaticLocalVar(const VarDecl *BVD) { - return cast<llvm::Constant>(GetAddrOfLocalVar(BVD)); -} - const llvm::Type *CodeGenFunction::ConvertTypeForMem(QualType T) { return CGM.getTypes().ConvertTypeForMem(T); } @@ -289,10 +279,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, EmitStartEHSpec(CurCodeDecl); EmitFunctionProlog(*CurFnInfo, CurFn, Args); - if (CXXThisDecl) - CXXThisValue = Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this"); - if (CXXVTTDecl) - CXXVTTValue = Builder.CreateLoad(LocalDeclMap[CXXVTTDecl], "vtt"); + if (D && isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance()) + CGM.getCXXABI().EmitInstanceFunctionProlog(*this); // If any of the arguments have a variably modified type, make sure to // emit the type size. @@ -336,30 +324,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { DebugInfo = CGM.getDebugInfo(); FunctionArgList Args; + QualType ResTy = FD->getResultType(); CurGD = GD; - if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { - if (MD->isInstance()) { - // Create the implicit 'this' decl. - // FIXME: I'm not entirely sure I like using a fake decl just for code - // generation. Maybe we can come up with a better way? - CXXThisDecl = ImplicitParamDecl::Create(getContext(), 0, - FD->getLocation(), - &getContext().Idents.get("this"), - MD->getThisType(getContext())); - Args.push_back(std::make_pair(CXXThisDecl, CXXThisDecl->getType())); - - // Check if we need a VTT parameter as well. - if (CodeGenVTables::needsVTTParameter(GD)) { - // FIXME: The comment about using a fake decl above applies here too. - QualType T = getContext().getPointerType(getContext().VoidPtrTy); - CXXVTTDecl = - ImplicitParamDecl::Create(getContext(), 0, FD->getLocation(), - &getContext().Idents.get("vtt"), T); - Args.push_back(std::make_pair(CXXVTTDecl, CXXVTTDecl->getType())); - } - } - } + if (isa<CXXMethodDecl>(FD) && cast<CXXMethodDecl>(FD)->isInstance()) + CGM.getCXXABI().BuildInstanceFunctionParams(*this, ResTy, Args); if (FD->getNumParams()) { const FunctionProtoType* FProto = FD->getType()->getAs<FunctionProtoType>(); @@ -374,7 +343,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { if (Stmt *Body = FD->getBody()) BodyRange = Body->getSourceRange(); // Emit the standard function prologue. - StartFunction(GD, FD->getResultType(), Fn, Args, BodyRange.getBegin()); + StartFunction(GD, ResTy, Fn, Args, BodyRange.getBegin()); // Generate the body of the function. if (isa<CXXDestructorDecl>(FD)) |