From b915e9e0fc85ba6f398b3fab0db6a81a8913af94 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:17:04 +0000 Subject: Vendor import of llvm trunk r290819: https://llvm.org/svn/llvm-project/llvm/trunk@290819 --- lib/CodeGen/SafeStackLayout.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/CodeGen/SafeStackLayout.cpp') diff --git a/lib/CodeGen/SafeStackLayout.cpp b/lib/CodeGen/SafeStackLayout.cpp index fb433c1856a6..7d4dbd13abf4 100644 --- a/lib/CodeGen/SafeStackLayout.cpp +++ b/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); -- cgit v1.3