unsigned AlignmentData = encode(Align);
unsigned OldData = getGlobalValueSubClassData();
setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
- assert(getAlign() == Align && "Alignment representation error!");
+ assert(MaybeAlign(getAlignment()) == Align &&
+ "Alignment representation error!");
}
void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
SGVar->setConstant(false);
}
if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
- MaybeAlign DAlign = DGVar->getAlign();
- MaybeAlign SAlign = SGVar->getAlign();
- MaybeAlign Align = std::nullopt;
- if (DAlign || SAlign)
- Align = std::max(DAlign.valueOrOne(), SAlign.valueOrOne());
-
+ MaybeAlign Align(
+ std::max(DGVar->getAlignment(), SGVar->getAlignment()));
SGVar->setAlignment(Align);
DGVar->setAlignment(Align);
}
inconvertibleErrorCode());
Uncommon().CommonSize =
GV->getParent()->getDataLayout().getTypeAllocSize(GV->getValueType());
- Uncommon().CommonAlign = GVar->getAlign() ? GVar->getAlign()->value() : 0;
+ Uncommon().CommonAlign = GVar->getAlignment();
}
const GlobalObject *GO = GV->getAliaseeObject();
if (SrcMI->getOperand(1).isGlobal()) {
const GlobalObject *GO =
dyn_cast<GlobalObject>(SrcMI->getOperand(1).getGlobal());
- if (GO && GO->getAlign() && *GO->getAlign() >= 4)
+ if (GO && GO->getAlignment() >= 4)
IsWordAligned = true;
} else if (SrcMI->getOperand(1).isImm()) {
int64_t Value = SrcMI->getOperand(1).getImm();
auto *GA = GlobalAlias::create(G->getValueType(), PtrType->getAddressSpace(),
G->getLinkage(), "", BitcastF, G->getParent());
- const MaybeAlign FAlign = F->getAlign();
- const MaybeAlign GAlign = G->getAlign();
- if (FAlign || GAlign)
- F->setAlignment(std::max(FAlign.valueOrOne(), GAlign.valueOrOne()));
- else
- F->setAlignment(std::nullopt);
+ F->setAlignment(MaybeAlign(std::max(F->getAlignment(), G->getAlignment())));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
GA->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
removeUsers(F);
F->replaceAllUsesWith(NewF);
+ MaybeAlign MaxAlignment(std::max(G->getAlignment(), NewF->getAlignment()));
+
writeThunkOrAlias(F, G);
writeThunkOrAlias(F, NewF);
- const MaybeAlign NewFAlign = NewF->getAlign();
- const MaybeAlign GAlign = G->getAlign();
- if (NewFAlign || GAlign)
- F->setAlignment(std::max(NewFAlign.valueOrOne(), GAlign.valueOrOne()));
- else
- F->setAlignment(std::nullopt);
+ F->setAlignment(MaxAlignment);
F->setLinkage(GlobalValue::PrivateLinkage);
++NumDoubleWeak;
++NumFunctionsMerged;
// - Need to poison all copies, not just the main thread's one.
if (G->isThreadLocal()) return false;
// For now, just ignore this Global if the alignment is large.
- if (G->getAlign() && *G->getAlign() > getMinRedzoneSizeForGlobal()) return false;
+ if (G->getAlignment() > getMinRedzoneSizeForGlobal()) return false;
// For non-COFF targets, only instrument globals known to be defined by this
// TU.
GlobalVariable::NotThreadLocal,
1);
- const Align kMaxAlignment(Value::MaximumAlignment);
- EXPECT_TRUE(kMaxAlignment.value() == 4294967296ULL);
- Dummy0->setAlignment(kMaxAlignment);
- EXPECT_TRUE(Dummy0->getAlign());
- EXPECT_EQ(*Dummy0->getAlign(), kMaxAlignment);
+ EXPECT_TRUE(Value::MaximumAlignment == 4294967296ULL);
+ Dummy0->setAlignment(Align(4294967296ULL));
+ EXPECT_EQ(Dummy0->getAlignment(), 4294967296ULL);
// Make sure the address space isn't dropped when returning this.
Constant *Dummy1 = M->getOrInsertGlobal("dummy", Int32Ty);