Use the shared asmprinter code for printing special llvm globals

llvm-svn: 24695
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 13c136f..f3505fb 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -58,6 +58,8 @@
     COMMDirectiveTakesAlignment = false;
     HasDotTypeDotSizeDirective = false;
     forDarwin = true;
+    StaticCtorsSection = ".mod_init_func";
+    StaticDtorsSection = ".mod_term_func";
     break;
   case X86Subtarget::isCygwin:
     GlobalPrefix = "_";
@@ -74,21 +76,6 @@
   return AsmPrinter::doInitialization(M);
 }
 
-/// EmitXXStructorList - Emit the ctor or dtor list.  On darwin, this just 
-/// prints out the function pointers.
-void X86SharedAsmPrinter::EmitXXStructorList(Constant *List) {
-  // Should be an array of '{ int, void ()* }' structs.  The first value is the
-  // init priority, which we ignore.
-  if (!isa<ConstantArray>(List)) return;
-  ConstantArray *InitList = cast<ConstantArray>(List);
-  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
-    if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
-      if (CS->getNumOperands() != 2) return;  // Not array of 2-element structs.
-                                              // Emit the function pointer.
-      EmitGlobalConstant(CS->getOperand(1));
-    }
-}
-
 bool X86SharedAsmPrinter::doFinalization(Module &M) {
   const TargetData &TD = TM.getTargetData();
 
@@ -97,28 +84,9 @@
        E = M.global_end(); I != E; ++I) {
     if (!I->hasInitializer()) continue;   // External global require no code
     
-    // Check to see if this is a special global used by LLVM.
-    if (I->hasAppendingLinkage()) {
-      if (I->getName() == "llvm.used")
-        continue;  // No need to emit this at all.
-      if (I->getName() == "llvm.global_ctors") {
-        if (forDarwin)
-          SwitchSection(".mod_init_func", 0);
-        else
-          SwitchSection(".ctors,\"aw\",@progbits", 0);
-        EmitAlignment(2, 0);
-        EmitXXStructorList(I->getInitializer());
-        continue;
-      } else if (I->getName() == "llvm.global_dtors") {
-        if (forDarwin)
-          SwitchSection(".mod_term_func", 0);
-        else
-          SwitchSection(".dtors,\"aw\",@progbits", 0);
-        EmitAlignment(2, 0);
-        EmitXXStructorList(I->getInitializer());
-        continue;
-      }
-    }
+    // Check to see if this is a special global used by LLVM, if so, emit it.
+    if (I->hasAppendingLinkage() && EmitSpecialLLVMGlobal(I))
+      continue;
     
     O << "\n\n";
     std::string name = Mang->getValueName(I);