OSDN Git Service

Rename isWeakForLinker to mayBeOverridden. Use it
authorDuncan Sands <baldrick@free.fr>
Mon, 29 Sep 2008 11:25:42 +0000 (11:25 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 29 Sep 2008 11:25:42 +0000 (11:25 +0000)
instead of hasWeakLinkage in a bunch of optimization
passes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56782 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f57b23f..b0e58d4 100644 (file)
@@ -111,9 +111,10 @@ public:
   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 ||
index b867705..cee3b23 100644 (file)
@@ -477,7 +477,7 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
             "': 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 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
       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 @@ static bool LinkAlias(Module *Dest, const Module *Src,
     } 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 @@ static bool LinkAlias(Module *Dest, const Module *Src,
     } 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 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
           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()) {
index 08f0597..8789b82 100644 (file)
@@ -871,7 +871,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
       }
     }
 
-    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) {
index 7de8900..0e4b09a 100644 (file)
@@ -73,7 +73,7 @@ DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
 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) {
index 7457e08..dcf1830 100644 (file)
@@ -55,7 +55,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
       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);
index 0d04bf5..a2c8746 100644 (file)
@@ -275,7 +275,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   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()) {
index 9525f46..f384c33 100644 (file)
@@ -504,7 +504,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
 
   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())
index 4d2881e..0df6249 100644 (file)
@@ -85,7 +85,7 @@ SelectSectionForGlobal(const GlobalValue *GV) const {
   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();
index 557c3af..53ba880 100644 (file)
@@ -675,7 +675,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
   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 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
   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()) {
index 424adaa..6e8c68b 100644 (file)
@@ -253,7 +253,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   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())
index 03fd326..edbacb3 100644 (file)
@@ -240,7 +240,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
       assert(0 && "Unexpected section kind!");
     }
 
-    if (GV->isWeakForLinker())
+    if (GV->mayBeOverridden())
       Flags |= SectionFlags::Linkonce;
   }
 
@@ -291,7 +291,7 @@ const Section*
 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);
index 6e596b4..366a542 100644 (file)
@@ -383,7 +383,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
     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 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     }
 
     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) {
index 897548b..3e7d860 100644 (file)
@@ -63,7 +63,7 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
 
     // 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;
index aecec44..66fc2e3 100644 (file)
@@ -155,7 +155,7 @@ bool IPCP::PropagateConstantReturn(Function &F) {
 
   // 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.
index 6221844..adaa9c1 100644 (file)
@@ -76,7 +76,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
     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 {
index d0b5185..c665b12 100644 (file)
@@ -174,17 +174,21 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS,
   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.