[PATCH] Devirtualize llvm::Value and all subclasses

Pete Cooper peter_cooper at apple.com
Tue Jun 16 16:46:28 PDT 2015


Hi Nick

As you were the last person to attempt this on PR889, I thought i’d see how you like this series of patches.

I’ve tried to devirtualize a small number of virtual methods at a time, hence the bunch of patches.  Unfortunately the last one is pretty huge as it handles all the places we used to call delete on Value’s and now need to call a destroy method to dispatch to the correct subclass.  I’m not sure there’s a great way to split the last one up.

David, i’ve CCed you specifically to ask about how safe some of the changes here are.  In particular, the way i’ve changed things is:
- If a subclass is final (and i’ve added final where I can), then I give it its own delete method which just does ‘using User::operator delete’.  Is this reasonable?  Do i need to handle any other kinds of delete like User does?
- If a subclass is not able to be final, then i’ve added a destroy() method and switch on the value kind to then call ‘delete cast<SubClass>(this)’

Thanks to Duncan for the tip on std::default_delete, i’ve made use of this on various places which had a std::unique_ptr of say Instruction or Value.  The default deleter for those calls destroy() instead of delete.  Deleter’s aren’t needed for final subclasses because I was able to give them a delete method instead.

I also extended helpers like DeleteContainerPointers to take a std::default_delete so that we can forward to the destroy methods where needed.

I measured memory usage on the verify_uselist_order test case Duncan has been using.  This contains debug info and is measured with 'llc ~/verify-uselistorder.lto.opt.bc -o /dev/null --filetype=obj -disable-verify’.  Prior to this change we consumed 814MB, and 800MB after.  So almost 2% savings.  This is in line with what I was expecting as the savings is 8 bytes per Value, but due to malloc alignment on Mac OS, we only save that on an average of half of values.

Finally, this is the order I did all the work locally.  If any of this makes sense to be squashed or split, please let me know.  In the first patch for example I create Constant.def, but I later change that to Value.def.  This one should obviously be fixed to be Value.def from the start.

Cheers,
Pete

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Create-Constant.def-helper.patch
Type: application/octet-stream
Size: 4306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Devirt-Constant-destroyConstant.patch
Type: application/octet-stream
Size: 5191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Devirt-Constant-replaceUsesOfWithOnConstant.patch
Type: application/octet-stream
Size: 4483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Devirtualize-Instruction-clone_impl.patch
Type: application/octet-stream
Size: 20343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Devirtualize-getSuccessorV-getNumSuccessorsV-and-set.patch
Type: application/octet-stream
Size: 6834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Don-t-cast-Constant-to-Value-as-we-will-soon-have-no.patch
Type: application/octet-stream
Size: 1886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-Devirt-GlobalValue-removeFromParent-and-eraseFromPar.patch
Type: application/octet-stream
Size: 5313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-Devirt-GlobalValue-copyAttributesFrom.patch
Type: application/octet-stream
Size: 5496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0007.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-Harden-the-types-of-copyGVAttributes.patch
Type: application/octet-stream
Size: 5833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0010-Initial-patch-to-remove-the-rest-of-virtual-which-me.patch
Type: application/octet-stream
Size: 72440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/25002cf0/attachment-0009.obj>


More information about the llvm-commits mailing list