diff --git a/llvm/include/llvm/IR/GlobalObject.h b/llvm/include/llvm/IR/GlobalObject.h --- a/llvm/include/llvm/IR/GlobalObject.h +++ b/llvm/include/llvm/IR/GlobalObject.h @@ -82,6 +82,12 @@ return decodeMaybeAlign(AlignmentData); } + /// Sets the alignment attribute of the GlobalObject. + void setAlignment(Align Align); + + /// Sets the alignment attribute of the GlobalObject. + /// This method will be deprecated as the alignment property should always be + /// defined. void setAlignment(MaybeAlign Align); unsigned getGlobalObjectSubClassData() const { diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -289,7 +289,7 @@ const Config &Conf); struct CommonResolution { uint64_t Size = 0; - MaybeAlign Align; + Align Align; /// Record if at least one instance of the common was marked as prevailing bool Prevailing = false; }; diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -150,7 +150,7 @@ // If the alignment was parsed as an attribute, move to the alignment // field. if (MaybeAlign A = FnAttrs.getAlignment()) { - Fn->setAlignment(A); + Fn->setAlignment(*A); FnAttrs.removeAttribute(Attribute::Alignment); } @@ -6047,7 +6047,7 @@ Fn->setCallingConv(CC); Fn->setAttributes(PAL); Fn->setUnnamedAddr(UnnamedAddr); - Fn->setAlignment(MaybeAlign(Alignment)); + Fn->setAlignment(Alignment); Fn->setSection(Section); Fn->setPartition(Partition); Fn->setComdat(C); diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -127,6 +127,15 @@ assert(getAlign() == Align && "Alignment representation error!"); } +void GlobalObject::setAlignment(Align Align) { + assert(Align <= MaximumAlignment && + "Alignment is greater than MaximumAlignment!"); + unsigned AlignmentData = encode(Align); + unsigned OldData = getGlobalValueSubClassData(); + setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData); + assert(getAlign() && *getAlign() == Align && "Alignment representation error!"); +} + void GlobalObject::copyAttributesFrom(const GlobalObject *Src) { GlobalValue::copyAttributesFrom(Src); setAlignment(Src->getAlign()); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -839,8 +839,7 @@ auto &CommonRes = RegularLTO.Commons[std::string(Sym.getIRName())]; CommonRes.Size = std::max(CommonRes.Size, Sym.getCommonSize()); if (uint32_t SymAlignValue = Sym.getCommonAlignment()) { - const Align SymAlign(SymAlignValue); - CommonRes.Align = std::max(SymAlign, CommonRes.Align.valueOrOne()); + CommonRes.Align = std::max(Align(SymAlignValue), CommonRes.Align); } CommonRes.Prevailing |= Res.Prevailing; } diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -3300,7 +3300,7 @@ MaybeAlign Alignment = CB->getRetAlign(); assert(Alignment && "HeapToShared on allocation without alignment attribute"); - SharedMem->setAlignment(MaybeAlign(Alignment)); + SharedMem->setAlignment(*Alignment); A.changeAfterManifest(IRPosition::callsite_returned(*CB), *NewBuffer); A.deleteAfterManifest(*CB); diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2306,7 +2306,7 @@ G->getThreadLocalMode(), G->getAddressSpace()); NewGlobal->copyAttributesFrom(G); NewGlobal->setComdat(G->getComdat()); - NewGlobal->setAlignment(MaybeAlign(getMinRedzoneSizeForGlobal())); + NewGlobal->setAlignment(Align(getMinRedzoneSizeForGlobal())); // Don't fold globals with redzones. ODR violation detector and redzone // poisoning implicitly creates a dependence on the global's address, so it // is no longer valid for it to be marked unnamed_addr.