[cfe-dev] Caching a unified ParentMap in the ASTContext?

Jordan Rose jordan_rose at apple.com
Wed Jan 2 09:58:22 PST 2013


On Jan 2, 2013, at 2:21 , Manuel Klimek <klimek at google.com> wrote:

> On Wed, Dec 12, 2012 at 11:25 AM, Manuel Klimek <klimek at google.com> wrote:
> On Wed, Dec 12, 2012 at 2:19 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> (+Olaf Krzikalla, a known external user of the classic ParentMap)
> 
> The analyzer seems to be the primary user of the "classic" ParentMap; it's also scattered over the rewriters, but I'm not sure it's ever actually used there. All of the uses of our ParentMap seem like they could easily be implemented on top of ASTMatcher's DenseMap implementation, though I'm a little concerned about (a) the ability to update parents, which Olaf uses, and (b) the careful handling of PseudoObjectExprs and OpaqueValueExprs used for proper source locations in the analyzer.
> 
> I also don't like the idea that building a ParentMap traverses the entire AST. That includes everything pulled in in every header file, when usually the analyzer only needs to deal with a single function at a time. I'm not sure what to say about this, though; making ParentMaps specific to Decls seems problematic in a different way: you can't match across everything as easily. And if you allow both per-function and global parent maps, you're doing redundant work.
> 
> Hm. I'm not sure what I think yet, but I'm leaning towards using your lazily constructed global map on ASTContext and yet still keeping the per-function maps on AnalysisDeclContext. Unifying the two types is fine, though.
> 
> One thing I'm concerned about is how performance critical the parent map for the analyzer is - we'll need to expand ours to work for at least all types of nodes that have pointer identity (including TypeLoc and NestedNameSpecifierLoc, as those are crucial for refactorings), while the analyzer (currently) seems to only need statements.
> 
> Ping :) Or should I just come up with a patch so we have something concrete to look at?

Whoops, sorry I missed this. Unfortunately, ParentMap is indeed in the analyzer's hot path, which is probably already not a great thing. I'm not sure how much making it more generic will cost, though. The way we use it, every statement's parent should be another statement or NULL; that would change to being another statement, a CXXInitializer, or the enclosing function Decl. Slightly more expensive to check the "expression is consumed" during the analyzer run; we're okay with taking the hit during the diagnostics emission for finding good path note locations.


> Before trying to come up with a patch I'd be interested whether you expect the analyzer to need parents for different node types anyway, and whether you think the additional performance hit of building a more generic parent map would be prohibitive.


I can think of uses outside of just statement->statement mappings, but obviously we've gotten this far with only that.

I'm not so worried about the cost of building the map; the analyzer run tends to dwarf any linear-time operations anyway. I just don't want to build it for the entire translation unit, since we won't use most of it and we're already caching the per-function ones. I don't think that's a design issue, though.

So, okay, let's see a patch. :-)
Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130102/e8fe351b/attachment.html>


More information about the cfe-dev mailing list