[PATCH] Store reference to corresponding PassInfo in Pass

Carl-Anton Ingmarsson ca.ingmarsson at gmail.com
Sun Dec 29 09:06:24 PST 2013


When profiling the rust compiler I noticed that it spends a lot of time
in llvm::PassRegistry::getPassInfo(). Although
llvm::PassRegistry::getPassInfo() is reasonably simple it involves a
lock and a hash table lookup which by no means is free.

Since a Pass is closely associated with it's PassInfo I think it makes
sense to keep a reference to the PassInfo from the Pass and then add a
Pass::getPassInfo() function that users can use to get the PassInfo from
a Pass object.

I first tried to lookup and store the PassInfo reference in the Pass
constructor but this unfortunately didn't work since some Pass
implementations doesn't register it's corresponding PassInfo until the
first Pass is constructed. This could be fixed by changing the Pass
constructor to take the PassInfo and then subclasses could pass the
result of it's "initialize***Pass" to the parent constructor. Since this
involves changing all the Pass implementations I decided to do a simpler
version for now and hear your opinions.

I've attached the simple (hacky) version that simply calls
llvm::PassRegistry::getPassInfo() inside llvm::Pass::getPassInfo() if
the PassInfo hasn't previously been fetched.

In my test this reduces the percentage of time spent in
llvm::PassRegistry::getPassInfo() from 6.21% to 0.03%. (The new
llvm::Pass::getPassInfo() doesn't show up in the profile at all)

Best regards,
Carl-Anton
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Store-PassInfo-in-Pass.patch
Type: text/x-patch
Size: 4826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131229/355d78fb/attachment.bin>


More information about the llvm-commits mailing list