| 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/wasm/wasm-opcodes.h" | 10 #include "src/wasm/wasm-opcodes.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 Node* Terminate(Node* effect, Node* control); | 92 Node* Terminate(Node* effect, Node* control); |
| 93 Node* Merge(unsigned count, Node** controls); | 93 Node* Merge(unsigned count, Node** controls); |
| 94 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control); | 94 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control); |
| 95 Node* EffectPhi(unsigned count, Node** effects, Node* control); | 95 Node* EffectPhi(unsigned count, Node** effects, Node* control); |
| 96 Node* NumberConstant(int32_t value); | 96 Node* NumberConstant(int32_t value); |
| 97 Node* Int32Constant(int32_t value); | 97 Node* Int32Constant(int32_t value); |
| 98 Node* Int64Constant(int64_t value); | 98 Node* Int64Constant(int64_t value); |
| 99 Node* Float32Constant(float value); | 99 Node* Float32Constant(float value); |
| 100 Node* Float64Constant(double value); | 100 Node* Float64Constant(double value); |
| 101 Node* Constant(Handle<Object> value); | 101 Node* Constant(Handle<Object> value); |
| 102 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right); | 102 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
| 103 Node* Unop(wasm::WasmOpcode opcode, Node* input); | 103 wasm::WasmCodePosition position = wasm::kNoCodePosition); |
| 104 Node* Unop(wasm::WasmOpcode opcode, Node* input, |
| 105 wasm::WasmCodePosition position = wasm::kNoCodePosition); |
| 104 unsigned InputCount(Node* node); | 106 unsigned InputCount(Node* node); |
| 105 bool IsPhiWithMerge(Node* phi, Node* merge); | 107 bool IsPhiWithMerge(Node* phi, Node* merge); |
| 106 void AppendToMerge(Node* merge, Node* from); | 108 void AppendToMerge(Node* merge, Node* from); |
| 107 void AppendToPhi(Node* merge, Node* phi, Node* from); | 109 void AppendToPhi(Node* phi, Node* from); |
| 108 | 110 |
| 109 //----------------------------------------------------------------------- | 111 //----------------------------------------------------------------------- |
| 110 // Operations that read and/or write {control} and {effect}. | 112 // Operations that read and/or write {control} and {effect}. |
| 111 //----------------------------------------------------------------------- | 113 //----------------------------------------------------------------------- |
| 112 Node* Branch(Node* cond, Node** true_node, Node** false_node); | 114 Node* Branch(Node* cond, Node** true_node, Node** false_node); |
| 113 Node* Switch(unsigned count, Node* key); | 115 Node* Switch(unsigned count, Node* key); |
| 114 Node* IfValue(int32_t value, Node* sw); | 116 Node* IfValue(int32_t value, Node* sw); |
| 115 Node* IfDefault(Node* sw); | 117 Node* IfDefault(Node* sw); |
| 116 Node* Return(unsigned count, Node** vals); | 118 Node* Return(unsigned count, Node** vals); |
| 117 Node* ReturnVoid(); | 119 Node* ReturnVoid(); |
| 118 Node* Unreachable(); | 120 Node* Unreachable(wasm::WasmCodePosition position); |
| 119 | 121 |
| 120 Node* CallDirect(uint32_t index, Node** args); | 122 Node* CallDirect(uint32_t index, Node** args, |
| 121 Node* CallImport(uint32_t index, Node** args); | 123 wasm::WasmCodePosition position); |
| 122 Node* CallIndirect(uint32_t index, Node** args); | 124 Node* CallImport(uint32_t index, Node** args, |
| 125 wasm::WasmCodePosition position); |
| 126 Node* CallIndirect(uint32_t index, Node** args, |
| 127 wasm::WasmCodePosition position); |
| 123 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig); | 128 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig); |
| 124 void BuildWasmToJSWrapper(Handle<JSFunction> function, | 129 void BuildWasmToJSWrapper(Handle<JSFunction> function, |
| 125 wasm::FunctionSig* sig); | 130 wasm::FunctionSig* sig); |
| 126 | 131 |
| 127 Node* ToJS(Node* node, Node* context, wasm::LocalType type); | 132 Node* ToJS(Node* node, Node* context, wasm::LocalType type); |
| 128 Node* FromJS(Node* node, Node* context, wasm::LocalType type); | 133 Node* FromJS(Node* node, Node* context, wasm::LocalType type); |
| 129 Node* Invert(Node* node); | 134 Node* Invert(Node* node); |
| 130 Node* FunctionTable(); | 135 Node* FunctionTable(); |
| 131 | 136 |
| 132 //----------------------------------------------------------------------- | 137 //----------------------------------------------------------------------- |
| 133 // Operations that concern the linear memory. | 138 // Operations that concern the linear memory. |
| 134 //----------------------------------------------------------------------- | 139 //----------------------------------------------------------------------- |
| 135 Node* MemSize(uint32_t offset); | 140 Node* MemSize(uint32_t offset); |
| 136 Node* LoadGlobal(uint32_t index); | 141 Node* LoadGlobal(uint32_t index); |
| 137 Node* StoreGlobal(uint32_t index, Node* val); | 142 Node* StoreGlobal(uint32_t index, Node* val); |
| 138 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index, | 143 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index, |
| 139 uint32_t offset); | 144 uint32_t offset, wasm::WasmCodePosition position); |
| 140 Node* StoreMem(MachineType type, Node* index, uint32_t offset, Node* val); | 145 Node* StoreMem(MachineType type, Node* index, uint32_t offset, Node* val, |
| 146 wasm::WasmCodePosition position); |
| 141 | 147 |
| 142 static void PrintDebugName(Node* node); | 148 static void PrintDebugName(Node* node); |
| 143 | 149 |
| 144 Node* Control() { return *control_; } | 150 Node* Control() { return *control_; } |
| 145 Node* Effect() { return *effect_; } | 151 Node* Effect() { return *effect_; } |
| 146 | 152 |
| 147 void set_module(wasm::ModuleEnv* module) { this->module_ = module; } | 153 void set_module(wasm::ModuleEnv* module) { this->module_ = module; } |
| 148 | 154 |
| 149 void set_control_ptr(Node** control) { this->control_ = control; } | 155 void set_control_ptr(Node** control) { this->control_ = control; } |
| 150 | 156 |
| 151 void set_effect_ptr(Node** effect) { this->effect_ = effect; } | 157 void set_effect_ptr(Node** effect) { this->effect_ = effect; } |
| 152 | 158 |
| 153 wasm::FunctionSig* GetFunctionSignature() { return function_signature_; } | 159 wasm::FunctionSig* GetFunctionSignature() { return function_signature_; } |
| 154 | 160 |
| 155 void Int64LoweringForTesting(); | 161 void Int64LoweringForTesting(); |
| 156 | 162 |
| 157 void SetSourcePosition(Node* node, int position); | 163 void SetSourcePosition(Node* node, wasm::WasmCodePosition position); |
| 158 | 164 |
| 159 private: | 165 private: |
| 160 static const int kDefaultBufferSize = 16; | 166 static const int kDefaultBufferSize = 16; |
| 161 friend class WasmTrapHelper; | 167 friend class WasmTrapHelper; |
| 162 | 168 |
| 163 Zone* zone_; | 169 Zone* zone_; |
| 164 JSGraph* jsgraph_; | 170 JSGraph* jsgraph_; |
| 165 wasm::ModuleEnv* module_; | 171 wasm::ModuleEnv* module_; |
| 166 Node* mem_buffer_; | 172 Node* mem_buffer_; |
| 167 Node* mem_size_; | 173 Node* mem_size_; |
| 168 Node* function_table_; | 174 Node* function_table_; |
| 169 Node** control_; | 175 Node** control_; |
| 170 Node** effect_; | 176 Node** effect_; |
| 171 Node** cur_buffer_; | 177 Node** cur_buffer_; |
| 172 size_t cur_bufsize_; | 178 size_t cur_bufsize_; |
| 173 Node* def_buffer_[kDefaultBufferSize]; | 179 Node* def_buffer_[kDefaultBufferSize]; |
| 174 | 180 |
| 175 WasmTrapHelper* trap_; | 181 WasmTrapHelper* trap_; |
| 176 wasm::FunctionSig* function_signature_; | 182 wasm::FunctionSig* function_signature_; |
| 177 SetOncePointer<const Operator> allocate_heap_number_operator_; | 183 SetOncePointer<const Operator> allocate_heap_number_operator_; |
| 178 | 184 |
| 179 compiler::SourcePositionTable* source_position_table_ = nullptr; | 185 compiler::SourcePositionTable* source_position_table_ = nullptr; |
| 180 | 186 |
| 181 // Internal helper methods. | 187 // Internal helper methods. |
| 182 JSGraph* jsgraph() { return jsgraph_; } | 188 JSGraph* jsgraph() { return jsgraph_; } |
| 183 Graph* graph(); | 189 Graph* graph(); |
| 184 | 190 |
| 185 Node* String(const char* string); | 191 Node* String(const char* string); |
| 186 Node* MemBuffer(uint32_t offset); | 192 Node* MemBuffer(uint32_t offset); |
| 187 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset); | 193 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset, |
| 194 wasm::WasmCodePosition position); |
| 188 | 195 |
| 189 Node* MaskShiftCount32(Node* node); | 196 Node* MaskShiftCount32(Node* node); |
| 190 Node* MaskShiftCount64(Node* node); | 197 Node* MaskShiftCount64(Node* node); |
| 191 | 198 |
| 192 Node* BuildCCall(MachineSignature* sig, Node** args); | 199 Node* BuildCCall(MachineSignature* sig, Node** args); |
| 193 Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args); | 200 Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args, |
| 201 wasm::WasmCodePosition position); |
| 194 | 202 |
| 195 Node* BuildF32Neg(Node* input); | 203 Node* BuildF32Neg(Node* input); |
| 196 Node* BuildF64Neg(Node* input); | 204 Node* BuildF64Neg(Node* input); |
| 197 Node* BuildF32CopySign(Node* left, Node* right); | 205 Node* BuildF32CopySign(Node* left, Node* right); |
| 198 Node* BuildF64CopySign(Node* left, Node* right); | 206 Node* BuildF64CopySign(Node* left, Node* right); |
| 199 Node* BuildF32Min(Node* left, Node* right); | 207 Node* BuildF32Min(Node* left, Node* right); |
| 200 Node* BuildF32Max(Node* left, Node* right); | 208 Node* BuildF32Max(Node* left, Node* right); |
| 201 Node* BuildF64Min(Node* left, Node* right); | 209 Node* BuildF64Min(Node* left, Node* right); |
| 202 Node* BuildF64Max(Node* left, Node* right); | 210 Node* BuildF64Max(Node* left, Node* right); |
| 203 Node* BuildI32SConvertF32(Node* input); | 211 Node* BuildI32SConvertF32(Node* input, wasm::WasmCodePosition position); |
| 204 Node* BuildI32SConvertF64(Node* input); | 212 Node* BuildI32SConvertF64(Node* input, wasm::WasmCodePosition position); |
| 205 Node* BuildI32UConvertF32(Node* input); | 213 Node* BuildI32UConvertF32(Node* input, wasm::WasmCodePosition position); |
| 206 Node* BuildI32UConvertF64(Node* input); | 214 Node* BuildI32UConvertF64(Node* input, wasm::WasmCodePosition position); |
| 207 Node* BuildI32Ctz(Node* input); | 215 Node* BuildI32Ctz(Node* input); |
| 208 Node* BuildI32Popcnt(Node* input); | 216 Node* BuildI32Popcnt(Node* input); |
| 209 Node* BuildI64Ctz(Node* input); | 217 Node* BuildI64Ctz(Node* input); |
| 210 Node* BuildI64Popcnt(Node* input); | 218 Node* BuildI64Popcnt(Node* input); |
| 211 Node* BuildBitCountingCall(Node* input, ExternalReference ref, | 219 Node* BuildBitCountingCall(Node* input, ExternalReference ref, |
| 212 MachineRepresentation input_type); | 220 MachineRepresentation input_type); |
| 213 | 221 |
| 214 Node* BuildCFuncInstruction(ExternalReference ref, MachineType type, | 222 Node* BuildCFuncInstruction(ExternalReference ref, MachineType type, |
| 215 Node* input0, Node* input1 = nullptr); | 223 Node* input0, Node* input1 = nullptr); |
| 216 Node* BuildF32Trunc(Node* input); | 224 Node* BuildF32Trunc(Node* input); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 241 MachineRepresentation parameter_representation, | 249 MachineRepresentation parameter_representation, |
| 242 const MachineType result_type); | 250 const MachineType result_type); |
| 243 Node* BuildF32SConvertI64(Node* input); | 251 Node* BuildF32SConvertI64(Node* input); |
| 244 Node* BuildF32UConvertI64(Node* input); | 252 Node* BuildF32UConvertI64(Node* input); |
| 245 Node* BuildF64SConvertI64(Node* input); | 253 Node* BuildF64SConvertI64(Node* input); |
| 246 Node* BuildF64UConvertI64(Node* input); | 254 Node* BuildF64UConvertI64(Node* input); |
| 247 | 255 |
| 248 Node* BuildFloatToIntConversionInstruction( | 256 Node* BuildFloatToIntConversionInstruction( |
| 249 Node* input, ExternalReference ref, | 257 Node* input, ExternalReference ref, |
| 250 MachineRepresentation parameter_representation, | 258 MachineRepresentation parameter_representation, |
| 251 const MachineType result_type); | 259 const MachineType result_type, wasm::WasmCodePosition position); |
| 252 Node* BuildI64SConvertF32(Node* input); | 260 Node* BuildI64SConvertF32(Node* input, wasm::WasmCodePosition position); |
| 253 Node* BuildI64UConvertF32(Node* input); | 261 Node* BuildI64UConvertF32(Node* input, wasm::WasmCodePosition position); |
| 254 Node* BuildI64SConvertF64(Node* input); | 262 Node* BuildI64SConvertF64(Node* input, wasm::WasmCodePosition position); |
| 255 Node* BuildI64UConvertF64(Node* input); | 263 Node* BuildI64UConvertF64(Node* input, wasm::WasmCodePosition position); |
| 256 | 264 |
| 257 Node* BuildI32DivS(Node* left, Node* right); | 265 Node* BuildI32DivS(Node* left, Node* right, wasm::WasmCodePosition position); |
| 258 Node* BuildI32RemS(Node* left, Node* right); | 266 Node* BuildI32RemS(Node* left, Node* right, wasm::WasmCodePosition position); |
| 259 Node* BuildI32DivU(Node* left, Node* right); | 267 Node* BuildI32DivU(Node* left, Node* right, wasm::WasmCodePosition position); |
| 260 Node* BuildI32RemU(Node* left, Node* right); | 268 Node* BuildI32RemU(Node* left, Node* right, wasm::WasmCodePosition position); |
| 261 | 269 |
| 262 Node* BuildI64DivS(Node* left, Node* right); | 270 Node* BuildI64DivS(Node* left, Node* right, wasm::WasmCodePosition position); |
| 263 Node* BuildI64RemS(Node* left, Node* right); | 271 Node* BuildI64RemS(Node* left, Node* right, wasm::WasmCodePosition position); |
| 264 Node* BuildI64DivU(Node* left, Node* right); | 272 Node* BuildI64DivU(Node* left, Node* right, wasm::WasmCodePosition position); |
| 265 Node* BuildI64RemU(Node* left, Node* right); | 273 Node* BuildI64RemU(Node* left, Node* right, wasm::WasmCodePosition position); |
| 266 Node* BuildDiv64Call(Node* left, Node* right, ExternalReference ref, | 274 Node* BuildDiv64Call(Node* left, Node* right, ExternalReference ref, |
| 267 MachineType result_type, int trap_zero); | 275 MachineType result_type, int trap_zero, |
| 276 wasm::WasmCodePosition position); |
| 268 | 277 |
| 269 Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, | 278 Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, |
| 270 Node* control); | 279 Node* control); |
| 271 Node* BuildChangeInt32ToTagged(Node* value); | 280 Node* BuildChangeInt32ToTagged(Node* value); |
| 272 Node* BuildChangeFloat64ToTagged(Node* value); | 281 Node* BuildChangeFloat64ToTagged(Node* value); |
| 273 Node* BuildChangeTaggedToFloat64(Node* value); | 282 Node* BuildChangeTaggedToFloat64(Node* value); |
| 274 | 283 |
| 275 Node* BuildChangeInt32ToSmi(Node* value); | 284 Node* BuildChangeInt32ToSmi(Node* value); |
| 276 Node* BuildChangeSmiToInt32(Node* value); | 285 Node* BuildChangeSmiToInt32(Node* value); |
| 277 Node* BuildChangeSmiToFloat64(Node* value); | 286 Node* BuildChangeSmiToFloat64(Node* value); |
| 278 Node* BuildTestNotSmi(Node* value); | 287 Node* BuildTestNotSmi(Node* value); |
| 279 Node* BuildSmiShiftBitsConstant(); | 288 Node* BuildSmiShiftBitsConstant(); |
| 280 | 289 |
| 281 Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control); | 290 Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control); |
| 282 Node* BuildLoadHeapNumberValue(Node* value, Node* control); | 291 Node* BuildLoadHeapNumberValue(Node* value, Node* control); |
| 283 Node* BuildHeapNumberValueIndexConstant(); | 292 Node* BuildHeapNumberValueIndexConstant(); |
| 284 | 293 |
| 285 Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { | 294 Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { |
| 286 Node** buf = Buffer(new_count); | 295 Node** buf = Buffer(new_count); |
| 287 if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); | 296 if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); |
| 288 return buf; | 297 return buf; |
| 289 } | 298 } |
| 290 }; | 299 }; |
| 291 } // namespace compiler | 300 } // namespace compiler |
| 292 } // namespace internal | 301 } // namespace internal |
| 293 } // namespace v8 | 302 } // namespace v8 |
| 294 | 303 |
| 295 #endif // V8_COMPILER_WASM_COMPILER_H_ | 304 #endif // V8_COMPILER_WASM_COMPILER_H_ |
| OLD | NEW |