[PATCH] D127357: [pseudo] wip/prototype: use LR0 instead of SLR1 table

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 15:31:13 PDT 2022


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

This ignores the lookahead token when deciding what to reduce, we always reduce
unconditionally. The main effects are:

- all potential partial parses are visible e.g. to error recovery. (In error scenarios, the intended reduction may not occur with SLR1 when the error occurs at the lookahead token).
- the size of the LR table is much smaller (In this patch we go from 340kB => 120kB, and the encoding isn't efficient)
- we explore more dead-ends due to lack of lookahead, and parser runs slower
- with this patch, the LR0 table parses ~1/3 slower than the SLR1. (LR0 allows code simplifications so we may win some of this back)

This patch uses `eod` as a dummy lookahead token for reduce actions:
i.e. reduces are Actions[State, eod]. The structure of glrParse is preserved:
we still track heads as "pending actions". To allow either LR0 or SLR1 to be
used, we perform lookups for both the actual lookahead token and eod.

In a real implementation we'd probably want to:

- switch glrParse to track head nodes, instead of pending actions on them. This should simplify the code there somewhat.
- use a separate storage in LRTable for reduce actions, like a parallel vector<RuleID> (sorted by stateid) and vector<size_t> (indexed by stateid)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127357

Files:
  clang-tools-extra/pseudo/benchmarks/Benchmark.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127357.435361.patch
Type: text/x-patch
Size: 5979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220608/cf625c23/attachment.bin>


More information about the cfe-commits mailing list