[llvm-commits] [llvm] r78510 - in /llvm/trunk: include/llvm/MC/MCSection.h include/llvm/Target/TargetAsmInfo.h include/llvm/Target/TargetLoweringObjectFile.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/MC/MCSection.cpp lib/Target/ARM/ARMTargetObjectFile.h lib/Target/PIC16/PIC16Section.h lib/Target/PIC16/PIC16TargetAsmInfo.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/TargetAsmInfo.cpp lib/Target/TargetLoweringObjectFile.cpp

Chris Lattner sabre at nondot.org
Sat Aug 8 15:41:53 PDT 2009


Author: lattner
Date: Sat Aug  8 17:41:53 2009
New Revision: 78510

URL: http://llvm.org/viewvc/llvm-project?rev=78510&view=rev
Log:
1. Make MCSection an abstract class.
2. Move section switch printing to MCSection virtual method which takes a
   TAI.  This eliminates textual formatting stuff from TLOF.
3. Eliminate SwitchToSectionDirective, getSectionFlagsAsString, and 
   TLOFELF::AtIsCommentChar.


Modified:
    llvm/trunk/include/llvm/MC/MCSection.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/MC/MCSection.cpp
    llvm/trunk/lib/Target/ARM/ARMTargetObjectFile.h
    llvm/trunk/lib/Target/PIC16/PIC16Section.h
    llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp

Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Sat Aug  8 17:41:53 2009
@@ -20,6 +20,8 @@
 
 namespace llvm {
   class MCContext;
+  class TargetAsmInfo;
+  class raw_ostream;
   
   /// MCSection - Instances of this class represent a uniqued identifier for a
   /// section in the current translation unit.  The MCContext class uniques and
@@ -43,13 +45,13 @@
   public:
     virtual ~MCSection();
 
-    static MCSection *Create(const StringRef &Name, bool IsDirective, 
-                             SectionKind K, MCContext &Ctx);
-    
     const std::string &getName() const { return Name; }
     bool isDirective() const { return IsDirective; }
     
     SectionKind getKind() const { return Kind; }
+    
+    virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                      raw_ostream &OS) const = 0;
   };
 
   
@@ -60,7 +62,9 @@
     
     static MCSectionELF *Create(const StringRef &Name, bool IsDirective, 
                                 SectionKind K, MCContext &Ctx);
-    
+
+    virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                      raw_ostream &OS) const;
   };
 
   class MCSectionMachO : public MCSection {
@@ -70,6 +74,9 @@
     
     static MCSectionMachO *Create(const StringRef &Name, bool IsDirective, 
                                   SectionKind K, MCContext &Ctx);
+
+    virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                      raw_ostream &OS) const;
   };
   
   class MCSectionCOFF : public MCSection {
@@ -79,6 +86,9 @@
     
     static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective, 
                                    SectionKind K, MCContext &Ctx);
+    
+    virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                      raw_ostream &OS) const;
   };
   
 } // end namespace llvm

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sat Aug  8 17:41:53 2009
@@ -182,11 +182,6 @@
 
     //===--- Section Switching Directives ---------------------------------===//
     
-    /// SwitchToSectionDirective - This is the directive used when we want to
-    /// emit a global to an arbitrary section.  The section name is emited after
-    /// this.
-    const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
-    
     /// JumpTableDirective - if non-null, the directive to emit before a jump
     /// table.
     const char *JumpTableDirective;
@@ -432,9 +427,6 @@
     unsigned getTextAlignFillValue() const {
       return TextAlignFillValue;
     }
-    const char *getSwitchToSectionDirective() const {
-      return SwitchToSectionDirective;
-    }
     const char *getGlobalDirective() const {
       return GlobalDirective;
     }

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Sat Aug  8 17:41:53 2009
@@ -169,14 +169,6 @@
     return 0;
   }
   
