Visibility hidden GVs do not require extra load of symbol address from the GOT or...
authorEvan Cheng <evan.cheng@apple.com>
Thu, 4 Dec 2008 01:56:50 +0000 (01:56 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 4 Dec 2008 01:56:50 +0000 (01:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60519 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMISelLowering.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCSubtarget.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/X86Subtarget.cpp
test/CodeGen/X86/hidden-vis-2.ll [new file with mode: 0644]

index 69452c13601f90c588fe5ea3be1e8ec19181207c..42aee2677cdb1f3ead9ec4060f68c6f192f3bcf6 100644 (file)
@@ -830,7 +830,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
 /// even in non-static mode.
 static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) {
-  return RelocM != Reloc::Static &&
+  return RelocM != Reloc::Static && !GV->hasHiddenVisibility() &&
     (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
      (GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode()));
 }
index 3ed7265840147f263d12f1713b57d29458201843..8d91b5c2f1e9ad15994f343dc8131679d294a814 100644 (file)
@@ -387,8 +387,9 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
 
     // External or weakly linked global variables need non-lazily-resolved stubs
     if (TM.getRelocationModel() != Reloc::Static) {
-      if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
-            GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
+      if (!GV->hasHiddenVisibility() &&
+          (GV->isDeclaration() || GV->hasWeakLinkage() ||
+           GV->hasLinkOnceLinkage() || GV->hasCommonLinkage())) {
         GVStubs.insert(Name);
         printSuffixedName(Name, "$non_lazy_ptr");
         if (GV->hasExternalWeakLinkage())
index 14983fcf1de3c92fa38d964c85d8716bd3e01343..aef47866bf2afc471969d1f6af6d1d6f4aac6c11 100644 (file)
@@ -141,7 +141,9 @@ bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const {
   // We never hae stubs if HasLazyResolverStubs=false or if in static mode.
   if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
     return false;
-  
+  // Extra load is not needed for symbols with hidden visibility.
+  if (GV->hasHiddenVisibility())
+    return false;
   return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
          GV->hasCommonLinkage() ||
          (GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode());
index 66319c398161ef286079d5213ff04ab8b7dc4cdd..d5cb8bd13ca31599f22a71983e7c52b4c6a31c63 100644 (file)
@@ -391,6 +391,8 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
             FnStubs.insert(Name);
             printSuffixedName(Name, "$stub");
           }
+        } else if (GV->hasHiddenVisibility()) {
+          O << Name;
         } else {
           GVStubs.insert(Name);
           printSuffixedName(Name, "$non_lazy_ptr");
index c17f2dc68254ad444b2863158ea90285af7ea0de..0e791324d38bc298e26d2fab4c20c82dce1a6050 100644 (file)
@@ -40,6 +40,9 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
   if (TM.getRelocationModel() != Reloc::Static &&
       TM.getCodeModel() != CodeModel::Large) {
     if (isTargetDarwin()) {
+      if (GV->hasHiddenVisibility())
+        // Extra load is not needed for symbols with hidden visibility.
+        return false;
       return (!isDirectCall &&
               (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
                GV->hasCommonLinkage() ||
diff --git a/test/CodeGen/X86/hidden-vis-2.ll b/test/CodeGen/X86/hidden-vis-2.ll
new file mode 100644 (file)
index 0000000..e000547
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin9   | grep mov | count 1
+; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin9 | not grep GOT
+
+@x = weak hidden global i32 0          ; <i32*> [#uses=1]
+
+define i32 @t() nounwind readonly {
+entry:
+       %0 = load i32* @x, align 4              ; <i32> [#uses=1]
+       ret i32 %0
+}