This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Reduce no of map searches. Assert map entry exists. [NFCI]
ClosedPublic

Authored by asbirlea on Mar 8 2019, 1:23 PM.

Details

Summary

This is a refactoring patch.

  • Reduce the number of map searches by reusing the iterator.
  • Add asserts to check that the entry is in the cache, as this is something BasicAA relies on to avoid infinite recursion.

Diff Detail

Event Timeline

asbirlea created this revision.Mar 8 2019, 1:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2019, 1:23 PM
Herald added subscribers: jlebar, sanjoy. · View Herald Transcript
chandlerc added inline comments.Mar 8 2019, 4:56 PM
lib/Analysis/BasicAliasAnalysis.cpp
1588–1592

While it's a bit awkward, I'd create a scope here because re-using CacheIt will be so tempting and is wrong.

AliasResult OrigAliasResult;
{
  // Limited lifetime iterator as we can't re-use it once we begin processing.
  auto CacheIt = AliasCache.find(Locs);
  ...
}
1606–1608

Here and below, the original code does the same number of lookups and seems more clear?

asbirlea updated this revision to Diff 189982.Mar 8 2019, 8:37 PM
asbirlea marked 2 inline comments as done.

Address comment.

lib/Analysis/BasicAliasAnalysis.cpp
1606–1608

Yes, that's true. This change refers to the second bullet point in the summary: adding the assert to check an entry was already in the map and it should only be updated here, never created.
I got tripped by this by accidentally clearing the cache and going into an infinite recursion.

Let me know if you'd prefer this in a separate change or the title updated to include this.

asbirlea edited the summary of this revision. (Show Details)Mar 8 2019, 8:38 PM
asbirlea retitled this revision from [BasicAA] Reduce no of map seaches [NFCI]. to [BasicAA] Reduce no of map searches. Assert map entry exists. [NFCI].Mar 8 2019, 8:40 PM
chandlerc accepted this revision.Mar 20 2019, 6:05 PM

LGTM, really nice!

lib/Analysis/BasicAliasAnalysis.cpp
1606–1608

No, I'd missed that this was enabling the assert, and I understand why that's valuable here, thanks.

This revision is now accepted and ready to land.Mar 20 2019, 6:05 PM
This revision was automatically updated to reflect the committed changes.