From c1ef06ac5264cb43f148590091606f0ed90a72e9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 19 Jan 2010 04:21:20 +0000 Subject: [PATCH] use BSSLocal classifier to identify 'lcomm' data instead of 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 --- .../llvm/Target/TargetLoweringObjectFile.h | 6 -- lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 26 +++------ .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 55 ++++++++----------- lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp | 26 +++------ 4 files changed, 41 insertions(+), 72 deletions(-) diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index b8da445cebd..304518abe78 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -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 { diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 738f257833f..fd26169db3f 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -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(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: diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 4b69f0bb7cf..e17d89a363b 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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(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: diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index f32a659f727..438c208ad8f 100644 --- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -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(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: