This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add a utility class, ThreadLocalCache, for storing non static thread local objects.
ClosedPublic

Authored by rriddle on Oct 15 2020, 3:23 PM.

Details

Summary

(Note: This is a reland of D82597)

This class allows for defining thread local objects that have a set non-static lifetime. This internals of the cache use a static thread_local map between the various different non-static objects and the desired value type. When a non-static object destructs, it simply nulls out the entry in the static map. This will leave an entry in the map, but erase any of the data for the associated value. The current use cases for this are in the MLIRContext, meaning that the number of items in the static map is ~1-2 which aren't particularly costly enough to warrant the complexity of pruning. If a use case arises that requires pruning of the map, the functionality can be added.

This is especially useful in the context of MLIR for implementing thread-local caching of context level objects that would otherwise have very high lock contention. This revision adds a thread local cache in the MLIRContext for attributes, identifiers, and types to reduce some of the locking burden. This led to a speedup of several seconds when compiling a somewhat large mlir module.

Diff Detail

Event Timeline

rriddle created this revision.Oct 15 2020, 3:23 PM
rriddle requested review of this revision.Oct 15 2020, 3:23 PM

Is there anything different from last time I reviewed? I LGTM the original one, so I rather just look at what's new if anything.

Is there anything different from last time I reviewed? I LGTM the original one, so I rather just look at what's new if anything.

(Apologies, I thought I posted it but forgot to hit submit)
Only tangible difference is that I removed all of the broken erase functionality from StorageUniquer. It's been broken and unused for a while, but becomes even more broken with this change. All of the threading related functionality is the same from the previous revision.

mehdi_amini accepted this revision.Oct 15 2020, 7:22 PM

OK, so still LGTM from last time :)

This revision is now accepted and ready to land.Oct 15 2020, 7:22 PM
jpienaar accepted this revision.Oct 16 2020, 11:46 AM

Thanks!