[flang-commits] [PATCH] D159027: [flang] Faster implementation of FindScope()

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Aug 28 15:27:25 PDT 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D159027

Files:
  flang/include/flang/Parser/provenance.h
  flang/include/flang/Semantics/scope.h
  flang/include/flang/Semantics/semantics.h
  flang/lib/Semantics/check-io.cpp
  flang/lib/Semantics/scope.cpp
  flang/lib/Semantics/semantics.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159027.554074.patch
Type: text/x-patch
Size: 7532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230828/6fb7894f/attachment-0001.bin>


More information about the flang-commits mailing list