Put constant data to .const, .const_data, .literal{4|8|16} sections.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 8 Mar 2007 01:07:07 +0000 (01:07 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 8 Mar 2007 01:07:07 +0000 (01:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35016 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index 75003e6b748b23c727ab55067e8ce9b86903b847..ad9a1e8e9f00714f8012498e1ea43eab13c9cf5b 100644 (file)
@@ -145,7 +145,8 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     
     std::string name = Mang->getValueName(I);
     Constant *C = I->getInitializer();
-    unsigned Size = TD->getTypeSize(C->getType());
+    const Type *Type = C->getType();
+    unsigned Size = TD->getTypeSize(Type);
     unsigned Align = TD->getPreferredAlignmentLog(I);
 
     if (I->hasHiddenVisibility())
@@ -250,8 +251,28 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       } else {
         if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(TAI->getBSSSection(), I);
-        else
+        else if (!I->isConstant())
           SwitchToDataSection(TAI->getDataSection(), I);
+        else {
+          // Read-only data.
+          bool isIntFPLiteral = Type->isInteger()  || Type->isFloatingPoint();
+          if (C->ContainsRelocations() && Subtarget->isTargetDarwin() &&
+              TM.getRelocationModel() != Reloc::Static)
+            SwitchToDataSection("\t.const_data\n");
+          else if (isIntFPLiteral && Size == 4 &&
+                   TAI->getFourByteConstantSection())
+            SwitchToDataSection(TAI->getFourByteConstantSection(), I);
+          else if (isIntFPLiteral && Size == 8 &&
+                   TAI->getEightByteConstantSection())
+            SwitchToDataSection(TAI->getEightByteConstantSection(), I);
+          else if (isIntFPLiteral && Size == 16 &&
+                   TAI->getSixteenByteConstantSection())
+            SwitchToDataSection(TAI->getSixteenByteConstantSection(), I);
+          else if (TAI->getReadOnlySection())
+            SwitchToDataSection(TAI->getReadOnlySection(), I);
+          else
+            SwitchToDataSection(TAI->getDataSection(), I);
+        }
       }
       
       break;
index c66862aec6292380a92f4695cb9a8442032a47fc..74977dfa5bf4e92b45d37dc785e5b29402e4f766 100644 (file)
@@ -56,6 +56,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     EightByteConstantSection = "\t.literal8\n";
     if (Subtarget->is64Bit())
       SixteenByteConstantSection = "\t.literal16\n";
+    ReadOnlySection = "\t.const\n";
     LCOMMDirective = "\t.lcomm\t";
     COMMDirectiveTakesAlignment = false;
     HasDotTypeDotSizeDirective = false;
@@ -103,6 +104,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     // bool HasDotLoc; // Defaults to false.
     // HasDotFile - True if target asm supports .file directives.
     // bool HasDotFile; // Defaults to false.
+    ReadOnlySection = "\t.section\t.rodata\n";
     PrivateGlobalPrefix = ".L";
     WeakRefDirective = "\t.weak\t";
     DwarfRequiresFrameSection = false;