[llvm] 6fe6d8d - Revert "[reland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from llvm"

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 13:39:32 PST 2022


Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Tue, Dec 13, 2022 at 12:18 AM Guillaume Chatelet via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
>
> Author: Guillaume Chatelet
> Date: 2022-12-12T21:18:15Z
> New Revision: 6fe6d8d329fceedf70e942eb445673f93210b203
>
> URL: https://github.com/llvm/llvm-project/commit/6fe6d8d329fceedf70e942eb445673f93210b203
> DIFF: https://github.com/llvm/llvm-project/commit/6fe6d8d329fceedf70e942eb445673f93210b203.diff
>
> LOG: Revert "[reland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from llvm"
>
> This reverts commit 3bbfaee23d41c099547c652f87b252ab6e1f6c46.
>
> Added:
>
>
> Modified:
>     llvm/lib/IR/Globals.cpp
>     llvm/lib/Linker/LinkModules.cpp
>     llvm/lib/Object/IRSymtab.cpp
>     llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
>     llvm/lib/Transforms/IPO/MergeFunctions.cpp
>     llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>     llvm/unittests/IR/ValueTest.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
> index c208ab0f3d6ba..ac9b830f9952c 100644
> --- a/llvm/lib/IR/Globals.cpp
> +++ b/llvm/lib/IR/Globals.cpp
> @@ -124,7 +124,8 @@ void GlobalObject::setAlignment(MaybeAlign Align) {
>    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) {
>
> diff  --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
> index 2f5fac4951f29..17c3f09a23b72 100644
> --- a/llvm/lib/Linker/LinkModules.cpp
> +++ b/llvm/lib/Linker/LinkModules.cpp
> @@ -352,12 +352,8 @@ bool ModuleLinker::linkIfNeeded(GlobalValue &GV,
>          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);
>        }
>
> diff  --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
> index 54ee000b302f8..5a7ecdb1fc25a 100644
> --- a/llvm/lib/Object/IRSymtab.cpp
> +++ b/llvm/lib/Object/IRSymtab.cpp
> @@ -289,7 +289,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
>                                       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();
>
> diff  --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
> index 1b79774544c6d..605b2d2642e5a 100644
> --- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
> +++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
> @@ -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->getAlign() && *GO->getAlign() >= 4)
> +            if (GO && GO->getAlignment() >= 4)
>                IsWordAligned = true;
>            } else if (SrcMI->getOperand(1).isImm()) {
>              int64_t Value = SrcMI->getOperand(1).getImm();
>
> diff  --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
> index 2c02a396291c6..b850591b4aa65 100644
> --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
> +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
> @@ -775,12 +775,7 @@ void MergeFunctions::writeAlias(Function *F, Function *G) {
>    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);
> @@ -827,15 +822,12 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
>      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;
>
> diff  --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> index 7f5826bb8a2b2..94aec1415e40e 100644
> --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> @@ -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->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.
>
> diff  --git a/llvm/unittests/IR/ValueTest.cpp b/llvm/unittests/IR/ValueTest.cpp
> index 76a0b0c04f5f2..958340645d518 100644
> --- a/llvm/unittests/IR/ValueTest.cpp
> +++ b/llvm/unittests/IR/ValueTest.cpp
> @@ -61,11 +61,9 @@ TEST(GlobalTest, CreateAddressSpace) {
>                           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);
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list