[PATCH] D129712: [WIP] [Bitstream] take Expected<T> off critical reading paths

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 18:08:45 PDT 2022


sammccall created this revision.
sammccall added reviewers: adamcz, ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, hiraditya.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

BitstreamReader can encounter many types of error and returns Expected<T> to
signal them. This is rich & typesafe, though adds some overhead.

Unfortunately this technique is used for functions as low-level as "read an
n-bit integer" which are called frequently, and the overhead adds up.

This patch tries to avoid this:

- next to low-level functions that return Expected (e.g. Read), adds a lower-level ReadE which returns the value, and signals errors out of band.
- ReadE sets a "last error" object on the stream which needs to be checked
- it turns out there are cases where we can safely elide/combine some checks, simplifying control flow
- Read is still available with the same signature, but implemented on ReadE.
- ReadRecord is converted to use ReadE and friends
- to avoid inlining a bunch of "makeStringError" formatting into hot functions, we convert the errors used to a custom error type which is cheaper.

A motivating use case: clangd builds a clang PCH ones and then reuses it for
many reparses of the main file. This patch speeds up those reparses by ~7%
(tested with clang/lib/Sema/SemaOverload.cpp and clangd/AST.cpp).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129712

Files:
  llvm/include/llvm/Bitstream/BitCodes.h
  llvm/include/llvm/Bitstream/BitstreamReader.h
  llvm/lib/Bitstream/Reader/BitstreamReader.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129712.444480.patch
Type: text/x-patch
Size: 24949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220714/dfc0afda/attachment.bin>


More information about the llvm-commits mailing list