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