diff options
author | Guillaume Chatelet <gchatelet@google.com> | 2020-06-29 11:24:36 +0000 |
---|---|---|
committer | Guillaume Chatelet <gchatelet@google.com> | 2020-06-29 11:24:36 +0000 |
commit | 368a5e3a666ff38432be538370c46ff800fface1 (patch) | |
tree | 3b6b1b3586051f5fe8f5358d0b0b51235097796d /llvm/lib/IR/DataLayout.cpp | |
parent | 3521ecf1f8a3cf5e4811f93a9a809fc722462bbf (diff) | |
download | llvm-368a5e3a666ff38432be538370c46ff800fface1.zip llvm-368a5e3a666ff38432be538370c46ff800fface1.tar.gz llvm-368a5e3a666ff38432be538370c46ff800fface1.tar.bz2 |
[Alignment][NFC] migrate DataLayout::getPreferredAlignment
This patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Differential Revision: https://reviews.llvm.org/D82752
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 58ef87a..b0613c8 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -846,15 +846,14 @@ int64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, return Result; } -/// getPreferredAlignment - Return the preferred alignment of the specified -/// global. This includes an explicitly requested alignment (if the global -/// has one). -unsigned DataLayout::getPreferredAlignment(const GlobalVariable *GV) const { - unsigned GVAlignment = GV->getAlignment(); +/// getPreferredAlign - Return the preferred alignment of the specified global. +/// This includes an explicitly requested alignment (if the global has one). +Align DataLayout::getPreferredAlign(const GlobalVariable *GV) const { + MaybeAlign GVAlignment = GV->getAlign(); // If a section is specified, always precisely honor explicit alignment, // so we don't insert padding into a section we don't control. if (GVAlignment && GV->hasSection()) - return GVAlignment; + return *GVAlignment; // If no explicit alignment is specified, compute the alignment based on // the IR type. If an alignment is specified, increase it to match the ABI @@ -863,30 +862,24 @@ unsigned DataLayout::getPreferredAlignment(const GlobalVariable *GV) const { // FIXME: Not sure it makes sense to use the alignment of the type if // there's already an explicit alignment specification. Type *ElemType = GV->getValueType(); - unsigned Alignment = getPrefTypeAlignment(ElemType); - if (GVAlignment >= Alignment) { - Alignment = GVAlignment; - } else if (GVAlignment != 0) { - Alignment = std::max(GVAlignment, getABITypeAlignment(ElemType)); + Align Alignment = getPrefTypeAlign(ElemType); + if (GVAlignment) { + if (*GVAlignment >= Alignment) + Alignment = *GVAlignment; + else + Alignment = std::max(*GVAlignment, getABITypeAlign(ElemType)); } // If no explicit alignment is specified, and the global is large, increase // the alignment to 16. // FIXME: Why 16, specifically? - if (GV->hasInitializer() && GVAlignment == 0) { - if (Alignment < 16) { + if (GV->hasInitializer() && !GVAlignment) { + if (Alignment < Align(16)) { // If the global is not external, see if it is large. If so, give it a // larger alignment. if (getTypeSizeInBits(ElemType) > 128) - Alignment = 16; // 16-byte alignment. + Alignment = Align(16); // 16-byte alignment. } } return Alignment; } - -/// getPreferredAlignmentLog - Return the preferred alignment of the -/// specified global, returned in log form. This includes an explicitly -/// requested alignment (if the global has one). -unsigned DataLayout::getPreferredAlignmentLog(const GlobalVariable *GV) const { - return Log2_32(getPreferredAlignment(GV)); -} |