[all-commits] [llvm/llvm-project] b37daf: [pseudo] Store shift and goto actions in a compact...

Sam McCall via All-commits all-commits at lists.llvm.org
Mon Jul 4 10:40:23 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b37dafd5dc83a5f1fc4ca7e37e4944364ff9d5b7
      https://github.com/llvm/llvm-project/commit/b37dafd5dc83a5f1fc4ca7e37e4944364ff9d5b7
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-07-04 (Mon, 04 Jul 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/unittests/LRTableTest.cpp

  Log Message:
  -----------
  [pseudo] Store shift and goto actions in a compact structure with faster lookup.

The actions table is very compact but the binary search to find the
correct action is relatively expensive.
A hashtable is faster but pretty large (64 bits per value, plus empty
slots, and lookup is constant time but not trivial due to collisions).

The structure in this patch uses 1.25 bits per entry (whether present or absent)
plus the size of the values, and lookup is trivial.

The Shift table is 119KB = 27KB values + 92KB keys.
The Goto table is 86KB = 30KB values + 57KB keys.
(Goto has a smaller keyspace as #nonterminals < #terminals, and more entries).

This patch improves glrParse speed by 28%: 4.69 => 5.99 MB/s
Overall the table grows by 60%: 142 => 228KB.

By comparison, DenseMap<unsigned, StateID> is "only" 16% faster (5.43 MB/s),
and results in a 285% larger table (547 KB) vs the baseline.

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




More information about the All-commits mailing list