[PATCH] Change MCTextAtom to use std::list instead of std::vector

Stephen Checkoway s at pahtak.org
Tue Oct 15 11:27:55 PDT 2013


Changing MCTextAtom to use a list instead of a vector reduces the memory usage of running llvm-objdump -disassemble -symbolize -cfg ninja from 16 GB to 9 MB.

I believe the problem is that erasing elements from the vector doesn't free up any space so each time an atom is split, we still have all the space for those instructions.

Using a list also enables us to use std::list::splice() to split the instructions in constant time. There is still a linear scan to find the split point.

Maybe something could be done using smarter data structures or smarter choices of the order atoms are split, but I haven't gone down that route.

One consequence of switching to a list is that the MCTextAtom::at() function becomes inefficient since you would need to perform the linear scan. However, this is only used in two locations: MCModuleYAML and llvm-objdump. In both cases, the code was iterating over every instruction so the patch changes the loops to use iterators and MCTextAtom::at() is removed.

The patch could be split into two parts, one that changes from vector to list and fixes the two at() uses, and one that replaces the copy() + erase() with splice().

I still run out of memory trying to run it on my chromium with debug symbols but as Ahmed pointed out, there is probably room for improvement still. (A singly linked list would save some but C++98 doesn't appear to have one and there are probably better optimizations.)

-- 
Stephen Checkoway

-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCTextAtom-use-list.diff
Type: application/octet-stream
Size: 3921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/aded28dd/attachment.obj>
-------------- next part --------------






More information about the llvm-commits mailing list