From 73fcc95f0fdebdae62dbef9174b8a775c01affe9 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 11 Sep 2009 00:07:24 +0000 Subject: [PATCH] Pass GlobalDecls to GenerateCode and StartFunction. llvm-svn: 81485 --- clang/lib/CodeGen/CGCXX.cpp | 31 ++++++++++++++++----------- clang/lib/CodeGen/CodeGenFunction.cpp | 25 ++++++++++++--------- clang/lib/CodeGen/CodeGenFunction.h | 11 +++++----- clang/lib/CodeGen/CodeGenModule.h | 13 +++++------ 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index e169881eeca1..e739a9ce6c9a 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -114,7 +114,7 @@ CodeGenModule::EmitCXXGlobalInitFunc() { void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, const VarDecl **Decls, unsigned NumDecls) { - StartFunction(0, getContext().VoidTy, Fn, FunctionArgList(), + StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(), SourceLocation()); for (unsigned i = 0; i != NumDecls; ++i) { @@ -714,7 +714,7 @@ void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D, llvm::Function *Fn = GetAddrOfCXXConstructor(D, Type); - CodeGenFunction(*this).GenerateCode(D, Fn); + CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn); SetFunctionDefinitionAttributes(D, Fn); SetLLVMFunctionAttributesForDefinition(D, Fn); @@ -750,7 +750,7 @@ void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type) { llvm::Function *Fn = GetAddrOfCXXDestructor(D, Type); - CodeGenFunction(*this).GenerateCode(D, Fn); + CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn); SetFunctionDefinitionAttributes(D, Fn); SetLLVMFunctionAttributesForDefinition(D, Fn); @@ -1548,12 +1548,14 @@ void CodeGenFunction::EmitClassCopyAssignment( /// SynthesizeDefaultConstructor - synthesize a default constructor void -CodeGenFunction::SynthesizeDefaultConstructor(const CXXConstructorDecl *CD, +CodeGenFunction::SynthesizeDefaultConstructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args) { - StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation()); - EmitCtorPrologue(CD); + const CXXConstructorDecl *Ctor = cast(GD.getDecl()); + + StartFunction(GD, FD->getResultType(), Fn, Args, SourceLocation()); + EmitCtorPrologue(Ctor); FinishFunction(); } @@ -1572,14 +1574,15 @@ CodeGenFunction::SynthesizeDefaultConstructor(const CXXConstructorDecl *CD, /// Virtual base class subobjects shall be copied only once by the /// implicitly-defined copy constructor -void CodeGenFunction::SynthesizeCXXCopyConstructor(const CXXConstructorDecl *CD, +void CodeGenFunction::SynthesizeCXXCopyConstructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args) { - const CXXRecordDecl *ClassDecl = cast(CD->getDeclContext()); + const CXXConstructorDecl *Ctor = cast(GD.getDecl()); + const CXXRecordDecl *ClassDecl = Ctor->getParent(); assert(!ClassDecl->hasUserDeclaredCopyConstructor() && "SynthesizeCXXCopyConstructor - copy constructor has definition already"); - StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation()); + StartFunction(GD, Ctor->getResultType(), Fn, Args, SourceLocation()); FunctionArgList::const_iterator i = Args.begin(); const VarDecl *ThisArg = i->first; @@ -2003,17 +2006,19 @@ void CodeGenFunction::EmitDtorEpilogue(const CXXDestructorDecl *DD) { } } -void CodeGenFunction::SynthesizeDefaultDestructor(const CXXDestructorDecl *CD, +void CodeGenFunction::SynthesizeDefaultDestructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args) { - const CXXRecordDecl *ClassDecl = cast(CD->getDeclContext()); + const CXXDestructorDecl *Dtor = cast(GD.getDecl()); + + const CXXRecordDecl *ClassDecl = Dtor->getParent(); assert(!ClassDecl->hasUserDeclaredDestructor() && "SynthesizeDefaultDestructor - destructor has user declaration"); (void) ClassDecl; - StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation()); - EmitDtorEpilogue(CD); + StartFunction(GD, Dtor->getResultType(), Fn, Args, SourceLocation()); + EmitDtorEpilogue(Dtor); FinishFunction(); } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 05f94371cb28..d42d0723fa8c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -141,10 +141,12 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { Ptr->eraseFromParent(); } -void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy, +void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, SourceLocation StartLoc) { + const Decl *D = GD.getDecl(); + DidCallStackSave = false; CurCodeDecl = CurFuncDecl = D; FnRetTy = RetTy; @@ -199,8 +201,10 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy, } } -void CodeGenFunction::GenerateCode(const FunctionDecl *FD, +void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { + const FunctionDecl *FD = cast(GD.getDecl()); + // Check if we should generate debug info for this function. if (CGM.getDebugInfo() && !FD->hasAttr()) DebugInfo = CGM.getDebugInfo(); @@ -230,7 +234,7 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, // FIXME: Support CXXTryStmt here, too. if (const CompoundStmt *S = FD->getCompoundBody()) { - StartFunction(FD, FD->getResultType(), Fn, Args, S->getLBracLoc()); + StartFunction(GD, FD->getResultType(), Fn, Args, S->getLBracLoc()); if (const CXXConstructorDecl *CD = dyn_cast(FD)) EmitCtorPrologue(CD); EmitStmt(S); @@ -246,19 +250,20 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, if (CD->isCopyConstructor(getContext())) { assert(!ClassDecl->hasUserDeclaredCopyConstructor() && "bogus constructor is being synthesize"); - SynthesizeCXXCopyConstructor(CD, FD, Fn, Args); + SynthesizeCXXCopyConstructor(GD, FD, Fn, Args); } else { assert(!ClassDecl->hasUserDeclaredConstructor() && "bogus constructor is being synthesize"); - SynthesizeDefaultConstructor(CD, FD, Fn, Args); + SynthesizeDefaultConstructor(GD, FD, Fn, Args); } } - else if (const CXXDestructorDecl *DD = dyn_cast(FD)) - SynthesizeDefaultDestructor(DD, FD, Fn, Args); - else if (const CXXMethodDecl *MD = dyn_cast(FD)) - if (MD->isCopyAssignment()) - SynthesizeCXXCopyAssignment(MD, FD, Fn, Args); + else if (isa(FD)) + SynthesizeDefaultDestructor(GD, FD, Fn, Args); + else if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (MD->isCopyAssignment()) + SynthesizeCXXCopyAssignment(MD, FD, Fn, Args); + } // Destroy the 'this' declaration. if (CXXThisDecl) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 07804a93963e..c7aefb64e201 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -345,9 +345,8 @@ public: llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E); const llvm::Type *BuildByRefType(const ValueDecl *D); - void GenerateCode(const FunctionDecl *FD, - llvm::Function *Fn); - void StartFunction(const Decl *D, QualType RetTy, + void GenerateCode(GlobalDecl GD, llvm::Function *Fn); + void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, SourceLocation StartLoc); @@ -369,7 +368,7 @@ public: void EmitCtorPrologue(const CXXConstructorDecl *CD); - void SynthesizeCXXCopyConstructor(const CXXConstructorDecl *CD, + void SynthesizeCXXCopyConstructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args); @@ -379,12 +378,12 @@ public: llvm::Function *Fn, const FunctionArgList &Args); - void SynthesizeDefaultConstructor(const CXXConstructorDecl *CD, + void SynthesizeDefaultConstructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args); - void SynthesizeDefaultDestructor(const CXXDestructorDecl *CD, + void SynthesizeDefaultDestructor(GlobalDecl GD, const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index d5b0bfa6a8df..c8ac249540ec 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -17,6 +17,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/AST/Attr.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclObjC.h" #include "CGBlocks.h" #include "CGCall.h" #include "CGCXX.h" @@ -74,11 +75,9 @@ namespace CodeGen { class GlobalDecl { llvm::PointerIntPair Value; - void init(const Decl *D) { + void Init(const Decl *D) { assert(!isa(D) && "Use other ctor with ctor decls!"); assert(!isa(D) && "Use other ctor with dtor decls!"); - assert(isa(D) || isa(D) - && "Invalid decl type passed to GlobalDecl ctor!"); Value.setPointer(D); } @@ -86,9 +85,11 @@ class GlobalDecl { public: GlobalDecl() {} - GlobalDecl(const VarDecl *D) { init(D);} - GlobalDecl(const FunctionDecl *D) { init(D); } - + GlobalDecl(const VarDecl *D) { Init(D);} + GlobalDecl(const FunctionDecl *D) { Init(D); } + GlobalDecl(const BlockDecl *D) { Init(D); } + GlobalDecl(const ObjCMethodDecl *D) { Init(D); } + GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {} GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)