<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Chandler,<div class=""><br class=""></div><div class="">In my measurements, this captures about half of the regression, i.e. the regression goes from ~20% to ~10%.  While the reader/writer locks are gone from the profile, several other PassManager related pieces of code have jumped up to take their place:</div><div class=""><br class=""></div><div class=""><img apple-inline="yes" id="BA377117-954A-41EF-85AD-F546440CB136" height="178" width="910" apple-width="yes" apple-height="yes" src="cid:AB3F0D0A-18D1-467B-9A6A-FA0B3ACB6EE3@apple.com" class=""></div><div class=""><br class=""></div><div class="">—Owen</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Jan 27, 2015, at 3:42 PM, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" class="">chandlerc@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hi resistor,<br class=""><br class="">The pass manager relies on the static registry of PassInfo objects to<br class="">perform all manner of its functionality. I don't understand why it does<br class="">much of this. My very vague understanding is that this registry is<br class="">touched both during static initialization *and* while each pass is being<br class="">constructed. As a consequence it is hard to make accessing it not<br class="">require a acquiring some lock. This lock ends up in the hot path of<br class="">setting up, tearing down, and invaliditing analyses in the legacy pass<br class="">manager.<br class=""><br class="">On most systems you can observe this as a non-trivial % of the time<br class="">spent in 'ninja check-llvm'. However, I haven't really seen it be more<br class="">than 1% in extreme cases of compiling more real-world software,<br class="">including LTO.<br class=""><br class="">Unfortunately, some of the GPU JITs are seeing this taking essentially<br class="">all of their time because they have very small IR running through<br class="">a small pass pipeline very many times (at least, this is the vague<br class="">understanding I have of it).<br class=""><br class="">This patch tries to minimize the cost of looking up PassInfo objects by<br class="">leveraging the fact that the objects themselves are immutable and they<br class="">are allocated separately on the heap and so don't have their address<br class="">change. It also requires a change I made the last time I tried to debug<br class="">this problem which removed the ability to de-register a pass from the<br class="">registry. This patch creates a single access path to these objects<br class="">inside the PMTopLevelManager which memoizes the result of querying the<br class="">registry. This is somewhat gross as I don't really know if<br class="">PMTopLevelManager is the *right* place to put it, and I dislike using<br class="">a mutable member to memoize things, but it seems to work.<br class=""><br class="">For long-lived pass managers this should completely eliminate<br class="">the cost of acquiring locks to look into the pass registry once the<br class="">memoized cache is warm. For 'ninja check' I measured about 10% reduction<br class="">in CPU time, and about a 1% reduction in total time on a machine with 32<br class="">hardware threads. For normal compilation, I don't know how much this<br class="">will help, sadly. We will still pay the cost while we populate the<br class="">memoized cache. I don't think it will hurt though, and for LTO or<br class="">compiles with many small functions it should still be a win.<br class=""><br class=""><a href="http://reviews.llvm.org/D7213" class="">http://reviews.llvm.org/D7213</a><br class=""><br class="">Files:<br class="">  include/llvm/IR/LegacyPassManagers.h<br class="">  lib/IR/LegacyPassManager.cpp<br class=""><br class="">EMAIL PREFERENCES<br class="">  http://reviews.llvm.org/settings/panel/emailpreferences/<br class=""><span id="cid:4E650BB5-FBAD-488C-BE32-320B41FAE722@apple.com"><D7213.18862.patch></span></div></blockquote></div><br class=""></div></div></body></html>