[llvm-commits] [llvm] r56782 - in /llvm/trunk: include/llvm/ lib/Linker/ lib/Target/ lib/Target/ARM/AsmPrinter/ lib/Target/IA64/ lib/Target/Mips/ lib/Target/PowerPC/AsmPrinter/ lib/Target/Sparc/ lib/Target/X86/AsmPrinter/ lib/Transforms/IPO/ lib/Transforms/Utils/

Duncan Sands baldrick at free.fr
Mon Sep 29 04:25:43 PDT 2008


Author: baldrick
Date: Mon Sep 29 06:25:42 2008
New Revision: 56782

URL: http://llvm.org/viewvc/llvm-project?rev=56782&view=rev
Log:
Rename isWeakForLinker to mayBeOverridden.  Use it
instead of hasWeakLinkage in a bunch of optimization
passes.

Modified:
    llvm/trunk/include/llvm/GlobalValue.h
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
    llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
    llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp
    llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp
    llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
    llvm/trunk/lib/Transforms/IPO/PruneEH.cpp
    llvm/trunk/lib/Transforms/Utils/InlineCost.cpp

Modified: llvm/trunk/include/llvm/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalValue.h?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/include/llvm/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/GlobalValue.h Mon Sep 29 06:25:42 2008
@@ -111,9 +111,10 @@
   void setLinkage(LinkageTypes LT) { Linkage = LT; }
   LinkageTypes getLinkage() const { return Linkage; }
 
