]> granicus.if.org Git - clang/commitdiff
Add a global CreateGlobalInitOrDestructFunction and use it for creating global init...
authorAnders Carlsson <andersca@mac.com>
Tue, 8 Jun 2010 22:40:05 +0000 (22:40 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 8 Jun 2010 22:40:05 +0000 (22:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105649 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDeclCXX.cpp

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