[cfe-commits] [PATCH] New compile-time constant value representation

Richard Smith richard at metafoo.co.uk
Fri Dec 2 11:09:55 PST 2011


Hi,

During the implementation of C++11 constexpr support, it's become clear that
APValue is far from ideal as a representation of compile-time constants. In
particular, for large structs or arrays, its in-memory representation is
extremely wasteful and very malloc-heavy, and its interface results in many
unnecessary APValue copies.

Attached is a rewrite intended to solve these problems. This separates the
storage of the constant value (ConstValueStorage, a bump ptr allocated lump of
memory) from the constant value traversal / updating interface (the ConstValue
class hierarchy, modeled on TypeLoc). Only one allocation is performed for a
full-object, in the common cases.

I've not finished integrating this into the rest of clang (and removing
APValue) yet, so I sadly can't give any measured numbers for the change in
performance and memory usage from this change. However, some quick
calculations on SPEC's 445.gobmk's josekidb.c, on x86_64, indicates this
should reduce ~65000 mallocs of a total of about 10.9MB to ~1000 bump
allocations of a total of about 260KB (if we built that file in C++11 mode).
For reference, the AST nodes which store the initializers in this file occupy
~16MB.

Reviews of the approach and the code itself would be very much appreciated; if
the result of such a review is "Don't do it this way!", I'd much rather know
sooner than later.

Thanks!
Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: constvalue.diff
Type: text/x-patch
Size: 42932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111202/27005ba3/attachment.bin>


More information about the cfe-commits mailing list