[llvm-commits] [llvm] r77132 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/Target/DarwinTargetAsmInfo.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/TargetAsmInfo.cpp

Chris Lattner sabre at nondot.org
Sat Jul 25 23:11:56 PDT 2009


Author: lattner
Date: Sun Jul 26 01:11:33 2009
New Revision: 77132

URL: http://llvm.org/viewvc/llvm-project?rev=77132&view=rev
Log:
introduce specialized mergable const sectionkinds for elements of size 4/8/16 to
simplify targets.

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

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun Jul 26 01:11:33 2009
@@ -60,6 +60,17 @@
           /// constant pool entries etc.
           MergableConst,
       
+              /// MergableConst4 - This is a section used by 4-byte constants,
+              /// for example, floats.
+              MergableConst4,
+      
+              /// MergableConst8 - This is a section used by 8-byte constants,
+              /// for example, doubles.
+              MergableConst8,
+
+              /// MergableConst16 - This is a section used by 16-byte constants,
+              /// for example, vectors.
+              MergableConst16,
       
       /// Writable - This is the base of all segments that need to be written
       /// to during program runtime.
@@ -118,11 +129,18 @@
     }
     
     bool isReadOnly() const {
-      return K == ReadOnly || K == MergableCString || K == MergableConst;
+      return K == ReadOnly || K == MergableCString || isMergableConst();
     }
 
     bool isMergableCString() const { return K == MergableCString; }
-    bool isMergableConst() const { return K == MergableConst; }
+    bool isMergableConst() const {
+      return K == MergableConst || K == MergableConst4 ||
+             K == MergableConst8 || K == MergableConst16;
+    }
+    
+    bool isMergableConst4() const { return K == MergableConst4; }
+    bool isMergableConst8() const { return K == MergableConst8; }
+    bool isMergableConst16() const { return K == MergableConst16; }
     
     bool isWritable() const {
       return isThreadLocal() || isGlobalWritableData();
@@ -167,6 +185,9 @@
     static SectionKind getReadOnly()         { return get(ReadOnly); }
     static SectionKind getMergableCString()  { return get(MergableCString); }
     static SectionKind getMergableConst()    { return get(MergableConst); }
+    static SectionKind getMergableConst4()   { return get(MergableConst4); }
+    static SectionKind getMergableConst8()   { return get(MergableConst8); }
+    static SectionKind getMergableConst16()  { return get(MergableConst16); }
     static SectionKind getThreadBSS()        { return get(ThreadBSS); }
     static SectionKind getThreadData()       { return get(ThreadData); }
     static SectionKind getBSS()              { return get(BSS); }

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

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Sun Jul 26 01:11:33 2009
@@ -148,9 +148,13 @@
     return MergeableStringSection(cast<GlobalVariable>(GV));
   
   if (Kind.isMergableConst()) {
-    const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
-    const TargetData *TD = TM.getTargetData();
-    return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
+    if (Kind.isMergableConst4())
+      return FourByteConstantSection;
+    if (Kind.isMergableConst8())
+      return EightByteConstantSection;
+    if (Kind.isMergableConst16() && SixteenByteConstantSection)
+      return SixteenByteConstantSection;
+    return ReadOnlySection;  // .const
   }
   
   // FIXME: ROData -> const in -static mode that is relocatable but they happen

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

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Sun Jul 26 01:11:33 2009
@@ -52,6 +52,7 @@
   if (Kind.isText()) return TextSection;
   if (Kind.isMergableCString())
     return MergeableStringSection(cast<GlobalVariable>(GV));
+  
   if (Kind.isMergableConst()) {
     const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
     const TargetData *TD = TM.getTargetData();
@@ -132,8 +133,6 @@
   return Flags;
 }
 
-
-
 const char *
 ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
   if (Kind.isText())                 return ".gnu.linkonce.t.";

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun Jul 26 01:11:33 2009
@@ -19,6 +19,7 @@
 #include "llvm/Module.h"
 #include "llvm/Type.h"
 #include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Support/Dwarf.h"
@@ -217,7 +218,9 @@
 }
 
 static SectionKind SectionKindForGlobal(const GlobalValue *GV,
-                                        Reloc::Model ReloModel) {
+                                        const TargetMachine &TM) {
+  Reloc::Model ReloModel = TM.getRelocationModel();
+  
   // Early exit - functions should be always in text sections.
   const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
   if (GVar == 0)
@@ -249,8 +252,15 @@
       if (isConstantString(C))
         return SectionKind::getMergableCString();
       
-      // Otherwise, just drop it into a mergable constant section.
-      return SectionKind::getMergableConst();
+      // Otherwise, just drop it into a mergable constant section.  If we have
+      // a section for this size, use it, otherwise use the arbitrary sized
+      // mergable section.
+      switch (TM.getTargetData()->getTypeAllocSize(C->getType())) {
+      case 4:  return SectionKind::getMergableConst4();
+      case 8:  return SectionKind::getMergableConst8();
+      case 16: return SectionKind::getMergableConst16();
+      default: return SectionKind::getMergableConst();
+      }
       
     case Constant::LocalRelocation:
       // In static relocation model, the linker will resolve all addresses, so
@@ -299,7 +309,7 @@
   assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
          "Can only be used for global definitions");
   
-  SectionKind Kind = SectionKindForGlobal(GV, TM.getRelocationModel());
+  SectionKind Kind = SectionKindForGlobal(GV, TM);
 
   // Select section name.
   if (GV->hasSection()) {





More information about the llvm-commits mailing list