[all-commits] [llvm/llvm-project] e727bd: [flang] Faster implementation of FindScope()

Peter Klausler via All-commits all-commits at lists.llvm.org
Tue Aug 29 08:00:11 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e727bda14e2b6b194193779560e6e92f90679f35
      https://github.com/llvm/llvm-project/commit/e727bda14e2b6b194193779560e6e92f90679f35
  Author: Peter Klausler <pklausler at nvidia.com>
  Date:   2023-08-29 (Tue, 29 Aug 2023)

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

  Log Message:
  -----------
  [flang] Faster implementation of FindScope()

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.

Differential Revision: https://reviews.llvm.org/D159027




More information about the All-commits mailing list