[cfe-commits] r81485 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CodeGenFunction.cpp CodeGenFunction.h CodeGenModule.h
Anders Carlsson
andersca at mac.com
Thu Sep 10 17:07:24 PDT 2009
Author: andersca
Date: Thu Sep 10 19:07:24 2009
New Revision: 81485
URL: http://llvm.org/viewvc/llvm-project?rev=81485&view=rev
Log:
Pass GlobalDecls to GenerateCode and StartFunction.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=81485&r1=81484&r2=81485&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Sep 10 19:07:24 2009
@@ -114,7 +114,7 @@
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 @@
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 @@
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 @@
/// 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<CXXConstructorDecl>(GD.getDecl());
+
+ StartFunction(GD, FD->getResultType(), Fn, Args, SourceLocation());
+ EmitCtorPrologue(Ctor);
FinishFunction();
}
@@ -1572,14 +1574,15 @@
/// 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<CXXRecordDecl>(CD->getDeclContext());
+ const CXXConstructorDecl *Ctor = cast<CXXConstructorDecl>(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::SynthesizeDefaultDestructor(const CXXDestructorDecl *CD,
+void CodeGenFunction::SynthesizeDefaultDestructor(GlobalDecl GD,
const FunctionDecl *FD,
llvm::Function *Fn,
const FunctionArgList &Args) {
- const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext());
+ const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(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();
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=81485&r1=81484&r2=81485&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu Sep 10 19:07:24 2009
@@ -141,10 +141,12 @@
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::GenerateCode(const FunctionDecl *FD,
+void CodeGenFunction::GenerateCode(GlobalDecl GD,
llvm::Function *Fn) {
+ const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
+
// Check if we should generate debug info for this function.
if (CGM.getDebugInfo() && !FD->hasAttr<NoDebugAttr>())
DebugInfo = CGM.getDebugInfo();
@@ -230,7 +234,7 @@
// 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<CXXConstructorDecl>(FD))
EmitCtorPrologue(CD);
EmitStmt(S);
@@ -246,19 +250,20 @@
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<CXXDestructorDecl>(FD))
- SynthesizeDefaultDestructor(DD, FD, Fn, Args);
- else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
- if (MD->isCopyAssignment())
- SynthesizeCXXCopyAssignment(MD, FD, Fn, Args);
+ else if (isa<CXXDestructorDecl>(FD))
+ SynthesizeDefaultDestructor(GD, FD, Fn, Args);
+ else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
+ if (MD->isCopyAssignment())
+ SynthesizeCXXCopyAssignment(MD, FD, Fn, Args);
+ }
// Destroy the 'this' declaration.
if (CXXThisDecl)
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=81485&r1=81484&r2=81485&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Sep 10 19:07:24 2009
@@ -345,9 +345,8 @@
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 @@
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 @@
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);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=81485&r1=81484&r2=81485&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Sep 10 19:07:24 2009
@@ -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 @@
class GlobalDecl {
llvm::PointerIntPair<const Decl*, 2> Value;
- void init(const Decl *D) {
+ void Init(const Decl *D) {
assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
- assert(isa<VarDecl>(D) || isa<FunctionDecl>(D)
- && "Invalid decl type passed to GlobalDecl ctor!");
Value.setPointer(D);
}
@@ -86,9 +85,11 @@
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)
More information about the cfe-commits
mailing list