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 #include "src/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 namespace internal { | 47 namespace internal { |
48 namespace compiler { | 48 namespace compiler { |
49 | 49 |
50 namespace { | 50 namespace { |
51 const Operator* UnsupportedOpcode(wasm::WasmOpcode opcode) { | 51 const Operator* UnsupportedOpcode(wasm::WasmOpcode opcode) { |
52 V8_Fatal(__FILE__, __LINE__, "Unsupported opcode #%d:%s", opcode, | 52 V8_Fatal(__FILE__, __LINE__, "Unsupported opcode #%d:%s", opcode, |
53 wasm::WasmOpcodes::OpcodeName(opcode)); | 53 wasm::WasmOpcodes::OpcodeName(opcode)); |
54 return nullptr; | 54 return nullptr; |
55 } | 55 } |
56 | 56 |
57 | |
58 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { | 57 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { |
59 Graph* g = jsgraph->graph(); | 58 Graph* g = jsgraph->graph(); |
60 if (g->end()) { | 59 if (g->end()) { |
61 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); | 60 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); |
62 } else { | 61 } else { |
63 g->SetEnd(g->NewNode(jsgraph->common()->End(1), node)); | 62 g->SetEnd(g->NewNode(jsgraph->common()->End(1), node)); |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 } // namespace | 66 } // namespace |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 control_(nullptr), | 277 control_(nullptr), |
279 effect_(nullptr), | 278 effect_(nullptr), |
280 cur_buffer_(def_buffer_), | 279 cur_buffer_(def_buffer_), |
281 cur_bufsize_(kDefaultBufferSize), | 280 cur_bufsize_(kDefaultBufferSize), |
282 trap_(new (zone) WasmTrapHelper(this)), | 281 trap_(new (zone) WasmTrapHelper(this)), |
283 function_signature_(function_signature), | 282 function_signature_(function_signature), |
284 source_position_table_(source_position_table) { | 283 source_position_table_(source_position_table) { |
285 DCHECK_NOT_NULL(jsgraph_); | 284 DCHECK_NOT_NULL(jsgraph_); |
286 } | 285 } |
287 | 286 |
288 | |
289 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } | 287 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } |
290 | 288 |
291 | |
292 Node* WasmGraphBuilder::Start(unsigned params) { | 289 Node* WasmGraphBuilder::Start(unsigned params) { |
293 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); | 290 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); |
294 graph()->SetStart(start); | 291 graph()->SetStart(start); |
295 return start; | 292 return start; |
296 } | 293 } |
297 | 294 |
298 | |
299 Node* WasmGraphBuilder::Param(unsigned index, wasm::LocalType type) { | 295 Node* WasmGraphBuilder::Param(unsigned index, wasm::LocalType type) { |
300 return graph()->NewNode(jsgraph()->common()->Parameter(index), | 296 return graph()->NewNode(jsgraph()->common()->Parameter(index), |
301 graph()->start()); | 297 graph()->start()); |
302 } | 298 } |
303 | 299 |
304 | |
305 Node* WasmGraphBuilder::Loop(Node* entry) { | 300 Node* WasmGraphBuilder::Loop(Node* entry) { |
306 return graph()->NewNode(jsgraph()->common()->Loop(1), entry); | 301 return graph()->NewNode(jsgraph()->common()->Loop(1), entry); |
307 } | 302 } |
308 | 303 |
309 | |
310 Node* WasmGraphBuilder::Terminate(Node* effect, Node* control) { | 304 Node* WasmGraphBuilder::Terminate(Node* effect, Node* control) { |
311 Node* terminate = | 305 Node* terminate = |
312 graph()->NewNode(jsgraph()->common()->Terminate(), effect, control); | 306 graph()->NewNode(jsgraph()->common()->Terminate(), effect, control); |
313 MergeControlToEnd(jsgraph(), terminate); | 307 MergeControlToEnd(jsgraph(), terminate); |
314 return terminate; | 308 return terminate; |
315 } | 309 } |
316 | 310 |
317 | |
318 unsigned WasmGraphBuilder::InputCount(Node* node) { | 311 unsigned WasmGraphBuilder::InputCount(Node* node) { |
319 return static_cast<unsigned>(node->InputCount()); | 312 return static_cast<unsigned>(node->InputCount()); |
320 } | 313 } |
321 | 314 |
322 | |
323 bool WasmGraphBuilder::IsPhiWithMerge(Node* phi, Node* merge) { | 315 bool WasmGraphBuilder::IsPhiWithMerge(Node* phi, Node* merge) { |
324 return phi && IrOpcode::IsPhiOpcode(phi->opcode()) && | 316 return phi && IrOpcode::IsPhiOpcode(phi->opcode()) && |
325 NodeProperties::GetControlInput(phi) == merge; | 317 NodeProperties::GetControlInput(phi) == merge; |
326 } | 318 } |
327 | 319 |
328 | |
329 void WasmGraphBuilder::AppendToMerge(Node* merge, Node* from) { | 320 void WasmGraphBuilder::AppendToMerge(Node* merge, Node* from) { |
330 DCHECK(IrOpcode::IsMergeOpcode(merge->opcode())); | 321 DCHECK(IrOpcode::IsMergeOpcode(merge->opcode())); |
331 merge->AppendInput(jsgraph()->zone(), from); | 322 merge->AppendInput(jsgraph()->zone(), from); |
332 int new_size = merge->InputCount(); | 323 int new_size = merge->InputCount(); |
333 NodeProperties::ChangeOp( | 324 NodeProperties::ChangeOp( |
334 merge, jsgraph()->common()->ResizeMergeOrPhi(merge->op(), new_size)); | 325 merge, jsgraph()->common()->ResizeMergeOrPhi(merge->op(), new_size)); |
335 } | 326 } |
336 | 327 |
337 void WasmGraphBuilder::AppendToPhi(Node* phi, Node* from) { | 328 void WasmGraphBuilder::AppendToPhi(Node* phi, Node* from) { |
338 DCHECK(IrOpcode::IsPhiOpcode(phi->opcode())); | 329 DCHECK(IrOpcode::IsPhiOpcode(phi->opcode())); |
339 int new_size = phi->InputCount(); | 330 int new_size = phi->InputCount(); |
340 phi->InsertInput(jsgraph()->zone(), phi->InputCount() - 1, from); | 331 phi->InsertInput(jsgraph()->zone(), phi->InputCount() - 1, from); |
341 NodeProperties::ChangeOp( | 332 NodeProperties::ChangeOp( |
342 phi, jsgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size)); | 333 phi, jsgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size)); |
343 } | 334 } |
344 | 335 |
345 | |
346 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { | 336 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { |
347 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); | 337 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); |
348 } | 338 } |
349 | 339 |
350 | |
351 Node* WasmGraphBuilder::Phi(wasm::LocalType type, unsigned count, Node** vals, | 340 Node* WasmGraphBuilder::Phi(wasm::LocalType type, unsigned count, Node** vals, |
352 Node* control) { | 341 Node* control) { |
353 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 342 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
354 Node** buf = Realloc(vals, count, count + 1); | 343 Node** buf = Realloc(vals, count, count + 1); |
355 buf[count] = control; | 344 buf[count] = control; |
356 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, | 345 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, |
357 buf); | 346 buf); |
358 } | 347 } |
359 | 348 |
360 | |
361 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, | 349 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, |
362 Node* control) { | 350 Node* control) { |
363 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 351 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
364 Node** buf = Realloc(effects, count, count + 1); | 352 Node** buf = Realloc(effects, count, count + 1); |
365 buf[count] = control; | 353 buf[count] = control; |
366 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, | 354 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, |
367 buf); | 355 buf); |
368 } | 356 } |
369 | 357 |
370 Node* WasmGraphBuilder::NumberConstant(int32_t value) { | 358 Node* WasmGraphBuilder::NumberConstant(int32_t value) { |
371 return jsgraph()->Constant(value); | 359 return jsgraph()->Constant(value); |
372 } | 360 } |
373 | 361 |
374 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 362 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
375 return jsgraph()->Int32Constant(value); | 363 return jsgraph()->Int32Constant(value); |
376 } | 364 } |
377 | 365 |
378 | |
379 Node* WasmGraphBuilder::Int64Constant(int64_t value) { | 366 Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
380 return jsgraph()->Int64Constant(value); | 367 return jsgraph()->Int64Constant(value); |
381 } | 368 } |
382 | 369 |
383 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, | 370 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
384 wasm::WasmCodePosition position) { | 371 wasm::WasmCodePosition position) { |
385 const Operator* op; | 372 const Operator* op; |
386 MachineOperatorBuilder* m = jsgraph()->machine(); | 373 MachineOperatorBuilder* m = jsgraph()->machine(); |
387 switch (opcode) { | 374 switch (opcode) { |
388 case wasm::kExprI32Add: | 375 case wasm::kExprI32Add: |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 case wasm::kExprF32AsmjsLoadMem: | 875 case wasm::kExprF32AsmjsLoadMem: |
889 return BuildAsmjsLoadMem(MachineType::Float32(), input); | 876 return BuildAsmjsLoadMem(MachineType::Float32(), input); |
890 case wasm::kExprF64AsmjsLoadMem: | 877 case wasm::kExprF64AsmjsLoadMem: |
891 return BuildAsmjsLoadMem(MachineType::Float64(), input); | 878 return BuildAsmjsLoadMem(MachineType::Float64(), input); |
892 default: | 879 default: |
893 op = UnsupportedOpcode(opcode); | 880 op = UnsupportedOpcode(opcode); |
894 } | 881 } |
895 return graph()->NewNode(op, input); | 882 return graph()->NewNode(op, input); |
896 } | 883 } |
897 | 884 |
898 | |
899 Node* WasmGraphBuilder::Float32Constant(float value) { | 885 Node* WasmGraphBuilder::Float32Constant(float value) { |
900 return jsgraph()->Float32Constant(value); | 886 return jsgraph()->Float32Constant(value); |
901 } | 887 } |
902 | 888 |
903 | |
904 Node* WasmGraphBuilder::Float64Constant(double value) { | 889 Node* WasmGraphBuilder::Float64Constant(double value) { |
905 return jsgraph()->Float64Constant(value); | 890 return jsgraph()->Float64Constant(value); |
906 } | 891 } |
907 | 892 |
908 | |
909 Node* WasmGraphBuilder::Constant(Handle<Object> value) { | 893 Node* WasmGraphBuilder::Constant(Handle<Object> value) { |
910 return jsgraph()->Constant(value); | 894 return jsgraph()->Constant(value); |
911 } | 895 } |
912 | 896 |
913 | |
914 Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node, | 897 Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node, |
915 Node** false_node) { | 898 Node** false_node) { |
916 DCHECK_NOT_NULL(cond); | 899 DCHECK_NOT_NULL(cond); |
917 DCHECK_NOT_NULL(*control_); | 900 DCHECK_NOT_NULL(*control_); |
918 Node* branch = | 901 Node* branch = |
919 graph()->NewNode(jsgraph()->common()->Branch(), cond, *control_); | 902 graph()->NewNode(jsgraph()->common()->Branch(), cond, *control_); |
920 *true_node = graph()->NewNode(jsgraph()->common()->IfTrue(), branch); | 903 *true_node = graph()->NewNode(jsgraph()->common()->IfTrue(), branch); |
921 *false_node = graph()->NewNode(jsgraph()->common()->IfFalse(), branch); | 904 *false_node = graph()->NewNode(jsgraph()->common()->IfFalse(), branch); |
922 return branch; | 905 return branch; |
923 } | 906 } |
924 | 907 |
925 | |
926 Node* WasmGraphBuilder::Switch(unsigned count, Node* key) { | 908 Node* WasmGraphBuilder::Switch(unsigned count, Node* key) { |
927 return graph()->NewNode(jsgraph()->common()->Switch(count), key, *control_); | 909 return graph()->NewNode(jsgraph()->common()->Switch(count), key, *control_); |
928 } | 910 } |
929 | 911 |
930 | |
931 Node* WasmGraphBuilder::IfValue(int32_t value, Node* sw) { | 912 Node* WasmGraphBuilder::IfValue(int32_t value, Node* sw) { |
932 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); | 913 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); |
933 return graph()->NewNode(jsgraph()->common()->IfValue(value), sw); | 914 return graph()->NewNode(jsgraph()->common()->IfValue(value), sw); |
934 } | 915 } |
935 | 916 |
936 | |
937 Node* WasmGraphBuilder::IfDefault(Node* sw) { | 917 Node* WasmGraphBuilder::IfDefault(Node* sw) { |
938 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); | 918 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); |
939 return graph()->NewNode(jsgraph()->common()->IfDefault(), sw); | 919 return graph()->NewNode(jsgraph()->common()->IfDefault(), sw); |
940 } | 920 } |
941 | 921 |
942 | |
943 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { | 922 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { |
944 DCHECK_NOT_NULL(*control_); | 923 DCHECK_NOT_NULL(*control_); |
945 DCHECK_NOT_NULL(*effect_); | 924 DCHECK_NOT_NULL(*effect_); |
946 | 925 |
947 if (count == 0) { | 926 if (count == 0) { |
948 // Handle a return of void. | 927 // Handle a return of void. |
949 vals[0] = jsgraph()->Int32Constant(0); | 928 vals[0] = jsgraph()->Int32Constant(0); |
950 count = 1; | 929 count = 1; |
951 } | 930 } |
952 | 931 |
953 Node** buf = Realloc(vals, count, count + 2); | 932 Node** buf = Realloc(vals, count, count + 2); |
954 buf[count] = *effect_; | 933 buf[count] = *effect_; |
955 buf[count + 1] = *control_; | 934 buf[count + 1] = *control_; |
956 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), count + 2, vals); | 935 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), count + 2, vals); |
957 | 936 |
958 MergeControlToEnd(jsgraph(), ret); | 937 MergeControlToEnd(jsgraph(), ret); |
959 return ret; | 938 return ret; |
960 } | 939 } |
961 | 940 |
962 | |
963 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } | 941 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } |
964 | 942 |
965 Node* WasmGraphBuilder::Unreachable(wasm::WasmCodePosition position) { | 943 Node* WasmGraphBuilder::Unreachable(wasm::WasmCodePosition position) { |
966 trap_->Unreachable(position); | 944 trap_->Unreachable(position); |
967 return nullptr; | 945 return nullptr; |
968 } | 946 } |
969 | 947 |
970 Node* WasmGraphBuilder::MaskShiftCount32(Node* node) { | 948 Node* WasmGraphBuilder::MaskShiftCount32(Node* node) { |
971 static const int32_t kMask32 = 0x1f; | 949 static const int32_t kMask32 = 0x1f; |
972 if (!jsgraph()->machine()->Word32ShiftIsSafe()) { | 950 if (!jsgraph()->machine()->Word32ShiftIsSafe()) { |
(...skipping 28 matching lines...) Expand all Loading... |
1001 | 979 |
1002 Node* WasmGraphBuilder::BuildF32Neg(Node* input) { | 980 Node* WasmGraphBuilder::BuildF32Neg(Node* input) { |
1003 Node* result = | 981 Node* result = |
1004 Unop(wasm::kExprF32ReinterpretI32, | 982 Unop(wasm::kExprF32ReinterpretI32, |
1005 Binop(wasm::kExprI32Xor, Unop(wasm::kExprI32ReinterpretF32, input), | 983 Binop(wasm::kExprI32Xor, Unop(wasm::kExprI32ReinterpretF32, input), |
1006 jsgraph()->Int32Constant(0x80000000))); | 984 jsgraph()->Int32Constant(0x80000000))); |
1007 | 985 |
1008 return result; | 986 return result; |
1009 } | 987 } |
1010 | 988 |
1011 | |
1012 Node* WasmGraphBuilder::BuildF64Neg(Node* input) { | 989 Node* WasmGraphBuilder::BuildF64Neg(Node* input) { |
1013 #if WASM_64 | 990 #if WASM_64 |
1014 Node* result = | 991 Node* result = |
1015 Unop(wasm::kExprF64ReinterpretI64, | 992 Unop(wasm::kExprF64ReinterpretI64, |
1016 Binop(wasm::kExprI64Xor, Unop(wasm::kExprI64ReinterpretF64, input), | 993 Binop(wasm::kExprI64Xor, Unop(wasm::kExprI64ReinterpretF64, input), |
1017 jsgraph()->Int64Constant(0x8000000000000000))); | 994 jsgraph()->Int64Constant(0x8000000000000000))); |
1018 | 995 |
1019 return result; | 996 return result; |
1020 #else | 997 #else |
1021 MachineOperatorBuilder* m = jsgraph()->machine(); | 998 MachineOperatorBuilder* m = jsgraph()->machine(); |
1022 | 999 |
1023 Node* old_high_word = graph()->NewNode(m->Float64ExtractHighWord32(), input); | 1000 Node* old_high_word = graph()->NewNode(m->Float64ExtractHighWord32(), input); |
1024 Node* new_high_word = Binop(wasm::kExprI32Xor, old_high_word, | 1001 Node* new_high_word = Binop(wasm::kExprI32Xor, old_high_word, |
1025 jsgraph()->Int32Constant(0x80000000)); | 1002 jsgraph()->Int32Constant(0x80000000)); |
1026 | 1003 |
1027 return graph()->NewNode(m->Float64InsertHighWord32(), input, new_high_word); | 1004 return graph()->NewNode(m->Float64InsertHighWord32(), input, new_high_word); |
1028 #endif | 1005 #endif |
1029 } | 1006 } |
1030 | 1007 |
1031 | |
1032 Node* WasmGraphBuilder::BuildF32CopySign(Node* left, Node* right) { | 1008 Node* WasmGraphBuilder::BuildF32CopySign(Node* left, Node* right) { |
1033 Node* result = Unop( | 1009 Node* result = Unop( |
1034 wasm::kExprF32ReinterpretI32, | 1010 wasm::kExprF32ReinterpretI32, |
1035 Binop(wasm::kExprI32Ior, | 1011 Binop(wasm::kExprI32Ior, |
1036 Binop(wasm::kExprI32And, Unop(wasm::kExprI32ReinterpretF32, left), | 1012 Binop(wasm::kExprI32And, Unop(wasm::kExprI32ReinterpretF32, left), |
1037 jsgraph()->Int32Constant(0x7fffffff)), | 1013 jsgraph()->Int32Constant(0x7fffffff)), |
1038 Binop(wasm::kExprI32And, Unop(wasm::kExprI32ReinterpretF32, right), | 1014 Binop(wasm::kExprI32And, Unop(wasm::kExprI32ReinterpretF32, right), |
1039 jsgraph()->Int32Constant(0x80000000)))); | 1015 jsgraph()->Int32Constant(0x80000000)))); |
1040 | 1016 |
1041 return result; | 1017 return result; |
1042 } | 1018 } |
1043 | 1019 |
1044 | |
1045 Node* WasmGraphBuilder::BuildF64CopySign(Node* left, Node* right) { | 1020 Node* WasmGraphBuilder::BuildF64CopySign(Node* left, Node* right) { |
1046 #if WASM_64 | 1021 #if WASM_64 |
1047 Node* result = Unop( | 1022 Node* result = Unop( |
1048 wasm::kExprF64ReinterpretI64, | 1023 wasm::kExprF64ReinterpretI64, |
1049 Binop(wasm::kExprI64Ior, | 1024 Binop(wasm::kExprI64Ior, |
1050 Binop(wasm::kExprI64And, Unop(wasm::kExprI64ReinterpretF64, left), | 1025 Binop(wasm::kExprI64And, Unop(wasm::kExprI64ReinterpretF64, left), |
1051 jsgraph()->Int64Constant(0x7fffffffffffffff)), | 1026 jsgraph()->Int64Constant(0x7fffffffffffffff)), |
1052 Binop(wasm::kExprI64And, Unop(wasm::kExprI64ReinterpretF64, right), | 1027 Binop(wasm::kExprI64And, Unop(wasm::kExprI64ReinterpretF64, right), |
1053 jsgraph()->Int64Constant(0x8000000000000000)))); | 1028 jsgraph()->Int64Constant(0x8000000000000000)))); |
1054 | 1029 |
1055 return result; | 1030 return result; |
1056 #else | 1031 #else |
1057 MachineOperatorBuilder* m = jsgraph()->machine(); | 1032 MachineOperatorBuilder* m = jsgraph()->machine(); |
1058 | 1033 |
1059 Node* high_word_left = graph()->NewNode(m->Float64ExtractHighWord32(), left); | 1034 Node* high_word_left = graph()->NewNode(m->Float64ExtractHighWord32(), left); |
1060 Node* high_word_right = | 1035 Node* high_word_right = |
1061 graph()->NewNode(m->Float64ExtractHighWord32(), right); | 1036 graph()->NewNode(m->Float64ExtractHighWord32(), right); |
1062 | 1037 |
1063 Node* new_high_word = | 1038 Node* new_high_word = |
1064 Binop(wasm::kExprI32Ior, Binop(wasm::kExprI32And, high_word_left, | 1039 Binop(wasm::kExprI32Ior, Binop(wasm::kExprI32And, high_word_left, |
1065 jsgraph()->Int32Constant(0x7fffffff)), | 1040 jsgraph()->Int32Constant(0x7fffffff)), |
1066 Binop(wasm::kExprI32And, high_word_right, | 1041 Binop(wasm::kExprI32And, high_word_right, |
1067 jsgraph()->Int32Constant(0x80000000))); | 1042 jsgraph()->Int32Constant(0x80000000))); |
1068 | 1043 |
1069 return graph()->NewNode(m->Float64InsertHighWord32(), left, new_high_word); | 1044 return graph()->NewNode(m->Float64InsertHighWord32(), left, new_high_word); |
1070 #endif | 1045 #endif |
1071 } | 1046 } |
1072 | 1047 |
1073 | |
1074 Node* WasmGraphBuilder::BuildF32Min(Node* left, Node* right) { | 1048 Node* WasmGraphBuilder::BuildF32Min(Node* left, Node* right) { |
1075 Diamond left_le_right(graph(), jsgraph()->common(), | 1049 Diamond left_le_right(graph(), jsgraph()->common(), |
1076 Binop(wasm::kExprF32Le, left, right)); | 1050 Binop(wasm::kExprF32Le, left, right)); |
1077 | 1051 |
1078 Diamond right_lt_left(graph(), jsgraph()->common(), | 1052 Diamond right_lt_left(graph(), jsgraph()->common(), |
1079 Binop(wasm::kExprF32Lt, right, left)); | 1053 Binop(wasm::kExprF32Lt, right, left)); |
1080 | 1054 |
1081 Diamond left_is_not_nan(graph(), jsgraph()->common(), | 1055 Diamond left_is_not_nan(graph(), jsgraph()->common(), |
1082 Binop(wasm::kExprF32Eq, left, left)); | 1056 Binop(wasm::kExprF32Eq, left, left)); |
1083 | 1057 |
1084 return left_le_right.Phi( | 1058 return left_le_right.Phi( |
1085 wasm::kAstF32, left, | 1059 wasm::kAstF32, left, |
1086 right_lt_left.Phi( | 1060 right_lt_left.Phi( |
1087 wasm::kAstF32, right, | 1061 wasm::kAstF32, right, |
1088 left_is_not_nan.Phi( | 1062 left_is_not_nan.Phi( |
1089 wasm::kAstF32, | 1063 wasm::kAstF32, |
1090 Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)), | 1064 Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)), |
1091 Binop(wasm::kExprF32Mul, left, Float32Constant(1.0))))); | 1065 Binop(wasm::kExprF32Mul, left, Float32Constant(1.0))))); |
1092 } | 1066 } |
1093 | 1067 |
1094 | |
1095 Node* WasmGraphBuilder::BuildF32Max(Node* left, Node* right) { | 1068 Node* WasmGraphBuilder::BuildF32Max(Node* left, Node* right) { |
1096 Diamond left_ge_right(graph(), jsgraph()->common(), | 1069 Diamond left_ge_right(graph(), jsgraph()->common(), |
1097 Binop(wasm::kExprF32Ge, left, right)); | 1070 Binop(wasm::kExprF32Ge, left, right)); |
1098 | 1071 |
1099 Diamond right_gt_left(graph(), jsgraph()->common(), | 1072 Diamond right_gt_left(graph(), jsgraph()->common(), |
1100 Binop(wasm::kExprF32Gt, right, left)); | 1073 Binop(wasm::kExprF32Gt, right, left)); |
1101 | 1074 |
1102 Diamond left_is_not_nan(graph(), jsgraph()->common(), | 1075 Diamond left_is_not_nan(graph(), jsgraph()->common(), |
1103 Binop(wasm::kExprF32Eq, left, left)); | 1076 Binop(wasm::kExprF32Eq, left, left)); |
1104 | 1077 |
1105 return left_ge_right.Phi( | 1078 return left_ge_right.Phi( |
1106 wasm::kAstF32, left, | 1079 wasm::kAstF32, left, |
1107 right_gt_left.Phi( | 1080 right_gt_left.Phi( |
1108 wasm::kAstF32, right, | 1081 wasm::kAstF32, right, |
1109 left_is_not_nan.Phi( | 1082 left_is_not_nan.Phi( |
1110 wasm::kAstF32, | 1083 wasm::kAstF32, |
1111 Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)), | 1084 Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)), |
1112 Binop(wasm::kExprF32Mul, left, Float32Constant(1.0))))); | 1085 Binop(wasm::kExprF32Mul, left, Float32Constant(1.0))))); |
1113 } | 1086 } |
1114 | 1087 |
1115 | |
1116 Node* WasmGraphBuilder::BuildF64Min(Node* left, Node* right) { | 1088 Node* WasmGraphBuilder::BuildF64Min(Node* left, Node* right) { |
1117 Diamond left_le_right(graph(), jsgraph()->common(), | 1089 Diamond left_le_right(graph(), jsgraph()->common(), |
1118 Binop(wasm::kExprF64Le, left, right)); | 1090 Binop(wasm::kExprF64Le, left, right)); |
1119 | 1091 |
1120 Diamond right_lt_left(graph(), jsgraph()->common(), | 1092 Diamond right_lt_left(graph(), jsgraph()->common(), |
1121 Binop(wasm::kExprF64Lt, right, left)); | 1093 Binop(wasm::kExprF64Lt, right, left)); |
1122 | 1094 |
1123 Diamond left_is_not_nan(graph(), jsgraph()->common(), | 1095 Diamond left_is_not_nan(graph(), jsgraph()->common(), |
1124 Binop(wasm::kExprF64Eq, left, left)); | 1096 Binop(wasm::kExprF64Eq, left, left)); |
1125 | 1097 |
1126 return left_le_right.Phi( | 1098 return left_le_right.Phi( |
1127 wasm::kAstF64, left, | 1099 wasm::kAstF64, left, |
1128 right_lt_left.Phi( | 1100 right_lt_left.Phi( |
1129 wasm::kAstF64, right, | 1101 wasm::kAstF64, right, |
1130 left_is_not_nan.Phi( | 1102 left_is_not_nan.Phi( |
1131 wasm::kAstF64, | 1103 wasm::kAstF64, |
1132 Binop(wasm::kExprF64Mul, right, Float64Constant(1.0)), | 1104 Binop(wasm::kExprF64Mul, right, Float64Constant(1.0)), |
1133 Binop(wasm::kExprF64Mul, left, Float64Constant(1.0))))); | 1105 Binop(wasm::kExprF64Mul, left, Float64Constant(1.0))))); |
1134 } | 1106 } |
1135 | 1107 |
1136 | |
1137 Node* WasmGraphBuilder::BuildF64Max(Node* left, Node* right) { | 1108 Node* WasmGraphBuilder::BuildF64Max(Node* left, Node* right) { |
1138 Diamond left_ge_right(graph(), jsgraph()->common(), | 1109 Diamond left_ge_right(graph(), jsgraph()->common(), |
1139 Binop(wasm::kExprF64Ge, left, right)); | 1110 Binop(wasm::kExprF64Ge, left, right)); |
1140 | 1111 |
1141 Diamond right_gt_left(graph(), jsgraph()->common(), | 1112 Diamond right_gt_left(graph(), jsgraph()->common(), |
1142 Binop(wasm::kExprF64Lt, right, left)); | 1113 Binop(wasm::kExprF64Lt, right, left)); |
1143 | 1114 |
1144 Diamond left_is_not_nan(graph(), jsgraph()->common(), | 1115 Diamond left_is_not_nan(graph(), jsgraph()->common(), |
1145 Binop(wasm::kExprF64Eq, left, left)); | 1116 Binop(wasm::kExprF64Eq, left, left)); |
1146 | 1117 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 jsgraph()->isolate()), | 1248 jsgraph()->isolate()), |
1278 MachineRepresentation::kWord64)); | 1249 MachineRepresentation::kWord64)); |
1279 } | 1250 } |
1280 | 1251 |
1281 Node* WasmGraphBuilder::BuildI32Popcnt(Node* input) { | 1252 Node* WasmGraphBuilder::BuildI32Popcnt(Node* input) { |
1282 return BuildBitCountingCall( | 1253 return BuildBitCountingCall( |
1283 input, ExternalReference::wasm_word32_popcnt(jsgraph()->isolate()), | 1254 input, ExternalReference::wasm_word32_popcnt(jsgraph()->isolate()), |
1284 MachineRepresentation::kWord32); | 1255 MachineRepresentation::kWord32); |
1285 } | 1256 } |
1286 | 1257 |
1287 | |
1288 Node* WasmGraphBuilder::BuildI64Popcnt(Node* input) { | 1258 Node* WasmGraphBuilder::BuildI64Popcnt(Node* input) { |
1289 return Unop(wasm::kExprI64UConvertI32, | 1259 return Unop(wasm::kExprI64UConvertI32, |
1290 BuildBitCountingCall(input, ExternalReference::wasm_word64_popcnt( | 1260 BuildBitCountingCall(input, ExternalReference::wasm_word64_popcnt( |
1291 jsgraph()->isolate()), | 1261 jsgraph()->isolate()), |
1292 MachineRepresentation::kWord64)); | 1262 MachineRepresentation::kWord64)); |
1293 } | 1263 } |
1294 | 1264 |
1295 Node* WasmGraphBuilder::BuildF32Trunc(Node* input) { | 1265 Node* WasmGraphBuilder::BuildF32Trunc(Node* input) { |
1296 MachineType type = MachineType::Float32(); | 1266 MachineType type = MachineType::Float32(); |
1297 ExternalReference ref = | 1267 ExternalReference ref = |
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2445 } | 2415 } |
2446 Node* jsval = | 2416 Node* jsval = |
2447 ToJS(retval, context, | 2417 ToJS(retval, context, |
2448 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 2418 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); |
2449 Node* ret = | 2419 Node* ret = |
2450 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); | 2420 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); |
2451 | 2421 |
2452 MergeControlToEnd(jsgraph(), ret); | 2422 MergeControlToEnd(jsgraph(), ret); |
2453 } | 2423 } |
2454 | 2424 |
2455 | |
2456 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function, | 2425 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function, |
2457 wasm::FunctionSig* sig) { | 2426 wasm::FunctionSig* sig) { |
2458 int js_count = function->shared()->internal_formal_parameter_count(); | 2427 int js_count = function->shared()->internal_formal_parameter_count(); |
2459 int wasm_count = static_cast<int>(sig->parameter_count()); | 2428 int wasm_count = static_cast<int>(sig->parameter_count()); |
2460 int param_count; | 2429 int param_count; |
2461 if (jsgraph()->machine()->Is64()) { | 2430 if (jsgraph()->machine()->Is64()) { |
2462 param_count = wasm_count; | 2431 param_count = wasm_count; |
2463 } else { | 2432 } else { |
2464 param_count = Int64Lowering::GetParameterCountAfterLowering(sig); | 2433 param_count = Int64Lowering::GetParameterCountAfterLowering(sig); |
2465 } | 2434 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 graph()->NewNode(jsgraph()->machine()->Word32Sar(), | 2507 graph()->NewNode(jsgraph()->machine()->Word32Sar(), |
2539 val, jsgraph()->Int32Constant(31)), | 2508 val, jsgraph()->Int32Constant(31)), |
2540 call, start); | 2509 call, start); |
2541 } else { | 2510 } else { |
2542 ret = graph()->NewNode(jsgraph()->common()->Return(), val, call, start); | 2511 ret = graph()->NewNode(jsgraph()->common()->Return(), val, call, start); |
2543 } | 2512 } |
2544 | 2513 |
2545 MergeControlToEnd(jsgraph(), ret); | 2514 MergeControlToEnd(jsgraph(), ret); |
2546 } | 2515 } |
2547 | 2516 |
2548 | |
2549 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { | 2517 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { |
2550 DCHECK(module_ && module_->instance); | 2518 DCHECK(module_ && module_->instance); |
2551 if (offset == 0) { | 2519 if (offset == 0) { |
2552 if (!mem_buffer_) { | 2520 if (!mem_buffer_) { |
2553 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( | 2521 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( |
2554 reinterpret_cast<uintptr_t>(module_->instance->mem_start), | 2522 reinterpret_cast<uintptr_t>(module_->instance->mem_start), |
2555 RelocInfo::WASM_MEMORY_REFERENCE); | 2523 RelocInfo::WASM_MEMORY_REFERENCE); |
2556 } | 2524 } |
2557 return mem_buffer_; | 2525 return mem_buffer_; |
2558 } else { | 2526 } else { |
2559 return jsgraph()->RelocatableIntPtrConstant( | 2527 return jsgraph()->RelocatableIntPtrConstant( |
2560 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), | 2528 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), |
2561 RelocInfo::WASM_MEMORY_REFERENCE); | 2529 RelocInfo::WASM_MEMORY_REFERENCE); |
2562 } | 2530 } |
2563 } | 2531 } |
2564 | 2532 |
2565 | |
2566 Node* WasmGraphBuilder::MemSize(uint32_t offset) { | 2533 Node* WasmGraphBuilder::MemSize(uint32_t offset) { |
2567 DCHECK(module_ && module_->instance); | 2534 DCHECK(module_ && module_->instance); |
2568 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); | 2535 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
2569 if (offset == 0) { | 2536 if (offset == 0) { |
2570 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); | 2537 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); |
2571 return mem_size_; | 2538 return mem_size_; |
2572 } else { | 2539 } else { |
2573 return jsgraph()->Int32Constant(size + offset); | 2540 return jsgraph()->Int32Constant(size + offset); |
2574 } | 2541 } |
2575 } | 2542 } |
2576 | 2543 |
2577 | |
2578 Node* WasmGraphBuilder::FunctionTable() { | 2544 Node* WasmGraphBuilder::FunctionTable() { |
2579 DCHECK(module_ && module_->instance && | 2545 DCHECK(module_ && module_->instance && |
2580 !module_->instance->function_table.is_null()); | 2546 !module_->instance->function_table.is_null()); |
2581 if (!function_table_) { | 2547 if (!function_table_) { |
2582 function_table_ = jsgraph()->Constant(module_->instance->function_table); | 2548 function_table_ = jsgraph()->Constant(module_->instance->function_table); |
2583 } | 2549 } |
2584 return function_table_; | 2550 return function_table_; |
2585 } | 2551 } |
2586 | 2552 |
2587 | |
2588 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { | 2553 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { |
2589 DCHECK(module_ && module_->instance && module_->instance->globals_start); | 2554 DCHECK(module_ && module_->instance && module_->instance->globals_start); |
2590 MachineType mem_type = module_->GetGlobalType(index); | 2555 MachineType mem_type = module_->GetGlobalType(index); |
2591 Node* addr = jsgraph()->IntPtrConstant( | 2556 Node* addr = jsgraph()->IntPtrConstant( |
2592 reinterpret_cast<uintptr_t>(module_->instance->globals_start + | 2557 reinterpret_cast<uintptr_t>(module_->instance->globals_start + |
2593 module_->module->globals[index].offset)); | 2558 module_->module->globals[index].offset)); |
2594 const Operator* op = jsgraph()->machine()->Load(mem_type); | 2559 const Operator* op = jsgraph()->machine()->Load(mem_type); |
2595 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_, | 2560 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_, |
2596 *control_); | 2561 *control_); |
2597 *effect_ = node; | 2562 *effect_ = node; |
2598 return node; | 2563 return node; |
2599 } | 2564 } |
2600 | 2565 |
2601 | |
2602 Node* WasmGraphBuilder::StoreGlobal(uint32_t index, Node* val) { | 2566 Node* WasmGraphBuilder::StoreGlobal(uint32_t index, Node* val) { |
2603 DCHECK(module_ && module_->instance && module_->instance->globals_start); | 2567 DCHECK(module_ && module_->instance && module_->instance->globals_start); |
2604 MachineType mem_type = module_->GetGlobalType(index); | 2568 MachineType mem_type = module_->GetGlobalType(index); |
2605 Node* addr = jsgraph()->IntPtrConstant( | 2569 Node* addr = jsgraph()->IntPtrConstant( |
2606 reinterpret_cast<uintptr_t>(module_->instance->globals_start + | 2570 reinterpret_cast<uintptr_t>(module_->instance->globals_start + |
2607 module_->module->globals[index].offset)); | 2571 module_->module->globals[index].offset)); |
2608 const Operator* op = jsgraph()->machine()->Store( | 2572 const Operator* op = jsgraph()->machine()->Store( |
2609 StoreRepresentation(mem_type.representation(), kNoWriteBarrier)); | 2573 StoreRepresentation(mem_type.representation(), kNoWriteBarrier)); |
2610 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val, | 2574 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val, |
2611 *effect_, *control_); | 2575 *effect_, *control_); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2706 Node* store = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), val, | 2670 Node* store = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), val, |
2707 *effect_, *control_); | 2671 *effect_, *control_); |
2708 *effect_ = store; | 2672 *effect_ = store; |
2709 return val; | 2673 return val; |
2710 } | 2674 } |
2711 | 2675 |
2712 void WasmGraphBuilder::PrintDebugName(Node* node) { | 2676 void WasmGraphBuilder::PrintDebugName(Node* node) { |
2713 PrintF("#%d:%s", node->id(), node->op()->mnemonic()); | 2677 PrintF("#%d:%s", node->id(), node->op()->mnemonic()); |
2714 } | 2678 } |
2715 | 2679 |
2716 | |
2717 Node* WasmGraphBuilder::String(const char* string) { | 2680 Node* WasmGraphBuilder::String(const char* string) { |
2718 return jsgraph()->Constant( | 2681 return jsgraph()->Constant( |
2719 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); | 2682 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); |
2720 } | 2683 } |
2721 | 2684 |
2722 | |
2723 Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); } | 2685 Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); } |
2724 | 2686 |
2725 void WasmGraphBuilder::Int64LoweringForTesting() { | 2687 void WasmGraphBuilder::Int64LoweringForTesting() { |
2726 if (jsgraph()->machine()->Is32()) { | 2688 if (jsgraph()->machine()->Is32()) { |
2727 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), | 2689 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), |
2728 jsgraph()->common(), jsgraph()->zone(), | 2690 jsgraph()->common(), jsgraph()->zone(), |
2729 function_signature_); | 2691 function_signature_); |
2730 r.LowerGraph(); | 2692 r.LowerGraph(); |
2731 } | 2693 } |
2732 } | 2694 } |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 const wasm::WasmFunction* function) { | 3092 const wasm::WasmFunction* function) { |
3131 WasmCompilationUnit* unit = | 3093 WasmCompilationUnit* unit = |
3132 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); | 3094 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); |
3133 ExecuteCompilation(unit); | 3095 ExecuteCompilation(unit); |
3134 return FinishCompilation(unit); | 3096 return FinishCompilation(unit); |
3135 } | 3097 } |
3136 | 3098 |
3137 } // namespace compiler | 3099 } // namespace compiler |
3138 } // namespace internal | 3100 } // namespace internal |
3139 } // namespace v8 | 3101 } // namespace v8 |
OLD | NEW |