This is an archive of the discontinued LLVM Phabricator instance.

[flang] Faster implementation of FindScope()
ClosedPublic

Authored by klausler on Aug 28 2023, 3:27 PM.

Details

Summary

The utility semantics::SemanticsContext::FindScope() maps a contiguous
range of cooked source characters to the innermost Scope containing
them. Its implementation is unacceptably slow on large (tens of
thousands of lines) source files with many program units; it traverses
each level of the scope tree linearly.

Replace this implementation with a single instance of std::multimap<>
used as an index from each Scope's source range back to the Scope.

Compilation time with "-fsyntax-only" on the 50,000-line test case
that motivated this change drops from 4.36s to 3.72s, and FindScope()
no longer stands out egregiously in the profile.

Diff Detail

Event Timeline

klausler created this revision.Aug 28 2023, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 3:27 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
klausler requested review of this revision.Aug 28 2023, 3:27 PM
PeteSteinfeld accepted this revision.Aug 28 2023, 5:53 PM

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Aug 28 2023, 5:53 PM
This revision was automatically updated to reflect the committed changes.