Commit 58247e87 authored by jochen's avatar jochen Committed by Commit bot

Use preexisting SharedFunctionInfos in the asm-wasm builder

BUG=chromium:675114
R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2583113002
Cr-Commit-Position: refs/heads/master@{#41796}
parent 81dd9847
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/asmjs/asm-typer.h" #include "src/asmjs/asm-typer.h"
#include "src/asmjs/asm-wasm-builder.h" #include "src/asmjs/asm-wasm-builder.h"
#include "src/assert-scope.h" #include "src/assert-scope.h"
#include "src/compilation-info.h"
#include "src/execution.h" #include "src/execution.h"
#include "src/factory.h" #include "src/factory.h"
#include "src/handles.h" #include "src/handles.h"
...@@ -160,13 +161,11 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle<JSReceiver> stdlib, ...@@ -160,13 +161,11 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle<JSReceiver> stdlib,
} // namespace } // namespace
MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(ParseInfo* info) { MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
ErrorThrower thrower(info->isolate(), "Asm.js -> WebAssembly conversion"); ErrorThrower thrower(info->isolate(), "Asm.js -> WebAssembly conversion");
base::ElapsedTimer asm_wasm_timer; base::ElapsedTimer asm_wasm_timer;
asm_wasm_timer.Start(); asm_wasm_timer.Start();
wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), wasm::AsmWasmBuilder builder(info);
info->ast_value_factory(), info->script(),
info->literal());
Handle<FixedArray> foreign_globals; Handle<FixedArray> foreign_globals;
auto asm_wasm_result = builder.Run(&foreign_globals); auto asm_wasm_result = builder.Run(&foreign_globals);
if (!asm_wasm_result.success) { if (!asm_wasm_result.success) {
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class CompilationInfo;
class JSArrayBuffer; class JSArrayBuffer;
class ParseInfo;
// Interface to compile and instantiate for asmjs. // Interface to compile and instantiate for asmjs.
class AsmJs { class AsmJs {
public: public:
static MaybeHandle<FixedArray> CompileAsmViaWasm(ParseInfo* info); static MaybeHandle<FixedArray> CompileAsmViaWasm(CompilationInfo* info);
static bool IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data, static bool IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib); Handle<JSReceiver> stdlib);
static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate, static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate,
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "src/ast/ast.h" #include "src/ast/ast.h"
#include "src/ast/scopes.h" #include "src/ast/scopes.h"
#include "src/codegen.h" #include "src/codegen.h"
#include "src/compilation-info.h"
#include "src/compiler.h" #include "src/compiler.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/parsing/parse-info.h" #include "src/parsing/parse-info.h"
...@@ -46,7 +47,7 @@ struct ForeignVariable { ...@@ -46,7 +47,7 @@ struct ForeignVariable {
class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
public: public:
AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, CompilationInfo* info,
AstValueFactory* ast_value_factory, Handle<Script> script, AstValueFactory* ast_value_factory, Handle<Script> script,
FunctionLiteral* literal, AsmTyper* typer) FunctionLiteral* literal, AsmTyper* typer)
: local_variables_(ZoneHashMap::kDefaultHashMapCapacity, : local_variables_(ZoneHashMap::kDefaultHashMapCapacity,
...@@ -61,6 +62,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -61,6 +62,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
literal_(literal), literal_(literal),
isolate_(isolate), isolate_(isolate),
zone_(zone), zone_(zone),
info_(info),
ast_value_factory_(ast_value_factory), ast_value_factory_(ast_value_factory),
script_(script), script_(script),
typer_(typer), typer_(typer),
...@@ -136,12 +138,10 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -136,12 +138,10 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
Zone zone(isolate_->allocator(), ZONE_NAME); Zone zone(isolate_->allocator(), ZONE_NAME);
DeclarationScope* new_func_scope = nullptr; DeclarationScope* new_func_scope = nullptr;
if (decl->fun()->body() == nullptr) { if (decl->fun()->body() == nullptr) {
// TODO(bradnelson): Refactor parser so we don't need a // TODO(titzer/bradnelson): Reuse SharedFunctionInfos used here when
// SharedFunctionInfo to parse a single function, // compiling the wasm module.
// or squirrel away the SharedFunctionInfo to use later. Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfo(
Handle<SharedFunctionInfo> shared = decl->fun(), script_, info_, LazyCompilationMode::kAlways);
isolate_->factory()->NewSharedFunctionInfoForLiteral(decl->fun(),
script_);
shared->set_is_toplevel(false); shared->set_is_toplevel(false);
ParseInfo info(&zone, script_); ParseInfo info(&zone, script_);
info.set_shared_info(shared); info.set_shared_info(shared);
...@@ -1938,6 +1938,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -1938,6 +1938,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
FunctionLiteral* literal_; FunctionLiteral* literal_;
Isolate* isolate_; Isolate* isolate_;
Zone* zone_; Zone* zone_;
CompilationInfo* info_;
AstValueFactory* ast_value_factory_; AstValueFactory* ast_value_factory_;
Handle<Script> script_; Handle<Script> script_;
AsmTyper* typer_; AsmTyper* typer_;
...@@ -1959,26 +1960,22 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -1959,26 +1960,22 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl);
}; };
AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, AsmWasmBuilder::AsmWasmBuilder(CompilationInfo* info)
AstValueFactory* ast_value_factory, : info_(info),
Handle<Script> script, FunctionLiteral* literal) typer_(info->isolate(), info->zone(), info->script(), info->literal()) {}
: isolate_(isolate),
zone_(zone),
ast_value_factory_(ast_value_factory),
script_(script),
literal_(literal),
typer_(isolate, zone, script, literal) {}
// TODO(aseemgarg): probably should take zone (to write wasm to) as input so // TODO(aseemgarg): probably should take zone (to write wasm to) as input so
// that zone in constructor may be thrown away once wasm module is written. // that zone in constructor may be thrown away once wasm module is written.
AsmWasmBuilder::Result AsmWasmBuilder::Run(Handle<FixedArray>* foreign_args) { AsmWasmBuilder::Result AsmWasmBuilder::Run(Handle<FixedArray>* foreign_args) {
AsmWasmBuilderImpl impl(isolate_, zone_, ast_value_factory_, script_, Zone* zone = info_->zone();
literal_, &typer_); AsmWasmBuilderImpl impl(info_->isolate(), zone, info_,
info_->parse_info()->ast_value_factory(),
info_->script(), info_->literal(), &typer_);
bool success = impl.Build(); bool success = impl.Build();
*foreign_args = impl.GetForeignArgs(); *foreign_args = impl.GetForeignArgs();
ZoneBuffer* module_buffer = new (zone_) ZoneBuffer(zone_); ZoneBuffer* module_buffer = new (zone) ZoneBuffer(zone);
impl.builder_->WriteTo(*module_buffer); impl.builder_->WriteTo(*module_buffer);
ZoneBuffer* asm_offsets_buffer = new (zone_) ZoneBuffer(zone_); ZoneBuffer* asm_offsets_buffer = new (zone) ZoneBuffer(zone);
impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer);
return {module_buffer, asm_offsets_buffer, success}; return {module_buffer, asm_offsets_buffer, success};
} }
......
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class FunctionLiteral; class CompilationInfo;
class Script;
namespace wasm { namespace wasm {
...@@ -27,9 +26,7 @@ class AsmWasmBuilder { ...@@ -27,9 +26,7 @@ class AsmWasmBuilder {
bool success; bool success;
}; };
explicit AsmWasmBuilder(Isolate* isolate, Zone* zone, explicit AsmWasmBuilder(CompilationInfo* info);
AstValueFactory* ast_value_factory,
Handle<Script> script, FunctionLiteral* root);
Result Run(Handle<FixedArray>* foreign_args); Result Run(Handle<FixedArray>* foreign_args);
static const char* foreign_init_name; static const char* foreign_init_name;
...@@ -38,11 +35,7 @@ class AsmWasmBuilder { ...@@ -38,11 +35,7 @@ class AsmWasmBuilder {
const AsmTyper* typer() { return &typer_; } const AsmTyper* typer() { return &typer_; }
private: private:
Isolate* isolate_; CompilationInfo* info_;
Zone* zone_;
AstValueFactory* ast_value_factory_;
Handle<Script> script_;
FunctionLiteral* literal_;
AsmTyper typer_; AsmTyper typer_;
}; };
} // namespace wasm } // namespace wasm
......
...@@ -431,7 +431,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) { ...@@ -431,7 +431,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) {
!info->shared_info()->is_asm_wasm_broken() && !info->is_debug()) { !info->shared_info()->is_asm_wasm_broken() && !info->is_debug()) {
EnsureFeedbackMetadata(info); EnsureFeedbackMetadata(info);
MaybeHandle<FixedArray> wasm_data; MaybeHandle<FixedArray> wasm_data;
wasm_data = AsmJs::CompileAsmViaWasm(info->parse_info()); wasm_data = AsmJs::CompileAsmViaWasm(info);
if (!wasm_data.is_null()) { if (!wasm_data.is_null()) {
info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
......
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