Commit c53f9f97 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[compile] Remove AST numbering

Bug: v8:7178
Change-Id: Ib86942acff8419699d739c6fb28479613b04e745
Reviewed-on: https://chromium-review.googlesource.com/878179
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50846}
parent 71f758a2
......@@ -1236,8 +1236,6 @@ v8_source_set("v8_base") {
"src/assert-scope.h",
"src/ast/ast-function-literal-id-reindexer.cc",
"src/ast/ast-function-literal-id-reindexer.h",
"src/ast/ast-numbering.cc",
"src/ast/ast-numbering.h",
"src/ast/ast-source-ranges.h",
"src/ast/ast-traversal-visitor.h",
"src/ast/ast-value-factory.cc",
......
......@@ -564,8 +564,6 @@
'../src/assert-scope.cc',
'../src/ast/ast-function-literal-id-reindexer.cc',
'../src/ast/ast-function-literal-id-reindexer.h',
'../src/ast/ast-numbering.cc',
'../src/ast/ast-numbering.h',
'../src/ast/ast-source-ranges.h',
'../src/ast/ast-traversal-visitor.h',
'../src/ast/ast-value-factory.cc',
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/ast/ast-numbering.h"
#include "src/ast/ast.h"
#include "src/ast/scopes.h"
#include "src/compiler.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
class AstNumberingVisitor final : public AstVisitor<AstNumberingVisitor> {
public:
AstNumberingVisitor(uintptr_t stack_limit, Zone* zone) : zone_(zone) {
InitializeAstVisitor(stack_limit);
}
bool Renumber(FunctionLiteral* node);
private:
// AST node visitor interface.
#define DEFINE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT
void VisitSuspend(Suspend* node);
void VisitStatementsAndDeclarations(Block* node);
void VisitStatements(ZoneList<Statement*>* statements);
void VisitDeclarations(Declaration::List* declarations);
void VisitArguments(ZoneList<Expression*>* arguments);
void VisitLiteralProperty(LiteralProperty* property);
Zone* zone() const { return zone_; }
Zone* zone_;
FunctionKind function_kind_;
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
DISALLOW_COPY_AND_ASSIGN(AstNumberingVisitor);
};
void AstNumberingVisitor::VisitVariableDeclaration(VariableDeclaration* node) {
VisitVariableProxy(node->proxy());
}
void AstNumberingVisitor::VisitEmptyStatement(EmptyStatement* node) {
}
void AstNumberingVisitor::VisitSloppyBlockFunctionStatement(
SloppyBlockFunctionStatement* node) {
Visit(node->statement());
}
void AstNumberingVisitor::VisitContinueStatement(ContinueStatement* node) {
}
void AstNumberingVisitor::VisitBreakStatement(BreakStatement* node) {
}
void AstNumberingVisitor::VisitDebuggerStatement(DebuggerStatement* node) {
}
void AstNumberingVisitor::VisitNativeFunctionLiteral(
NativeFunctionLiteral* node) {
}
void AstNumberingVisitor::VisitDoExpression(DoExpression* node) {
Visit(node->block());
Visit(node->result());
}
void AstNumberingVisitor::VisitLiteral(Literal* node) {
}
void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) {
}
void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) {
}
void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) {
}
void AstNumberingVisitor::VisitSuperPropertyReference(
SuperPropertyReference* node) {
Visit(node->this_var());
Visit(node->home_object());
}
void AstNumberingVisitor::VisitSuperCallReference(SuperCallReference* node) {
Visit(node->this_var());
Visit(node->new_target_var());
Visit(node->this_function_var());
}
void AstNumberingVisitor::VisitExpressionStatement(ExpressionStatement* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitReturnStatement(ReturnStatement* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitSuspend(Suspend* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitYield(Yield* node) { VisitSuspend(node); }
void AstNumberingVisitor::VisitYieldStar(YieldStar* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitAwait(Await* node) { VisitSuspend(node); }
void AstNumberingVisitor::VisitThrow(Throw* node) {
Visit(node->exception());
}
void AstNumberingVisitor::VisitUnaryOperation(UnaryOperation* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitCountOperation(CountOperation* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitBlock(Block* node) {
VisitStatementsAndDeclarations(node);
}
void AstNumberingVisitor::VisitStatementsAndDeclarations(Block* node) {
Scope* scope = node->scope();
DCHECK(scope == nullptr || !scope->HasBeenRemoved());
if (scope) VisitDeclarations(scope->declarations());
VisitStatements(node->statements());
}
void AstNumberingVisitor::VisitFunctionDeclaration(FunctionDeclaration* node) {
VisitVariableProxy(node->proxy());
VisitFunctionLiteral(node->fun());
}
void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) {
VisitArguments(node->arguments());
}
void AstNumberingVisitor::VisitWithStatement(WithStatement* node) {
Visit(node->expression());
Visit(node->statement());
}
void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) {
Visit(node->body());
Visit(node->cond());
}
void AstNumberingVisitor::VisitWhileStatement(WhileStatement* node) {
Visit(node->cond());
Visit(node->body());
}
void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) {
DCHECK(node->scope() == nullptr || !node->scope()->HasBeenRemoved());
Visit(node->try_block());
Visit(node->catch_block());
}
void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) {
Visit(node->try_block());
Visit(node->finally_block());
}
void AstNumberingVisitor::VisitProperty(Property* node) {
Visit(node->key());
Visit(node->obj());
}
void AstNumberingVisitor::VisitResolvedProperty(ResolvedProperty* node) {
Visit(node->object());
Visit(node->property());
}
void AstNumberingVisitor::VisitAssignment(Assignment* node) {
Visit(node->target());
Visit(node->value());
}
void AstNumberingVisitor::VisitCompoundAssignment(CompoundAssignment* node) {
VisitBinaryOperation(node->binary_operation());
// We don't need to recurse down the assignment version since we already did
// the binop.
DCHECK_EQ(node->target(), node->binary_operation()->left());
DCHECK_EQ(node->value(), node->binary_operation()->right());
}
void AstNumberingVisitor::VisitBinaryOperation(BinaryOperation* node) {
Visit(node->left());
Visit(node->right());
}
void AstNumberingVisitor::VisitNaryOperation(NaryOperation* node) {
Visit(node->first());
for (size_t i = 0; i < node->subsequent_length(); ++i) {
Visit(node->subsequent(i));
}
}
void AstNumberingVisitor::VisitCompareOperation(CompareOperation* node) {
Visit(node->left());
Visit(node->right());
}
void AstNumberingVisitor::VisitSpread(Spread* node) {
Visit(node->expression());
}
void AstNumberingVisitor::VisitEmptyParentheses(EmptyParentheses* node) {
UNREACHABLE();
}
void AstNumberingVisitor::VisitGetIterator(GetIterator* node) {
Visit(node->iterable());
}
void AstNumberingVisitor::VisitGetTemplateObject(GetTemplateObject* node) {}
void AstNumberingVisitor::VisitImportCallExpression(
ImportCallExpression* node) {
Visit(node->argument());
}
void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) {
Visit(node->enumerable()); // Not part of loop.
Visit(node->each());
Visit(node->body());
}
void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) {
Visit(node->assign_iterator()); // Not part of loop.
Visit(node->assign_next());
Visit(node->next_result());
Visit(node->result_done());
Visit(node->assign_each());
Visit(node->body());
}
void AstNumberingVisitor::VisitConditional(Conditional* node) {
Visit(node->condition());
Visit(node->then_expression());
Visit(node->else_expression());
}
void AstNumberingVisitor::VisitIfStatement(IfStatement* node) {
Visit(node->condition());
if (!node->condition()->ToBooleanIsFalse()) {
Visit(node->then_statement());
}
if (node->HasElseStatement() && !node->condition()->ToBooleanIsTrue()) {
Visit(node->else_statement());
}
}
void AstNumberingVisitor::VisitSwitchStatement(SwitchStatement* node) {
Visit(node->tag());
for (CaseClause* clause : *node->cases()) {
if (!clause->is_default()) Visit(clause->label());
VisitStatements(clause->statements());
}
}
void AstNumberingVisitor::VisitForStatement(ForStatement* node) {
if (node->init() != nullptr) Visit(node->init()); // Not part of loop.
if (node->cond() != nullptr) Visit(node->cond());
if (node->next() != nullptr) Visit(node->next());
Visit(node->body());
}
void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) {
if (node->extends()) Visit(node->extends());
if (node->constructor()) Visit(node->constructor());
if (node->static_fields_initializer() != nullptr) {
Visit(node->static_fields_initializer());
}
if (node->instance_fields_initializer_function() != nullptr) {
Visit(node->instance_fields_initializer_function());
}
for (int i = 0; i < node->properties()->length(); i++) {
VisitLiteralProperty(node->properties()->at(i));
}
}
void AstNumberingVisitor::VisitInitializeClassFieldsStatement(
InitializeClassFieldsStatement* node) {
for (int i = 0; i < node->fields()->length(); i++) {
VisitLiteralProperty(node->fields()->at(i));
}
}
void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) {
for (int i = 0; i < node->properties()->length(); i++) {
VisitLiteralProperty(node->properties()->at(i));
}
}
void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) {
Visit(node->key());
Visit(node->value());
}
void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) {
for (int i = 0; i < node->values()->length(); i++) {
Visit(node->values()->at(i));
}
}
void AstNumberingVisitor::VisitCall(Call* node) {
Visit(node->expression());
VisitArguments(node->arguments());
}
void AstNumberingVisitor::VisitCallNew(CallNew* node) {
Visit(node->expression());
VisitArguments(node->arguments());
}
void AstNumberingVisitor::VisitStatements(ZoneList<Statement*>* statements) {
if (statements == nullptr) return;
for (int i = 0; i < statements->length(); i++) {
Visit(statements->at(i));
if (statements->at(i)->IsJump()) break;
}
}
void AstNumberingVisitor::VisitDeclarations(Declaration::List* decls) {
for (Declaration* decl : *decls) Visit(decl);
}
void AstNumberingVisitor::VisitArguments(ZoneList<Expression*>* arguments) {
for (int i = 0; i < arguments->length(); i++) {
Visit(arguments->at(i));
}
}
void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
if (node->ShouldEagerCompile()) {
// If the function literal is being eagerly compiled, recurse into the
// declarations and body of the function literal.
if (!AstNumbering::Renumber(stack_limit_, zone_, node)) {
SetStackOverflow();
return;
}
}
}
void AstNumberingVisitor::VisitRewritableExpression(
RewritableExpression* node) {
Visit(node->expression());
}
bool AstNumberingVisitor::Renumber(FunctionLiteral* node) {
DeclarationScope* scope = node->scope();
DCHECK(!scope->HasBeenRemoved());
function_kind_ = node->kind();
VisitDeclarations(scope->declarations());
VisitStatements(node->body());
return !HasStackOverflow();
}
bool AstNumbering::Renumber(uintptr_t stack_limit, Zone* zone,
FunctionLiteral* function) {
DisallowHeapAllocation no_allocation;
DisallowHandleAllocation no_handles;
DisallowHandleDereference no_deref;
AstNumberingVisitor visitor(stack_limit, zone);
return visitor.Renumber(function);
}
} // namespace internal
} // namespace v8
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_AST_AST_NUMBERING_H_
#define V8_AST_AST_NUMBERING_H_
#include <stdint.h>
namespace v8 {
namespace internal {
// Forward declarations.
class FunctionLiteral;
class Isolate;
class Zone;
namespace AstNumbering {
// Assign bailout IDs, and generator suspend IDs to an AST node tree; perform
// catch prediction for TryStatements.
bool Renumber(uintptr_t stack_limit, Zone* zone, FunctionLiteral* function);
} // namespace AstNumbering
// Some details on suspend IDs
// -------------------------
//
// In order to assist Ignition in generating bytecode for a generator function,
// we assign a unique number (the suspend ID) to each Suspend node in its AST.
// We also annotate loops with the number of suspends they contain
// (loop.suspend_count) and the smallest ID of those (loop.first_suspend_id),
// and we annotate the function itself with the number of suspends it contains
// (function.suspend_count).
//
// The way in which we choose the IDs is simply by enumerating the Suspend
// nodes.
// Ignition relies on the following properties:
// - For each loop l and each suspend y of l:
// l.first_suspend_id <=
// s.suspend_id < l.first_suspend_id + l.suspend_count
// - For the generator function f itself and each suspend s of f:
// 0 <= s.suspend_id < f.suspend_count
} // namespace internal
} // namespace v8
#endif // V8_AST_AST_NUMBERING_H_
......@@ -10,7 +10,6 @@
#include "src/api.h"
#include "src/asmjs/asm-js.h"
#include "src/assembler-inl.h"
#include "src/ast/ast-numbering.h"
#include "src/ast/prettyprinter.h"
#include "src/ast/scopes.h"
#include "src/base/optional.h"
......@@ -370,16 +369,6 @@ CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job,
return status;
}
bool Renumber(ParseInfo* parse_info) {
RuntimeCallTimerScope runtimeTimer(
parse_info->runtime_call_stats(),
parse_info->on_background_thread()
? RuntimeCallCounterId::kCompileBackgroundRenumber
: RuntimeCallCounterId::kCompileRenumber);
return AstNumbering::Renumber(parse_info->stack_limit(), parse_info->zone(),
parse_info->literal());
}
std::unique_ptr<CompilationJob> PrepareAndExecuteUnoptimizedCompileJobs(
ParseInfo* parse_info, FunctionLiteral* literal,
AccountingAllocator* allocator, CompilationJobList* inner_function_jobs) {
......@@ -867,7 +856,6 @@ bool Compiler::Analyze(ParseInfo* parse_info) {
: RuntimeCallCounterId::kCompileAnalyse);
if (!Rewriter::Rewrite(parse_info)) return false;
DeclarationScope::Analyze(parse_info);
if (!Renumber(parse_info)) return false;
return true;
}
......
......@@ -71,7 +71,7 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
static bool ParseAndAnalyze(ParseInfo* parse_info,
Handle<SharedFunctionInfo> shared_info,
Isolate* isolate);
// Rewrite, analyze scopes, and renumber.
// Rewrite and analyze scopes.
static bool Analyze(ParseInfo* parse_info);
// ===========================================================================
......
......@@ -795,7 +795,6 @@ class RuntimeCallTimer final {
V(CompileBackgroundEval) \
V(CompileBackgroundIgnition) \
V(CompileBackgroundScript) \
V(CompileBackgroundRenumber) \
V(CompileBackgroundRewriteReturnResult) \
V(CompileBackgroundScopeAnalysis) \
V(CompileDeserialize) \
......@@ -805,7 +804,6 @@ class RuntimeCallTimer final {
V(CompileGetFromOptimizedCodeMap) \
V(CompileIgnition) \
V(CompileIgnitionFinalization) \
V(CompileRenumber) \
V(CompileRewriteReturnResult) \
V(CompileScopeAnalysis) \
V(CompileScript) \
......
......@@ -5,7 +5,6 @@
#include "test/cctest/compiler/function-tester.h"
#include "src/api.h"
#include "src/ast/ast-numbering.h"
#include "src/compilation-info.h"
#include "src/compiler.h"
#include "src/compiler/linkage.h"
......
......@@ -34,7 +34,6 @@
#include "src/v8.h"
#include "src/api.h"
#include "src/ast/ast-numbering.h"
#include "src/ast/ast-value-factory.h"
#include "src/ast/ast.h"
#include "src/compiler.h"
......
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