-  /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
-  /// 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 TargetAsmInfo &TAI) const {
-  }
-  
 protected:
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
@@ -187,7 +179,6 @@
   
 
 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
-  bool AtIsCommentChar;  // True if @ is the comment character on this target.
   bool HasCrazyBSS;
 protected:
   /// TLSDataSection - Section directive for Thread Local data.
@@ -212,12 +203,9 @@
   const MCSection *getELFSection(const char *Name, bool isDirective,
                                  SectionKind Kind) const;
 public:
-  /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
-  /// is "@".
-  TargetLoweringObjectFileELF(bool atIsCommentChar = false,
-                              // FIXME: REMOVE AFTER UNIQUING IS FIXED.
+  TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
                               bool hasCrazyBSS = false)
-    : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
+    : HasCrazyBSS(hasCrazyBSS) {}
   
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
@@ -230,10 +218,6 @@
   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
                            Mangler *Mang, const TargetMachine &TM) const;
   
-  void getSectionFlagsAsString(SectionKind Kind,
-                               SmallVectorImpl<char> &Str,
-                               const TargetAsmInfo &TAI) const;
-  
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;
@@ -288,10 +272,6 @@
   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
                            Mangler *Mang, const TargetMachine &TM) const;
   
-  virtual void getSectionFlagsAsString(SectionKind Kind,
-                                       SmallVectorImpl<char> &Str,
-                                       const TargetAsmInfo &TAI) const;
-  
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sat Aug  8 17:41:53 2009
@@ -94,18 +94,7 @@
 
   if (NS == 0) return;
   
-  // If section is named we need to switch into it via special '.section'
-  // directive and also append funky flags. Otherwise - section name is just
-  // some magic assembler directive.
-  if (!NS->isDirective()) {
-    SmallString<32> FlagsStr;
-    getObjFileLowering().getSectionFlagsAsString(NS->getKind(), FlagsStr, *TAI);
-
-    O << TAI->getSwitchToSectionDirective()
-      << CurrentSection->getName() << FlagsStr.c_str() << '\n';
-  } else {
-    O << CurrentSection->getName() << '\n';
-  }
+  NS->PrintSwitchToSection(*TAI, O);
 }
 
 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {

Modified: llvm/trunk/lib/MC/MCSection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSection.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCSection.cpp (original)
+++ llvm/trunk/lib/MC/MCSection.cpp Sat Aug  8 17:41:53 2009
@@ -9,8 +9,14 @@
 
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
+//===----------------------------------------------------------------------===//
+// MCSection
+//===----------------------------------------------------------------------===//
+
 MCSection::~MCSection() {
 }
 
@@ -22,26 +28,124 @@
   Entry = this;
 }
 
-MCSection *MCSection::
-Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
-  return new (Ctx) MCSection(Name, IsDirective, K, Ctx);
-}
-
+//===----------------------------------------------------------------------===//
+// MCSectionELF
+//===----------------------------------------------------------------------===//
 
 MCSectionELF *MCSectionELF::
 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
   return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
 }
 
