[llvm-commits] [llvm] r78055 - in /llvm/trunk: include/llvm/MC/SectionKind.h lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/TargetLoweringObjectFile.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp

Chris Lattner sabre at nondot.org
Mon Aug 3 22:35:56 PDT 2009


Author: lattner
Date: Tue Aug  4 00:35:56 2009
New Revision: 78055

URL: http://llvm.org/viewvc/llvm-project?rev=78055&view=rev
Log:
make MergeableCString be a SectionKind "abstract class", and
add new concrete versions for 1/2/4-byte mergable strings.

These are not actually created yet.

Modified:
    llvm/trunk/include/llvm/MC/SectionKind.h
    llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp

Modified: llvm/trunk/include/llvm/MC/SectionKind.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/SectionKind.h?rev=78055&r1=78054&r2=78055&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/SectionKind.h (original)
+++ llvm/trunk/include/llvm/MC/SectionKind.h Tue Aug  4 00:35:56 2009
@@ -38,13 +38,20 @@
     /// SectionKind are not mergeable.
     ReadOnly,
 
-        /// MergeableCString - This is a special section for nul-terminated
-        /// strings.  The linker can unique the C strings, knowing their
-        /// semantics.  Because it uniques based on the nul terminators, the
-        /// compiler can't put strings in this section that have embeded nuls
-        /// in them.
-        MergeableCString,
+        /// MergableCString - Any null-terminated string which allows merging.
+        /// These values are known to end in a nul value of the specified size,
+        /// not otherwise contain a nul value, and be mergable.  This allows the
+        /// linker to unique the strings if it so desires.
+
+           /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
+           Mergeable1ByteCString,
     
+           /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
+           Mergeable2ByteCString,
+
+           /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
+           Mergeable4ByteCString,
+
         /// MergeableConst - These are sections for merging fixed-length
         /// constants together.  For example, this can be used to unique
         /// constant pool entries etc.
@@ -119,15 +126,22 @@
   bool isText() const { return K == Text; }
   
   bool isReadOnly() const {
-    return K == ReadOnly || K == MergeableCString || isMergeableConst();
+    return K == ReadOnly || isMergeableCString() ||
+           isMergeableConst();
   }
 
-  bool isMergeableCString() const { return K == MergeableCString; }
+  bool isMergeableCString() const {
+    return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
+           K == Mergeable4ByteCString;
+  }
+  bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
+  bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
+  bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
+  
   bool isMergeableConst() const {
     return K == MergeableConst || K == MergeableConst4 ||
            K == MergeableConst8 || K == MergeableConst16;
   }
-  
   bool isMergeableConst4() const { return K == MergeableConst4; }
   bool isMergeableConst8() const { return K == MergeableConst8; }
   bool isMergeableConst16() const { return K == MergeableConst16; }
@@ -177,7 +191,15 @@
   static SectionKind getMetadata() { return get(Metadata); }
   static SectionKind getText() { return get(Text); }
   static SectionKind getReadOnly() { return get(ReadOnly); }
-  static SectionKind getMergeableCString() { return get(MergeableCString); }
+  static SectionKind getMergeable1ByteCString() {
+    return get(Mergeable1ByteCString);
+  }
+  static SectionKind getMergeable2ByteCString() {
+    return get(Mergeable2ByteCString);
+  }
+  static SectionKind getMergeable4ByteCString() {
+    return get(Mergeable4ByteCString);
+  }
   static SectionKind getMergeableConst() { return get(MergeableConst); }
   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
   static SectionKind getMergeableConst8() { return get(MergeableConst8); }

Modified: llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=78055&r1=78054&r2=78055&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Tue Aug  4 00:35:56 2009
@@ -905,6 +905,7 @@
     getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
   SwitchToSection(TheSection);
 
+  /// FIXME: Drive this off the section!
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||

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

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Tue Aug  4 00:35:56 2009
@@ -135,8 +135,10 @@
       // If initializer is a null-terminated string, put it in a "cstring"
       // section if the target has it.
       if (isConstantString(C))
-        return SectionKind::getMergeableCString();
+        return SectionKind::getMergeable1ByteCString();
       
+      // FIXME: Detect 2/4 byte strings.
+        
       // 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.
