This is an archive of the discontinued LLVM Phabricator instance.

FuncUnwinders: General clean up and optimization
AbandonedPublic

Authored by labath on May 10 2019, 1:36 AM.

Details

Summary

A large chunk of this file was dealing with the caching of unwind plans.
In this patch I create a helper class to encapsulate this behavior and
leave the functions to deal with the actual work, which is to compute
the actual plan.

Since the caching now is handled by a separate class, it is also
possible to optimize it better without hampering readability. The way I
achieve that is by using a special shared_ptr value to mean "not
initialized" which means we can avoid having a special bool flag for
that purpose. This results in a net decrease of the size of the
FuncUnwinders object.

Event Timeline

labath created this revision.May 10 2019, 1:36 AM
clayborg added inline comments.May 10 2019, 7:20 AM
include/lldb/Symbol/FuncUnwinders.h
117

maybe use:

llvm::Optional<lldb::UnwindPlanSP> m_plan_sp;

Then just check if it has no value, and if so compute and set it either to a valid shared pointer or an empty one?

labath marked an inline comment as done.May 10 2019, 7:28 AM
labath added inline comments.
include/lldb/Symbol/FuncUnwinders.h
117

That would work, but it would increase the size of the FuncUnwinders struct by about 80 bytes (8 bytes for each LazyPlan object). I can do that, but given that "uncomputed value" trick is internal to the class and does not leak out or affect the implementation, it seemed like a worthwhile optimization to me.

clayborg added inline comments.May 10 2019, 7:45 AM
include/lldb/Symbol/FuncUnwinders.h
117

Actually isn't there a pointer union class that can steal bool bits from the aligned values and not increase the size?

clayborg added inline comments.May 10 2019, 7:46 AM
include/lldb/Symbol/FuncUnwinders.h
117

I believe the clang type system steals 3 bits from a Type * to encode "const" and a few other type qualifiers

labath marked an inline comment as done.May 10 2019, 7:59 AM
labath added inline comments.
include/lldb/Symbol/FuncUnwinders.h
117

Yes, there is a llvm::PointerIntPair, but AFAICT that only works with a raw pointer, not a shared_ptr. I believe implementing a similar trick for shared_ptr would be possible, but it would definitely be tricky. Way more trickier than this..

labath abandoned this revision.Nov 26 2019, 6:46 AM