| OLD | NEW |
| 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 #ifndef V8_COMPILER_WASM_COMPILER_H_ | 5 #ifndef V8_COMPILER_WASM_COMPILER_H_ |
| 6 #define V8_COMPILER_WASM_COMPILER_H_ | 6 #define V8_COMPILER_WASM_COMPILER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 // Clients of this interface shouldn't depend on lots of compiler internals. | 10 // Clients of this interface shouldn't depend on lots of compiler internals. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 namespace compiler { | 47 namespace compiler { |
| 48 class WasmCompilationUnit final { | 48 class WasmCompilationUnit final { |
| 49 public: | 49 public: |
| 50 WasmCompilationUnit(Isolate* isolate, wasm::ModuleBytesEnv* module_env, | 50 WasmCompilationUnit(Isolate* isolate, wasm::ModuleBytesEnv* module_env, |
| 51 const wasm::WasmFunction* function, bool is_sync = true); | 51 const wasm::WasmFunction* function, bool is_sync = true); |
| 52 WasmCompilationUnit(Isolate* isolate, wasm::ModuleEnv* module_env, | 52 WasmCompilationUnit(Isolate* isolate, wasm::ModuleEnv* module_env, |
| 53 wasm::FunctionBody body, wasm::WasmName name, int index, | 53 wasm::FunctionBody body, wasm::WasmName name, int index, |
| 54 bool is_sync = true); | 54 bool is_sync = true); |
| 55 | 55 |
| 56 Zone* graph_zone() { return graph_zone_.get(); } | |
| 57 int func_index() const { return func_index_; } | 56 int func_index() const { return func_index_; } |
| 58 | 57 |
| 58 void ReopenCentryStub() { centry_stub_ = handle(*centry_stub_, isolate_); } |
| 59 void InitializeHandles(); | 59 void InitializeHandles(); |
| 60 void ExecuteCompilation(); | 60 void ExecuteCompilation(); |
| 61 Handle<Code> FinishCompilation(wasm::ErrorThrower* thrower); | 61 Handle<Code> FinishCompilation(wasm::ErrorThrower* thrower); |
| 62 | 62 |
| 63 static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, | 63 static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, |
| 64 Isolate* isolate, | 64 Isolate* isolate, |
| 65 wasm::ModuleBytesEnv* module_env, | 65 wasm::ModuleBytesEnv* module_env, |
| 66 const wasm::WasmFunction* function); | 66 const wasm::WasmFunction* function); |
| 67 | 67 |
| 68 void set_memory_cost(size_t memory_cost) { memory_cost_ = memory_cost; } |
| 69 size_t memory_cost() const { return memory_cost_; } |
| 70 |
| 68 private: | 71 private: |
| 69 SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms); | 72 SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms); |
| 70 | 73 |
| 71 Isolate* isolate_; | 74 Isolate* isolate_; |
| 72 wasm::ModuleEnv* module_env_; | 75 wasm::ModuleEnv* module_env_; |
| 73 wasm::FunctionBody func_body_; | 76 wasm::FunctionBody func_body_; |
| 74 wasm::WasmName func_name_; | 77 wasm::WasmName func_name_; |
| 75 bool is_sync_; | 78 bool is_sync_; |
| 76 // The graph zone is deallocated at the end of ExecuteCompilation. | 79 // The graph zone is deallocated at the end of ExecuteCompilation by virtue of |
| 77 std::unique_ptr<Zone> graph_zone_; | 80 // it being zone allocated. |
| 78 JSGraph* jsgraph_; | 81 JSGraph* jsgraph_ = nullptr; |
| 79 Zone compilation_zone_; | 82 // the compilation_zone_, info_, and job_ fields need to survive past |
| 80 CompilationInfo info_; | 83 // ExecuteCompilation, onto FinishCompilation (which happens on the main |
| 84 // thread). |
| 85 std::unique_ptr<Zone> compilation_zone_; |
| 86 std::unique_ptr<CompilationInfo> info_; |
| 81 std::unique_ptr<CompilationJob> job_; | 87 std::unique_ptr<CompilationJob> job_; |
| 88 Handle<Code> centry_stub_; |
| 82 int func_index_; | 89 int func_index_; |
| 83 wasm::Result<wasm::DecodeStruct*> graph_construction_result_; | 90 wasm::Result<wasm::DecodeStruct*> graph_construction_result_; |
| 84 bool ok_ = true; | 91 bool ok_ = true; |
| 85 #if DEBUG | 92 size_t memory_cost_ = 0; |
| 86 bool handles_initialized_ = false; | |
| 87 #endif // DEBUG | |
| 88 ZoneVector<trap_handler::ProtectedInstructionData> | |
| 89 protected_instructions_; // Instructions that are protected by the signal | |
| 90 // handler. | |
| 91 | |
| 92 void ExecuteCompilationInternal(); | 93 void ExecuteCompilationInternal(); |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit); | 95 DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 // Wraps a JS function, producing a code object that can be called from WASM. | 98 // Wraps a JS function, producing a code object that can be called from WASM. |
| 98 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, | 99 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, |
| 99 wasm::FunctionSig* sig, uint32_t index, | 100 wasm::FunctionSig* sig, uint32_t index, |
| 100 Handle<String> module_name, | 101 Handle<String> module_name, |
| 101 MaybeHandle<String> import_name, | 102 MaybeHandle<String> import_name, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 112 wasm::FunctionSig* sig, | 113 wasm::FunctionSig* sig, |
| 113 Handle<WasmInstanceObject> instance); | 114 Handle<WasmInstanceObject> instance); |
| 114 | 115 |
| 115 // Abstracts details of building TurboFan graph nodes for WASM to separate | 116 // Abstracts details of building TurboFan graph nodes for WASM to separate |
| 116 // the WASM decoder from the internal details of TurboFan. | 117 // the WASM decoder from the internal details of TurboFan. |
| 117 class WasmTrapHelper; | 118 class WasmTrapHelper; |
| 118 typedef ZoneVector<Node*> NodeVector; | 119 typedef ZoneVector<Node*> NodeVector; |
| 119 class WasmGraphBuilder { | 120 class WasmGraphBuilder { |
| 120 public: | 121 public: |
| 121 WasmGraphBuilder( | 122 WasmGraphBuilder( |
| 122 wasm::ModuleEnv* module_env, Zone* z, JSGraph* g, wasm::FunctionSig* sig, | 123 wasm::ModuleEnv* module_env, Zone* z, JSGraph* g, |
| 124 Handle<Code> centry_stub_, wasm::FunctionSig* sig, |
| 123 compiler::SourcePositionTable* source_position_table = nullptr); | 125 compiler::SourcePositionTable* source_position_table = nullptr); |
| 124 | 126 |
| 125 Node** Buffer(size_t count) { | 127 Node** Buffer(size_t count) { |
| 126 if (count > cur_bufsize_) { | 128 if (count > cur_bufsize_) { |
| 127 size_t new_size = count + cur_bufsize_ + 5; | 129 size_t new_size = count + cur_bufsize_ + 5; |
| 128 cur_buffer_ = | 130 cur_buffer_ = |
| 129 reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*))); | 131 reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*))); |
| 130 cur_bufsize_ = new_size; | 132 cur_bufsize_ = new_size; |
| 131 } | 133 } |
| 132 return cur_buffer_; | 134 return cur_buffer_; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 bool has_simd() const { return has_simd_; } | 264 bool has_simd() const { return has_simd_; } |
| 263 | 265 |
| 264 wasm::ModuleEnv* module_env() const { return module_; } | 266 wasm::ModuleEnv* module_env() const { return module_; } |
| 265 | 267 |
| 266 private: | 268 private: |
| 267 static const int kDefaultBufferSize = 16; | 269 static const int kDefaultBufferSize = 16; |
| 268 friend class WasmTrapHelper; | 270 friend class WasmTrapHelper; |
| 269 | 271 |
| 270 Zone* zone_; | 272 Zone* zone_; |
| 271 JSGraph* jsgraph_; | 273 JSGraph* jsgraph_; |
| 274 Node* centry_stub_node_; |
| 272 wasm::ModuleEnv* module_ = nullptr; | 275 wasm::ModuleEnv* module_ = nullptr; |
| 273 Node* mem_buffer_ = nullptr; | 276 Node* mem_buffer_ = nullptr; |
| 274 Node* mem_size_ = nullptr; | 277 Node* mem_size_ = nullptr; |
| 275 NodeVector signature_tables_; | 278 NodeVector signature_tables_; |
| 276 NodeVector function_tables_; | 279 NodeVector function_tables_; |
| 277 NodeVector function_table_sizes_; | 280 NodeVector function_table_sizes_; |
| 278 Node** control_ = nullptr; | 281 Node** control_ = nullptr; |
| 279 Node** effect_ = nullptr; | 282 Node** effect_ = nullptr; |
| 280 Node** cur_buffer_; | 283 Node** cur_buffer_; |
| 281 size_t cur_bufsize_; | 284 size_t cur_bufsize_; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 408 } |
| 406 | 409 |
| 407 int AddParameterNodes(Node** args, int pos, int param_count, | 410 int AddParameterNodes(Node** args, int pos, int param_count, |
| 408 wasm::FunctionSig* sig); | 411 wasm::FunctionSig* sig); |
| 409 }; | 412 }; |
| 410 } // namespace compiler | 413 } // namespace compiler |
| 411 } // namespace internal | 414 } // namespace internal |
| 412 } // namespace v8 | 415 } // namespace v8 |
| 413 | 416 |
| 414 #endif // V8_COMPILER_WASM_COMPILER_H_ | 417 #endif // V8_COMPILER_WASM_COMPILER_H_ |
| OLD | NEW |