-  /// isWeakForLinker - Determines if symbol is weak for linker having weak or
-  /// linkonce or common or extweak LLVM linkage.
-  bool isWeakForLinker() const {
+  /// mayBeOverridden - Whether the definition of this global may be replaced
+  /// at link time.  For example, if a function has weak linkage then the code
+  /// defining it may be replaced by different code.
+  bool mayBeOverridden() const {
     return (Linkage == WeakLinkage ||
             Linkage == LinkOnceLinkage ||
             Linkage == CommonLinkage ||

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Sep 29 06:25:42 2008
@@ -477,7 +477,7 @@
             "': can only link appending global with another appending global!");
     LinkFromSrc = true; // Special cased.
     LT = Src->getLinkage();
-  } else if (Src->isWeakForLinker()) {
+  } else if (Src->mayBeOverridden()) {
     // At this point we know that Dest has LinkOnce, External*, Weak, Common,
     // or DLL* linkage.
     if ((Dest->hasLinkOnceLinkage() &&
@@ -489,7 +489,7 @@
       LinkFromSrc = false;
       LT = Dest->getLinkage();
     }
-  } else if (Dest->isWeakForLinker()) {
+  } else if (Dest->mayBeOverridden()) {
     // At this point we know that Src has External* or DLL* linkage.
     if (Src->hasExternalWeakLinkage()) {
       LinkFromSrc = false;
@@ -757,7 +757,7 @@
     } else if (GlobalVariable *DGVar = dyn_cast_or_null<GlobalVariable>(DGV)) {
       // The only allowed way is to link alias with external declaration or weak
       // symbol..
-      if (DGVar->isDeclaration() || DGVar->isWeakForLinker()) {
+      if (DGVar->isDeclaration() || DGVar->mayBeOverridden()) {
         // But only if aliasee is global too...
         if (!isa<GlobalVariable>(DAliasee))
           return Error(Err, "Global-Alias Collision on '" + SGA->getName() +
@@ -786,7 +786,7 @@
     } else if (Function *DF = dyn_cast_or_null<Function>(DGV)) {
       // The only allowed way is to link alias with external declaration or weak
       // symbol...
-      if (DF->isDeclaration() || DF->isWeakForLinker()) {
+      if (DF->isDeclaration() || DF->mayBeOverridden()) {
         // But only if aliasee is function too...
         if (!isa<Function>(DAliasee))
           return Error(Err, "Function-Alias Collision on '" + SGA->getName() +
@@ -862,10 +862,10 @@
           if (DGV->getInitializer() != SInit)
             return Error(Err, "Global Variable Collision on '" + SGV->getName() +
                          "': global variables have different initializers");
-        } else if (DGV->isWeakForLinker()) {
+        } else if (DGV->mayBeOverridden()) {
           // Nothing is required, mapped values will take the new global
           // automatically.
-        } else if (SGV->isWeakForLinker()) {
+        } else if (SGV->mayBeOverridden()) {
           // Nothing is required, mapped values will take the new global
           // automatically.
         } else if (DGV->hasAppendingLinkage()) {

Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -871,7 +871,7 @@
       }
     }
 
-    if (GVar->hasInternalLinkage() || GVar->isWeakForLinker()) {
+    if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (TAI->getLCOMMDirective() != NULL) {

Modified: llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Mon Sep 29 06:25:42 2008
@@ -73,7 +73,7 @@
 const Section*
 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);
-  bool isWeak = GV->isWeakForLinker();
+  bool isWeak = GV->mayBeOverridden();
   bool isNonStatic = (DTM->getRelocationModel() != Reloc::Static);
 
   switch (Kind) {

Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Mon Sep 29 06:25:42 2008
@@ -55,7 +55,7 @@
       return getNamedSection(Name.c_str(), Flags);
     }
   } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
-    if (GVar->isWeakForLinker()) {
+    if (GVar->mayBeOverridden()) {
       std::string Name = UniqueSectionForGlobal(GVar, Kind);
       unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
       return getNamedSection(Name.c_str(), Flags);

Modified: llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -275,7 +275,7 @@
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
+        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (GVar->hasInternalLinkage()) {

Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -504,7 +504,7 @@
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
+        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (GVar->hasInternalLinkage())

Modified: llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp Mon Sep 29 06:25:42 2008
@@ -85,7 +85,7 @@
   SectionKind::Kind K = SectionKindForGlobal(GV);
   const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
 
-  if (GVA && (!GVA->isWeakForLinker()))
+  if (GVA && (!GVA->mayBeOverridden()))
     switch (K) {
       case SectionKind::SmallData:
         return getSmallDataSection();

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=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -675,7 +675,7 @@
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
       (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
-       GVar->isWeakForLinker())) {
+       GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (GVar->hasExternalLinkage()) {
@@ -900,7 +900,7 @@
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
       (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
-       GVar->isWeakForLinker())) {
+       GVar->mayBeOverridden())) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
     if (GVar->hasExternalLinkage()) {

Modified: llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -253,7 +253,7 @@
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
+        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (GVar->hasInternalLinkage())

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Mon Sep 29 06:25:42 2008
@@ -240,7 +240,7 @@
       assert(0 && "Unexpected section kind!");
     }
 
-    if (GV->isWeakForLinker())
+    if (GV->mayBeOverridden())
       Flags |= SectionFlags::Linkonce;
   }
 
@@ -291,7 +291,7 @@
 TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);
 
-  if (GV->isWeakForLinker()) {
+  if (GV->mayBeOverridden()) {
     std::string Name = UniqueSectionForGlobal(GV, Kind);
     unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
     return getNamedSection(Name.c_str(), Flags);

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=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Mon Sep 29 06:25:42 2008
@@ -383,7 +383,7 @@
     if (shouldPrintStub(TM, Subtarget)) {
       // Link-once, declaration, or Weakly-linked global variables need
       // non-lazily-resolved stubs
-      if (GV->isDeclaration() || GV->isWeakForLinker()) {
+      if (GV->isDeclaration() || GV->mayBeOverridden()) {
         // Dynamically-resolved functions need a stub for the function.
         if (isCallOp && isa<Function>(GV)) {
           // Function stubs are no longer needed for Mac OS X 10.5 and up.
@@ -790,7 +790,7 @@
     }
 
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
+        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (TAI->getLCOMMDirective() != NULL) {

Modified: llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp Mon Sep 29 06:25:42 2008
@@ -63,7 +63,7 @@
 
     // Definitions with weak linkage may be overridden at linktime with
     // something that writes memory, so treat them like declarations.
-    if (F->isDeclaration() || F->hasWeakLinkage()) {
+    if (F->isDeclaration() || F->mayBeOverridden()) {
       if (!F->onlyReadsMemory())
         // May write memory.
         return false;

Modified: llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Mon Sep 29 06:25:42 2008
@@ -155,7 +155,7 @@
 
   // If this function could be overridden later in the link stage, we can't
   // propagate information about its results into callers.
-  if (F.hasLinkOnceLinkage() || F.hasWeakLinkage())
+  if (F.hasLinkOnceLinkage() || F.mayBeOverridden())
     return false;
   
   // Check to see if this function returns a constant.

Modified: llvm/trunk/lib/Transforms/IPO/PruneEH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PruneEH.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PruneEH.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PruneEH.cpp Mon Sep 29 06:25:42 2008
@@ -76,7 +76,7 @@
     if (F == 0) {
       SCCMightUnwind = true;
       SCCMightReturn = true;
-    } else if (F->isDeclaration() || F->hasWeakLinkage()) {
+    } else if (F->isDeclaration() || F->mayBeOverridden()) {
       SCCMightUnwind |= !F->doesNotThrow();
       SCCMightReturn |= !F->doesNotReturn();
     } else {

Modified: llvm/trunk/lib/Transforms/Utils/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineCost.cpp?rev=56782&r1=56781&r2=56782&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineCost.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineCost.cpp Mon Sep 29 06:25:42 2008
@@ -174,17 +174,21 @@
   Instruction *TheCall = CS.getInstruction();
   Function *Callee = CS.getCalledFunction();
   const Function *Caller = TheCall->getParent()->getParent();
-  
+
   // Don't inline a directly recursive call.
   if (Caller == Callee ||
       // Don't inline functions which can be redefined at link-time to mean
-      // something else.  link-once linkage is ok though.
-      Callee->hasWeakLinkage() ||
-      
+      // something else.
+      // FIXME: We allow link-once linkage since in practice all versions of
+      // the function have the same body (C++ ODR) - but the LLVM definition
+      // of LinkOnceLinkage doesn't require this.
+      (Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()
+       ) ||
+
       // Don't inline functions marked noinline.
       NeverInline.count(Callee))
     return 2000000000;
-  
+
   // InlineCost - This value measures how good of an inline candidate this call
   // site is to inline.  A lower inline cost make is more likely for the call to
   // be inlined.  This value may go negative.





More information about the llvm-commits mailing list