Eliminate SectionFlags, just embed a SectionKind into Section
instead and drive things based off of that.

llvm-svn: 77184
diff --git a/llvm/lib/Target/ARM/ARMTargetAsmInfo.cpp b/llvm/lib/Target/ARM/ARMTargetAsmInfo.cpp
index 95f19c8..983a609 100644
--- a/llvm/lib/Target/ARM/ARMTargetAsmInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetAsmInfo.cpp
@@ -59,8 +59,7 @@
   ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
   Subtarget = &TM.getSubtarget<ARMSubtarget>();
 
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
 
   NeedsSet = false;
   HasLEB128 = true;
diff --git a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
index 3c1f6cb..1154aaf 100644
--- a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
@@ -1130,9 +1130,10 @@
   const Section *TheSection = TAI->SectionForGlobal(GVar);
   SwitchToSection(TheSection);
 
+  // FIXME: get this stuff from section kind flags.
   if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() &&
       // Don't put things that should go in the cstring section into "comm".
-      !TheSection->hasFlag(SectionFlags::Strings)) {
+      !TheSection->getKind().isMergeableCString()) {
     if (GVar->hasExternalLinkage()) {
       if (const char *Directive = TAI->getZeroFillDirective()) {
         O << "\t.globl\t" << name << "\n";
diff --git a/llvm/lib/Target/CellSPU/SPUTargetAsmInfo.cpp b/llvm/lib/Target/CellSPU/SPUTargetAsmInfo.cpp
index c4d3546..2dcd37b 100644
--- a/llvm/lib/Target/CellSPU/SPUTargetAsmInfo.cpp
+++ b/llvm/lib/Target/CellSPU/SPUTargetAsmInfo.cpp
@@ -35,8 +35,7 @@
 
   // BSS section needs to be emitted as ".section"
   BSSSection = "\t.section\t.bss";
-  BSSSection_ = getUnnamedSection("\t.section\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.section\t.bss", SectionKind::BSS);
 
   SupportsDebugInformation = true;
   NeedsSet = true;
diff --git a/llvm/lib/Target/DarwinTargetAsmInfo.cpp b/llvm/lib/Target/DarwinTargetAsmInfo.cpp
index 845da66..b3bcf4b 100644
--- a/llvm/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/llvm/lib/Target/DarwinTargetAsmInfo.cpp
@@ -29,28 +29,29 @@
   : TargetAsmInfo(TM) {
 
   CStringSection_ = getUnnamedSection("\t.cstring",
-                                SectionFlags::Mergeable |SectionFlags::Strings);
+                                      SectionKind::MergeableCString);
   FourByteConstantSection = getUnnamedSection("\t.literal4\n",
-                                              SectionFlags::Mergeable);
+                                              SectionKind::MergeableConst4);
   EightByteConstantSection = getUnnamedSection("\t.literal8\n",
-                                               SectionFlags::Mergeable);
+                                               SectionKind::MergeableConst8);
 
   // Note: 16-byte constant section is subtarget specific and should be provided
   // there, if needed.
   SixteenByteConstantSection = 0;
 
-  ReadOnlySection = getUnnamedSection("\t.const", SectionFlags::None);
+  ReadOnlySection = getUnnamedSection("\t.const", SectionKind::ReadOnly);
 
   TextCoalSection =
     getNamedSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions",
-                    SectionFlags::Code);
+                    SectionKind::Text);
   ConstTextCoalSection = getNamedSection("\t__TEXT,__const_coal,coalesced",
-                                         SectionFlags::None);
+                                         SectionKind::Text);
   ConstDataCoalSection = getNamedSection("\t__DATA,__const_coal,coalesced",
-                                         SectionFlags::None);
-  ConstDataSection = getUnnamedSection("\t.const_data", SectionFlags::None);
+                                         SectionKind::Text);
+  ConstDataSection = getUnnamedSection("\t.const_data",
+                                       SectionKind::ReadOnlyWithRel);
   DataCoalSection = getNamedSection("\t__DATA,__datacoal_nt,coalesced",
-                                    SectionFlags::Writable);
+                                    SectionKind::DataRel);
     
   
   // Common settings for all Darwin targets.
