restructure code a bit to make use of continue (simplifying things). Generalize
authorChris Lattner <sabre@nondot.org>
Wed, 17 Jan 2007 17:44:25 +0000 (17:44 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 17 Jan 2007 17:44:25 +0000 (17:44 +0000)
the .zerofill directive emission to not be darwin-specific

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33304 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86AsmPrinter.cpp

index bea3914fe649be3752c28655937186af58546e7d..de12d7cdeec111b6441d46e5e380bf23b7283bd6 100644 (file)
@@ -138,18 +138,26 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     unsigned Size = TD->getTypeSize(C->getType());
     unsigned Align = TD->getPreferredAlignmentLog(I);
 
-    if (C->isNullValue() && /* FIXME: Verify correct */
-        !I->hasSection() &&
-        (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-         I->hasLinkOnceLinkage() ||
-         (Subtarget->isTargetDarwin() && 
-          I->hasExternalLinkage()))) {
-      if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
+    if (I->hasHiddenVisibility())
+      if (const char *Directive = TAI->getHiddenDirective())
+        O << Directive << name << "\n";
+    if (Subtarget->isTargetELF())
+      O << "\t.type " << name << ",@object\n";
+    
+    if (C->isNullValue()) {
       if (I->hasExternalLinkage()) {
+        if (const char *Directive = TAI->getZeroFillDirective()) {
           O << "\t.globl\t" << name << "\n";
-          O << "\t.zerofill __DATA__, __common, " << name << ", "
+          O << Directive << "__DATA__, __common, " << name << ", "
             << Size << ", " << Align;
-      } else {
+          continue;
+        }
+      }
+      
+      if (!I->hasSection() &&
+          (I->hasInternalLinkage() || I->hasWeakLinkage() ||
+           I->hasLinkOnceLinkage())) {
+        if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (!NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(TAI->getBSSSection(), I);
         else
@@ -170,96 +178,91 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
           if (TAI->getCOMMDirectiveTakesAlignment())
             O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
         }
+        O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
+        continue;
       }
-      O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
-    } else {
-      switch (I->getLinkage()) {
-      case GlobalValue::LinkOnceLinkage:
-      case GlobalValue::WeakLinkage:
-        if (Subtarget->isTargetDarwin()) {
-          O << "\t.globl " << name << "\n"
-            << "\t.weak_definition " << name << "\n";
-          SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
-        } else if (Subtarget->isTargetCygMing()) {
-          std::string SectionName(".section\t.data$linkonce." +
-                                  name +
-                                  ",\"aw\"");
-          SwitchToDataSection(SectionName.c_str(), I);
-          O << "\t.globl " << 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";
-        }
-        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::ExternalLinkage:
-        // If external or appending, declare as a global symbol
-        O << "\t.globl " << name << "\n";
-        // FALL THROUGH
-      case GlobalValue::InternalLinkage: {
-        if (I->isConstant()) {
-          const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
-          if (TAI->getCStringSection() && CVA && CVA->isCString()) {
-            SwitchToDataSection(TAI->getCStringSection(), I);
-            break;
-          }
-        }
-        // FIXME: special handling for ".ctors" & ".dtors" sections
-        if (I->hasSection() &&
-            (I->getSection() == ".ctors" ||
-             I->getSection() == ".dtors")) {
-          std::string SectionName = ".section " + I->getSection();
-          
-          if (Subtarget->isTargetCygMing()) {
-            SectionName += ",\"aw\"";
-          } else {
-            assert(!Subtarget->isTargetDarwin());
-            SectionName += ",\"aw\",@progbits";
-          }
+    }
 
-          SwitchToDataSection(SectionName.c_str());
-        } else {
-          if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
-            SwitchToDataSection(TAI->getBSSSection(), I);
-          else
-            SwitchToDataSection(TAI->getDataSection(), I);
+    switch (I->getLinkage()) {
+    case GlobalValue::LinkOnceLinkage:
+    case GlobalValue::WeakLinkage:
+      if (Subtarget->isTargetDarwin()) {
+        O << "\t.globl " << name << "\n"
+          << "\t.weak_definition " << name << "\n";
+        SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
+      } else if (Subtarget->isTargetCygMing()) {
+        std::string SectionName(".section\t.data$linkonce." +
+                                name +
+                                ",\"aw\"");
+        SwitchToDataSection(SectionName.c_str(), I);
+        O << "\t.globl " << 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";
+      }
+      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::ExternalLinkage:
+      // If external or appending, declare as a global symbol
+      O << "\t.globl " << name << "\n";
+      // FALL THROUGH
+    case GlobalValue::InternalLinkage: {
+      if (I->isConstant()) {
+        const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+        if (TAI->getCStringSection() && CVA && CVA->isCString()) {
+          SwitchToDataSection(TAI->getCStringSection(), I);
+          break;
         }
-        
-        break;
       }
-      default:
-        assert(0 && "Unknown linkage type!");
+      // FIXME: special handling for ".ctors" & ".dtors" sections
+      if (I->hasSection() &&
+          (I->getSection() == ".ctors" ||
+           I->getSection() == ".dtors")) {
+        std::string SectionName = ".section " + I->getSection();
+        
+        if (Subtarget->isTargetCygMing()) {
+          SectionName += ",\"aw\"";
+        } else {
+          assert(!Subtarget->isTargetDarwin());
+          SectionName += ",\"aw\",@progbits";
+        }
+
+        SwitchToDataSection(SectionName.c_str());
+      } else {
+        if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
+          SwitchToDataSection(TAI->getBSSSection(), I);
+        else
+          SwitchToDataSection(TAI->getDataSection(), I);
       }
+      
+      break;
+    }
+    default:
+      assert(0 && "Unknown linkage type!");
+    }
 
-      EmitAlignment(Align, I);
-      O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
-        << "\n";
-      if (TAI->hasDotTypeDotSizeDirective())
-        O << "\t.size " << 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))
-        if (GV->hasExternalWeakLinkage())
-          ExtWeakSymbols.insert(GV);
+    EmitAlignment(Align, I);
+    O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
+      << "\n";
+    if (TAI->hasDotTypeDotSizeDirective())
+      O << "\t.size " << 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))
+      if (GV->hasExternalWeakLinkage())
+        ExtWeakSymbols.insert(GV);
 
-      EmitGlobalConstant(C);
-      O << '\n';
-    }
-    if (I->hasHiddenVisibility())
-      if (const char *Directive = TAI->getHiddenDirective())
-        O << Directive << name << "\n";
-    
-    if (Subtarget->isTargetELF())
-      O << "\t.type " << name << ",@object\n";
+    EmitGlobalConstant(C);
+    O << '\n';
   }
   
   // Output linker support code for dllexported globals