[Lex] Simplify and cleanup the updateConsecutiveMacroArgTokens implementation.
authorHaojian Wu <hokein.wu@gmail.com>
Fri, 30 Sep 2022 08:34:04 +0000 (10:34 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Fri, 7 Oct 2022 07:16:08 +0000 (09:16 +0200)
commit74e4f778cf16cbf7163b5c6de6027a43f5e9169f
tree5fe82715d46cb37715b5a96d77b0346071f8351a
parent83d93d3c11ac9727bf3d4c5c956de44233cc7f87
[Lex] Simplify and cleanup the updateConsecutiveMacroArgTokens implementation.

The code falls back to the pre-2011 partition-file-id solution (see for
[details](https://reviews.llvm.org/D20401#3823476)).

This patch simplifies/rewrites the code based on the partition-based-on-file-id
idea. The new implementation is optimized by reducing the number of
calling getFileID (~40% drop).

Despite the huge drop of getFileID, this is a marignal improvment on
speed (becase the number of calling non-cached getFileID is roughly
the same). It removes the evaluation-order performance gap between gcc-built-clang
and clang-built-clang.

SemaExpr.cpp:
- before: 315063 SLocEntries, FileID scans: 388230 linear, 1393437 binary. 458893 cache hits, 672299 getFileID calls
- after:  313494 SLocEntries, FileID scans: 397525 linear, 1451890 binary, 176714 cache hits, 397144 getFileID calls

FindTarget.cpp:
- before: 279984 SLocEntries, FileID scans: 361926 linear, 1275930 binary, 436072 cache hits, 632150 getFileID calls
- after:  278426 SLocEntries, FileID scans: 371279 linear, 1333963 binary, 153705 cache hits, 356814 getFileID calls

Differential Revision: https://reviews.llvm.org/D134942
clang/lib/Lex/TokenLexer.cpp