Mark vector ctpop, cttz, and ctlz as Expand on x86.
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.cpp
index 7e7dc8861a7c48206d41ebd03ea3a43a754f1906..17bcaac90c3f8b67143725cedf823c495b64994f 100644 (file)
@@ -115,14 +115,18 @@ void X86SharedAsmPrinter::decorateName(std::string &Name,
 
 /// doInitialization
 bool X86SharedAsmPrinter::doInitialization(Module &M) {
-  if (Subtarget->isTargetELF() ||
-      Subtarget->isTargetCygMing() ||
-      Subtarget->isTargetDarwin()) {
+  if (TAI->doesSupportDebugInformation()) {
     // Emit initial debug information.
     DW.BeginModule(&M);
   }
 
-  return AsmPrinter::doInitialization(M);
+  bool Result = AsmPrinter::doInitialization(M);
+
+  // Darwin wants symbols to be quoted if they have complex names.
+  if (Subtarget->isTargetDarwin())
+    Mang->setUseQuotes(true);
+
+  return Result;
 }
 
 bool X86SharedAsmPrinter::doFinalization(Module &M) {
@@ -164,9 +168,9 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     }
     
     if (Subtarget->isTargetELF())
-      O << "\t.type " << name << ",@object\n";
+      O << "\t.type\t" << name << ",@object\n";
     
-    if (C->isNullValue()) {
+    if (C->isNullValue() && !I->hasSection()) {
       if (I->hasExternalLinkage()) {
         if (const char *Directive = TAI->getZeroFillDirective()) {
           O << "\t.globl\t" << name << "\n";
@@ -176,7 +180,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
         }
       }
       
-      if (!I->hasSection() && !I->isThreadLocal() &&
+      if (!I->isThreadLocal() &&
           (I->hasInternalLinkage() || I->hasWeakLinkage() ||
            I->hasLinkOnceLinkage())) {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
@@ -209,7 +213,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
       if (Subtarget->isTargetDarwin()) {
-        O << "\t.globl " << name << "\n"
+        O << "\t.globl\t" << name << "\n"
           << "\t.weak_definition " << name << "\n";
         SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
       } else if (Subtarget->isTargetCygMing()) {
@@ -217,25 +221,25 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
                                 name +
                                 ",\"aw\"");
         SwitchToDataSection(SectionName.c_str(), I);
-        O << "\t.globl " << name << "\n"
+        O << "\t.globl\t" << name << "\n"
           << "\t.linkonce same_size\n";
       } else {
         std::string SectionName("\t.section\t.llvm.linkonce.d." +
                                 name +
                                 ",\"aw\",@progbits");
         SwitchToDataSection(SectionName.c_str(), I);
-        O << "\t.weak " << name << "\n";
+        O << "\t.weak\t" << name << "\n";
       }
       break;
-    case GlobalValue::AppendingLinkage:
-      // FIXME: appending linkage variables should go into a section of
-      // their name or something.  For now, just emit them as external.
     case GlobalValue::DLLExportLinkage:
       DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
       // FALL THROUGH
+    case GlobalValue::AppendingLinkage:
+      // FIXME: appending linkage variables should go into a section of
+      // their name or something.  For now, just emit them as external.
     case GlobalValue::ExternalLinkage:
       // If external or appending, declare as a global symbol
-      O << "\t.globl " << name << "\n";
+      O << "\t.globl\t" << name << "\n";
       // FALL THROUGH
     case GlobalValue::InternalLinkage: {
       if (I->isConstant()) {
@@ -301,7 +305,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
       << "\n";
     if (TAI->hasDotTypeDotSizeDirective())
-      O << "\t.size " << name << ", " << Size << "\n";
+      O << "\t.size\t" << name << ", " << Size << "\n";
     // If the initializer is a extern weak symbol, remember to emit the weak
     // reference!
     if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
@@ -309,11 +313,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
         ExtWeakSymbols.insert(GV);
 
     EmitGlobalConstant(C);
-    O << '\n';
   }
   
   // Output linker support code for dllexported globals
-  if (DLLExportedGVs.begin() != DLLExportedGVs.end()) {
+  if (!DLLExportedGVs.empty()) {
     SwitchToDataSection(".section .drectve");
   }
 
@@ -323,7 +326,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     O << "\t.ascii \" -export:" << *i << ",data\"\n";
   }    
 
-  if (DLLExportedFns.begin() != DLLExportedFns.end()) {
+  if (!DLLExportedFns.empty()) {
     SwitchToDataSection(".section .drectve");
   }
 
@@ -349,8 +352,17 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
 
     O << "\n";
 
+    if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) {
+      // Add the (possibly multiple) personalities to the set of global values.
+      const std::vector<Function *>& Personalities = MMI->getPersonalities();
+
+      for (std::vector<Function *>::const_iterator I = Personalities.begin(),
+             E = Personalities.end(); I != E; ++I)
+        if (*I) GVStubs.insert("_" + (*I)->getName());
+    }
+
     // Output stubs for external and common global variables.
-    if (GVStubs.begin() != GVStubs.end())
+    if (!GVStubs.empty())
       SwitchToDataSection(
                     ".section __IMPORT,__pointers,non_lazy_symbol_pointers");
     for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
@@ -386,8 +398,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     DW.EndModule();
   }
 
-  AsmPrinter::doFinalization(M);
-  return false; // success
+  return AsmPrinter::doFinalization(M);
 }
 
 /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code