aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-11 00:07:24 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-11 00:07:24 +0000
commit0ff8bafde95f6fa51ccea70738c1b99db870bddc (patch)
treeb290b7d3e83628560c4f13023792a630f679e424 /lib/CodeGen
parent555b4bb2749aea2ec8e2adc351a71ec1cb9bdc33 (diff)
Pass GlobalDecls to GenerateCode and StartFunction.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81485 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGCXX.cpp31
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp25
-rw-r--r--lib/CodeGen/CodeGenFunction.h11
-rw-r--r--lib/CodeGen/CodeGenModule.h13
4 files changed, 45 insertions, 35 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index e169881eec..e739a9ce6c 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/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<CXXConstructorDecl>(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<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::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<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();
}
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 05f94371cb..d42d0723fa 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/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<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 @@ 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<CXXConstructorDecl>(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<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)
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 07804a9396..c7aefb64e2 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/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/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index d5b0bfa6a8..c8ac249540 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/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<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 @@ 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)