summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorEli Friedman <efriedma@codeaurora.org>2018-08-29 23:46:26 +0000
committerEli Friedman <efriedma@codeaurora.org>2018-08-29 23:46:26 +0000
commit3769639335ac3924b24f62c1b4fed6609e0fe988 (patch)
treec941c1f0e7a1512756f076977588893436faf2c4 /llvm
parent6556e6b9290adc40cdcec7e844a1334dda8b7c50 (diff)
downloadbcm5719-llvm-3769639335ac3924b24f62c1b4fed6609e0fe988.tar.gz
bcm5719-llvm-3769639335ac3924b24f62c1b4fed6609e0fe988.zip
[NFC] Make getPreferredAlignment honor section markings.
This should more accurately reflect what the AsmPrinter will actually do. This is NFC, as far as I can tell; all the places that might be affected already have an extra check to avoid using the result of getPreferredAlignment in this situation. Differential Revision: https://reviews.llvm.org/D51377 llvm-svn: 340999
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/GlobalMerge.cpp11
-rw-r--r--llvm/lib/IR/DataLayout.cpp16
2 files changed, 16 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index f4526c64f1e..69d1e13cec7 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -462,17 +462,8 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
for (j = i; j != -1; j = GlobalSet.find_next(j)) {
Type *Ty = Globals[j]->getValueType();
- // Make sure we use the same alignment AsmPrinter would use. There
- // currently isn't any helper to compute that, so we compute it
- // explicitly here.
- //
- // getPreferredAlignment will sometimes return an alignment higher
- // than the explicitly specified alignment; we must ignore that
- // if the section is explicitly specified, to avoid inserting extra
- // padding into that section.
+ // Make sure we use the same alignment AsmPrinter would use.
unsigned Align = DL.getPreferredAlignment(Globals[j]);
- if (Globals[j]->hasSection() && Globals[j]->getAlignment())
- Align = Globals[j]->getAlignment();
unsigned Padding = alignTo(MergedSize, Align) - MergedSize;
MergedSize += Padding;
MergedSize += DL.getTypeAllocSize(Ty);
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index 62c67127276..18d502a52ca 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -808,15 +808,29 @@ int64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
/// global. This includes an explicitly requested alignment (if the global
/// has one).
unsigned DataLayout::getPreferredAlignment(const GlobalVariable *GV) const {
+ unsigned GVAlignment = GV->getAlignment();
+ // 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;
+
+ // 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
+ // alignment of the IR type.
+ //
+ // 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);
- unsigned GVAlignment = GV->getAlignment();
if (GVAlignment >= Alignment) {
Alignment = GVAlignment;
} else if (GVAlignment != 0) {
Alignment = std::max(GVAlignment, getABITypeAlignment(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 the global is not external, see if it is large. If so, give it a
OpenPOWER on IntegriCloud