This is an archive of the discontinued LLVM Phabricator instance.

[XRay][compiler-rt][NFC] Refactor global TLS variables behind an accessor function.
ClosedPublic

Authored by dberris on Aug 28 2017, 9:42 PM.

Details

Summary

This change hides all the initialization of thread_local variables used
by the XRay FDR mode implementation behind a function call. This makes
initialization of thread-local data to be done lazily, instead of
eagerly when they're done as globals. It also gives us an isolation
mechanism if/when we want to change the TLS implementation from using
the C++ thread_local keyword, for something more ad-hoc (potentialy
using pthread directly) on some platforms or set-ups where we cannot use
the C++ thread_local variables.

Event Timeline

dberris created this revision.Aug 28 2017, 9:42 PM
eizan accepted this revision.Aug 29 2017, 5:04 AM

Out of curiosity, why did you make bool Revision 'volatile'? Will it be modified elsewhere?

This revision is now accepted and ready to land.Aug 29 2017, 5:04 AM

Thanks, @eizan

Out of curiosity, why did you make bool Revision 'volatile'? Will it be modified elsewhere?

The recursion guard? That's so that we make sure all the loads and stores are in the same order as they appear in the code.

If we don't use the volatile keyword there, the compiler may be free to elide some of the stores or consolidate them into a single one. Seen this optimisation happen in the wild enough to learn from it. :)

This revision was automatically updated to reflect the committed changes.