[llvm-commits] CVS: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp X86AsmPrinter.cpp X86Subtarget.cpp

Anton Korobeynikov asl at math.spbu.ru
Wed Jan 17 02:33:27 PST 2007



Changes in directory llvm/lib/Target/X86:

X86ATTAsmPrinter.cpp updated: 1.90 -> 1.91
X86AsmPrinter.cpp updated: 1.228 -> 1.229
X86Subtarget.cpp updated: 1.48 -> 1.49
---
Log message:

* Fix one more bug in PIC codegen: extra load is needed for *all* 
non-statics.
* Introduce new option to output zero-initialized data to .bss section. 
This can reduce size of binaries. Enable it by default for ELF & 
Cygwin/Mingw targets. Probably, Darwin should be also added.


---
Diffs of the changes:  (+24 -16)

 X86ATTAsmPrinter.cpp |   23 ++++++++++-------------
 X86AsmPrinter.cpp    |   11 +++++++++--
 X86Subtarget.cpp     |    6 +++++-
 3 files changed, 24 insertions(+), 16 deletions(-)


Index: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.90 llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.91
--- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.90	Tue Jan 16 10:41:57 2007
+++ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp	Wed Jan 17 04:33:08 2007
@@ -323,22 +323,19 @@
       O << Offset;
 
     if (isMemOp) {
-      if (isExt) {
-        if (Subtarget->isPICStyleGOT()) {
+      if (Subtarget->isPICStyleGOT()) {
+        if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
           O << "@GOT";
-        } else if (Subtarget->isPICStyleRIPRel()) {
+        else
+          O << "@GOTOFF";
+      } else     
+        if (isExt && Subtarget->isPICStyleRIPRel())
           O << "@GOTPCREL(%rip)";
-        } else if (Subtarget->is64Bit() && !NotRIPRel)
-            // Use rip when possible to reduce code size, except when
-            // index or base register are also part of the address. e.g.
-            // foo(%rip)(%rcx,%rax,4) is not legal
-            O << "(%rip)";
-      } else {
-        if (Subtarget->is64Bit() && !NotRIPRel)
+        else if (Subtarget->is64Bit() && !NotRIPRel)
+          // Use rip when possible to reduce code size, except when
+          // index or base register are also part of the address. e.g.
+          // foo(%rip)(%rcx,%rax,4) is not legal
           O << "(%rip)";
-        else if (Subtarget->isPICStyleGOT())
-          O << "@GOTOFF";
-      }
     }
 
     return;


Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.228 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.229
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.228	Tue Jan 16 10:41:57 2007
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp	Wed Jan 17 04:33:08 2007
@@ -28,6 +28,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetOptions.h"
 using namespace llvm;
 
 static X86FunctionInfo calculateFunctionInfo(const Function *F,
@@ -149,7 +150,10 @@
           O << "\t.zerofill __DATA__, __common, " << name << ", "
             << Size << ", " << Align;
       } else {
-        SwitchToDataSection(TAI->getDataSection(), I);
+        if (!NoZerosInBSS && TAI->getBSSSection())
+          SwitchToDataSection(TAI->getBSSSection(), I);
+        else
+          SwitchToDataSection(TAI->getDataSection(), I);
         if (TAI->getLCOMMDirective() != NULL) {
           if (I->hasInternalLinkage()) {
             O << TAI->getLCOMMDirective() << name << "," << Size;
@@ -224,7 +228,10 @@
 
           SwitchToDataSection(SectionName.c_str());
         } else {
-          SwitchToDataSection(TAI->getDataSection(), I);
+          if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
+            SwitchToDataSection(TAI->getBSSSection(), I);
+          else
+            SwitchToDataSection(TAI->getDataSection(), I);
         }
         
         break;


Index: llvm/lib/Target/X86/X86Subtarget.cpp
diff -u llvm/lib/Target/X86/X86Subtarget.cpp:1.48 llvm/lib/Target/X86/X86Subtarget.cpp:1.49
--- llvm/lib/Target/X86/X86Subtarget.cpp:1.48	Fri Jan 12 13:20:47 2007
+++ llvm/lib/Target/X86/X86Subtarget.cpp	Wed Jan 17 04:33:08 2007
@@ -36,10 +36,14 @@
                                        bool isDirectCall) const
 {
   if (TM.getRelocationModel() != Reloc::Static)
-    if (isTargetDarwin() || isPICStyleGOT()) {
+    if (isTargetDarwin()) {
       return (!isDirectCall &&
               (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
                (GV->isExternal() && !GV->hasNotBeenReadFromBytecode())));
+    } else if (isPICStyleGOT()) {
+      // Extra load is needed for all non-statics.
+      return (!isDirectCall &&
+              (GV->isExternal() || !GV->hasInternalLinkage()));
     } else if (isTargetCygMing() || isTargetWindows()) {
       return (GV->hasDLLImportLinkage());
     }






More information about the llvm-commits mailing list