@@ -290,8 +292,10 @@
     getOrCreateSection("\t.rodata", false, SectionKind::getReadOnly());
   TLSDataSection =
     getOrCreateSection("\t.tdata", false, SectionKind::getThreadData());
+  
+  // FIXME: No reason to make this.
   CStringSection = getOrCreateSection("\t.rodata.str", true,
-                               SectionKind::getMergeableCString());
+                               SectionKind::getMergeable1ByteCString());
 
   TLSBSSSection = getOrCreateSection("\t.tbss", false, 
                                      SectionKind::getThreadBSS());
@@ -392,12 +396,16 @@
     Str.push_back('x');
   if (Kind.isWriteable())
     Str.push_back('w');
-  if (Kind.isMergeableCString() ||
+  if (Kind.isMergeable1ByteCString() ||
+      Kind.isMergeable2ByteCString() ||
+      Kind.isMergeable4ByteCString() ||
       Kind.isMergeableConst4() ||
       Kind.isMergeableConst8() ||
       Kind.isMergeableConst16())
     Str.push_back('M');
-  if (Kind.isMergeableCString())
+  if (Kind.isMergeable1ByteCString() ||
+      Kind.isMergeable2ByteCString() ||
+      Kind.isMergeable4ByteCString())
     Str.push_back('S');
   if (Kind.isThreadLocal())
     Str.push_back('T');
@@ -419,11 +427,15 @@
   
   Str.append(KindStr, KindStr+strlen(KindStr));
   
-  if (Kind.isMergeableCString()) {
-    // TODO: Eventually handle multiple byte character strings.  For now, all
-    // mergable C strings are single byte.
+  if (Kind.isMergeable1ByteCString()) {
     Str.push_back(',');
     Str.push_back('1');
+  } else if (Kind.isMergeable2ByteCString()) {
+    Str.push_back(',');
+    Str.push_back('2');
+  } else if (Kind.isMergeable4ByteCString()) {
+    Str.push_back(',');
+    Str.push_back('4');
   } else if (Kind.isMergeableConst4()) {
     Str.push_back(',');
     Str.push_back('4');
@@ -469,7 +481,9 @@
   
   if (Kind.isText()) return TextSection;
   
-  if (Kind.isMergeableCString()) {
+  if (Kind.isMergeable1ByteCString() ||
+      Kind.isMergeable2ByteCString() ||
+      Kind.isMergeable4ByteCString()) {
    assert(CStringSection && "Should have string section prefix");
     
     // We also need alignment here.
@@ -478,9 +492,17 @@
     unsigned Align = 
       TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV));
     
-    std::string Name = CStringSection->getName() + "1." + utostr(Align);
-    return getOrCreateSection(Name.c_str(), false,
-                              SectionKind::getMergeableCString());
+    const char *SizeSpec = "1.";
+    if (Kind.isMergeable2ByteCString())
+      SizeSpec = "2.";
+    else if (Kind.isMergeable4ByteCString())
+      SizeSpec = "4.";
+    else
+      assert(Kind.isMergeable1ByteCString() && "unknown string width");
+    
+    
+    std::string Name = CStringSection->getName() + SizeSpec + utostr(Align);
+    return getOrCreateSection(Name.c_str(), false, Kind);
   }
   
   if (Kind.isMergeableConst()) {
@@ -549,7 +571,7 @@
                                    SectionKind::getDataRel());
   
   CStringSection = getOrCreateSection("\t.cstring", true,
-                               SectionKind::getMergeableCString());
+                               SectionKind::getMergeable1ByteCString());
   FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
                                 SectionKind::getMergeableConst4());
   EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
@@ -660,7 +682,7 @@
   }
   
   // FIXME: Alignment check should be handled by section classifier.
-  if (Kind.isMergeableCString()) {
+  if (Kind.isMergeable1ByteCString()) {
     Constant *C = cast<GlobalVariable>(GV)->getInitializer();
     const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
     const TargetData &TD = *TM.getTargetData();

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=78055&r1=78054&r2=78055&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Tue Aug  4 00:35:56 2009
@@ -788,6 +788,7 @@
     getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
   SwitchToSection(TheSection);
 
+  // FIXME: get this stuff from section kind flags.
   if (C->isNullValue() && !GVar->hasSection() &&
       // Don't put things that should go in the cstring section into "comm".
       !TheSection->getKind().isMergeableCString()) {





More information about the llvm-commits mailing list