llvm.org GIT mirror llvm / 5df3186
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 Duncan Sands 11 years ago
16 changed file(s) with 35 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
110110 void setLinkage(LinkageTypes LT) { Linkage = LT; }
111111 LinkageTypes getLinkage() const { return Linkage; }
112112
113 /// isWeakForLinker - Determines if symbol is weak for linker having weak or
114 /// linkonce or common or extweak LLVM linkage.
115 bool isWeakForLinker() const {
113 /// mayBeOverridden - Whether the definition of this global may be replaced
114 /// at link time. For example, if a function has weak linkage then the code
115 /// defining it may be replaced by different code.
116 bool mayBeOverridden() const {
116117 return (Linkage == WeakLinkage ||
117118 Linkage == LinkOnceLinkage ||
118119 Linkage == CommonLinkage ||
476476 "': can only link appending global with another appending global!");
477477 LinkFromSrc = true; // Special cased.
478478 LT = Src->getLinkage();
479 } else if (Src->isWeakForLinker()) {
479 } else if (Src->mayBeOverridden()) {
480480 // At this point we know that Dest has LinkOnce, External*, Weak, Common,
481481 // or DLL* linkage.
482482 if ((Dest->hasLinkOnceLinkage() &&
488488 LinkFromSrc = false;
489489 LT = Dest->getLinkage();
490490 }
491 } else if (Dest->isWeakForLinker()) {
491 } else if (Dest->mayBeOverridden()) {
492492 // At this point we know that Src has External* or DLL* linkage.
493493 if (Src->hasExternalWeakLinkage()) {
494494 LinkFromSrc = false;
756756 } else if (GlobalVariable *DGVar = dyn_cast_or_null(DGV)) {
757757 // The only allowed way is to link alias with external declaration or weak
758758 // symbol..
759 if (DGVar->isDeclaration() || DGVar->isWeakForLinker()) {
759 if (DGVar->isDeclaration() || DGVar->mayBeOverridden()) {
760760 // But only if aliasee is global too...
761761 if (!isa(DAliasee))
762762 return Error(Err, "Global-Alias Collision on '" + SGA->getName() +
785785 } else if (Function *DF = dyn_cast_or_null(DGV)) {
786786 // The only allowed way is to link alias with external declaration or weak
787787 // symbol...
788 if (DF->isDeclaration() || DF->isWeakForLinker()) {
788 if (DF->isDeclaration() || DF->mayBeOverridden()) {
789789 // But only if aliasee is function too...
790790 if (!isa(DAliasee))
791791 return Error(Err, "Function-Alias Collision on '" + SGA->getName() +
861861 if (DGV->getInitializer() != SInit)
862862 return Error(Err, "Global Variable Collision on '" + SGV->getName() +
863863 "': global variables have different initializers");
864 } else if (DGV->isWeakForLinker()) {
864 } else if (DGV->mayBeOverridden()) {
865865 // Nothing is required, mapped values will take the new global
866866 // automatically.
867 } else if (SGV->isWeakForLinker()) {
867 } else if (SGV->mayBeOverridden()) {
868868 // Nothing is required, mapped values will take the new global
869869 // automatically.
870870 } else if (DGV->hasAppendingLinkage()) {
870870 }
871871 }
872872
873 if (GVar->hasInternalLinkage() || GVar->isWeakForLinker()) {
873 if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
874874 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
875875
876876 if (TAI->getLCOMMDirective() != NULL) {
7272 const Section*
7373 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
7474 SectionKind::Kind Kind = SectionKindForGlobal(GV);
75 bool isWeak = GV->isWeakForLinker();
75 bool isWeak = GV->mayBeOverridden();
7676 bool isNonStatic = (DTM->getRelocationModel() != Reloc::Static);
7777
7878 switch (Kind) {
5454 return getNamedSection(Name.c_str(), Flags);
5555 }
5656 } else if (const GlobalVariable *GVar = dyn_cast(GV)) {
57 if (GVar->isWeakForLinker()) {
57 if (GVar->mayBeOverridden()) {
5858 std::string Name = UniqueSectionForGlobal(GVar, Kind);
5959 unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
6060 return getNamedSection(Name.c_str(), Flags);
274274
275275 if (C->isNullValue() && !GVar->hasSection()) {
276276 if (!GVar->isThreadLocal() &&
277 (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
277 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
278278 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
279279
280280 if (GVar->hasInternalLinkage()) {
503503
504504 if (C->isNullValue() && !GVar->hasSection()) {
505505 if (!GVar->isThreadLocal() &&
506 (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
506 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
507507 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
508508
509509 if (GVar->hasInternalLinkage())
8484 SectionKind::Kind K = SectionKindForGlobal(GV);
8585 const GlobalVariable *GVA = dyn_cast(GV);
8686
87 if (GVA && (!GVA->isWeakForLinker()))
87 if (GVA && (!GVA->mayBeOverridden()))
8888 switch (K) {
8989 case SectionKind::SmallData:
9090 return getSmallDataSection();
674674 if (C->isNullValue() && /* FIXME: Verify correct */
675675 !GVar->hasSection() &&
676676 (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
677 GVar->isWeakForLinker())) {
677 GVar->mayBeOverridden())) {
678678 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
679679
680680 if (GVar->hasExternalLinkage()) {
899899 if (C->isNullValue() && /* FIXME: Verify correct */
900900 !GVar->hasSection() &&
901901 (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
902 GVar->isWeakForLinker())) {
902 GVar->mayBeOverridden())) {
903903 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
904904
905905 if (GVar->hasExternalLinkage()) {
252252
253253 if (C->isNullValue() && !GVar->hasSection()) {
254254 if (!GVar->isThreadLocal() &&
255 (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
255 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
256256 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
257257
258258 if (GVar->hasInternalLinkage())
239239 assert(0 && "Unexpected section kind!");
240240 }
241241
242 if (GV->isWeakForLinker())
242 if (GV->mayBeOverridden())
243243 Flags |= SectionFlags::Linkonce;
244244 }
245245
290290 TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
291291 SectionKind::Kind Kind = SectionKindForGlobal(GV);
292292
293 if (GV->isWeakForLinker()) {
293 if (GV->mayBeOverridden()) {
294294 std::string Name = UniqueSectionForGlobal(GV, Kind);
295295 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
296296 return getNamedSection(Name.c_str(), Flags);
382382 if (shouldPrintStub(TM, Subtarget)) {
383383 // Link-once, declaration, or Weakly-linked global variables need
384384 // non-lazily-resolved stubs
385 if (GV->isDeclaration() || GV->isWeakForLinker()) {
385 if (GV->isDeclaration() || GV->mayBeOverridden()) {
386386 // Dynamically-resolved functions need a stub for the function.
387387 if (isCallOp && isa(GV)) {
388388 // Function stubs are no longer needed for Mac OS X 10.5 and up.
789789 }
790790
791791 if (!GVar->isThreadLocal() &&
792 (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
792 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
793793 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
794794
795795 if (TAI->getLCOMMDirective() != NULL) {
6262
6363 // Definitions with weak linkage may be overridden at linktime with
6464 // something that writes memory, so treat them like declarations.
65 if (F->isDeclaration() || F->hasWeakLinkage()) {
65 if (F->isDeclaration() || F->mayBeOverridden()) {
6666 if (!F->onlyReadsMemory())
6767 // May write memory.
6868 return false;
154154
155155 // If this function could be overridden later in the link stage, we can't
156156 // propagate information about its results into callers.
157 if (F.hasLinkOnceLinkage() || F.hasWeakLinkage())
157 if (F.hasLinkOnceLinkage() || F.mayBeOverridden())
158158 return false;
159159
160160 // Check to see if this function returns a constant.
7575 if (F == 0) {
7676 SCCMightUnwind = true;
7777 SCCMightReturn = true;
78 } else if (F->isDeclaration() || F->hasWeakLinkage()) {
78 } else if (F->isDeclaration() || F->mayBeOverridden()) {
7979 SCCMightUnwind |= !F->doesNotThrow();
8080 SCCMightReturn |= !F->doesNotReturn();
8181 } else {
173173 Instruction *TheCall = CS.getInstruction();
174174 Function *Callee = CS.getCalledFunction();
175175 const Function *Caller = TheCall->getParent()->getParent();
176
176
177177 // Don't inline a directly recursive call.
178178 if (Caller == Callee ||
179179 // Don't inline functions which can be redefined at link-time to mean
180 // something else. link-once linkage is ok though.
181 Callee->hasWeakLinkage() ||
182
180 // something else.
181 // FIXME: We allow link-once linkage since in practice all versions of
182 // the function have the same body (C++ ODR) - but the LLVM definition
183 // of LinkOnceLinkage doesn't require this.
184 (Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()
185 ) ||
186
183187 // Don't inline functions marked noinline.
184188 NeverInline.count(Callee))
185189 return 2000000000;
186
190
187191 // InlineCost - This value measures how good of an inline candidate this call
188192 // site is to inline. A lower inline cost make is more likely for the call to
189193 // be inlined. This value may go negative.