mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-04 02:24:29 +00:00
Move merging of alignment to a central location. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223418 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -525,17 +525,7 @@ static void forceRenaming(GlobalValue *GV, StringRef Name) {
|
|||||||
/// copy additional attributes (those not needed to construct a GlobalValue)
|
/// copy additional attributes (those not needed to construct a GlobalValue)
|
||||||
/// from the SrcGV to the DestGV.
|
/// from the SrcGV to the DestGV.
|
||||||
static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
||||||
// Use the maximum alignment, rather than just copying the alignment of SrcGV.
|
|
||||||
auto *DestGO = dyn_cast<GlobalObject>(DestGV);
|
|
||||||
unsigned Alignment;
|
|
||||||
if (DestGO)
|
|
||||||
Alignment = std::max(DestGO->getAlignment(), SrcGV->getAlignment());
|
|
||||||
|
|
||||||
DestGV->copyAttributesFrom(SrcGV);
|
DestGV->copyAttributesFrom(SrcGV);
|
||||||
|
|
||||||
if (DestGO)
|
|
||||||
DestGO->setAlignment(Alignment);
|
|
||||||
|
|
||||||
forceRenaming(DestGV, SrcGV->getName());
|
forceRenaming(DestGV, SrcGV->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1051,6 +1041,9 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) {
|
|||||||
if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
|
if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
|
||||||
if (C)
|
if (C)
|
||||||
NewGO->setComdat(C);
|
NewGO->setComdat(C);
|
||||||
|
|
||||||
|
if (DGV && DGV->hasCommonLinkage() && SGV->hasCommonLinkage())
|
||||||
|
NewGO->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure to remember this mapping.
|
// Make sure to remember this mapping.
|
||||||
@ -1072,13 +1065,9 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) {
|
|||||||
GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
|
GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
|
||||||
GlobalValue *DGV,
|
GlobalValue *DGV,
|
||||||
bool LinkFromSrc) {
|
bool LinkFromSrc) {
|
||||||
unsigned Alignment = 0;
|
|
||||||
bool ClearConstant = false;
|
bool ClearConstant = false;
|
||||||
|
|
||||||
if (DGV) {
|
if (DGV) {
|
||||||
if (DGV->hasCommonLinkage() && SGVar->hasCommonLinkage())
|
|
||||||
Alignment = std::max(SGVar->getAlignment(), DGV->getAlignment());
|
|
||||||
|
|
||||||
auto *DGVar = dyn_cast<GlobalVariable>(DGV);
|
auto *DGVar = dyn_cast<GlobalVariable>(DGV);
|
||||||
if (!SGVar->isConstant() || (DGVar && !DGVar->isConstant()))
|
if (!SGVar->isConstant() || (DGVar && !DGVar->isConstant()))
|
||||||
ClearConstant = true;
|
ClearConstant = true;
|
||||||
@ -1086,8 +1075,6 @@ GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
|
|||||||
|
|
||||||
if (!LinkFromSrc) {
|
if (!LinkFromSrc) {
|
||||||
if (auto *NewGVar = dyn_cast<GlobalVariable>(DGV)) {
|
if (auto *NewGVar = dyn_cast<GlobalVariable>(DGV)) {
|
||||||
if (Alignment)
|
|
||||||
NewGVar->setAlignment(Alignment);
|
|
||||||
if (NewGVar->isDeclaration() && ClearConstant)
|
if (NewGVar->isDeclaration() && ClearConstant)
|
||||||
NewGVar->setConstant(false);
|
NewGVar->setConstant(false);
|
||||||
}
|
}
|
||||||
@ -1103,9 +1090,6 @@ GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
|
|||||||
SGVar->getName(), /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
|
SGVar->getName(), /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
|
||||||
SGVar->getType()->getAddressSpace());
|
SGVar->getType()->getAddressSpace());
|
||||||
|
|
||||||
if (Alignment)
|
|
||||||
NewDGV->setAlignment(Alignment);
|
|
||||||
|
|
||||||
return NewDGV;
|
return NewDGV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user