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