[llvm-commits] CVS: llvm/lib/Target/X86/X86AsmPrinter.cpp

Chris Lattner sabre at nondot.org
Wed Jan 17 09:44:43 PST 2007



Changes in directory llvm/lib/Target/X86:

X86AsmPrinter.cpp updated: 1.229 -> 1.230
---
Log message:

restructure code a bit to make use of continue (simplifying things).  Generalize
the .zerofill directive emission to not be darwin-specific


---
Diffs of the changes:  (+95 -92)

 X86AsmPrinter.cpp |  187 +++++++++++++++++++++++++++---------------------------
 1 files changed, 95 insertions(+), 92 deletions(-)


Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.229 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.230
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.229	Wed Jan 17 04:33:08 2007
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp	Wed Jan 17 11:44:25 2007
@@ -138,18 +138,26 @@
     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 << ", at 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 @@
           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\", at 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\", at 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\", at 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\", at 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 << ", at object\n";
+    EmitGlobalConstant(C);
+    O << '\n';
   }
   
   // Output linker support code for dllexported globals






More information about the llvm-commits mailing list