Add a global CreateGlobalInitOrDestructFunction and use it for creating global init or destruction functions.

llvm-svn: 105649
This commit is contained in:
Anders Carlsson
2010-06-08 22:40:05 +00:00
parent 9eb101c5d3
commit b2839e4aa1

View File

@@ -143,6 +143,17 @@ CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args)); Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
} }
static llvm::Function *
CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
const llvm::FunctionType *FTy,
llvm::StringRef Name) {
llvm::Function *Fn =
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
Name, &CGM.getModule());
return Fn;
}
void void
CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D) { CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D) {
const llvm::FunctionType *FTy const llvm::FunctionType *FTy
@@ -151,8 +162,7 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D) {
// Create a variable initialization function. // Create a variable initialization function.
llvm::Function *Fn = llvm::Function *Fn =
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
"__cxx_global_var_init", &TheModule);
CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D); CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D);
@@ -169,9 +179,8 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
false); false);
// Create our global initialization function. // Create our global initialization function.
llvm::Function *Fn = llvm::Function *Fn =
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
"_GLOBAL__I_a", &TheModule);
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
&CXXGlobalInits[0], &CXXGlobalInits[0],
@@ -194,8 +203,7 @@ void CodeGenModule::EmitCXXGlobalDtorFunc() {
// Create our global destructor function. // Create our global destructor function.
llvm::Function *Fn = llvm::Function *Fn =
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
"_GLOBAL__D_a", &TheModule);
CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors); CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
AddGlobalDtor(Fn); AddGlobalDtor(Fn);
@@ -440,10 +448,8 @@ CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args, CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args,
FunctionType::ExtInfo()); FunctionType::ExtInfo());
const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false); const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
llvm::Function *Fn = llvm::Function *Fn =
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
"__cxx_global_array_dtor",
&CGM.getModule());
StartFunction(GlobalDecl(), getContext().VoidTy, Fn, Args, SourceLocation()); StartFunction(GlobalDecl(), getContext().VoidTy, Fn, Args, SourceLocation());