[llvm-commits] [llvm] r93847 - in /llvm/trunk: include/llvm/Target/TargetLoweringObjectFile.h lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

Chris Lattner sabre at nondot.org
Mon Jan 18 20:21:20 PST 2010


Author: lattner
Date: Mon Jan 18 22:21:20 2010
New Revision: 93847

URL: http://llvm.org/viewvc/llvm-project?rev=93847&view=rev
Log:
use BSSLocal classifier to identify 'lcomm' data instead of
duplicating the logic (differently) in lots of different targets.

Modified:
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=93847&r1=93846&r2=93847&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Mon Jan 18 22:21:20 2010
@@ -313,12 +313,6 @@
     return ConstTextCoalSection;
   }
   
-  /// getDataCommonSection - Return the "__DATA,__common" section we put
-  /// zerofill (aka bss) data into.
-  bool isDataCommonSection(const MCSection *Section) const {
-    return Section == DataCommonSection;
-  }
-  
   /// getLazySymbolPointerSection - Return the section corresponding to
   /// the .lazy_symbol_pointer directive.
   const MCSection *getLazySymbolPointerSection() const {

Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=93847&r1=93846&r2=93847&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Mon Jan 18 22:21:20 2010
@@ -1220,25 +1220,15 @@
   
   // Handle the zerofill directive on darwin, which is a special form of BSS
   // emission.
-  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
-    TargetLoweringObjectFileMachO &TLOFMacho = 
-      static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
-    if (TLOFMacho.isDataCommonSection(TheSection)) {
-      // .globl _foo
-      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
-      // .zerofill __DATA, __common, _foo, 400, 5
-      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
-      return;
-    }
+  if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
+    // .globl _foo
+    OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+    // .zerofill __DATA, __common, _foo, 400, 5
+    OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+    return;
   }
   
-  OutStreamer.SwitchSection(TheSection);
-
-  // FIXME: get this stuff from section kind flags.
-  if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() &&
-      // Don't put things that should go in the cstring section into "comm".
-      !TheSection->getKind().isMergeableCString() &&
-      (GVar->hasLocalLinkage() || GVar->hasLocalLinkage())) {
+  if (GVKind.isBSSLocal()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     if (isDarwin) {
@@ -1262,6 +1252,8 @@
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::CommonLinkage:
   case GlobalValue::LinkOnceAnyLinkage:

Modified: llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=93847&r1=93846&r2=93847&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Mon Jan 18 22:21:20 2010
@@ -733,10 +733,7 @@
     return;
   }
   
-  OutStreamer.SwitchSection(getObjFileLowering().
-                            SectionForGlobal(GVar, GVKind, Mang, TM));
-
-  if (C->isNullValue() && !GVar->hasSection() && GVar->hasLocalLinkage()) {
+  if (GVKind.isBSSLocal()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size;
@@ -750,28 +747,30 @@
     return;
   }
 
+  OutStreamer.SwitchSection(getObjFileLowering().
+                            SectionForGlobal(GVar, GVKind, Mang, TM));
+  
   switch (GVar->getLinkage()) {
-   case GlobalValue::LinkOnceAnyLinkage:
-   case GlobalValue::LinkOnceODRLinkage:
-   case GlobalValue::WeakAnyLinkage:
-   case GlobalValue::WeakODRLinkage:
-   case GlobalValue::CommonLinkage:
-   case GlobalValue::LinkerPrivateLinkage:
+  case GlobalValue::LinkOnceAnyLinkage:
+  case GlobalValue::LinkOnceODRLinkage:
+  case GlobalValue::WeakAnyLinkage:
+  case GlobalValue::WeakODRLinkage:
+  case GlobalValue::LinkerPrivateLinkage:
     O << "\t.global " << *GVarSym;
     O << "\n\t.type " << *GVarSym << ", @object\n\t.weak " << *GVarSym << '\n';
     break;
-   case GlobalValue::AppendingLinkage:
+  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:
+  case GlobalValue::ExternalLinkage:
     // If external or appending, declare as a global symbol
     O << "\t.global " << *GVarSym;
     O << "\n\t.type " << *GVarSym << ", @object\n";
     // FALL THROUGH
-   case GlobalValue::InternalLinkage:
-   case GlobalValue::PrivateLinkage:
+  case GlobalValue::InternalLinkage:
+  case GlobalValue::PrivateLinkage:
     break;
-   default:
+  default:
     llvm_unreachable("Unknown linkage type!");
   }
 
@@ -976,25 +975,15 @@
   
   // Handle the zerofill directive on darwin, which is a special form of BSS
   // emission.
-  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
-    TargetLoweringObjectFileMachO &TLOFMacho = 
-      static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
-    if (TLOFMacho.isDataCommonSection(TheSection)) {
-      // .globl _foo
-      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
-      // .zerofill __DATA, __common, _foo, 400, 5
-      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
-      return;
-    }
+  if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
+    // .globl _foo
+    OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+    // .zerofill __DATA, __common, _foo, 400, 5
+    OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+    return;
   }
   
-  OutStreamer.SwitchSection(TheSection);
-
-  /// FIXME: Drive this off the section!
-  if (C->isNullValue() && /* FIXME: Verify correct */
-      !GVar->hasSection() && GVar->hasLocalLinkage() &&
-      // Don't put things that should go in the cstring section into "comm".
-      !TheSection->getKind().isMergeableCString()) {
+  if (GVKind.isBSSLocal()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size << ',' << Align;
@@ -1008,6 +997,8 @@
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::LinkOnceAnyLinkage:
   case GlobalValue::LinkOnceODRLinkage:

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp?rev=93847&r1=93846&r2=93847&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp Mon Jan 18 22:21:20 2010
@@ -699,25 +699,15 @@
 
   // Handle the zerofill directive on darwin, which is a special form of BSS
   // emission.
-  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
-    TargetLoweringObjectFileMachO &TLOFMacho = 
-        static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
-    if (TLOFMacho.isDataCommonSection(TheSection)) {
-      // .globl _foo
-      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
-      // .zerofill __DATA, __common, _foo, 400, 5
-      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
-      return;
-    }
+  if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
+    // .globl _foo
+    OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+    // .zerofill __DATA, __common, _foo, 400, 5
+    OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+    return;
   }
 
-  OutStreamer.SwitchSection(TheSection);
-  
-  // FIXME: get this stuff from section kind flags.
-  if (C->isNullValue() && !GVar->hasSection() &&
-      // Don't put things that should go in the cstring section into "comm".
-      !TheSection->getKind().isMergeableCString() &&
-      !GVar->isThreadLocal() && GVar->hasLocalLinkage()) {
+  if (GVKind.isBSSLocal()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     if (const char *LComm = MAI->getLCOMMDirective()) {
@@ -742,6 +732,8 @@
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::CommonLinkage:
   case GlobalValue::LinkOnceAnyLinkage:





More information about the llvm-commits mailing list