[llvm-commits] [llvm] r77134 - in /llvm/trunk: include/llvm/Target/DarwinTargetAsmInfo.h include/llvm/Target/ELFTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/ELFWriter.cpp lib/Target/DarwinTargetAsmInfo.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/TargetAsmInfo.cpp

Chris Lattner sabre at nondot.org
Sat Jul 25 23:27:32 PDT 2009


Author: lattner
Date: Sun Jul 26 01:26:55 2009
New Revision: 77134

URL: http://llvm.org/viewvc/llvm-project?rev=77134&view=rev
Log:
simplify getSectionForMergableConstant to take a SectionKind.

Modified:
    llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp

Modified: llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h?rev=77134&r1=77133&r2=77134&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h Sun Jul 26 01:26:55 2009
@@ -40,8 +40,7 @@
                                       Mangler *Mang) const;
 
     
-    virtual const Section *
-    getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
+    virtual const Section *getSectionForMergableConstant(SectionKind Kind)const;
     
   private:
     const Section* MergeableStringSection(const GlobalVariable *GV) const;

Modified: llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h?rev=77134&r1=77133&r2=77134&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Sun Jul 26 01:26:55 2009
@@ -29,7 +29,7 @@
     /// specified size and relocation information, return a section that it
     /// should be placed in.
     virtual const Section *
-    getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
+    getSectionForMergableConstant(SectionKind Kind) const;
     
     /// getFlagsForNamedSection - If this target wants to be able to infer
     /// section flags based on the name of the section specified for a global

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun Jul 26 01:26:55 2009
@@ -710,8 +710,7 @@
     /// getSectionForMergableConstant - Given a mergable constant with the
     /// specified size and relocation information, return a section that it
     /// should be placed in.
-    virtual const Section *
-    getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
+    virtual const Section *getSectionForMergableConstant(SectionKind Kind)const;
 
     
     /// getSectionPrefixForUniqueGlobal - Return a string that we should prepend

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Jul 26 01:26:55 2009
@@ -301,17 +301,28 @@
   const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
   if (CP.empty()) return;
 
-  const TargetData &TD = *TM.getTargetData();
-  
   // Calculate sections for constant pool entries. We collect entries to go into
   // the same section together to reduce amount of section switch statements.
   SmallVector<SectionCPs, 4> CPSections;
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
     const MachineConstantPoolEntry &CPE = CP[i];
     unsigned Align = CPE.getAlignment();
-    uint64_t Size = TD.getTypeAllocSize(CPE.getType());
-    const Section *S =
-      TAI->getSectionForMergableConstant(Size, CPE.getRelocationInfo());
+    
+    SectionKind Kind;
+    switch (CPE.getRelocationInfo()) {
+    default: llvm_unreachable("Unknown section kind");
+    case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
+    case 1: Kind = SectionKind::getReadOnlyWithRelLocal(); break;
+    case 0:
+      switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
+      case 4:   Kind = SectionKind::getMergableConst4(); break;
+      case 8:   Kind = SectionKind::getMergableConst8(); break;
+      case 16:  Kind = SectionKind::getMergableConst16(); break;
+      default:  Kind = SectionKind::getMergableConst(); break;
+      }
+    }
+
+    const Section *S = TAI->getSectionForMergableConstant(Kind);
     
     // The number of sections are small, just do a linear search from the
     // last section to the first.

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=77134&r1=77133&r2=77134&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Sun Jul 26 01:26:55 2009
@@ -29,7 +29,6 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "elfwriter"
-
 #include "ELF.h"
 #include "ELFWriter.h"
 #include "ELFCodeEmitter.h"
@@ -155,10 +154,21 @@
 
 // Get a constant pool section based on the section name returned by TAI
 ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
-  uint64_t Size = TM.getTargetData()->getTypeAllocSize(CPE.getType());
+  SectionKind Kind;
+  switch (CPE.getRelocationInfo()) {
+  default: llvm_unreachable("Unknown section kind");
+  case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
+  case 1: Kind = SectionKind::getReadOnlyWithRelLocal(); break;
+  case 0:
+    switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
+    case 4:   Kind = SectionKind::getMergableConst4(); break;
+    case 8:   Kind = SectionKind::getMergableConst8(); break;
+    case 16:  Kind = SectionKind::getMergableConst16(); break;
+    default:  Kind = SectionKind::getMergableConst(); break;
+    }
+  }
   
-  std::string CstPoolName =
-    TAI->getSectionForMergableConstant(Size,CPE.getRelocationInfo())->getName();
+  std::string CstPoolName = TAI->getSectionForMergableConstant(Kind)->getName();
   return getSection(CstPoolName,
                     ELFSection::SHT_PROGBITS,
                     ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC,

Modified: llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp?rev=77134&r1=77133&r2=77134&view=diff

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Sun Jul 26 01:26:55 2009
@@ -188,25 +188,18 @@
 }
 
 const Section *
-DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
-                                                   unsigned ReloInfo) const {
+DarwinTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
   // If this constant requires a relocation, we have to put it in the data
   // segment, not in the text segment.
-  if (ReloInfo != 0)
+  if (Kind.isDataRel())
     return ConstDataSection;
   
-  switch (Size) {
-  default: break;
-  case 4:
+  if (Kind.isMergableConst4())
     return FourByteConstantSection;
-  case 8:
+  if (Kind.isMergableConst8())
     return EightByteConstantSection;
-  case 16:
-    if (SixteenByteConstantSection)
-      return SixteenByteConstantSection;
-    break;
-  }
-  
+  if (Kind.isMergableConst16() && SixteenByteConstantSection)
+    return SixteenByteConstantSection;
   return ReadOnlySection;  // .const
 }
 

Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=77134&r1=77133&r2=77134&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Sun Jul 26 01:26:55 2009
@@ -92,21 +92,8 @@
 /// specified size and relocation information, return a section that it
 /// should be placed in.
 const Section *
-ELFTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
-                                                unsigned ReloInfo) const {
-  // If this constant pool entry has relocations, stick it into a relocatable
-  // section.
-  if (ReloInfo == 2)
-    return DataRelROSection;
-  if (ReloInfo == 1)
-    return DataRelROLocalSection;
-  
-  switch (Size) {
-  default: return ReadOnlySection;   // .rodata
-  case 4:  return MergableConst4Section;
-  case 8:  return MergableConst8Section;
-  case 16: return MergableConst16Section;
-  }
+ELFTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
+  return SelectSectionForGlobal(0, Kind);
 }
 
 /// getFlagsForNamedSection - If this target wants to be able to infer

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun Jul 26 01:26:55 2009
@@ -372,9 +372,8 @@
 /// specified size and relocation information, return a section that it
 /// should be placed in.
 const Section *
-TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
-                                             unsigned ReloInfo) const {
-  if (ReloInfo == 0)
+TargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
+  if (Kind.isReadOnly())
     if (const Section *S = getReadOnlySection())
       return S;
   





More information about the llvm-commits mailing list