diff options
author | Eli Friedman <efriedma@quicinc.com> | 2025-06-09 13:51:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-09 13:51:03 -0700 |
commit | 9f82ac5738fced23716ac6f9c5744f99d6b6ba92 (patch) | |
tree | 7b73b889458d262ca48740245748607971852365 /llvm/lib/IR/Value.cpp | |
parent | f9b98e386ed2b2e2885b9e6dffceb1c915c282b8 (diff) | |
download | llvm-9f82ac5738fced23716ac6f9c5744f99d6b6ba92.zip llvm-9f82ac5738fced23716ac6f9c5744f99d6b6ba92.tar.gz llvm-9f82ac5738fced23716ac6f9c5744f99d6b6ba92.tar.bz2 |
Remove GlobalObject::getAlign/setAlignment (#143188)
Currently, GlobalObject has an "alignment" property... but it's
basically nonsense: alignment doesn't mean the same thing for variables
and functions, and it's completely meaningless for ifuncs.
This "removes" (actually marking protected) the methods from
GlobalObject, adds the relevant methods to Function and GlobalVariable,
and adjusts the code appropriately.
This should make future alignment-related cleanups easier.
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index d6cb65d..02c16e2 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -957,30 +957,27 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, Align Value::getPointerAlignment(const DataLayout &DL) const { assert(getType()->isPointerTy() && "must be pointer"); - if (auto *GO = dyn_cast<GlobalObject>(this)) { - if (isa<Function>(GO)) { - Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne(); - switch (DL.getFunctionPtrAlignType()) { - case DataLayout::FunctionPtrAlignType::Independent: - return FunctionPtrAlign; - case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign: - return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne()); - } - llvm_unreachable("Unhandled FunctionPtrAlignType"); + if (const Function *F = dyn_cast<Function>(this)) { + Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne(); + switch (DL.getFunctionPtrAlignType()) { + case DataLayout::FunctionPtrAlignType::Independent: + return FunctionPtrAlign; + case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign: + return std::max(FunctionPtrAlign, F->getAlign().valueOrOne()); } - const MaybeAlign Alignment(GO->getAlign()); + llvm_unreachable("Unhandled FunctionPtrAlignType"); + } else if (auto *GVar = dyn_cast<GlobalVariable>(this)) { + const MaybeAlign Alignment(GVar->getAlign()); if (!Alignment) { - if (auto *GVar = dyn_cast<GlobalVariable>(GO)) { - Type *ObjectType = GVar->getValueType(); - if (ObjectType->isSized()) { - // If the object is defined in the current Module, we'll be giving - // it the preferred alignment. Otherwise, we have to assume that it - // may only have the minimum ABI alignment. - if (GVar->isStrongDefinitionForLinker()) - return DL.getPreferredAlign(GVar); - else - return DL.getABITypeAlign(ObjectType); - } + Type *ObjectType = GVar->getValueType(); + if (ObjectType->isSized()) { + // If the object is defined in the current Module, we'll be giving + // it the preferred alignment. Otherwise, we have to assume that it + // may only have the minimum ABI alignment. + if (GVar->isStrongDefinitionForLinker()) + return DL.getPreferredAlign(GVar); + else + return DL.getABITypeAlign(ObjectType); } } return Alignment.valueOrOne(); |