+void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                        raw_ostream &OS) const {
+  if (isDirective()) {
+    OS << getName() << '\n';
+    return;
+  }
+
+  OS << "\t.section\t" << getName();
+  
+  // Handle the weird solaris syntax if desired.
+  if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
+      !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
+    if (!getKind().isMetadata())
+      OS << ",#alloc";
+    if (getKind().isText())
+      OS << ",#execinstr";
+    if (getKind().isWriteable())
+      OS << ",#write";
+    if (getKind().isThreadLocal())
+      OS << ",#tls";
+  } else {
+    OS << ",\"";
+  
+    if (!getKind().isMetadata())
+      OS << 'a';
+    if (getKind().isText())
+      OS << 'x';
+    if (getKind().isWriteable())
+      OS << 'w';
+    if (getKind().isMergeable1ByteCString() ||
+        getKind().isMergeable2ByteCString() ||
+        getKind().isMergeable4ByteCString() ||
+        getKind().isMergeableConst4() ||
+        getKind().isMergeableConst8() ||
+        getKind().isMergeableConst16())
+      OS << 'M';
+    if (getKind().isMergeable1ByteCString() ||
+        getKind().isMergeable2ByteCString() ||
+        getKind().isMergeable4ByteCString())
+      OS << 'S';
+    if (getKind().isThreadLocal())
+      OS << 'T';
+    
+    OS << "\",";
+    
+    // If comment string is '@', e.g. as on ARM - use '%' instead
+    if (TAI.getCommentString()[0] == '@')
+      OS << '%';
+    else
+      OS << '@';
+    
+    if (getKind().isBSS() || getKind().isThreadBSS())
+      OS << "nobits";
+    else
+      OS << "progbits";
+    
+    if (getKind().isMergeable1ByteCString()) {
+      OS << ",1";
+    } else if (getKind().isMergeable2ByteCString()) {
+      OS << ",2";
+    } else if (getKind().isMergeable4ByteCString()) {
+      OS << ",4";
+    } else if (getKind().isMergeableConst4()) {
+      OS << ",4";
+    } else if (getKind().isMergeableConst8()) {
+      OS << ",8";
+    } else if (getKind().isMergeableConst16()) {
+      OS << ",16";
+    }
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// MCSectionMachO
+//===----------------------------------------------------------------------===//
 
 MCSectionMachO *MCSectionMachO::
 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
   return new (Ctx) MCSectionMachO(Name, IsDirective, K, Ctx);
 }
 
+void MCSectionMachO::PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                          raw_ostream &OS) const {
+  if (!isDirective())
+    OS << "\t.section\t" << getName() << '\n';
+  else
+    OS << getName() << '\n';
+}
+
+//===----------------------------------------------------------------------===//
+// MCSectionCOFF
+//===----------------------------------------------------------------------===//
 
 MCSectionCOFF *MCSectionCOFF::
 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
   return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
 }
 
+void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                         raw_ostream &OS) const {
+  
+  if (isDirective()) {
+    OS << getName() << '\n';
+    return;
+  }
+  OS << "\t.section\t" << getName() << ",\"";
+  if (getKind().isText())
+    OS << 'x';
+  if (getKind().isWriteable())
+    OS << 'w';
+  OS << "\"\n";
+}

Modified: llvm/trunk/lib/Target/ARM/ARMTargetObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetObjectFile.h?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetObjectFile.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetObjectFile.h Sat Aug  8 17:41:53 2009
@@ -16,7 +16,7 @@
   
   class ARMElfTargetObjectFile : public TargetLoweringObjectFileELF {
   public:
-    ARMElfTargetObjectFile() : TargetLoweringObjectFileELF(true) {}
+    ARMElfTargetObjectFile() : TargetLoweringObjectFileELF() {}
     
     void Initialize(MCContext &Ctx, const TargetMachine &TM) {
       TargetLoweringObjectFileELF::Initialize(Ctx, TM);

Modified: llvm/trunk/lib/Target/PIC16/PIC16Section.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Section.h?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Section.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Section.h Sat Aug  8 17:41:53 2009
@@ -16,6 +16,7 @@
 
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
@@ -28,9 +29,14 @@
                                   SectionKind K, MCContext &Ctx) {
       return new (Ctx) MCSectionPIC16(Name, IsDirective, K, Ctx);
     }
+    
+    
+    virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
+                                      raw_ostream &OS) const {
+      OS << getName() << '\n';
+    }
+
   };
-  
-  
 
 } // end namespace llvm
 

Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Sat Aug  8 17:41:53 2009
@@ -33,7 +33,6 @@
   ZeroDirective = NULL;
   AsciiDirective = " dt ";
   AscizDirective = NULL;
