[parser] Annotate ReportMessage with NOINLINE and Expect with V8_UNLIKELY

This allows the compiler to generate slightly better code and actually reduces
binary size a little.

Bug: v8:7926
Change-Id: Ib43ff1508ab85b5ffabfa4338d4f0ebacb7eac0c
Reviewed-on: https://chromium-review.googlesource.com/c/1309637
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57162}
This commit is contained in:
Toon Verwaest 2018-10-31 10:05:50 +01:00 committed by Commit Bot
parent 8097107a23
commit e10607a3ff

View File

@ -692,7 +692,7 @@ class ParserBase {
void Expect(Token::Value token) { void Expect(Token::Value token) {
Token::Value next = Next(); Token::Value next = Next();
if (next != token) { if (V8_UNLIKELY(next != token)) {
ReportUnexpectedToken(next); ReportUnexpectedToken(next);
} }
} }
@ -701,12 +701,12 @@ class ParserBase {
// Check for automatic semicolon insertion according to // Check for automatic semicolon insertion according to
// the rules given in ECMA-262, section 7.9, page 21. // the rules given in ECMA-262, section 7.9, page 21.
Token::Value tok = peek(); Token::Value tok = peek();
if (tok == Token::SEMICOLON) { if (V8_LIKELY(tok == Token::SEMICOLON)) {
Next(); Next();
return; return;
} }
if (scanner()->HasLineTerminatorBeforeNext() || if (V8_LIKELY(scanner()->HasLineTerminatorBeforeNext() ||
Token::IsAutoSemicolon(tok)) { Token::IsAutoSemicolon(tok))) {
return; return;
} }
@ -748,7 +748,7 @@ class ParserBase {
void ExpectContextualKeyword(Token::Value token) { void ExpectContextualKeyword(Token::Value token) {
DCHECK(Token::IsContextualKeyword(token)); DCHECK(Token::IsContextualKeyword(token));
Expect(Token::IDENTIFIER); Expect(Token::IDENTIFIER);
if (scanner()->current_contextual_token() != token) { if (V8_UNLIKELY(scanner()->current_contextual_token() != token)) {
ReportUnexpectedToken(scanner()->current_token()); ReportUnexpectedToken(scanner()->current_token());
} }
} }
@ -858,31 +858,32 @@ class ParserBase {
} }
// Report syntax errors. // Report syntax errors.
void ReportMessage(MessageTemplate message) { V8_NOINLINE void ReportMessage(MessageTemplate message) {
Scanner::Location source_location = scanner()->location(); Scanner::Location source_location = scanner()->location();
impl()->ReportMessageAt(source_location, message, impl()->ReportMessageAt(source_location, message,
static_cast<const char*>(nullptr), kSyntaxError); static_cast<const char*>(nullptr), kSyntaxError);
} }
template <typename T> template <typename T>
void ReportMessage(MessageTemplate message, T arg, V8_NOINLINE void ReportMessage(MessageTemplate message, T arg,
ParseErrorType error_type = kSyntaxError) { ParseErrorType error_type = kSyntaxError) {
Scanner::Location source_location = scanner()->location(); Scanner::Location source_location = scanner()->location();
impl()->ReportMessageAt(source_location, message, arg, error_type); impl()->ReportMessageAt(source_location, message, arg, error_type);
} }
void ReportMessageAt(Scanner::Location location, MessageTemplate message, V8_NOINLINE void ReportMessageAt(Scanner::Location location,
ParseErrorType error_type) { MessageTemplate message,
ParseErrorType error_type) {
impl()->ReportMessageAt(location, message, impl()->ReportMessageAt(location, message,
static_cast<const char*>(nullptr), error_type); static_cast<const char*>(nullptr), error_type);
} }
void ReportUnexpectedToken(Token::Value token); V8_NOINLINE void ReportUnexpectedToken(Token::Value token);
void ReportUnexpectedTokenAt( V8_NOINLINE void ReportUnexpectedTokenAt(
Scanner::Location location, Token::Value token, Scanner::Location location, Token::Value token,
MessageTemplate message = MessageTemplate::kUnexpectedToken); MessageTemplate message = MessageTemplate::kUnexpectedToken);
void ReportClassifierError( V8_NOINLINE void ReportClassifierError(
const typename ExpressionClassifier::Error& error) { const typename ExpressionClassifier::Error& error) {
if (classifier()->does_error_reporting()) { if (classifier()->does_error_reporting()) {
impl()->ReportMessageAt(error.location, error.message(), error.arg); impl()->ReportMessageAt(error.location, error.message(), error.arg);
@ -3474,7 +3475,7 @@ void ParserBase<Impl>::ExpectMetaProperty(Token::Value property_name,
const char* full_name, int pos) { const char* full_name, int pos) {
Consume(Token::PERIOD); Consume(Token::PERIOD);
ExpectContextualKeyword(property_name); ExpectContextualKeyword(property_name);
if (scanner()->literal_contains_escapes()) { if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
impl()->ReportMessageAt(Scanner::Location(pos, end_position()), impl()->ReportMessageAt(Scanner::Location(pos, end_position()),
MessageTemplate::kInvalidEscapedMetaProperty, MessageTemplate::kInvalidEscapedMetaProperty,
full_name); full_name);