diff --git a/llvm/lib/Target/ELFTargetAsmInfo.cpp b/llvm/lib/Target/ELFTargetAsmInfo.cpp
index 927cb38..cefcb5d 100644
--- a/llvm/lib/Target/ELFTargetAsmInfo.cpp
+++ b/llvm/lib/Target/ELFTargetAsmInfo.cpp
@@ -27,28 +27,24 @@
 ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
   : TargetAsmInfo(TM) {
 
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
-  ReadOnlySection = getNamedSection("\t.rodata", SectionFlags::None);
-  TLSDataSection = getNamedSection("\t.tdata",
-                                   SectionFlags::Writable | SectionFlags::TLS);
-  TLSBSSSection = getNamedSection("\t.tbss",
-                SectionFlags::Writable | SectionFlags::TLS | SectionFlags::BSS);
+  ReadOnlySection = getNamedSection("\t.rodata", SectionKind::ReadOnly);
+  TLSDataSection = getNamedSection("\t.tdata", SectionKind::ThreadData);
+  TLSBSSSection = getNamedSection("\t.tbss", SectionKind::ThreadBSS);
 
-  DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writable);
+  DataRelSection = getNamedSection("\t.data.rel", SectionKind::DataRel);
   DataRelLocalSection = getNamedSection("\t.data.rel.local",
-                                        SectionFlags::Writable);
+                                        SectionKind::DataRelLocal);
   DataRelROSection = getNamedSection("\t.data.rel.ro",
-                                     SectionFlags::Writable);
+                                     SectionKind::ReadOnlyWithRel);
   DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local",
-                                          SectionFlags::Writable);
+                                          SectionKind::ReadOnlyWithRelLocal);
     
   MergeableConst4Section = getNamedSection(".rodata.cst4",
-                  SectionFlags::setEntitySize(SectionFlags::Mergeable, 4));
+                                           SectionKind::MergeableConst4);
   MergeableConst8Section = getNamedSection(".rodata.cst8",
-                  SectionFlags::setEntitySize(SectionFlags::Mergeable, 8));
+                                           SectionKind::MergeableConst8);
   MergeableConst16Section = getNamedSection(".rodata.cst16",
-                  SectionFlags::setEntitySize(SectionFlags::Mergeable, 16));
+                                            SectionKind::MergeableConst16);
 }
 
 
@@ -98,28 +94,30 @@
 /// getFlagsForNamedSection - If this target wants to be able to infer
 /// section flags based on the name of the section specified for a global
 /// variable, it can implement this.
