[llvm-commits] [llvm] r78068 - in /llvm/trunk: include/llvm/Target/TargetLoweringObjectFile.h lib/Target/TargetLoweringObjectFile.cpp test/CodeGen/X86/global-sections.ll

Chris Lattner sabre at nondot.org
Tue Aug 4 09:27:17 PDT 2009


Author: lattner
Date: Tue Aug  4 11:27:13 2009
New Revision: 78068

URL: http://llvm.org/viewvc/llvm-project?rev=78068&view=rev
Log:
enhance codegen to put 16-bit character strings into the 
__TEXT,__ustring section on darwin.

Modified:
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
    llvm/trunk/test/CodeGen/X86/global-sections.ll

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Tue Aug  4 11:27:13 2009
@@ -224,6 +224,7 @@
   
 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
   const MCSection *CStringSection;
+  const MCSection *UStringSection;
   const MCSection *TextCoalSection;
   const MCSection *ConstTextCoalSection;
   const MCSection *ConstDataCoalSection;

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

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Tue Aug  4 11:27:13 2009
@@ -593,11 +593,13 @@
                                    SectionKind::getDataRel());
   
   CStringSection = getOrCreateSection("\t.cstring", true,
-                               SectionKind::getMergeable1ByteCString());
+                                      SectionKind::getMergeable1ByteCString());
+  UStringSection = getOrCreateSection("__TEXT,__ustring", false,
+                                      SectionKind::getMergeable2ByteCString());
   FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
-                                SectionKind::getMergeableConst4());
+                                             SectionKind::getMergeableConst4());
   EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
-                                SectionKind::getMergeableConst8());
+                                             SectionKind::getMergeableConst8());
   
   // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
   // to using it in -static mode.
@@ -704,18 +706,15 @@
   }
   
   // FIXME: Alignment check should be handled by section classifier.
-  if (Kind.isMergeable1ByteCString()) {
-    Constant *C = cast<GlobalVariable>(GV)->getInitializer();
-    const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
-    const TargetData &TD = *TM.getTargetData();
-    unsigned Size = TD.getTypeAllocSize(Ty);
-    if (Size) {
-      unsigned Align = TD.getPreferredAlignment(cast<GlobalVariable>(GV));
-      if (Align <= 32)
+  if (Kind.isMergeable1ByteCString() ||
+      Kind.isMergeable2ByteCString()) {
+    if (TM.getTargetData()->getPreferredAlignment(
+                                              cast<GlobalVariable>(GV)) < 32) {
+      if (Kind.isMergeable1ByteCString())
         return CStringSection;
+      assert(Kind.isMergeable2ByteCString());
+      return UStringSection;
     }
-    
-    return ReadOnlySection;
   }
   
   if (Kind.isMergeableConst()) {
@@ -725,11 +724,10 @@
       return EightByteConstantSection;
     if (Kind.isMergeableConst16() && SixteenByteConstantSection)
       return SixteenByteConstantSection;
-    return ReadOnlySection;  // .const
   }
-  
-  // FIXME: ROData -> const in -static mode that is relocatable but they happen
-  // by the static linker.  Why not mergeable?
+
+  // Otherwise, if it is readonly, but not something we can specially optimize,
+  // just drop it in .const.
   if (Kind.isReadOnly())
     return ReadOnlySection;
 

Modified: llvm/trunk/test/CodeGen/X86/global-sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections.ll?rev=78068&r1=78067&r2=78068&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-sections.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-sections.ll Tue Aug  4 11:27:13 2009
@@ -101,7 +101,7 @@
 
 @G8 = constant [4 x i16] [ i16 1, i16 2, i16 3, i16 0 ]
 
-; DARWIN:	.const
+; DARWIN:	.section	__TEXT,__ustring
 ; DARWIN:	.globl _G8
 ; DARWIN: _G8:
 
@@ -111,7 +111,7 @@
 
 @G9 = constant [4 x i32] [ i32 1, i32 2, i32 3, i32 0 ]
 
-; ARWIN:	.const   [[ already in const section]]
+; DARWIN:	.const
 ; DARWIN:	.globl _G9
 ; DARWIN: _G9:
 





More information about the llvm-commits mailing list