From 5df3186f598163258fabf3448d9372843804d1ab Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Mon, 29 Sep 2008 11:25:42 +0000 Subject: Rename isWeakForLinker to mayBeOverridden. Use it 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 --- include/llvm/GlobalValue.h | 7 ++++--- lib/Linker/LinkModules.cpp | 12 ++++++------ lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 2 +- lib/Target/DarwinTargetAsmInfo.cpp | 2 +- lib/Target/ELFTargetAsmInfo.cpp | 2 +- lib/Target/IA64/IA64AsmPrinter.cpp | 2 +- lib/Target/Mips/MipsAsmPrinter.cpp | 2 +- lib/Target/Mips/MipsTargetAsmInfo.cpp | 2 +- lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 4 ++-- lib/Target/Sparc/SparcAsmPrinter.cpp | 2 +- lib/Target/TargetAsmInfo.cpp | 4 ++-- lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp | 4 ++-- lib/Transforms/IPO/AddReadAttrs.cpp | 2 +- lib/Transforms/IPO/IPConstantPropagation.cpp | 2 +- lib/Transforms/IPO/PruneEH.cpp | 2 +- lib/Transforms/Utils/InlineCost.cpp | 14 +++++++++----- 16 files changed, 35 insertions(+), 30 deletions(-) diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index f57b23f1d7..b0e58d4451 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -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 || diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index b867705fe1..cee3b23e2a 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -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(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(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(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(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()) { diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 08f05978b6..8789b82591 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -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) { diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 7de8900365..0e4b09adfe 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -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) { diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 7457e0827c..dcf18309e9 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -55,7 +55,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { return getNamedSection(Name.c_str(), Flags); } } else if (const GlobalVariable *GVar = dyn_cast(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); diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp index 0d04bf54b4..a2c87462db 100644 --- a/lib/Target/IA64/IA64AsmPrinter.cpp +++ b/lib/Target/IA64/IA64AsmPrinter.cpp @@ -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()) { diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp index 9525f46bcb..f384c33e02 100644 --- a/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/MipsAsmPrinter.cpp @@ -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()) diff --git a/lib/Target/Mips/MipsTargetAsmInfo.cpp b/lib/Target/Mips/MipsTargetAsmInfo.cpp index 4d2881e09b..0df62492f3 100644 --- a/lib/Target/Mips/MipsTargetAsmInfo.cpp +++ b/lib/Target/Mips/MipsTargetAsmInfo.cpp @@ -85,7 +85,7 @@ SelectSectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind K = SectionKindForGlobal(GV); const GlobalVariable *GVA = dyn_cast(GV); - if (GVA && (!GVA->isWeakForLinker())) + if (GVA && (!GVA->mayBeOverridden())) switch (K) { case SectionKind::SmallData: return getSmallDataSection(); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 557c3af86f..53ba8803c7 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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()) { diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp index 424adaa7c3..6e8c68b658 100644 --- a/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -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()) diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 03fd326fa4..edbacb3d49 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -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); diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 6e596b48db..366a5429a3 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -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(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) { diff --git a/lib/Transforms/IPO/AddReadAttrs.cpp b/lib/Transforms/IPO/AddReadAttrs.cpp index 897548bad5..3e7d860d1d 100644 --- a/lib/Transforms/IPO/AddReadAttrs.cpp +++ b/lib/Transforms/IPO/AddReadAttrs.cpp @@ -63,7 +63,7 @@ bool AddReadAttrs::runOnSCC(const std::vector &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; diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index aecec44aea..66fc2e33ea 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -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. diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 622184415c..adaa9c1680 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -76,7 +76,7 @@ bool PruneEH::runOnSCC(const std::vector &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 { diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index d0b51855d9..c665b12634 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -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. -- cgit v1.2.3