[reland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from...
authorGuillaume Chatelet <gchatelet@google.com>
Mon, 12 Dec 2022 16:37:51 +0000 (16:37 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Mon, 12 Dec 2022 16:38:18 +0000 (16:38 +0000)
Differential Revision: https://reviews.llvm.org/D139836

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

index ac9b830..c208ab0 100644 (file)
@@ -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) {
index 17c3f09..2f5fac4 100644 (file)
@@ -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);
       }
index 5a7ecdb..54ee000 100644 (file)
@@ -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();
index 605b2d2..1b79774 100644 (file)
@@ -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();
index b850591..2c02a39 100644 (file)
@@ -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);
@@ -822,12 +827,15 @@ 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);
 
-    F->setAlignment(MaxAlignment);
+    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->setLinkage(GlobalValue::PrivateLinkage);
     ++NumDoubleWeak;
     ++NumFunctionsMerged;
index 94aec14..7f5826b 100644 (file)
@@ -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.
index 9583406..76a0b0c 100644 (file)
@@ -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);