This is an archive of the discontinued LLVM Phabricator instance.

[Lexer] Speedup LexTokenInternal
ClosedPublic

Authored by serge-sans-paille on Nov 14 2022, 9:46 AM.

Details

Summary

Only reset "NeedsCleaning" flag in case of re-entrant call.
Do not needlessly blank IdentifierInfo. This information will be set
once the token type is picked.

This yields a nice 1% speedup when pre-processing sqlite amalgamation
through:

valgrind --tool=callgrind ./bin/clang -E sqlite3.c -o/dev/null

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 9:46 AM
serge-sans-paille requested review of this revision.Nov 14 2022, 9:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 9:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Compile time tracker record : https://llvm-compile-time-tracker.com/compare.php?from=f71d32a0eea47b3d2bb43d6be15cf09d47ef6971&to=b4df7d2a01aacd29ae539b04e72b3667e2362aa1&stat=instructions:u
The cost of preprocessing is hidden by the optimization time, but -O0 gives an hint of the expected speedup.

lattner accepted this revision.Nov 14 2022, 5:06 PM

Nice! I'd love someone else's eyes on this, but that's a great speedup!

This revision is now accepted and ready to land.Nov 14 2022, 5:06 PM
aaron.ballman added inline comments.
clang/lib/Lex/Lexer.cpp
3522

Was this setting the identifier info to nullptr as a shorthand to clear *any* token data that was previously built up (basically, a cheaper call to startToken())? Should we be asserting that Token::PtrData is nullptr?

4143–4145

Unrelated formatting changes?

4172–4174

Unrelated formatting changes?

Add extra assert to ensure we start lexing in a clean state

aaron.ballman accepted this revision.Nov 16 2022, 5:12 AM

LGTM! FYI: there's still some unrelated formatting changes ;-)

This revision was automatically updated to reflect the committed changes.
foad added a subscriber: foad.Nov 17 2022, 6:21 AM
foad added inline comments.
clang/lib/Lex/Lexer.cpp
3520–3521

Messages are backwards. They should be like "Result needs cleaning!" and "Result has not been reset!".

clang/lib/Lex/Lexer.cpp
3520–3521

Fixed as c8ecbaa2eba9de4338642bbfb6efd75b286878cb. Thanks for pointing that out.