-unsigned ELFTargetAsmInfo::getFlagsForNamedSection(const char *Name) const {
-  unsigned Flags = 0;
-  if (Name[0] != '.') return 0;
+SectionKind::Kind ELFTargetAsmInfo::getKindForNamedSection(const char *Name,
+                                                   SectionKind::Kind K) const {
+  if (Name[0] != '.') return K;
   
   // Some lame default implementation based on some magic section names.
   if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
       strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
       strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
       strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
-    Flags |= SectionFlags::BSS;
-  else if (strcmp(Name, ".tdata") == 0 ||
-           strncmp(Name, ".tdata.", 7) == 0 ||
-           strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
-           strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
-    Flags |= SectionFlags::TLS;
-  else if (strcmp(Name, ".tbss") == 0 ||
-           strncmp(Name, ".tbss.", 6) == 0 ||
-           strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
-           strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
-    Flags |= SectionFlags::BSS | SectionFlags::TLS;
+    return SectionKind::BSS;
   
-  return Flags;
+  if (strcmp(Name, ".tdata") == 0 ||
+      strncmp(Name, ".tdata.", 7) == 0 ||
+      strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
+      strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
+    return SectionKind::ThreadData;
+  
+  if (strcmp(Name, ".tbss") == 0 ||
+      strncmp(Name, ".tbss.", 6) == 0 ||
+      strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
+      strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
+    return SectionKind::ThreadBSS;
+  
+  return K;
 }
 
 const char *
@@ -152,37 +150,36 @@
   if (Size <= 16) {
     assert(getCStringSection() && "Should have string section prefix");
 
-    // We also need alignment here
+    // We also need alignment here.
+    // FIXME: this is getting the alignment of the character, not the alignment
+    // of the string!!
     unsigned Align = TD->getPrefTypeAlignment(Ty);
     if (Align < Size)
       Align = Size;
 
     std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align);
-    unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable |
-                                                 SectionFlags::Strings,
-                                                 Size);
-    return getNamedSection(Name.c_str(), Flags);
+    return getNamedSection(Name.c_str(), SectionKind::MergeableCString);
   }
 
   return getReadOnlySection();
 }
 
-void ELFTargetAsmInfo::getSectionFlags(unsigned Flags,
-                                       SmallVectorImpl<char> &Str) const {
+void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
+                                             SmallVectorImpl<char> &Str) const {
   Str.push_back(',');
   Str.push_back('"');
   
-  if (!(Flags & SectionFlags::Debug))
+  if (!Kind.isMetadata())
     Str.push_back('a');
-  if (Flags & SectionFlags::Code)
+  if (Kind.isText())
     Str.push_back('x');
-  if (Flags & SectionFlags::Writable)
+  if (Kind.isWriteable())
     Str.push_back('w');
-  if (Flags & SectionFlags::Mergeable)
+  if (Kind.isMergeableConst() || Kind.isMergeableCString())
     Str.push_back('M');
-  if (Flags & SectionFlags::Strings)
+  if (Kind.isMergeableCString())
     Str.push_back('S');
-  if (Flags & SectionFlags::TLS)
+  if (Kind.isThreadLocal())
     Str.push_back('T');
 
   Str.push_back('"');
@@ -195,16 +192,27 @@
     Str.push_back('@');
 
   const char *KindStr;
-  if (Flags & SectionFlags::BSS)
+  if (Kind.isBSS())
     KindStr = "nobits";
   else
     KindStr = "progbits";
   
   Str.append(KindStr, KindStr+strlen(KindStr));
 
-  if (unsigned entitySize = SectionFlags::getEntitySize(Flags)) {
+  if (Kind.isMergeableCString()) {
+    // TODO: Eventually handle multiple byte character strings.  For now, all
+    // mergable C strings are single byte.
     Str.push_back(',');
-    std::string Size = utostr(entitySize);
-    Str.append(Size.begin(), Size.end());
+    Str.push_back('1');
+  } 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');
   }
 }
diff --git a/llvm/lib/Target/MSP430/MSP430TargetAsmInfo.cpp b/llvm/lib/Target/MSP430/MSP430TargetAsmInfo.cpp
index 12ae552..65d2f39 100644
--- a/llvm/lib/Target/MSP430/MSP430TargetAsmInfo.cpp
+++ b/llvm/lib/Target/MSP430/MSP430TargetAsmInfo.cpp
@@ -18,6 +18,5 @@
   : ELFTargetAsmInfo(TM) {
   AlignmentIsInBytes = false;
     
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
 }
diff --git a/llvm/lib/Target/Mips/MipsTargetAsmInfo.cpp b/llvm/lib/Target/Mips/MipsTargetAsmInfo.cpp
index 4e7d1bd..9c90ff0 100644
--- a/llvm/lib/Target/Mips/MipsTargetAsmInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsTargetAsmInfo.cpp
@@ -30,8 +30,7 @@
   BSSSection                  = "\t.section\t.bss";
   CStringSection              = ".rodata.str";
 
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
     
   if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
     JumpTableDirective = "\t.word\t";
diff --git a/llvm/lib/Target/PIC16/PIC16AsmPrinter.cpp b/llvm/lib/Target/PIC16/PIC16AsmPrinter.cpp
index 7195551..a72b8e5 100644
--- a/llvm/lib/Target/PIC16/PIC16AsmPrinter.cpp
+++ b/llvm/lib/Target/PIC16/PIC16AsmPrinter.cpp
@@ -61,8 +61,8 @@
   // Now emit the instructions of function in its code section.
   const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str();
  
-  const Section *fCodeSection = TAI->getNamedSection(codeSection,
-                                                     SectionFlags::Code);
+  const Section *fCodeSection = 
+    TAI->getNamedSection(codeSection, SectionKind::Text);
   // Start the Code Section.
   O <<  "\n";
   SwitchToSection(fCodeSection);
@@ -291,8 +291,8 @@
   O << "\n"; 
   const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
 
-  const Section *fPDataSection = TAI->getNamedSection(SectionName,
-                                                      SectionFlags::Writable);
+  const Section *fPDataSection =
+    TAI->getNamedSection(SectionName, SectionKind::DataRel);
   SwitchToSection(fPDataSection);
   
   // Emit function frame label
diff --git a/llvm/lib/Target/PIC16/PIC16TargetAsmInfo.cpp b/llvm/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
index e8f216d..c855632 100644
--- a/llvm/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
+++ b/llvm/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
@@ -37,18 +37,21 @@
   ZeroDirective = NULL;
   AsciiDirective = " dt ";
   AscizDirective = NULL;
-  BSSSection_  = getNamedSection("udata.# UDATA",
-                              SectionFlags::Writable | SectionFlags::BSS);
-  ReadOnlySection = getNamedSection("romdata.# ROMDATA", SectionFlags::None);
-  DataSection = getNamedSection("idata.# IDATA", SectionFlags::Writable);
+  BSSSection_  = getNamedSection("udata.# UDATA", SectionKind::BSS);
+  ReadOnlySection = getNamedSection("romdata.# ROMDATA", SectionKind::ReadOnly);
+  DataSection = getNamedSection("idata.# IDATA", SectionKind::DataRel);
   SwitchToSectionDirective = "";
   // Need because otherwise a .text symbol is emitted by DwarfWriter
   // in BeginModule, and gpasm cribbs for that .text symbol.
-  TextSection = getUnnamedSection("", SectionFlags::Code);
+  TextSection = getUnnamedSection("", SectionKind::Text);
   PIC16Section *ROSection = new PIC16Section(getReadOnlySection());
   ROSections.push_back(ROSection);
-  ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls"));
-  ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs"));
+    
+  // FIXME: I don't know what the classification of these sections really is.
+  ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls",
+                                                      SectionKind::Metadata));
+  ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs",
+                                                     SectionKind::Metadata));
   // Set it to false because we weed to generate c file name and not bc file
   // name.
   HasSingleParameterDotFile = false;
@@ -95,7 +98,9 @@
   // No BSS section spacious enough was found. Crate a new one.
   if (!FoundBSS) {
     std::string name = PAN::getUdataSectionName(BSSSections.size());
-    const Section *NewSection = getNamedSection(name.c_str());
+    const Section *NewSection = getNamedSection(name.c_str(),
+                                                // FIXME.
+                                                SectionKind::Metadata);
 
     FoundBSS = new PIC16Section(NewSection);
 
@@ -135,7 +140,9 @@
   // No IDATA section spacious enough was found. Crate a new one.
   if (!FoundIDATA) {
     std::string name = PAN::getIdataSectionName(IDATASections.size());
-    const Section *NewSection = getNamedSection(name.c_str());
+    const Section *NewSection = getNamedSection(name.c_str(),
+                                                // FIXME.
+                                                SectionKind::Metadata);
 
     FoundIDATA = new PIC16Section(NewSection);
 
@@ -168,7 +175,9 @@
 
   // No Auto section was found. Crate a new one.
   if (!FoundAutoSec) {
-    const Section *NewSection = getNamedSection(name.c_str());
+    const Section *NewSection = getNamedSection(name.c_str(),
+                                                // FIXME.
+                                                SectionKind::Metadata);
 
     FoundAutoSec = new PIC16Section(NewSection);
 
@@ -316,7 +325,7 @@
   
   PIC16Section *NewBSS = FoundBSS;
   if (NewBSS == NULL) {
-    const Section *NewSection = getNamedSection(Name.c_str());
+    const Section *NewSection = getNamedSection(Name.c_str(), SectionKind::BSS);
     NewBSS = new PIC16Section(NewSection);
     BSSSections.push_back(NewBSS);
   }
@@ -367,7 +376,9 @@
 
   PIC16Section *NewIDATASec = FoundIDATASec;
   if (NewIDATASec == NULL) {
-    const Section *NewSection = getNamedSection(Name.c_str());
+    const Section *NewSection = getNamedSection(Name.c_str(),
+                                                // FIXME:
+                                                SectionKind::Metadata);
     NewIDATASec = new PIC16Section(NewSection);
     IDATASections.push_back(NewIDATASec);
   }
@@ -405,7 +416,8 @@
 
   PIC16Section *NewRomSec = FoundROSec;
   if (NewRomSec == NULL) {
-    const Section *NewSection = getNamedSection(Name.c_str());
+    const Section *NewSection = getNamedSection(Name.c_str(),
+                                                SectionKind::ReadOnly);
     NewRomSec = new PIC16Section(NewSection);
     ROSections.push_back(NewRomSec);
   }
diff --git a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
index 88663c4..bc0a794 100644
--- a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
@@ -899,7 +899,7 @@
       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
        GVar->isWeakForLinker()) &&
       // Don't put things that should go in the cstring section into "comm".
-      !TheSection->hasFlag(SectionFlags::Strings)) {
+      !TheSection->getKind().isMergeableCString()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     if (GVar->hasExternalLinkage()) {
diff --git a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
index c85dddf..d56a921 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
@@ -49,8 +49,7 @@
     return DW_EH_PE_absptr;
 }
 
-const char *
-PPCDarwinTargetAsmInfo::getEHGlobalPrefix() const {
+const char *PPCDarwinTargetAsmInfo::getEHGlobalPrefix() const {
   const PPCSubtarget* Subtarget = &TM.getSubtarget<PPCSubtarget>();
   if (Subtarget->getDarwinVers() > 9)
     return PrivateGlobalPrefix;
@@ -72,8 +71,7 @@
   BSSSection = "\t.section\t\".sbss\",\"aw\",@nobits";
 
   // PPC/Linux normally uses named section for BSS.
-  BSSSection_ = getNamedSection("\t.bss",
-                                SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getNamedSection("\t.bss", SectionKind::BSS);
 
   // Debug Information
   AbsoluteDebugSectionOffsets = true;
diff --git a/llvm/lib/Target/Sparc/SparcTargetAsmInfo.cpp b/llvm/lib/Target/Sparc/SparcTargetAsmInfo.cpp
index adec722..4bcaec0 100644
--- a/llvm/lib/Target/Sparc/SparcTargetAsmInfo.cpp
+++ b/llvm/lib/Target/Sparc/SparcTargetAsmInfo.cpp
@@ -27,25 +27,24 @@
   CStringSection=".rodata.str";
 
   // Sparc normally uses named section for BSS.
-  BSSSection_ = getNamedSection("\t.bss",
-                                SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getNamedSection("\t.bss", SectionKind::BSS);
 }
 
 
-void SparcELFTargetAsmInfo::getSectionFlags(unsigned Flags,
+void SparcELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
                                             SmallVectorImpl<char> &Str) const {
-  if (Flags & SectionFlags::Mergeable)
-    return ELFTargetAsmInfo::getSectionFlags(Flags, Str);
+  if (Kind.isMergeableConst() || Kind.isMergeableCString())
+    return ELFTargetAsmInfo::getSectionFlagsAsString(Kind, Str);
 
   // FIXME: Inefficient.
   std::string Res;
-  if (!(Flags & SectionFlags::Debug))
+  if (!Kind.isMetadata())
     Res += ",#alloc";
-  if (Flags & SectionFlags::Code)
+  if (Kind.isText())
     Res += ",#execinstr";
-  if (Flags & SectionFlags::Writable)
+  if (Kind.isWriteable())
     Res += ",#write";
-  if (Flags & SectionFlags::TLS)
+  if (Kind.isThreadLocal())
     Res += ",#tls";
 
   Str.append(Res.begin(), Res.end());
diff --git a/llvm/lib/Target/Sparc/SparcTargetAsmInfo.h b/llvm/lib/Target/Sparc/SparcTargetAsmInfo.h
index cf65c1f..943dcef 100644
--- a/llvm/lib/Target/Sparc/SparcTargetAsmInfo.h
+++ b/llvm/lib/Target/Sparc/SparcTargetAsmInfo.h
@@ -24,8 +24,8 @@
   struct SparcELFTargetAsmInfo : public ELFTargetAsmInfo {
     explicit SparcELFTargetAsmInfo(const TargetMachine &TM);
 
-    virtual void getSectionFlags(unsigned Flags,
-                                 SmallVectorImpl<char> &Str) const;
+    virtual void getSectionFlagsAsString(SectionKind Kind,
+                                         SmallVectorImpl<char> &Str) const;
 
   };
 
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetAsmInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetAsmInfo.cpp
index 3040262..1f9d34f 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetAsmInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetAsmInfo.cpp
@@ -28,6 +28,5 @@
 
   NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
     
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
 }
diff --git a/llvm/lib/Target/TargetAsmInfo.cpp b/llvm/lib/Target/TargetAsmInfo.cpp
index 28d6324..604c54e 100644
--- a/llvm/lib/Target/TargetAsmInfo.cpp
+++ b/llvm/lib/Target/TargetAsmInfo.cpp
@@ -122,8 +122,8 @@
   DwarfEHFrameSection = ".eh_frame";
   DwarfExceptionSection = ".gcc_except_table";
   AsmTransCBE = 0;
-  TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
-  DataSection = getUnnamedSection("\t.data", SectionFlags::Writable);
+  TextSection = getUnnamedSection("\t.text", SectionKind::Text);
+  DataSection = getUnnamedSection("\t.data", SectionKind::DataRel);
 }
 
 TargetAsmInfo::~TargetAsmInfo() {
@@ -199,23 +199,6 @@
   return false;
 }
 
-static unsigned SectionFlagsForGlobal(SectionKind Kind) {
-  // Decode flags from global and section kind.
-  unsigned Flags = SectionFlags::None;
-  if (Kind.isWeak())
-    Flags |= SectionFlags::Linkonce;
-  if (Kind.isBSS() || Kind.isThreadBSS())
-    Flags |= SectionFlags::BSS;
-  if (Kind.isThreadLocal())
-    Flags |= SectionFlags::TLS;
-  if (Kind.isText())
-    Flags |= SectionFlags::Code;
-  if (Kind.isWriteable())
-    Flags |= SectionFlags::Writable;
-
-  return Flags;
-}
-
 static SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV,
                                               const TargetMachine &TM) {
   Reloc::Model ReloModel = TM.getRelocationModel();
@@ -326,29 +309,21 @@
     if (const Section *TS = getSpecialCasedSectionGlobals(GV, Kind))
       return TS;
     
-    // Honour section already set, if any.
-    unsigned Flags = SectionFlagsForGlobal(Kind);
-
-    // This is an explicitly named section.
-    Flags |= SectionFlags::Named;
-    
     // If the target has magic semantics for certain section names, make sure to
     // pick up the flags.  This allows the user to write things with attribute
     // section and still get the appropriate section flags printed.
-    Flags |= getFlagsForNamedSection(GV->getSection().c_str());
+    GVKind = getKindForNamedSection(GV->getSection().c_str(), GVKind);
     
-    return getNamedSection(GV->getSection().c_str(), Flags);
+    return getNamedSection(GV->getSection().c_str(), GVKind);
   }
 
   // If this global is linkonce/weak and the target handles this by emitting it
   // into a 'uniqued' section name, create and return the section now.
   if (Kind.isWeak()) {
     if (const char *Prefix = getSectionPrefixForUniqueGlobal(Kind)) {
-      unsigned Flags = SectionFlagsForGlobal(Kind);
-
       // FIXME: Use mangler interface (PR4584).
       std::string Name = Prefix+GV->getNameStr();
-      return getNamedSection(Name.c_str(), Flags);
+      return getNamedSection(Name.c_str(), GVKind);
     }
   }
   
@@ -390,12 +365,12 @@
 
 
 const Section *TargetAsmInfo::getNamedSection(const char *Name,
-                                              unsigned Flags) const {
+                                              SectionKind::Kind Kind) const {
   Section &S = Sections[Name];
 
   // This is newly-created section, set it up properly.
   if (S.Name.empty()) {
-    S.Flags = Flags | SectionFlags::Named;
+    S.Kind = SectionKind::get(Kind, false /*weak*/, true /*Named*/);
     S.Name = Name;
   }
 
@@ -403,12 +378,13 @@
 }
 
 const Section*
-TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags) const {
+TargetAsmInfo::getUnnamedSection(const char *Directive,
+                                 SectionKind::Kind Kind) const {
   Section& S = Sections[Directive];
 
   // This is newly-created section, set it up properly.
   if (S.Name.empty()) {
-    S.Flags = Flags & ~SectionFlags::Named;
+    S.Kind = SectionKind::get(Kind, false /*weak*/, false /*Named*/);
     S.Name = Directive;
   }
 
diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
index 1260ced..90cbf80 100644
--- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
@@ -799,7 +799,7 @@
 
   if (C->isNullValue() && !GVar->hasSection() &&
       // Don't put things that should go in the cstring section into "comm".
-      !TheSection->hasFlag(SectionFlags::Strings)) {
+      !TheSection->getKind().isMergeableCString()) {
     if (GVar->hasExternalLinkage()) {
       if (const char *Directive = TAI->getZeroFillDirective()) {
         O << "\t.globl " << name << '\n';
diff --git a/llvm/lib/Target/X86/X86TargetAsmInfo.cpp b/llvm/lib/Target/X86/X86TargetAsmInfo.cpp
index 802d04a..04de225 100644
--- a/llvm/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -58,7 +58,7 @@
   // FIXME: Why don't we always use this section?
   if (is64Bit)
     SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
-                                                   SectionFlags::Mergeable);
+                                                 SectionKind::MergeableConst16);
   LCOMMDirective = "\t.lcomm\t";
 
   // Leopard and above support aligned common symbols.
@@ -128,8 +128,7 @@
   // Set up DWARF directives
   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
 
-  BSSSection_ = getUnnamedSection("\t.bss",
-                                  SectionFlags::Writable | SectionFlags::BSS);
+  BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
 
   // Debug Information
   AbsoluteDebugSectionOffsets = true;
@@ -278,13 +277,14 @@
 }
 
 
-void X86COFFTargetAsmInfo::getSectionFlags(unsigned Flags,
-                                           SmallVectorImpl<char> &Str) const {
+
+void X86COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
+                                            SmallVectorImpl<char> &Str) const {
   // FIXME: Inefficient.
   std::string Res = ",\"";
-  if (Flags & SectionFlags::Code)
+  if (Kind.isText())
     Res += 'x';
-  if (Flags & SectionFlags::Writable)
+  if (Kind.isWriteable())
     Res += 'w';
   Res += "\"";
 
@@ -314,8 +314,8 @@
 
   AlignmentIsInBytes = true;
 
-  TextSection = getUnnamedSection("_text", SectionFlags::Code);
-  DataSection = getUnnamedSection("_data", SectionFlags::Writable);
+  TextSection = getUnnamedSection("_text", SectionKind::Text);
+  DataSection = getUnnamedSection("_data", SectionKind::DataRel);
 
   JumpTableDataSection = NULL;
   SwitchToSectionDirective = "";
diff --git a/llvm/lib/Target/X86/X86TargetAsmInfo.h b/llvm/lib/Target/X86/X86TargetAsmInfo.h
index 75cd04c..d971680 100644
--- a/llvm/lib/Target/X86/X86TargetAsmInfo.h
+++ b/llvm/lib/Target/X86/X86TargetAsmInfo.h
@@ -56,8 +56,8 @@
     virtual const char *
     getSectionPrefixForUniqueGlobal(SectionKind kind) const;
     
-    virtual void getSectionFlags(unsigned Flags,
-                                 SmallVectorImpl<char> &Str) const;
+    virtual void getSectionFlagsAsString(SectionKind Kind,
+                                         SmallVectorImpl<char> &Str) const;
   };
 
   struct X86WinTargetAsmInfo : public X86GenericTargetAsmInfo {
diff --git a/llvm/lib/Target/XCore/XCoreTargetAsmInfo.cpp b/llvm/lib/Target/XCore/XCoreTargetAsmInfo.cpp
index 9f6727b..4c8786a 100644
--- a/llvm/lib/Target/XCore/XCoreTargetAsmInfo.cpp
+++ b/llvm/lib/Target/XCore/XCoreTargetAsmInfo.cpp
@@ -24,10 +24,9 @@
 XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM)
   : ELFTargetAsmInfo(TM) {
   SupportsDebugInformation = true;
-  TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
-  DataSection = getNamedSection("\t.dp.data", SectionFlags::Writable);
-  BSSSection_  = getNamedSection("\t.dp.bss", SectionFlags::Writable |
-                                 SectionFlags::BSS);
+  TextSection = getUnnamedSection("\t.text", SectionKind::Text);
+  DataSection = getNamedSection("\t.dp.data", SectionKind::DataRel);
+  BSSSection_  = getNamedSection("\t.dp.bss", SectionKind::BSS);
 
   // TLS globals are lowered in the backend to arrays indexed by the current
   // thread id. After lowering they require no special handling by the linker
@@ -36,9 +35,10 @@
   TLSBSSSection = BSSSection_;
 
   if (TM.getSubtargetImpl()->isXS1A())
-    ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::Writable);
+    // FIXME: Why is this writable???
+    ReadOnlySection = getNamedSection("\t.dp.rodata", SectionKind::DataRel);
   else
-    ReadOnlySection = getNamedSection("\t.cp.rodata", SectionFlags::None);
+    ReadOnlySection = getNamedSection("\t.cp.rodata", SectionKind::ReadOnly);
   Data16bitsDirective = "\t.short\t";
   Data32bitsDirective = "\t.long\t";
   Data64bitsDirective = 0;