[llvm-commits] [llvm] r76705 - 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
Tue Jul 21 17:28:44 PDT 2009


Author: lattner
Date: Tue Jul 21 19:28:43 2009
New Revision: 76705

URL: http://llvm.org/viewvc/llvm-project?rev=76705&view=rev
Log:
remove the SelectSectionForMachineConst hook, replacing it with
a new getSectionForMergableConstant hook.  This removes one dependence
of TAI on Type, and provides the hook with enough info to make the 
right decision based on whether the global has relocations etc.

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=76705&r1=76704&r2=76705&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h Tue Jul 21 19:28:43 2009
@@ -39,7 +39,10 @@
                                                SectionKind::Kind kind) const;
     virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
                                       Mangler *Mang) const;
-    const Section* SelectSectionForMachineConst(const Type *Ty) const;
+
+    
+    virtual const Section *
+    getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
     
   private:
     const Section* MergeableConstSection(const Type *Ty) const;

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

==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Tue Jul 21 19:28:43 2009
@@ -25,11 +25,16 @@
   struct ELFTargetAsmInfo: public TargetAsmInfo {
     explicit ELFTargetAsmInfo(const TargetMachine &TM);
 
+    /// 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;
+    
+    
     SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
     virtual std::string printSectionFlags(unsigned flags) const;
-    virtual const Section*
-    SelectSectionForMachineConst(const Type *Ty) const;
 
     const Section* DataRelSection;
     const Section* DataRelLocalSection;

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Tue Jul 21 19:28:43 2009
@@ -595,6 +595,14 @@
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
 
+    
+    /// 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;
+
+    
     /// SectionKindForGlobal - This hook allows the target to select proper
     /// section kind used for global emission.
 // FIXME: Eliminate this.
@@ -623,7 +631,6 @@
 
 // FIXME: Eliminate this.
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
-    virtual const Section* SelectSectionForMachineConst(const Type *Ty) const;
 
     /// getSLEB128Size - Compute the number of bytes required for a signed
     /// leb128 value.

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Jul 21 19:28:43 2009
@@ -302,13 +302,18 @@
   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) {
-    MachineConstantPoolEntry CPE = CP[i];
+    const MachineConstantPoolEntry &CPE = CP[i];
     unsigned Align = CPE.getAlignment();
-    const Section* S = TAI->SelectSectionForMachineConst(CPE.getType());
+    uint64_t Size = TD.getTypeAllocSize(CPE.getType());
+    const Section *S =
+      TAI->getSectionForMergableConstant(Size, CPE.getRelocationInfo());
+    
     // The number of sections are small, just do a linear search from the
     // last section to the first.
     bool Found = false;

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

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Tue Jul 21 19:28:43 2009
@@ -155,8 +155,10 @@
 
 // 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());
+  
   std::string CstPoolName =
-    TAI->SelectSectionForMachineConst(CPE.getType())->getName();
+    TAI->getSectionForMergableConstant(Size,CPE.getRelocationInfo())->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=76705&r1=76704&r2=76705&view=diff

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Tue Jul 21 19:28:43 2009
@@ -29,7 +29,7 @@
   : TargetAsmInfo(TM) {
 
   CStringSection_ = getUnnamedSection("\t.cstring",
-                                SectionFlags::Mergeable | SectionFlags::Strings);
+                                SectionFlags::Mergeable |SectionFlags::Strings);
   FourByteConstantSection = getUnnamedSection("\t.literal4\n",
                                               SectionFlags::Mergeable);
   EightByteConstantSection = getUnnamedSection("\t.literal8\n",
@@ -182,28 +182,30 @@
 const Section*
 DarwinTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
   const TargetData *TD = TM.getTargetData();
-
-  unsigned Size = TD->getTypeAllocSize(Ty);
-  if (Size == 4)
-    return FourByteConstantSection;
-  else if (Size == 8)
-    return EightByteConstantSection;
-  else if (Size == 16 && SixteenByteConstantSection)
-    return SixteenByteConstantSection;
-
-  return getReadOnlySection();
+  return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
 }
 
-const Section*
-DarwinTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
-  const Section* S = MergeableConstSection(Ty);
-
-  // Handle weird special case, when compiling PIC stuff.
-  if (S == getReadOnlySection() &&
-      TM.getRelocationModel() != Reloc::Static)
+const Section *
+DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
+                                                   unsigned ReloInfo) const {
+  // If this constant requires a relocation, we have to put it in the data
+  // segment, not in the text segment.
+  if (ReloInfo != 0)
     return ConstDataSection;
-
-  return S;
+  
+  switch (Size) {
+  default: break;
+  case 4:
+    return FourByteConstantSection;
+  case 8:
+    return EightByteConstantSection;
+  case 16:
+    if (SixteenByteConstantSection)
+      return SixteenByteConstantSection;
+    break;
+  }
+  
+  return ReadOnlySection;  // .const
 }
 
 std::string

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

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Tue Jul 21 19:28:43 2009
@@ -138,29 +138,37 @@
   return NULL;
 }
 
-const Section*
-ELFTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
-  // FIXME: Support data.rel stuff someday
-  return MergeableConstSection(Ty);
+/// getSectionForMergableConstant - Given a mergable constant with the
+/// specified size and relocation information, return a section that it
+/// should be placed in.
+const Section *
+ELFTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
+                                                unsigned ReloInfo) const {
+  // FIXME: IF this global requires a relocation, can we really put it in
+  // rodata???  This should check ReloInfo like darwin.
+  
+  const char *SecName = 0;
+  switch (Size) {
+  default: break;
+  case 4:  SecName = ".rodata.cst4"; break;
+  case 8:  SecName = ".rodata.cst8"; break;
+  case 16: SecName = ".rodata.cst16"; break;
+  }
+  
+  if (SecName)
+    return getNamedSection(SecName,
+                           SectionFlags::setEntitySize(SectionFlags::Mergeable|
+                                                       SectionFlags::Small,
+                                                       Size));
+  
+  return getReadOnlySection();  // .rodata
 }
 
+
 const Section*
 ELFTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
   const TargetData *TD = TM.getTargetData();
-
-  // FIXME: string here is temporary, until stuff will fully land in.
-  // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
-  // currently directly used by asmprinter.
-  unsigned Size = TD->getTypeAllocSize(Ty);
-  if (Size == 4 || Size == 8 || Size == 16) {
-    std::string Name =  ".rodata.cst" + utostr(Size);
-
-    return getNamedSection(Name.c_str(),
-                           SectionFlags::setEntitySize(SectionFlags::Mergeable,
-                                                       Size));
-  }
-
-  return getReadOnlySection();
+  return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
 }
 
 const Section*

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Tue Jul 21 19:28:43 2009
@@ -329,13 +329,20 @@
   return getDataSection();
 }
 
-// Lame default implementation. Calculate the section name for machine const.
-const Section*
-TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
+/// getSectionForMergableConstant - Given a mergable constant with the
+/// specified size and relocation information, return a section that it
+/// should be placed in.
+const Section *
+TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
+                                             unsigned ReloInfo) const {
   // FIXME: Support data.rel stuff someday
+  // Lame default implementation. Calculate the section name for machine const.
   return getDataSection();
 }
 
+
+
+
 std::string
 TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
                                       SectionKind::Kind Kind) const {





More information about the llvm-commits mailing list