Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: src/asmjs/asm-wasm-builder.cc

Issue 2583113002: Use preexisting SharedFunctionInfos in the asm-wasm builder (Closed)
Patch Set: comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/asmjs/asm-wasm-builder.h ('k') | src/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 // Required to get M_E etc. in MSVC. 7 // Required to get M_E etc. in MSVC.
8 #if defined(_WIN32) 8 #if defined(_WIN32)
9 #define _USE_MATH_DEFINES 9 #define _USE_MATH_DEFINES
10 #endif 10 #endif
11 #include <math.h> 11 #include <math.h>
12 12
13 #include "src/asmjs/asm-types.h" 13 #include "src/asmjs/asm-types.h"
14 #include "src/asmjs/asm-wasm-builder.h" 14 #include "src/asmjs/asm-wasm-builder.h"
15 #include "src/asmjs/switch-logic.h" 15 #include "src/asmjs/switch-logic.h"
16 16
17 #include "src/wasm/wasm-macro-gen.h" 17 #include "src/wasm/wasm-macro-gen.h"
18 #include "src/wasm/wasm-opcodes.h" 18 #include "src/wasm/wasm-opcodes.h"
19 19
20 #include "src/ast/ast.h" 20 #include "src/ast/ast.h"
21 #include "src/ast/scopes.h" 21 #include "src/ast/scopes.h"
22 #include "src/codegen.h" 22 #include "src/codegen.h"
23 #include "src/compilation-info.h"
23 #include "src/compiler.h" 24 #include "src/compiler.h"
24 #include "src/isolate.h" 25 #include "src/isolate.h"
25 #include "src/parsing/parse-info.h" 26 #include "src/parsing/parse-info.h"
26 27
27 namespace v8 { 28 namespace v8 {
28 namespace internal { 29 namespace internal {
29 namespace wasm { 30 namespace wasm {
30 31
31 #define RECURSE(call) \ 32 #define RECURSE(call) \
32 do { \ 33 do { \
33 DCHECK(!HasStackOverflow()); \ 34 DCHECK(!HasStackOverflow()); \
34 call; \ 35 call; \
35 if (HasStackOverflow()) return; \ 36 if (HasStackOverflow()) return; \
36 } while (false) 37 } while (false)
37 38
38 enum AsmScope { kModuleScope, kInitScope, kFuncScope, kExportScope }; 39 enum AsmScope { kModuleScope, kInitScope, kFuncScope, kExportScope };
39 enum ValueFate { kDrop, kLeaveOnStack }; 40 enum ValueFate { kDrop, kLeaveOnStack };
40 41
41 struct ForeignVariable { 42 struct ForeignVariable {
42 Handle<Name> name; 43 Handle<Name> name;
43 Variable* var; 44 Variable* var;
44 LocalType type; 45 LocalType type;
45 }; 46 };
46 47
47 class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { 48 class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
48 public: 49 public:
49 AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, 50 AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, CompilationInfo* info,
50 AstValueFactory* ast_value_factory, Handle<Script> script, 51 AstValueFactory* ast_value_factory, Handle<Script> script,
51 FunctionLiteral* literal, AsmTyper* typer) 52 FunctionLiteral* literal, AsmTyper* typer)
52 : local_variables_(ZoneHashMap::kDefaultHashMapCapacity, 53 : local_variables_(ZoneHashMap::kDefaultHashMapCapacity,
53 ZoneAllocationPolicy(zone)), 54 ZoneAllocationPolicy(zone)),
54 functions_(ZoneHashMap::kDefaultHashMapCapacity, 55 functions_(ZoneHashMap::kDefaultHashMapCapacity,
55 ZoneAllocationPolicy(zone)), 56 ZoneAllocationPolicy(zone)),
56 global_variables_(ZoneHashMap::kDefaultHashMapCapacity, 57 global_variables_(ZoneHashMap::kDefaultHashMapCapacity,
57 ZoneAllocationPolicy(zone)), 58 ZoneAllocationPolicy(zone)),
58 scope_(kModuleScope), 59 scope_(kModuleScope),
59 builder_(new (zone) WasmModuleBuilder(zone)), 60 builder_(new (zone) WasmModuleBuilder(zone)),
60 current_function_builder_(nullptr), 61 current_function_builder_(nullptr),
61 literal_(literal), 62 literal_(literal),
62 isolate_(isolate), 63 isolate_(isolate),
63 zone_(zone), 64 zone_(zone),
65 info_(info),
64 ast_value_factory_(ast_value_factory), 66 ast_value_factory_(ast_value_factory),
65 script_(script), 67 script_(script),
66 typer_(typer), 68 typer_(typer),
67 typer_failed_(false), 69 typer_failed_(false),
68 breakable_blocks_(zone), 70 breakable_blocks_(zone),
69 foreign_variables_(zone), 71 foreign_variables_(zone),
70 init_function_(nullptr), 72 init_function_(nullptr),
71 foreign_init_function_(nullptr), 73 foreign_init_function_(nullptr),
72 function_tables_(ZoneHashMap::kDefaultHashMapCapacity, 74 function_tables_(ZoneHashMap::kDefaultHashMapCapacity,
73 ZoneAllocationPolicy(zone)), 75 ZoneAllocationPolicy(zone)),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 131
130 void VisitVariableDeclaration(VariableDeclaration* decl) {} 132 void VisitVariableDeclaration(VariableDeclaration* decl) {}
131 133
132 void VisitFunctionDeclaration(FunctionDeclaration* decl) { 134 void VisitFunctionDeclaration(FunctionDeclaration* decl) {
133 DCHECK_EQ(kModuleScope, scope_); 135 DCHECK_EQ(kModuleScope, scope_);
134 DCHECK_NULL(current_function_builder_); 136 DCHECK_NULL(current_function_builder_);
135 FunctionLiteral* old_func = decl->fun(); 137 FunctionLiteral* old_func = decl->fun();
136 Zone zone(isolate_->allocator(), ZONE_NAME); 138 Zone zone(isolate_->allocator(), ZONE_NAME);
137 DeclarationScope* new_func_scope = nullptr; 139 DeclarationScope* new_func_scope = nullptr;
138 if (decl->fun()->body() == nullptr) { 140 if (decl->fun()->body() == nullptr) {
139 // TODO(bradnelson): Refactor parser so we don't need a 141 // TODO(titzer/bradnelson): Reuse SharedFunctionInfos used here when
140 // SharedFunctionInfo to parse a single function, 142 // compiling the wasm module.
141 // or squirrel away the SharedFunctionInfo to use later. 143 Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfo(
142 Handle<SharedFunctionInfo> shared = 144 decl->fun(), script_, info_, LazyCompilationMode::kAlways);
143 isolate_->factory()->NewSharedFunctionInfoForLiteral(decl->fun(),
144 script_);
145 shared->set_is_toplevel(false); 145 shared->set_is_toplevel(false);
146 ParseInfo info(&zone, script_); 146 ParseInfo info(&zone, script_);
147 info.set_shared_info(shared); 147 info.set_shared_info(shared);
148 info.set_toplevel(false); 148 info.set_toplevel(false);
149 info.set_language_mode(decl->fun()->scope()->language_mode()); 149 info.set_language_mode(decl->fun()->scope()->language_mode());
150 info.set_allow_lazy_parsing(false); 150 info.set_allow_lazy_parsing(false);
151 info.set_function_literal_id(shared->function_literal_id()); 151 info.set_function_literal_id(shared->function_literal_id());
152 info.set_ast_value_factory(ast_value_factory_); 152 info.set_ast_value_factory(ast_value_factory_);
153 info.set_ast_value_factory_owned(false); 153 info.set_ast_value_factory_owned(false);
154 // Create fresh function scope to use to parse the function in. 154 // Create fresh function scope to use to parse the function in.
(...skipping 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 1931
1932 ZoneHashMap local_variables_; 1932 ZoneHashMap local_variables_;
1933 ZoneHashMap functions_; 1933 ZoneHashMap functions_;
1934 ZoneHashMap global_variables_; 1934 ZoneHashMap global_variables_;
1935 AsmScope scope_; 1935 AsmScope scope_;
1936 WasmModuleBuilder* builder_; 1936 WasmModuleBuilder* builder_;
1937 WasmFunctionBuilder* current_function_builder_; 1937 WasmFunctionBuilder* current_function_builder_;
1938 FunctionLiteral* literal_; 1938 FunctionLiteral* literal_;
1939 Isolate* isolate_; 1939 Isolate* isolate_;
1940 Zone* zone_; 1940 Zone* zone_;
1941 CompilationInfo* info_;
1941 AstValueFactory* ast_value_factory_; 1942 AstValueFactory* ast_value_factory_;
1942 Handle<Script> script_; 1943 Handle<Script> script_;
1943 AsmTyper* typer_; 1944 AsmTyper* typer_;
1944 bool typer_failed_; 1945 bool typer_failed_;
1945 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_; 1946 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_;
1946 ZoneVector<ForeignVariable> foreign_variables_; 1947 ZoneVector<ForeignVariable> foreign_variables_;
1947 WasmFunctionBuilder* init_function_; 1948 WasmFunctionBuilder* init_function_;
1948 WasmFunctionBuilder* foreign_init_function_; 1949 WasmFunctionBuilder* foreign_init_function_;
1949 uint32_t next_table_index_; 1950 uint32_t next_table_index_;
1950 ZoneHashMap function_tables_; 1951 ZoneHashMap function_tables_;
1951 ImportedFunctionTable imported_function_table_; 1952 ImportedFunctionTable imported_function_table_;
1952 // Remember the parent node for reporting the correct location for ToNumber 1953 // Remember the parent node for reporting the correct location for ToNumber
1953 // conversions after calls. 1954 // conversions after calls.
1954 BinaryOperation* parent_binop_; 1955 BinaryOperation* parent_binop_;
1955 1956
1956 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 1957 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
1957 1958
1958 private: 1959 private:
1959 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); 1960 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl);
1960 }; 1961 };
1961 1962
1962 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, 1963 AsmWasmBuilder::AsmWasmBuilder(CompilationInfo* info)
1963 AstValueFactory* ast_value_factory, 1964 : info_(info),
1964 Handle<Script> script, FunctionLiteral* literal) 1965 typer_(info->isolate(), info->zone(), info->script(), info->literal()) {}
1965 : isolate_(isolate),
1966 zone_(zone),
1967 ast_value_factory_(ast_value_factory),
1968 script_(script),
1969 literal_(literal),
1970 typer_(isolate, zone, script, literal) {}
1971 1966
1972 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so 1967 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so
1973 // that zone in constructor may be thrown away once wasm module is written. 1968 // that zone in constructor may be thrown away once wasm module is written.
1974 AsmWasmBuilder::Result AsmWasmBuilder::Run(Handle<FixedArray>* foreign_args) { 1969 AsmWasmBuilder::Result AsmWasmBuilder::Run(Handle<FixedArray>* foreign_args) {
1975 AsmWasmBuilderImpl impl(isolate_, zone_, ast_value_factory_, script_, 1970 Zone* zone = info_->zone();
1976 literal_, &typer_); 1971 AsmWasmBuilderImpl impl(info_->isolate(), zone, info_,
1972 info_->parse_info()->ast_value_factory(),
1973 info_->script(), info_->literal(), &typer_);
1977 bool success = impl.Build(); 1974 bool success = impl.Build();
1978 *foreign_args = impl.GetForeignArgs(); 1975 *foreign_args = impl.GetForeignArgs();
1979 ZoneBuffer* module_buffer = new (zone_) ZoneBuffer(zone_); 1976 ZoneBuffer* module_buffer = new (zone) ZoneBuffer(zone);
1980 impl.builder_->WriteTo(*module_buffer); 1977 impl.builder_->WriteTo(*module_buffer);
1981 ZoneBuffer* asm_offsets_buffer = new (zone_) ZoneBuffer(zone_); 1978 ZoneBuffer* asm_offsets_buffer = new (zone) ZoneBuffer(zone);
1982 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); 1979 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer);
1983 return {module_buffer, asm_offsets_buffer, success}; 1980 return {module_buffer, asm_offsets_buffer, success};
1984 } 1981 }
1985 1982
1986 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; 1983 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__";
1987 const char* AsmWasmBuilder::single_function_name = "__single_function__"; 1984 const char* AsmWasmBuilder::single_function_name = "__single_function__";
1988 1985
1989 } // namespace wasm 1986 } // namespace wasm
1990 } // namespace internal 1987 } // namespace internal
1991 } // namespace v8 1988 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-wasm-builder.h ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698