summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-01-16 18:00:58 +0000
committerdim <dim@FreeBSD.org>2016-01-16 18:00:58 +0000
commita49d5469df472d80c9cc17394c71fa8244e6a759 (patch)
tree1aa6c4bf43100053e1c9992a26e30564c1146d38 /contrib/llvm/lib/Transforms/Utils
parent7c048a3e43696cd763f00aa2b8d7a2bb1e71e1be (diff)
downloadFreeBSD-src-a49d5469df472d80c9cc17394c71fa8244e6a759.zip
FreeBSD-src-a49d5469df472d80c9cc17394c71fa8244e6a759.tar.gz
Pull in r257902 from upstream llvm trunk, by James Y Knight (this will
be merged to the official release_38 branch soon, but we need it ASAP): Stop increasing alignment of externally-visible globals on ELF platforms. With ELF, the alignment of a global variable in a shared library will get copied into an executables linked against it, if the executable even accesss the variable. So, it's not possible to implicitly increase alignment based on access patterns, or you'll break existing binaries. This happened to affect libc++'s std::cout symbol, for example. See thread: http://thread.gmane.org/gmane.comp.compilers.clang.devel/45311 (This is a re-commit of r257719, without the bug reported in PR26144. I've tweaked the code to not assert-fail in enforceKnownAlignment when computeKnownBits doesn't recurse far enough to find the underlying Alloca/GlobalObject value.) Differential Revision: http://reviews.llvm.org/D16145
Diffstat (limited to 'contrib/llvm/lib/Transforms/Utils')
-rw-r--r--contrib/llvm/lib/Transforms/Utils/Local.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/contrib/llvm/lib/Transforms/Utils/Local.cpp b/contrib/llvm/lib/Transforms/Utils/Local.cpp
index d2793e5..1cb65fc 100644
--- a/contrib/llvm/lib/Transforms/Utils/Local.cpp
+++ b/contrib/llvm/lib/Transforms/Utils/Local.cpp
@@ -944,37 +944,44 @@ bool llvm::EliminateDuplicatePHINodes(BasicBlock *BB) {
static unsigned enforceKnownAlignment(Value *V, unsigned Align,
unsigned PrefAlign,
const DataLayout &DL) {
+ assert(PrefAlign > Align);
+
V = V->stripPointerCasts();
if (AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
+ // TODO: ideally, computeKnownBits ought to have used
+ // AllocaInst::getAlignment() in its computation already, making
+ // the below max redundant. But, as it turns out,
+ // stripPointerCasts recurses through infinite layers of bitcasts,
+ // while computeKnownBits is not allowed to traverse more than 6
+ // levels.
+ Align = std::max(AI->getAlignment(), Align);
+ if (PrefAlign <= Align)
+ return Align;
+
// If the preferred alignment is greater than the natural stack alignment
// then don't round up. This avoids dynamic stack realignment.
if (DL.exceedsNaturalStackAlignment(PrefAlign))
return Align;
- // If there is a requested alignment and if this is an alloca, round up.
- if (AI->getAlignment() >= PrefAlign)
- return AI->getAlignment();
AI->setAlignment(PrefAlign);
return PrefAlign;
}
if (auto *GO = dyn_cast<GlobalObject>(V)) {
+ // TODO: as above, this shouldn't be necessary.
+ Align = std::max(GO->getAlignment(), Align);
+ if (PrefAlign <= Align)
+ return Align;
+
// If there is a large requested alignment and we can, bump up the alignment
// of the global. If the memory we set aside for the global may not be the
// memory used by the final program then it is impossible for us to reliably
// enforce the preferred alignment.
- if (!GO->isStrongDefinitionForLinker())
+ if (!GO->canIncreaseAlignment())
return Align;
- if (GO->getAlignment() >= PrefAlign)
- return GO->getAlignment();
- // We can only increase the alignment of the global if it has no alignment
- // specified or if it is not assigned a section. If it is assigned a
- // section, the global could be densely packed with other objects in the
- // section, increasing the alignment could cause padding issues.
- if (!GO->hasSection() || GO->getAlignment() == 0)
- GO->setAlignment(PrefAlign);
- return GO->getAlignment();
+ GO->setAlignment(PrefAlign);
+ return PrefAlign;
}
return Align;
OpenPOWER on IntegriCloud