Skip to content

Commit ffc1205

Browse files
committed
[reland][NFC] Transition GlobalObject alignment from MaybeAlign to Align
This is a follow up on https://reviews.llvm.org/D142459#4081179. This first patch adds an overload to `GlobalObject::setAlignment` that accepts an `Align` type. This already handles most of the calls. This patch also converts a few call sites to the new type when this is safe. Here is the list of the remaining call sites: - [clang/lib/CodeGen/CodeGenModule.cpp:1688](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/clang/lib/CodeGen/CodeGenModule.cpp#L1688) - [llvm/lib/AsmParser/LLParser.cpp:1309](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/AsmParser/LLParser.cpp#L1309) - [llvm/lib/AsmParser/LLParser.cpp:6050](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/AsmParser/LLParser.cpp#L6050) - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:3871](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L3871) - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:4030](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4030) - [llvm/lib/IR/Core.cpp:2018](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/IR/Core.cpp#L2018) - [llvm/lib/IR/Globals.cpp:141](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/IR/Globals.cpp#L141) - [llvm/lib/Linker/IRMover.cpp:660](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Linker/IRMover.cpp#L660) - [llvm/lib/Linker/LinkModules.cpp:361](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Linker/LinkModules.cpp#L361) - [llvm/lib/Linker/LinkModules.cpp:362](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Linker/LinkModules.cpp#L362) - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:782](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Transforms/IPO/MergeFunctions.cpp#L782) - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:840](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Transforms/IPO/MergeFunctions.cpp#L840) - [llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1813](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp#L1813) - [llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp:27](https://github.com/llvm/llvm-project/blob/e195e6bad6706230a4b5fd4b5cc13de1f16f25cc/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp#L27) Differential Revision: https://reviews.llvm.org/D142708
1 parent be31f2c commit ffc1205

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

llvm/include/llvm/IR/GlobalObject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class GlobalObject : public GlobalValue {
8282
return decodeMaybeAlign(AlignmentData);
8383
}
8484

85+
/// Sets the alignment attribute of the GlobalObject.
86+
void setAlignment(Align Align);
87+
88+
/// Sets the alignment attribute of the GlobalObject.
89+
/// This method will be deprecated as the alignment property should always be
90+
/// defined.
8591
void setAlignment(MaybeAlign Align);
8692

8793
unsigned getGlobalObjectSubClassData() const {

llvm/include/llvm/LTO/LTO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class LTO {
289289
const Config &Conf);
290290
struct CommonResolution {
291291
uint64_t Size = 0;
292-
MaybeAlign Align;
292+
Align Alignment;
293293
/// Record if at least one instance of the common was marked as prevailing
294294
bool Prevailing = false;
295295
};

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
150150
// If the alignment was parsed as an attribute, move to the alignment
151151
// field.
152152
if (MaybeAlign A = FnAttrs.getAlignment()) {
153-
Fn->setAlignment(A);
153+
Fn->setAlignment(*A);
154154
FnAttrs.removeAttribute(Attribute::Alignment);
155155
}
156156

@@ -6047,7 +6047,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
60476047
Fn->setCallingConv(CC);
60486048
Fn->setAttributes(PAL);
60496049
Fn->setUnnamedAddr(UnnamedAddr);
6050-
Fn->setAlignment(MaybeAlign(Alignment));
6050+
Fn->setAlignment(Alignment);
60516051
Fn->setSection(Section);
60526052
Fn->setPartition(Partition);
60536053
Fn->setComdat(C);

llvm/lib/IR/Globals.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ void GlobalObject::setAlignment(MaybeAlign Align) {
127127
assert(getAlign() == Align && "Alignment representation error!");
128128
}
129129

130+
void GlobalObject::setAlignment(Align Align) {
131+
assert(Align <= MaximumAlignment &&
132+
"Alignment is greater than MaximumAlignment!");
133+
unsigned AlignmentData = encode(Align);
134+
unsigned OldData = getGlobalValueSubClassData();
135+
setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
136+
assert(getAlign() && *getAlign() == Align &&
137+
"Alignment representation error!");
138+
}
139+
130140
void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
131141
GlobalValue::copyAttributesFrom(Src);
132142
setAlignment(Src->getAlign());

llvm/lib/LTO/LTO.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,8 @@ LTO::addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
839839
auto &CommonRes = RegularLTO.Commons[std::string(Sym.getIRName())];
840840
CommonRes.Size = std::max(CommonRes.Size, Sym.getCommonSize());
841841
if (uint32_t SymAlignValue = Sym.getCommonAlignment()) {
842-
const Align SymAlign(SymAlignValue);
843-
CommonRes.Align = std::max(SymAlign, CommonRes.Align.valueOrOne());
842+
CommonRes.Alignment =
843+
std::max(Align(SymAlignValue), CommonRes.Alignment);
844844
}
845845
CommonRes.Prevailing |= Res.Prevailing;
846846
}
@@ -1116,15 +1116,15 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
11161116
if (OldGV && DL.getTypeAllocSize(OldGV->getValueType()) == I.second.Size) {
11171117
// Don't create a new global if the type is already correct, just make
11181118
// sure the alignment is correct.
1119-
OldGV->setAlignment(I.second.Align);
1119+
OldGV->setAlignment(I.second.Alignment);
11201120
continue;
11211121
}
11221122
ArrayType *Ty =
11231123
ArrayType::get(Type::getInt8Ty(RegularLTO.Ctx), I.second.Size);
11241124
auto *GV = new GlobalVariable(*RegularLTO.CombinedModule, Ty, false,
11251125
GlobalValue::CommonLinkage,
11261126
ConstantAggregateZero::get(Ty), "");
1127-
GV->setAlignment(I.second.Align);
1127+
GV->setAlignment(I.second.Alignment);
11281128
if (OldGV) {
11291129
OldGV->replaceAllUsesWith(ConstantExpr::getBitCast(GV, OldGV->getType()));
11301130
GV->takeName(OldGV);

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,7 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
33003300
MaybeAlign Alignment = CB->getRetAlign();
33013301
assert(Alignment &&
33023302
"HeapToShared on allocation without alignment attribute");
3303-
SharedMem->setAlignment(MaybeAlign(Alignment));
3303+
SharedMem->setAlignment(*Alignment);
33043304

33053305
A.changeAfterManifest(IRPosition::callsite_returned(*CB), *NewBuffer);
33063306
A.deleteAfterManifest(*CB);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ bool ModuleAddressSanitizer::InstrumentGlobals(IRBuilder<> &IRB, Module &M,
23062306
G->getThreadLocalMode(), G->getAddressSpace());
23072307
NewGlobal->copyAttributesFrom(G);
23082308
NewGlobal->setComdat(G->getComdat());
2309-
NewGlobal->setAlignment(MaybeAlign(getMinRedzoneSizeForGlobal()));
2309+
NewGlobal->setAlignment(Align(getMinRedzoneSizeForGlobal()));
23102310
// Don't fold globals with redzones. ODR violation detector and redzone
23112311
// poisoning implicitly creates a dependence on the global's address, so it
23122312
// is no longer valid for it to be marked unnamed_addr.

0 commit comments

Comments
 (0)