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. |
11 // Do not include anything from src/compiler here! | 11 // Do not include anything from src/compiler here! |
12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
13 #include "src/wasm/wasm-opcodes.h" | 13 #include "src/wasm/wasm-opcodes.h" |
14 #include "src/wasm/wasm-result.h" | 14 #include "src/wasm/wasm-result.h" |
15 #include "src/zone.h" | 15 #include "src/zone.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 namespace compiler { | 20 namespace compiler { |
21 // Forward declarations for some compiler data structures. | 21 // Forward declarations for some compiler data structures. |
22 class Node; | 22 class Node; |
23 class JSGraph; | 23 class JSGraph; |
24 class Graph; | 24 class Graph; |
25 class Operator; | 25 class Operator; |
26 class SourcePositionTable; | 26 class SourcePositionTable; |
27 class MachineOperatorBuilder; | |
28 } // namespace compiler | 27 } // namespace compiler |
29 | 28 |
30 namespace wasm { | 29 namespace wasm { |
31 // Forward declarations for some WASM data structures. | 30 // Forward declarations for some WASM data structures. |
32 struct ModuleEnv; | 31 struct ModuleEnv; |
33 struct WasmFunction; | 32 struct WasmFunction; |
34 class ErrorThrower; | 33 class ErrorThrower; |
35 struct DecodeStruct; | 34 struct DecodeStruct; |
36 | 35 |
37 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}. | 36 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 Handle<String> import_module, | 87 Handle<String> import_module, |
89 MaybeHandle<String> import_function); | 88 MaybeHandle<String> import_function); |
90 | 89 |
91 // Wraps a given wasm code object, producing a code object. | 90 // Wraps a given wasm code object, producing a code object. |
92 Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module, | 91 Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module, |
93 Handle<Code> wasm_code, uint32_t index); | 92 Handle<Code> wasm_code, uint32_t index); |
94 | 93 |
95 // Abstracts details of building TurboFan graph nodes for WASM to separate | 94 // Abstracts details of building TurboFan graph nodes for WASM to separate |
96 // the WASM decoder from the internal details of TurboFan. | 95 // the WASM decoder from the internal details of TurboFan. |
97 class WasmTrapHelper; | 96 class WasmTrapHelper; |
98 enum class Conversion { kNone, kOpaque, kInt32, kFloat32, kFloat64 }; | |
99 typedef ZoneVector<Node*> NodeVector; | 97 typedef ZoneVector<Node*> NodeVector; |
100 class WasmGraphBuilder { | 98 class WasmGraphBuilder { |
101 public: | 99 public: |
102 WasmGraphBuilder( | 100 WasmGraphBuilder( |
103 Zone* z, JSGraph* g, wasm::FunctionSig* function_signature, | 101 Zone* z, JSGraph* g, wasm::FunctionSig* function_signature, |
104 compiler::SourcePositionTable* source_position_table = nullptr); | 102 compiler::SourcePositionTable* source_position_table = nullptr); |
105 | 103 |
106 Node** Buffer(size_t count) { | 104 Node** Buffer(size_t count) { |
107 if (count > cur_bufsize_) { | 105 if (count > cur_bufsize_) { |
108 size_t new_size = count + cur_bufsize_ + 5; | 106 size_t new_size = count + cur_bufsize_ + 5; |
(...skipping 15 matching lines...) Expand all Loading... |
124 Node* Merge(unsigned count, Node** controls); | 122 Node* Merge(unsigned count, Node** controls); |
125 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control); | 123 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control); |
126 Node* EffectPhi(unsigned count, Node** effects, Node* control); | 124 Node* EffectPhi(unsigned count, Node** effects, Node* control); |
127 Node* NumberConstant(int32_t value); | 125 Node* NumberConstant(int32_t value); |
128 Node* Uint32Constant(uint32_t value); | 126 Node* Uint32Constant(uint32_t value); |
129 Node* Int32Constant(int32_t value); | 127 Node* Int32Constant(int32_t value); |
130 Node* Int64Constant(int64_t value); | 128 Node* Int64Constant(int64_t value); |
131 Node* Float32Constant(float value); | 129 Node* Float32Constant(float value); |
132 Node* Float64Constant(double value); | 130 Node* Float64Constant(double value); |
133 Node* HeapConstant(Handle<HeapObject> value); | 131 Node* HeapConstant(Handle<HeapObject> value); |
134 Node* DefaultS128Value(); | |
135 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right, | 132 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
136 wasm::WasmCodePosition position = wasm::kNoCodePosition); | 133 wasm::WasmCodePosition position = wasm::kNoCodePosition); |
137 Node* Unop(wasm::WasmOpcode opcode, Node* input, | 134 Node* Unop(wasm::WasmOpcode opcode, Node* input, |
138 wasm::WasmCodePosition position = wasm::kNoCodePosition); | 135 wasm::WasmCodePosition position = wasm::kNoCodePosition); |
139 unsigned InputCount(Node* node); | 136 unsigned InputCount(Node* node); |
140 bool IsPhiWithMerge(Node* phi, Node* merge); | 137 bool IsPhiWithMerge(Node* phi, Node* merge); |
141 void AppendToMerge(Node* merge, Node* from); | 138 void AppendToMerge(Node* merge, Node* from); |
142 void AppendToPhi(Node* phi, Node* from); | 139 void AppendToPhi(Node* phi, Node* from); |
143 | 140 |
144 //----------------------------------------------------------------------- | 141 //----------------------------------------------------------------------- |
(...skipping 14 matching lines...) Expand all Loading... |
159 Node* CallIndirect(uint32_t index, Node** args, | 156 Node* CallIndirect(uint32_t index, Node** args, |
160 wasm::WasmCodePosition position); | 157 wasm::WasmCodePosition position); |
161 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig); | 158 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig); |
162 void BuildWasmToJSWrapper(Handle<JSFunction> function, | 159 void BuildWasmToJSWrapper(Handle<JSFunction> function, |
163 wasm::FunctionSig* sig); | 160 wasm::FunctionSig* sig); |
164 | 161 |
165 Node* ToJS(Node* node, Node* context, wasm::LocalType type); | 162 Node* ToJS(Node* node, Node* context, wasm::LocalType type); |
166 Node* FromJS(Node* node, Node* context, wasm::LocalType type); | 163 Node* FromJS(Node* node, Node* context, wasm::LocalType type); |
167 Node* Invert(Node* node); | 164 Node* Invert(Node* node); |
168 Node* FunctionTable(uint32_t index); | 165 Node* FunctionTable(uint32_t index); |
169 Node* ChangeToRuntimeCall(Node* node, Runtime::FunctionId function_id, | |
170 Signature<Conversion>* signature); | |
171 | 166 |
172 //----------------------------------------------------------------------- | 167 //----------------------------------------------------------------------- |
173 // Operations that concern the linear memory. | 168 // Operations that concern the linear memory. |
174 //----------------------------------------------------------------------- | 169 //----------------------------------------------------------------------- |
175 Node* MemSize(uint32_t offset); | 170 Node* MemSize(uint32_t offset); |
176 Node* GetGlobal(uint32_t index); | 171 Node* GetGlobal(uint32_t index); |
177 Node* SetGlobal(uint32_t index, Node* val); | 172 Node* SetGlobal(uint32_t index, Node* val); |
178 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index, | 173 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index, |
179 uint32_t offset, uint32_t alignment, | 174 uint32_t offset, uint32_t alignment, |
180 wasm::WasmCodePosition position); | 175 wasm::WasmCodePosition position); |
(...skipping 13 matching lines...) Expand all Loading... |
194 void set_effect_ptr(Node** effect) { this->effect_ = effect; } | 189 void set_effect_ptr(Node** effect) { this->effect_ = effect; } |
195 | 190 |
196 wasm::FunctionSig* GetFunctionSignature() { return function_signature_; } | 191 wasm::FunctionSig* GetFunctionSignature() { return function_signature_; } |
197 | 192 |
198 void Int64LoweringForTesting(); | 193 void Int64LoweringForTesting(); |
199 | 194 |
200 void SetSourcePosition(Node* node, wasm::WasmCodePosition position); | 195 void SetSourcePosition(Node* node, wasm::WasmCodePosition position); |
201 | 196 |
202 Node* SimdOp(wasm::WasmOpcode opcode, const NodeVector& inputs); | 197 Node* SimdOp(wasm::WasmOpcode opcode, const NodeVector& inputs); |
203 | 198 |
204 bool has_simd_ops() { return has_simd_ops_; } | |
205 | |
206 private: | 199 private: |
207 static const int kDefaultBufferSize = 16; | 200 static const int kDefaultBufferSize = 16; |
208 friend class WasmTrapHelper; | 201 friend class WasmTrapHelper; |
209 | 202 |
210 Zone* zone_; | 203 Zone* zone_; |
211 JSGraph* jsgraph_; | 204 JSGraph* jsgraph_; |
212 wasm::ModuleEnv* module_; | 205 wasm::ModuleEnv* module_; |
213 Node* mem_buffer_; | 206 Node* mem_buffer_; |
214 Node* mem_size_; | 207 Node* mem_size_; |
215 NodeVector function_tables_; | 208 NodeVector function_tables_; |
216 Node** control_; | 209 Node** control_; |
217 Node** effect_; | 210 Node** effect_; |
218 Node** cur_buffer_; | 211 Node** cur_buffer_; |
219 size_t cur_bufsize_; | 212 size_t cur_bufsize_; |
220 Node* def_buffer_[kDefaultBufferSize]; | 213 Node* def_buffer_[kDefaultBufferSize]; |
221 | 214 |
222 WasmTrapHelper* trap_; | 215 WasmTrapHelper* trap_; |
223 wasm::FunctionSig* function_signature_; | 216 wasm::FunctionSig* function_signature_; |
224 SetOncePointer<const Operator> allocate_heap_number_operator_; | 217 SetOncePointer<const Operator> allocate_heap_number_operator_; |
225 | 218 |
226 compiler::SourcePositionTable* source_position_table_ = nullptr; | 219 compiler::SourcePositionTable* source_position_table_ = nullptr; |
227 bool has_simd_ops_ = false; | |
228 | 220 |
229 // Internal helper methods. | 221 // Internal helper methods. |
230 JSGraph* jsgraph() { return jsgraph_; } | 222 JSGraph* jsgraph() { return jsgraph_; } |
231 Graph* graph(); | 223 Graph* graph(); |
232 | 224 |
233 Node* String(const char* string); | 225 Node* String(const char* string); |
234 Node* MemBuffer(uint32_t offset); | 226 Node* MemBuffer(uint32_t offset); |
235 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset, | 227 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset, |
236 wasm::WasmCodePosition position); | 228 wasm::WasmCodePosition position); |
237 | 229 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 Node* BuildI64RemS(Node* left, Node* right, wasm::WasmCodePosition position); | 297 Node* BuildI64RemS(Node* left, Node* right, wasm::WasmCodePosition position); |
306 Node* BuildI64DivU(Node* left, Node* right, wasm::WasmCodePosition position); | 298 Node* BuildI64DivU(Node* left, Node* right, wasm::WasmCodePosition position); |
307 Node* BuildI64RemU(Node* left, Node* right, wasm::WasmCodePosition position); | 299 Node* BuildI64RemU(Node* left, Node* right, wasm::WasmCodePosition position); |
308 Node* BuildDiv64Call(Node* left, Node* right, ExternalReference ref, | 300 Node* BuildDiv64Call(Node* left, Node* right, ExternalReference ref, |
309 MachineType result_type, int trap_zero, | 301 MachineType result_type, int trap_zero, |
310 wasm::WasmCodePosition position); | 302 wasm::WasmCodePosition position); |
311 | 303 |
312 Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, | 304 Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, |
313 Node* control); | 305 Node* control); |
314 Node* BuildChangeInt32ToTagged(Node* value); | 306 Node* BuildChangeInt32ToTagged(Node* value); |
315 Node* BuildChangeTaggedToInt32(Node* value); | |
316 Node* BuildChangeFloat64ToTagged(Node* value); | 307 Node* BuildChangeFloat64ToTagged(Node* value); |
317 Node* BuildChangeTaggedToFloat64(Node* value); | 308 Node* BuildChangeTaggedToFloat64(Node* value); |
318 | 309 |
319 Node* BuildChangeInt32ToSmi(Node* value); | 310 Node* BuildChangeInt32ToSmi(Node* value); |
320 Node* BuildChangeSmiToInt32(Node* value); | 311 Node* BuildChangeSmiToInt32(Node* value); |
321 Node* BuildChangeUint32ToSmi(Node* value); | 312 Node* BuildChangeUint32ToSmi(Node* value); |
322 Node* BuildChangeSmiToFloat64(Node* value); | 313 Node* BuildChangeSmiToFloat64(Node* value); |
323 Node* BuildTestNotSmi(Node* value); | 314 Node* BuildTestNotSmi(Node* value); |
324 Node* BuildSmiShiftBitsConstant(); | 315 Node* BuildSmiShiftBitsConstant(); |
325 | 316 |
(...skipping 12 matching lines...) Expand all Loading... |
338 Node* BuildI32AsmjsDivU(Node* left, Node* right); | 329 Node* BuildI32AsmjsDivU(Node* left, Node* right); |
339 Node* BuildI32AsmjsRemU(Node* left, Node* right); | 330 Node* BuildI32AsmjsRemU(Node* left, Node* right); |
340 Node* BuildAsmjsLoadMem(MachineType type, Node* index); | 331 Node* BuildAsmjsLoadMem(MachineType type, Node* index); |
341 Node* BuildAsmjsStoreMem(MachineType type, Node* index, Node* val); | 332 Node* BuildAsmjsStoreMem(MachineType type, Node* index, Node* val); |
342 | 333 |
343 Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { | 334 Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { |
344 Node** buf = Buffer(new_count); | 335 Node** buf = Buffer(new_count); |
345 if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); | 336 if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); |
346 return buf; | 337 return buf; |
347 } | 338 } |
348 | |
349 // Simd helper functions | |
350 MachineOperatorBuilder* simd(); | |
351 }; | 339 }; |
352 } // namespace compiler | 340 } // namespace compiler |
353 } // namespace internal | 341 } // namespace internal |
354 } // namespace v8 | 342 } // namespace v8 |
355 | 343 |
356 #endif // V8_COMPILER_WASM_COMPILER_H_ | 344 #endif // V8_COMPILER_WASM_COMPILER_H_ |
OLD | NEW |