[all-commits] [llvm/llvm-project] 49e5a9: Add an algorithm for performing "optimal" layout o...
John McCall via All-commits
all-commits at lists.llvm.org
Mon Mar 23 20:24:58 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 49e5a97ec363a844b167340a82b54a01dc4e671a
https://github.com/llvm/llvm-project/commit/49e5a97ec363a844b167340a82b54a01dc4e671a
Author: John McCall <rjmccall at apple.com>
Date: 2020-03-23 (Mon, 23 Mar 2020)
Changed paths:
A llvm/include/llvm/Support/OptimalLayout.h
M llvm/lib/Support/CMakeLists.txt
A llvm/lib/Support/OptimalLayout.cpp
M llvm/unittests/Support/CMakeLists.txt
A llvm/unittests/Support/OptimalLayoutTest.cpp
Log Message:
-----------
Add an algorithm for performing "optimal" layout of a struct.
The algorithm supports both assigning a fixed offset to a field prior to
layout and allowing fields to have sizes that aren't multiples of their
required alignments. This means that the well-known algorithm of sorting
by decreasing alignment isn't always good enough. Still, we start with
that, and only if that leaves padding around do we fall back on a greedy
padding-minimizing algorithm.
There is no known efficient algorithm for producing a guaranteed-minimal
layout in all cases. In fact, allowing arbitrary fixed-offset fields means
there's a straightforward reduction from bin-packing, making this NP-hard.
But as usual with such problems, we can still efficiently produce adequate
solutions to the cases that matter most to us.
I intend to use this in coroutine frame layout, where the retcon lowerings
very badly want to minimize total space usage, and where the switch lowering
can indeed produce a header with interior padding if the promise field is
highly-aligned. But it may be useful in a much wider variety of situations.
More information about the All-commits
mailing list