summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SafeStackLayout.cpp
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-08-02 23:21:30 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-08-02 23:21:30 +0000
commitd99f80b48e1f3502357e21d071531432be333b8e (patch)
treeb7858ff8897d3b754b433c3e91e3c448fe9751ad /llvm/lib/CodeGen/SafeStackLayout.cpp
parent39bf39f35c208109f6d5907708ee53dee2878bed (diff)
downloadbcm5719-llvm-d99f80b48e1f3502357e21d071531432be333b8e.tar.gz
bcm5719-llvm-d99f80b48e1f3502357e21d071531432be333b8e.zip
[safestack] Layout large allocas first to reduce fragmentation.
llvm-svn: 277544
Diffstat (limited to 'llvm/lib/CodeGen/SafeStackLayout.cpp')
-rw-r--r--llvm/lib/CodeGen/SafeStackLayout.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp
index fb433c1856a..7d4dbd13abf 100644
--- a/llvm/lib/CodeGen/SafeStackLayout.cpp
+++ b/llvm/lib/CodeGen/SafeStackLayout.cpp
@@ -132,6 +132,14 @@ void StackLayout::computeLayout() {
// If this is replaced with something smarter, it must preserve the property
// that the first object is always at the offset 0 in the stack frame (for
// StackProtectorSlot), or handle stack protector in some other way.
+
+ // Sort objects by size (largest first) to reduce fragmentation.
+ if (StackObjects.size() > 2)
+ std::stable_sort(StackObjects.begin() + 1, StackObjects.end(),
+ [](const StackObject &a, const StackObject &b) {
+ return a.Size > b.Size;
+ });
+
for (auto &Obj : StackObjects)
layoutObject(Obj);
OpenPOWER on IntegriCloud