forked from OSchip/llvm-project
Pass GlobalDecls to GenerateCode and StartFunction.
llvm-svn: 81485
This commit is contained in:
parent
11ff570292
commit
73fcc95f0f
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,8 +85,10 @@ 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) {}
|
||||
|
|
Loading…
Reference in New Issue