Commit 74e1fe65 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parser] Pass next_ value from Next to Scan

For some reason the C++ compiler fails to realise that next_ cannot
change on entry into Scan from Next, and re-loads it, creating what
looks like a data dependency that stalls the next instruction.

Passing through a cached next_ value cleans up the generated code.

Change-Id: Iab62ed1890a3a720e5fa90a90e802305e3d55a82
Reviewed-on: https://chromium-review.googlesource.com/c/1331551
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57464}
parent a12f2445
......@@ -588,16 +588,17 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() {
return token;
}
void Scanner::Scan() {
TokenDesc& next_desc = next();
next_desc.literal_chars.Drop();
next_desc.raw_literal_chars.Drop();
next_desc.contextual_token = Token::UNINITIALIZED;
next_desc.invalid_template_escape_message = MessageTemplate::kNone;
void Scanner::Scan(TokenDesc* next_desc) {
DCHECK_EQ(next_desc, &next());
next_desc.token = ScanSingleToken();
DCHECK_IMPLIES(has_parser_error(), next_desc.token == Token::ILLEGAL);
next_desc.location.end_pos = source_pos();
next_desc->literal_chars.Drop();
next_desc->raw_literal_chars.Drop();
next_desc->contextual_token = Token::UNINITIALIZED;
next_desc->invalid_template_escape_message = MessageTemplate::kNone;
next_desc->token = ScanSingleToken();
DCHECK_IMPLIES(has_parser_error(), next_desc->token == Token::ILLEGAL);
next_desc->location.end_pos = source_pos();
#ifdef DEBUG
SanityCheckTokenDesc(current());
......@@ -606,6 +607,8 @@ void Scanner::Scan() {
#endif
}
void Scanner::Scan() { Scan(next_); }
} // namespace internal
} // namespace v8
......
......@@ -245,8 +245,10 @@ Token::Value Scanner::Next() {
// current_ as next_ and scan into it, leaving next_next_ uninitialized.
if (V8_LIKELY(next_next().token == Token::UNINITIALIZED)) {
next_ = previous;
next().after_line_terminator = false;
Scan();
// User 'previous' instead of 'next_' because for some reason the compiler
// thinks 'next_' could be modified before the entry into Scan.
previous->after_line_terminator = false;
Scan(previous);
} else {
next_ = next_next_;
next_next_ = previous;
......
......@@ -762,6 +762,11 @@ class Scanner {
// Scans a single JavaScript token.
V8_INLINE Token::Value ScanSingleToken();
V8_INLINE void Scan();
// Performance hack: pass through a pre-calculated "next()" value to avoid
// having to re-calculate it in Scan. You'd think the compiler would be able
// to hoist the next() calculation out of the inlined Scan method, but seems
// that pointer aliasing analysis fails show that this is safe.
V8_INLINE void Scan(TokenDesc* next_desc);
V8_INLINE Token::Value SkipWhiteSpace();
Token::Value SkipSingleHTMLComment();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment