From 7517b249caa793a9a01e4b6aff9c47fd88a153cc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 19 Jan 2010 04:48:20 +0000 Subject: [PATCH] add a bool for whether .lcomm takes an alignment instead of basing this on "isdarwin". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93852 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAsmInfo.h | 7 +++++++ lib/MC/MCAsmInfo.cpp | 1 + lib/MC/MCAsmInfoDarwin.cpp | 1 + lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 12 +++++------- lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 4 +++- lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp | 7 ++++--- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h index 1368e1f4249..a340a121384 100644 --- a/include/llvm/MC/MCAsmInfo.h +++ b/include/llvm/MC/MCAsmInfo.h @@ -202,6 +202,10 @@ namespace llvm { /// argument that specifies the alignment of the declaration. bool COMMDirectiveTakesAlignment; // Defaults to true. + /// LCOMMDirectiveTakesAlignment - True if LCOMMDirective takes a third + /// argument that specifies the alignment of the declaration. + bool LCOMMDirectiveTakesAlignment; // Defaults to false. + /// HasDotTypeDotSizeDirective - True if the target has .type and .size /// directives, this is true for most ELF targets. bool HasDotTypeDotSizeDirective; // Defaults to true. @@ -410,6 +414,9 @@ namespace llvm { bool getCOMMDirectiveTakesAlignment() const { return COMMDirectiveTakesAlignment; } + bool getLCOMMDirectiveTakesAlignment() const { + return LCOMMDirectiveTakesAlignment; + } bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; } diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp index 277a09e9e9a..4c53d7a284a 100644 --- a/lib/MC/MCAsmInfo.cpp +++ b/lib/MC/MCAsmInfo.cpp @@ -56,6 +56,7 @@ MCAsmInfo::MCAsmInfo() { LCOMMDirective = 0; COMMDirective = "\t.comm\t"; COMMDirectiveTakesAlignment = true; + LCOMMDirectiveTakesAlignment = false; HasDotTypeDotSizeDirective = true; HasSingleParameterDotFile = true; UsedDirective = 0; diff --git a/lib/MC/MCAsmInfoDarwin.cpp b/lib/MC/MCAsmInfoDarwin.cpp index 5de86e0c901..a1f6051990e 100644 --- a/lib/MC/MCAsmInfoDarwin.cpp +++ b/lib/MC/MCAsmInfoDarwin.cpp @@ -37,6 +37,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() { ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. HasMachoZeroFillDirective = true; // Uses .zerofill HasStaticCtorDtorReferenceInStaticMode = true; + LCOMMDirectiveTakesAlignment = true; SetDirective = "\t.set"; ProtectedDirective = "\t.globl\t"; HasDotTypeDotSizeDirective = false; diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index b1c1f55f17f..4485ad75efc 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -1202,14 +1202,12 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { if (GVKind.isBSSLocal()) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. - if (isDarwin) { - O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size - << ',' << Align; - } else if (MAI->getLCOMMDirective() != NULL) { - O << MAI->getLCOMMDirective() << *GVarSym << "," << Size; + if (const char *LCOMM = MAI->getLCOMMDirective()) { + O << LCOMM << *GVarSym << "," << Size; + if (MAI->getLCOMMDirectiveTakesAlignment()) + O << ',' << Align; } else { - if (GVar->hasLocalLinkage()) - O << "\t.local\t" << *GVarSym << '\n'; + O << "\t.local\t" << *GVarSym << '\n'; O << MAI->getCOMMDirective() << *GVarSym << "," << Size; if (MAI->getCOMMDirectiveTakesAlignment()) O << "," << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 6b8408f08a3..3698949ca4c 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -951,7 +951,9 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) { if (GVKind.isBSSLocal()) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. - O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size << ',' << Align; + O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size; + if (MAI->getLCOMMDirectiveTakesAlignment()) + O << ',' << Align; if (VerboseAsm) { O << "\t\t" << MAI->getCommentString() << " '"; diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index 22e2573c1c0..14deafe65a4 100644 --- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -647,17 +647,18 @@ void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) { } void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { - const TargetData *TD = TM.getTargetData(); MCSymbol *GVarSym = GetGlobalValueSymbol(GVar); Constant *C = GVar->getInitializer(); const Type *Type = C->getType(); + + const TargetData *TD = TM.getTargetData(); unsigned Size = TD->getTypeAllocSize(Type); unsigned Align = TD->getPreferredAlignmentLog(GVar); printVisibility(GVarSym, GVar->getVisibility()); - if (Subtarget->isTargetELF()) + if (MAI->hasDotTypeDotSizeDirective()) O << "\t.type\t" << *GVarSym << ",@object\n"; SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM); @@ -685,7 +686,7 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { if (const char *LComm = MAI->getLCOMMDirective()) { if (GVar->hasLocalLinkage()) { O << LComm << *GVarSym << ',' << Size; - if (Subtarget->isTargetDarwin()) + if (MAI->getLCOMMDirectiveTakesAlignment()) O << ',' << Align; } } else {