-  SwitchToSectionDirective = "";
     
   RomData8bitsDirective = " dw ";
   RomData16bitsDirective = " rom_di ";

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Sat Aug  8 17:41:53 2009
@@ -60,7 +60,7 @@
 static TargetLoweringObjectFile *CreateTLOF(const PPCTargetMachine &TM) {
   if (TM.getSubtargetImpl()->isDarwin())
     return new TargetLoweringObjectFileMachO();
-  return new TargetLoweringObjectFileELF(false, true);
+  return new TargetLoweringObjectFileELF(true);
 }
 
 

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sat Aug  8 17:41:53 2009
@@ -53,7 +53,6 @@
   AlignDirective = "\t.align\t";
   AlignmentIsInBytes = true;
   TextAlignFillValue = 0;
-  SwitchToSectionDirective = "\t.section\t";
   JumpTableDirective = 0;
   GlobalDirective = "\t.globl\t";
   SetDirective = 0;

Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=78510&r1=78509&r2=78510&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Sat Aug  8 17:41:53 2009
@@ -404,91 +404,6 @@
   
   return getELFSection(GV->getSection().c_str(), false, Kind);
 }
-      
-      
-      
-void TargetLoweringObjectFileELF::
-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('"');
-  
-  if (!Kind.isMetadata())
-    Str.push_back('a');
-  if (Kind.isText())
-    Str.push_back('x');
-  if (Kind.isWriteable())
-    Str.push_back('w');
-  if (Kind.isMergeable1ByteCString() ||
-      Kind.isMergeable2ByteCString() ||
-      Kind.isMergeable4ByteCString() ||
-      Kind.isMergeableConst4() ||
-      Kind.isMergeableConst8() ||
-      Kind.isMergeableConst16())
-    Str.push_back('M');
-  if (Kind.isMergeable1ByteCString() ||
-      Kind.isMergeable2ByteCString() ||
-      Kind.isMergeable4ByteCString())
-    Str.push_back('S');
-  if (Kind.isThreadLocal())
-    Str.push_back('T');
-  
-  Str.push_back('"');
-  Str.push_back(',');
-  
-  // If comment string is '@', e.g. as on ARM - use '%' instead
-  if (AtIsCommentChar)
-    Str.push_back('%');
-  else
-    Str.push_back('@');
-  
-  const char *KindStr;
-  if (Kind.isBSS() || Kind.isThreadBSS())
-    KindStr = "nobits";
-  else
-    KindStr = "progbits";
-  
-  Str.append(KindStr, KindStr+strlen(KindStr));
-  
-  if (Kind.isMergeable1ByteCString()) {
-    Str.push_back(',');
-    Str.push_back('1');
-  } else if (Kind.isMergeable2ByteCString()) {
-    Str.push_back(',');
-    Str.push_back('2');
-  } else if (Kind.isMergeable4ByteCString()) {
-    Str.push_back(',');
-    Str.push_back('4');
-  } else if (Kind.isMergeableConst4()) {
-    Str.push_back(',');
-    Str.push_back('4');
-  } else if (Kind.isMergeableConst8()) {
-    Str.push_back(',');
-    Str.push_back('8');
-  } else if (Kind.isMergeableConst16()) {
-    Str.push_back(',');
-    Str.push_back('1');
-    Str.push_back('6');
-  }
-}
-
 
 static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
   if (Kind.isText())                 return ".gnu.linkonce.t.";
@@ -865,21 +780,6 @@
   return getCOFFSection(GV->getSection().c_str(), false, Kind);
 }
 
-
-void TargetLoweringObjectFileCOFF::
-getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str,
-                        const TargetAsmInfo &TAI) const {
-  // FIXME: Inefficient.
-  std::string Res = ",\"";
-  if (Kind.isText())
-    Res += 'x';
-  if (Kind.isWriteable())
-    Res += 'w';
-  Res += "\"";
-  
-  Str.append(Res.begin(), Res.end());
-}
-
 static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
   if (Kind.isText())
     return ".text$linkonce";





More information about the llvm-commits mailing list