[all-commits] [llvm/llvm-project] 85eaec: [pseudo] Check follow-sets instead of tying reduce...

Sam McCall via All-commits all-commits at lists.llvm.org
Mon Jun 27 15:36:34 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 85eaecbe8e541924b6f87dd83f169056e74ce237
      https://github.com/llvm/llvm-project/commit/85eaecbe8e541924b6f87dd83f169056e74ce237
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-06-28 (Tue, 28 Jun 2022)

  Changed paths:
    M clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
    M clang-tools-extra/pseudo/lib/GLR.cpp
    M clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
    M clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
    M clang-tools-extra/pseudo/test/lr-build-basic.test
    M clang-tools-extra/pseudo/test/lr-build-conflicts.test
    M clang-tools-extra/pseudo/unittests/GLRTest.cpp
    M clang-tools-extra/pseudo/unittests/LRTableTest.cpp

  Log Message:
  -----------
  [pseudo] Check follow-sets instead of tying reduce actions to lookahead tokens.

Previously, the action table stores a reduce action for each lookahead
token it should allow. These tokens are the followSet(action.rule.target).

In practice, the follow sets are large, so we spend a bunch of time binary
searching around all these essentially-duplicates to check whether our lookahead
token is there.
However the number of reduces for a given state is very small, so we're
much better off linear scanning over them and performing a fast check for each.

D128318 was an attempt at this, storing a bitmap for each reduce.
However it's even more compact just to use the follow sets directly, as
there are fewer nonterminals than (state, rule) pairs. It's also faster.

This specialized approach means unbundling Reduce from other actions in
LRTable, so it's no longer useful to support it in Action. I suspect
Action will soon go away, as we store each kind of action separately.

This improves glrParse speed by 42% (3.30 -> 4.69 MB/s).
It also reduces LR table size by 59% (343 -> 142kB).

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




More information about the All-commits mailing list