use BSSLocal classifier to identify 'lcomm' data instead of
authorChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 04:21:20 +0000 (04:21 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 04:21:20 +0000 (04:21 +0000)
duplicating the logic (differently) in lots of different targets.

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

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

index b8da445cebd57555cf507fc1bb1ad44d9ef46fd7..304518abe787a349a06604b31db13b30c814a705 100644 (file)
@@ -313,12 +313,6 @@ public:
     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 {
index 738f257833f2c8e696ce0f0dbe50a095bdda8ba4..fd26169db3fd6ff5e747dfb623fc5ffdc68b2391 100644 (file)
@@ -1220,25 +1220,15 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
   
   // 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 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::CommonLinkage:
   case GlobalValue::LinkOnceAnyLinkage:
index 4b69f0bb7cfa35a6fc1c0dfe91ba4dc84fd9ff9d..e17d89a363b29689c7fc6b7ce52f97e45b33d151 100644 (file)
@@ -733,10 +733,7 @@ void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
     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 @@ void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
     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 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
   
   // 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 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::LinkOnceAnyLinkage:
   case GlobalValue::LinkOnceODRLinkage:
index f32a659f72784101c272ed5f3724a45856a200a6..438c208ad8fee98dd8dffb7c362110b77d50580a 100644 (file)
@@ -699,25 +699,15 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
 
   // 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 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
     return;
   }
 
+  OutStreamer.SwitchSection(TheSection);
+
   switch (GVar->getLinkage()) {
   case GlobalValue::CommonLinkage:
   case GlobalValue::LinkOnceAnyLinkage: