Simplify ModuleLinker::getLinkageResult. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217441 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-09-09 14:07:40 +00:00
parent b3fa7e412b
commit efed46fe31

View File

@@ -670,11 +670,22 @@ bool ModuleLinker::getComdatResult(const Comdat *SrcC,
LinkFromSrc); LinkFromSrc);
} }
/// getLinkageResult - This analyzes the two global values and determines what // FIXME: Duplicated from the gold plugin. This should be refactored somewhere.
/// the result will look like in the destination module. In particular, it static bool isDeclaration(const GlobalValue &V) {
/// computes the resultant linkage type and visibility, computes whether the if (V.hasAvailableExternallyLinkage())
/// global in the source should be copied over to the destination (replacing return true;
/// the existing one), and computes whether this linkage is an error or not.
if (V.isMaterializable())
return false;
return V.isDeclaration();
}
/// This analyzes the two global values and determines what the result will look
/// like in the destination module. In particular, it computes the resultant
/// linkage type and visibility, computes whether the global in the source
/// should be copied over to the destination (replacing the existing one), and
/// computes whether this linkage is an error or not.
bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src, bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
GlobalValue::LinkageTypes &LT, GlobalValue::LinkageTypes &LT,
GlobalValue::VisibilityTypes &Vis, GlobalValue::VisibilityTypes &Vis,
@@ -683,8 +694,8 @@ bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
assert(!Src->hasLocalLinkage() && assert(!Src->hasLocalLinkage() &&
"If Src has internal linkage, Dest shouldn't be set!"); "If Src has internal linkage, Dest shouldn't be set!");
bool SrcIsDeclaration = Src->isDeclaration() && !Src->isMaterializable(); bool SrcIsDeclaration = isDeclaration(*Src);
bool DestIsDeclaration = Dest->isDeclaration(); bool DestIsDeclaration = isDeclaration(*Dest);
if (SrcIsDeclaration) { if (SrcIsDeclaration) {
// If Src is external or if both Src & Dest are external.. Just link the // If Src is external or if both Src & Dest are external.. Just link the
@@ -703,17 +714,15 @@ bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
LinkFromSrc = false; LinkFromSrc = false;
LT = Dest->getLinkage(); LT = Dest->getLinkage();
} }
} else if (DestIsDeclaration && !Dest->hasDLLImportStorageClass()) { } else if (DestIsDeclaration) {
// If Dest is external but Src is not: // If Dest is external but Src is not:
LinkFromSrc = true; LinkFromSrc = true;
LT = Src->getLinkage(); LT = Src->getLinkage();
} else if (Src->isWeakForLinker()) { } else if (Src->isWeakForLinker()) {
// At this point we know that Dest has LinkOnce, External*, Weak, Common, assert(!Dest->hasExternalWeakLinkage());
// or DLL* linkage. assert(!Dest->hasAvailableExternallyLinkage());
if (Dest->hasExternalWeakLinkage() || if (Dest->hasLinkOnceLinkage() &&
Dest->hasAvailableExternallyLinkage() || (Src->hasWeakLinkage() || Src->hasCommonLinkage())) {
(Dest->hasLinkOnceLinkage() &&
(Src->hasWeakLinkage() || Src->hasCommonLinkage()))) {
LinkFromSrc = true; LinkFromSrc = true;
LT = Src->getLinkage(); LT = Src->getLinkage();
} else { } else {
@@ -721,20 +730,16 @@ bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
LT = Dest->getLinkage(); LT = Dest->getLinkage();
} }
} else if (Dest->isWeakForLinker()) { } else if (Dest->isWeakForLinker()) {
// At this point we know that Src has External* or DLL* linkage. assert(!Src->hasExternalWeakLinkage());
if (Src->hasExternalWeakLinkage()) { LinkFromSrc = true;
LinkFromSrc = false; LT = GlobalValue::ExternalLinkage;
LT = Dest->getLinkage();
} else {
LinkFromSrc = true;
LT = GlobalValue::ExternalLinkage;
}
} else { } else {
assert((Dest->hasExternalLinkage() || Dest->hasExternalWeakLinkage()) && assert(!Src->hasExternalWeakLinkage());
(Src->hasExternalLinkage() || Src->hasExternalWeakLinkage()) && assert(!Dest->hasExternalWeakLinkage());
assert(Dest->hasExternalLinkage() && Src->hasExternalLinkage() &&
"Unexpected linkage type!"); "Unexpected linkage type!");
return emitError("Linking globals named '" + Src->getName() + return emitError("Linking globals named '" + Src->getName() +
"': symbol multiply defined!"); "': symbol multiply defined!");
} }
// Compute the visibility. We follow the rules in the System V Application // Compute the visibility. We follow the rules in the System V Application