Skip to content

Commit

Permalink
[rereland][Alignment][NFC] Remove access to deprecated GlobalObject::…
Browse files Browse the repository at this point in the history
…getAlignment from llvm

Differential Revision: https://reviews.llvm.org/D139836
  • Loading branch information
gchatelet committed Dec 13, 2022
1 parent 5e89876 commit 43024b4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
3 changes: 1 addition & 2 deletions llvm/lib/IR/Globals.cpp
Expand Up @@ -124,8 +124,7 @@ void GlobalObject::setAlignment(MaybeAlign Align) {
unsigned AlignmentData = encode(Align);
unsigned OldData = getGlobalValueSubClassData();
setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
assert(MaybeAlign(getAlignment()) == Align &&
"Alignment representation error!");
assert(getAlign() == Align && "Alignment representation error!");
}

void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/Linker/LinkModules.cpp
Expand Up @@ -352,8 +352,12 @@ bool ModuleLinker::linkIfNeeded(GlobalValue &GV,
SGVar->setConstant(false);
}
if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
MaybeAlign Align(
std::max(DGVar->getAlignment(), SGVar->getAlignment()));
MaybeAlign DAlign = DGVar->getAlign();
MaybeAlign SAlign = SGVar->getAlign();
MaybeAlign Align = std::nullopt;
if (DAlign || SAlign)
Align = std::max(DAlign.valueOrOne(), SAlign.valueOrOne());

SGVar->setAlignment(Align);
DGVar->setAlignment(Align);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/IRSymtab.cpp
Expand Up @@ -289,7 +289,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
inconvertibleErrorCode());
Uncommon().CommonSize =
GV->getParent()->getDataLayout().getTypeAllocSize(GV->getValueType());
Uncommon().CommonAlign = GVar->getAlignment();
Uncommon().CommonAlign = GVar->getAlign() ? GVar->getAlign()->value() : 0;
}

const GlobalObject *GO = GV->getAliaseeObject();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
Expand Up @@ -843,7 +843,7 @@ bool PPCMIPeephole::simplifyCode() {
if (SrcMI->getOperand(1).isGlobal()) {
const GlobalObject *GO =
dyn_cast<GlobalObject>(SrcMI->getOperand(1).getGlobal());
if (GO && GO->getAlignment() >= 4)
if (GO && GO->getAlign() && *GO->getAlign() >= 4)
IsWordAligned = true;
} else if (SrcMI->getOperand(1).isImm()) {
int64_t Value = SrcMI->getOperand(1).getImm();
Expand Down
17 changes: 14 additions & 3 deletions llvm/lib/Transforms/IPO/MergeFunctions.cpp
Expand Up @@ -775,7 +775,12 @@ void MergeFunctions::writeAlias(Function *F, Function *G) {
auto *GA = GlobalAlias::create(G->getValueType(), PtrType->getAddressSpace(),
G->getLinkage(), "", BitcastF, G->getParent());

F->setAlignment(MaybeAlign(std::max(F->getAlignment(), G->getAlignment())));
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);
GA->takeName(G);
GA->setVisibility(G->getVisibility());
GA->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
Expand Down Expand Up @@ -822,12 +827,18 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
removeUsers(F);
F->replaceAllUsesWith(NewF);

MaybeAlign MaxAlignment(std::max(G->getAlignment(), NewF->getAlignment()));
// We collect alignment before writeThunkOrAlias that overwrites NewF and
// G's content.
const MaybeAlign NewFAlign = NewF->getAlign();
const MaybeAlign GAlign = G->getAlign();

writeThunkOrAlias(F, G);
writeThunkOrAlias(F, NewF);

F->setAlignment(MaxAlignment);
if (NewFAlign || GAlign)
F->setAlignment(std::max(NewFAlign.valueOrOne(), GAlign.valueOrOne()));
else
F->setAlignment(std::nullopt);
F->setLinkage(GlobalValue::PrivateLinkage);
++NumDoubleWeak;
++NumFunctionsMerged;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Expand Up @@ -1759,7 +1759,7 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
// - 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->getAlignment() > getMinRedzoneSizeForGlobal()) return false;
if (G->getAlign() && *G->getAlign() > getMinRedzoneSizeForGlobal()) return false;

// For non-COFF targets, only instrument globals known to be defined by this
// TU.
Expand Down
8 changes: 5 additions & 3 deletions llvm/unittests/IR/ValueTest.cpp
Expand Up @@ -61,9 +61,11 @@ TEST(GlobalTest, CreateAddressSpace) {
GlobalVariable::NotThreadLocal,
1);

EXPECT_TRUE(Value::MaximumAlignment == 4294967296ULL);
Dummy0->setAlignment(Align(4294967296ULL));
EXPECT_EQ(Dummy0->getAlignment(), 4294967296ULL);
const Align kMaxAlignment(Value::MaximumAlignment);
EXPECT_TRUE(kMaxAlignment.value() == 4294967296ULL);
Dummy0->setAlignment(kMaxAlignment);
EXPECT_TRUE(Dummy0->getAlign());
EXPECT_EQ(*Dummy0->getAlign(), kMaxAlignment);

// Make sure the address space isn't dropped when returning this.
Constant *Dummy1 = M->getOrInsertGlobal("dummy", Int32Ty);
Expand Down

0 comments on commit 43024b4

Please sign in to comment.