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 ||
"': 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() &&
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;
} 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() +
} 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() +
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()) {
}
}
- 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) {
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) {
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);
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()) {
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())
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();
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()) {
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()) {
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())
assert(0 && "Unexpected section kind!");
}
- if (GV->isWeakForLinker())
+ if (GV->mayBeOverridden())
Flags |= SectionFlags::Linkonce;
}
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);
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.
}
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) {
// 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;
// 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.
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 {
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.