From 5277b22687d3513dd29d5a9c8510cac740f933f6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 8 Aug 2009 20:43:12 +0000 Subject: [PATCH] eliminate TargetLoweringObjectFileSparc in favor of a TAI hook. A TAI hook is appropriate in this case because this is just an asm syntax issue, not a semantic difference. TLOF should model the semantics of the section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78498 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/TargetAsmInfo.h | 10 +++++++ .../llvm/Target/TargetLoweringObjectFile.h | 10 +++++-- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +- lib/Target/Sparc/SparcISelLowering.cpp | 28 +------------------ lib/Target/Sparc/SparcTargetAsmInfo.cpp | 2 ++ lib/Target/TargetAsmInfo.cpp | 1 + lib/Target/TargetLoweringObjectFile.cpp | 26 +++++++++++++++-- 7 files changed, 45 insertions(+), 34 deletions(-) diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h index 70d21122256..92b977154bc 100644 --- a/include/llvm/Target/TargetAsmInfo.h +++ b/include/llvm/Target/TargetAsmInfo.h @@ -158,6 +158,11 @@ namespace llvm { return NULL; } + /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun + /// Style" syntax for section switching ("#alloc,#write" etc) instead of the + /// normal ELF syntax (,"a,w") in .section directives. + bool SunStyleELFSectionSwitchSyntax; // Defaults to false. + //===--- Alignment Information ----------------------------------------===// /// AlignDirective - The directive used to emit round up to an alignment @@ -326,6 +331,11 @@ namespace llvm { return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS); } + + bool usesSunStyleELFSectionSwitchSyntax() const { + return SunStyleELFSectionSwitchSyntax; + } + // Accessors. // diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index f8d3f6f1759..e517fd375a5 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -25,6 +25,7 @@ namespace llvm { class GlobalValue; class Mangler; class TargetMachine; + class TargetAsmInfo; class TargetLoweringObjectFile { MCContext *Ctx; @@ -172,7 +173,8 @@ public: /// into a string that can be printed to the assembly file after the /// ".section foo" part of a section directive. virtual void getSectionFlagsAsString(SectionKind Kind, - SmallVectorImpl &Str) const { + SmallVectorImpl &Str, + const TargetAsmInfo &TAI) const { } protected: @@ -229,7 +231,8 @@ public: Mangler *Mang, const TargetMachine &TM) const; void getSectionFlagsAsString(SectionKind Kind, - SmallVectorImpl &Str) const; + SmallVectorImpl &Str, + const TargetAsmInfo &TAI) const; virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, @@ -286,7 +289,8 @@ public: Mangler *Mang, const TargetMachine &TM) const; virtual void getSectionFlagsAsString(SectionKind Kind, - SmallVectorImpl &Str) const; + SmallVectorImpl &Str, + const TargetAsmInfo &TAI) const; virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index a8cb465564b..68cd4a49ab6 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -99,7 +99,7 @@ void AsmPrinter::SwitchToSection(const MCSection *NS) { // some magic assembler directive. if (!NS->isDirective()) { SmallString<32> FlagsStr; - getObjFileLowering().getSectionFlagsAsString(NS->getKind(), FlagsStr); + getObjFileLowering().getSectionFlagsAsString(NS->getKind(), FlagsStr, *TAI); O << TAI->getSwitchToSectionDirective() << CurrentSection->getName() << FlagsStr.c_str() << '\n'; diff --git a/lib/Target/Sparc/SparcISelLowering.cpp b/lib/Target/Sparc/SparcISelLowering.cpp index 4f6a79ee535..b560b736d16 100644 --- a/lib/Target/Sparc/SparcISelLowering.cpp +++ b/lib/Target/Sparc/SparcISelLowering.cpp @@ -549,34 +549,8 @@ static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC) { } } -namespace { - -class TargetLoweringObjectFileSparc : public TargetLoweringObjectFileELF { -public: - void getSectionFlagsAsString(SectionKind Kind, - SmallVectorImpl &Str) const { - if (Kind.isMergeableConst() || Kind.isMergeableCString()) - return TargetLoweringObjectFileELF::getSectionFlagsAsString(Kind, Str); - - // FIXME: Inefficient. - std::string Res; - if (!Kind.isMetadata()) - Res += ",#alloc"; - if (Kind.isText()) - Res += ",#execinstr"; - if (Kind.isWriteable()) - Res += ",#write"; - if (Kind.isThreadLocal()) - Res += ",#tls"; - - Str.append(Res.begin(), Res.end()); - } -}; - -} - SparcTargetLowering::SparcTargetLowering(TargetMachine &TM) - : TargetLowering(TM, new TargetLoweringObjectFileSparc()) { + : TargetLowering(TM, new TargetLoweringObjectFileELF()) { // Set up the register classes. addRegisterClass(MVT::i32, SP::IntRegsRegisterClass); diff --git a/lib/Target/Sparc/SparcTargetAsmInfo.cpp b/lib/Target/Sparc/SparcTargetAsmInfo.cpp index 4a5f66cdb0f..6ec74e6e4fc 100644 --- a/lib/Target/Sparc/SparcTargetAsmInfo.cpp +++ b/lib/Target/Sparc/SparcTargetAsmInfo.cpp @@ -22,6 +22,8 @@ SparcELFTargetAsmInfo::SparcELFTargetAsmInfo() { ZeroDirective = "\t.skip\t"; CommentString = "!"; COMMDirectiveTakesAlignment = true; + + SunStyleELFSectionSwitchSyntax = true; } diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index b59e140a123..5ec36b6d158 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -49,6 +49,7 @@ TargetAsmInfo::TargetAsmInfo() { Data16bitsDirective = "\t.short\t"; Data32bitsDirective = "\t.long\t"; Data64bitsDirective = "\t.quad\t"; + SunStyleELFSectionSwitchSyntax = false; AlignDirective = "\t.align\t"; AlignmentIsInBytes = true; TextAlignFillValue = 0; diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index 8a60086f7a7..eabd6263727 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -18,8 +18,9 @@ #include "llvm/GlobalVariable.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSection.h" -#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/Mangler.h" #include "llvm/ADT/StringExtras.h" @@ -407,7 +408,25 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, void TargetLoweringObjectFileELF:: -getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl &Str) const { +getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl &Str, + const TargetAsmInfo &TAI) const { + // Handle the weird solaris syntax if desired. + if (TAI.usesSunStyleELFSectionSwitchSyntax() && + !Kind.isMergeableConst() && !Kind.isMergeableCString()) { + // FIXME: Inefficient. + std::string Res; + if (!Kind.isMetadata()) + Res += ",#alloc"; + if (Kind.isText()) + Res += ",#execinstr"; + if (Kind.isWriteable()) + Res += ",#write"; + if (Kind.isThreadLocal()) + Res += ",#tls"; + Str.append(Res.begin(), Res.end()); + return; + } + Str.push_back(','); Str.push_back('"'); @@ -848,7 +867,8 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, void TargetLoweringObjectFileCOFF:: -getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl &Str) const { +getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl &Str, + const TargetAsmInfo &TAI) const { // FIXME: Inefficient. std::string Res = ",\""; if (Kind.isText())