eliminate TargetLoweringObjectFileSparc in favor of a TAI hook.
authorChris Lattner <sabre@nondot.org>
Sat, 8 Aug 2009 20:43:12 +0000 (20:43 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 8 Aug 2009 20:43:12 +0000 (20:43 +0000)
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
include/llvm/Target/TargetLoweringObjectFile.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/Sparc/SparcISelLowering.cpp
lib/Target/Sparc/SparcTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/TargetLoweringObjectFile.cpp

index 70d2112225618dc34d9416351439d2ee5d6af2c9..92b977154bc2f539ef2a8982bfe98a8db25196fd 100644 (file)
@@ -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.
     //
index f8d3f6f17593a7daf0bf310dd2ec14e9d883d6b4..e517fd375a5d4e304a95c3336b06899d8f3e4601 100644 (file)
@@ -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<char> &Str) const {
+                                       SmallVectorImpl<char> &Str,
+                                       const TargetAsmInfo &TAI) const {
   }
   
 protected:
@@ -229,7 +231,8 @@ public:
                            Mangler *Mang, const TargetMachine &TM) const;
   
   void getSectionFlagsAsString(SectionKind Kind,
-                               SmallVectorImpl<char> &Str) const;
+                               SmallVectorImpl<char> &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<char> &Str) const;
+                                       SmallVectorImpl<char> &Str,
+                                       const TargetAsmInfo &TAI) const;
   
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
index a8cb465564befc56da3398288e523b9a1723f8d4..68cd4a49ab6af6bba34c0cecfec7d5c411ef2887 100644 (file)
@@ -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';
index 4f6a79ee535c85bed13275af38132f30d584fff9..b560b736d162223877721926e8f1e9b9f452ead2 100644 (file)
@@ -549,34 +549,8 @@ static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC) {
   }
 }
 
-namespace {
-
-class TargetLoweringObjectFileSparc : public TargetLoweringObjectFileELF {
-public:
-  void getSectionFlagsAsString(SectionKind Kind,
-                               SmallVectorImpl<char> &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);
index 4a5f66cdb0f2e12331ad30572c534bfd7556fddb..6ec74e6e4fc5a198c7aec75a9fc5ae8ad5e1b545 100644 (file)
@@ -22,6 +22,8 @@ SparcELFTargetAsmInfo::SparcELFTargetAsmInfo() {
   ZeroDirective = "\t.skip\t";
   CommentString = "!";
   COMMDirectiveTakesAlignment = true;
+  
+  SunStyleELFSectionSwitchSyntax = true;
 }
 
 
index b59e140a123769c9528c1bd855a805d989c1823d..5ec36b6d158a63ce3bfd7488ec6b224c8c0d55a8 100644 (file)
@@ -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;
index 8a60086f7a7e9cef397901207c08bb1ac3f39a09..eabd62637275b0e2126bb834b3a30561eebb7f47 100644 (file)
@@ -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<char> &Str) const {
+getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &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<char> &Str) const {
+getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str,
+                        const TargetAsmInfo &TAI) const {
   // FIXME: Inefficient.
   std::string Res = ",\"";
   if (Kind.isText())