add a bool for whether .lcomm takes an alignment instead of basing this on "isdarwin".

llvm-svn: 93852
This commit is contained in:
Chris Lattner 2010-01-19 04:48:20 +00:00
parent 6a160517a0
commit dccbb28bca
6 changed files with 21 additions and 11 deletions

View File

@ -202,6 +202,10 @@ namespace llvm {
/// argument that specifies the alignment of the declaration. /// argument that specifies the alignment of the declaration.
bool COMMDirectiveTakesAlignment; // Defaults to true. 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 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
/// directives, this is true for most ELF targets. /// directives, this is true for most ELF targets.
bool HasDotTypeDotSizeDirective; // Defaults to true. bool HasDotTypeDotSizeDirective; // Defaults to true.
@ -410,6 +414,9 @@ namespace llvm {
bool getCOMMDirectiveTakesAlignment() const { bool getCOMMDirectiveTakesAlignment() const {
return COMMDirectiveTakesAlignment; return COMMDirectiveTakesAlignment;
} }
bool getLCOMMDirectiveTakesAlignment() const {
return LCOMMDirectiveTakesAlignment;
}
bool hasDotTypeDotSizeDirective() const { bool hasDotTypeDotSizeDirective() const {
return HasDotTypeDotSizeDirective; return HasDotTypeDotSizeDirective;
} }

View File

@ -56,6 +56,7 @@ MCAsmInfo::MCAsmInfo() {
LCOMMDirective = 0; LCOMMDirective = 0;
COMMDirective = "\t.comm\t"; COMMDirective = "\t.comm\t";
COMMDirectiveTakesAlignment = true; COMMDirectiveTakesAlignment = true;
LCOMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = true; HasDotTypeDotSizeDirective = true;
HasSingleParameterDotFile = true; HasSingleParameterDotFile = true;
UsedDirective = 0; UsedDirective = 0;

View File

@ -37,6 +37,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
HasMachoZeroFillDirective = true; // Uses .zerofill HasMachoZeroFillDirective = true; // Uses .zerofill
HasStaticCtorDtorReferenceInStaticMode = true; HasStaticCtorDtorReferenceInStaticMode = true;
LCOMMDirectiveTakesAlignment = true;
SetDirective = "\t.set"; SetDirective = "\t.set";
ProtectedDirective = "\t.globl\t"; ProtectedDirective = "\t.globl\t";
HasDotTypeDotSizeDirective = false; HasDotTypeDotSizeDirective = false;

View File

@ -1202,13 +1202,11 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
if (GVKind.isBSSLocal()) { if (GVKind.isBSSLocal()) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (isDarwin) { if (const char *LCOMM = MAI->getLCOMMDirective()) {
O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size O << LCOMM << *GVarSym << "," << Size;
<< ',' << Align; if (MAI->getLCOMMDirectiveTakesAlignment())
} else if (MAI->getLCOMMDirective() != NULL) { O << ',' << Align;
O << MAI->getLCOMMDirective() << *GVarSym << "," << Size;
} else { } else {
if (GVar->hasLocalLinkage())
O << "\t.local\t" << *GVarSym << '\n'; O << "\t.local\t" << *GVarSym << '\n';
O << MAI->getCOMMDirective() << *GVarSym << "," << Size; O << MAI->getCOMMDirective() << *GVarSym << "," << Size;
if (MAI->getCOMMDirectiveTakesAlignment()) if (MAI->getCOMMDirectiveTakesAlignment())

View File

@ -951,7 +951,9 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
if (GVKind.isBSSLocal()) { if (GVKind.isBSSLocal()) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. 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) { if (VerboseAsm) {
O << "\t\t" << MAI->getCommentString() << " '"; O << "\t\t" << MAI->getCommentString() << " '";

View File

@ -647,17 +647,18 @@ void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
} }
void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
const TargetData *TD = TM.getTargetData();
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar); MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
Constant *C = GVar->getInitializer(); Constant *C = GVar->getInitializer();
const Type *Type = C->getType(); const Type *Type = C->getType();
const TargetData *TD = TM.getTargetData();
unsigned Size = TD->getTypeAllocSize(Type); unsigned Size = TD->getTypeAllocSize(Type);
unsigned Align = TD->getPreferredAlignmentLog(GVar); unsigned Align = TD->getPreferredAlignmentLog(GVar);
printVisibility(GVarSym, GVar->getVisibility()); printVisibility(GVarSym, GVar->getVisibility());
if (Subtarget->isTargetELF()) if (MAI->hasDotTypeDotSizeDirective())
O << "\t.type\t" << *GVarSym << ",@object\n"; O << "\t.type\t" << *GVarSym << ",@object\n";
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM); SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
@ -685,7 +686,7 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
if (const char *LComm = MAI->getLCOMMDirective()) { if (const char *LComm = MAI->getLCOMMDirective()) {
if (GVar->hasLocalLinkage()) { if (GVar->hasLocalLinkage()) {
O << LComm << *GVarSym << ',' << Size; O << LComm << *GVarSym << ',' << Size;
if (Subtarget->isTargetDarwin()) if (MAI->getLCOMMDirectiveTakesAlignment())
O << ',' << Align; O << ',' << Align;
} }
} else { } else {