| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/base/bits.h" | 5 #include "src/base/bits.h" |
| 6 #include "src/compiler/instruction-selector-impl.h" | 6 #include "src/compiler/instruction-selector-impl.h" |
| 7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
| 8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 outputs[output_count++] = g.DefineAsRegister(node); | 107 outputs[output_count++] = g.DefineAsRegister(node); |
| 108 if (cont->IsSet()) { | 108 if (cont->IsSet()) { |
| 109 outputs[output_count++] = g.DefineAsRegister(cont->result()); | 109 outputs[output_count++] = g.DefineAsRegister(cont->result()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 DCHECK_NE(0u, input_count); | 112 DCHECK_NE(0u, input_count); |
| 113 DCHECK_NE(0u, output_count); | 113 DCHECK_NE(0u, output_count); |
| 114 DCHECK_GE(arraysize(inputs), input_count); | 114 DCHECK_GE(arraysize(inputs), input_count); |
| 115 DCHECK_GE(arraysize(outputs), output_count); | 115 DCHECK_GE(arraysize(outputs), output_count); |
| 116 | 116 |
| 117 Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, | 117 selector->Emit(cont->Encode(opcode), output_count, outputs, input_count, |
| 118 outputs, input_count, inputs); | 118 inputs); |
| 119 if (cont->IsBranch()) instr->MarkAsControl(); | |
| 120 } | 119 } |
| 121 | 120 |
| 122 | 121 |
| 123 static void VisitBinop(InstructionSelector* selector, Node* node, | 122 static void VisitBinop(InstructionSelector* selector, Node* node, |
| 124 InstructionCode opcode) { | 123 InstructionCode opcode) { |
| 125 FlagsContinuation cont; | 124 FlagsContinuation cont; |
| 126 VisitBinop(selector, node, opcode, &cont); | 125 VisitBinop(selector, node, opcode, &cont); |
| 127 } | 126 } |
| 128 | 127 |
| 129 | 128 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 namespace { | 620 namespace { |
| 622 | 621 |
| 623 // Shared routine for multiple compare operations. | 622 // Shared routine for multiple compare operations. |
| 624 static void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 623 static void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
| 625 InstructionOperand left, InstructionOperand right, | 624 InstructionOperand left, InstructionOperand right, |
| 626 FlagsContinuation* cont) { | 625 FlagsContinuation* cont) { |
| 627 MipsOperandGenerator g(selector); | 626 MipsOperandGenerator g(selector); |
| 628 opcode = cont->Encode(opcode); | 627 opcode = cont->Encode(opcode); |
| 629 if (cont->IsBranch()) { | 628 if (cont->IsBranch()) { |
| 630 selector->Emit(opcode, g.NoOutput(), left, right, | 629 selector->Emit(opcode, g.NoOutput(), left, right, |
| 631 g.Label(cont->true_block()), | 630 g.Label(cont->true_block()), g.Label(cont->false_block())); |
| 632 g.Label(cont->false_block()))->MarkAsControl(); | |
| 633 } else { | 631 } else { |
| 634 DCHECK(cont->IsSet()); | 632 DCHECK(cont->IsSet()); |
| 635 // TODO(plind): Revisit and test this path. | 633 // TODO(plind): Revisit and test this path. |
| 636 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 634 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
| 637 } | 635 } |
| 638 } | 636 } |
| 639 | 637 |
| 640 | 638 |
| 641 // Shared routine for multiple float compare operations. | 639 // Shared routine for multiple float compare operations. |
| 642 void VisitFloat64Compare(InstructionSelector* selector, Node* node, | 640 void VisitFloat64Compare(InstructionSelector* selector, Node* node, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 } | 749 } |
| 752 break; | 750 break; |
| 753 } | 751 } |
| 754 | 752 |
| 755 // Continuation could not be combined with a compare, emit compare against 0. | 753 // Continuation could not be combined with a compare, emit compare against 0. |
| 756 MipsOperandGenerator g(selector); | 754 MipsOperandGenerator g(selector); |
| 757 InstructionCode const opcode = cont->Encode(kMipsCmp); | 755 InstructionCode const opcode = cont->Encode(kMipsCmp); |
| 758 InstructionOperand const value_operand = g.UseRegister(value); | 756 InstructionOperand const value_operand = g.UseRegister(value); |
| 759 if (cont->IsBranch()) { | 757 if (cont->IsBranch()) { |
| 760 selector->Emit(opcode, g.NoOutput(), value_operand, g.TempImmediate(0), | 758 selector->Emit(opcode, g.NoOutput(), value_operand, g.TempImmediate(0), |
| 761 g.Label(cont->true_block()), | 759 g.Label(cont->true_block()), g.Label(cont->false_block())); |
| 762 g.Label(cont->false_block()))->MarkAsControl(); | |
| 763 } else { | 760 } else { |
| 764 selector->Emit(opcode, g.DefineAsRegister(cont->result()), value_operand, | 761 selector->Emit(opcode, g.DefineAsRegister(cont->result()), value_operand, |
| 765 g.TempImmediate(0)); | 762 g.TempImmediate(0)); |
| 766 } | 763 } |
| 767 } | 764 } |
| 768 | 765 |
| 769 | 766 |
| 770 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, | 767 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, |
| 771 BasicBlock* fbranch) { | 768 BasicBlock* fbranch) { |
| 772 FlagsContinuation cont(kNotEqual, tbranch, fbranch); | 769 FlagsContinuation cont(kNotEqual, tbranch, fbranch); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | 803 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); |
| 807 inputs[0] = index_operand; | 804 inputs[0] = index_operand; |
| 808 std::fill(&inputs[1], &inputs[input_count], default_operand); | 805 std::fill(&inputs[1], &inputs[input_count], default_operand); |
| 809 for (size_t index = 0; index < case_count; ++index) { | 806 for (size_t index = 0; index < case_count; ++index) { |
| 810 size_t value = case_values[index] - min_value; | 807 size_t value = case_values[index] - min_value; |
| 811 BasicBlock* branch = case_branches[index]; | 808 BasicBlock* branch = case_branches[index]; |
| 812 DCHECK_LE(0u, value); | 809 DCHECK_LE(0u, value); |
| 813 DCHECK_LT(value + 2, input_count); | 810 DCHECK_LT(value + 2, input_count); |
| 814 inputs[value + 2] = g.Label(branch); | 811 inputs[value + 2] = g.Label(branch); |
| 815 } | 812 } |
| 816 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr) | 813 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr); |
| 817 ->MarkAsControl(); | |
| 818 return; | 814 return; |
| 819 } | 815 } |
| 820 | 816 |
| 821 // Generate a sequence of conditional jumps. | 817 // Generate a sequence of conditional jumps. |
| 822 size_t input_count = 2 + case_count * 2; | 818 size_t input_count = 2 + case_count * 2; |
| 823 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | 819 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); |
| 824 inputs[0] = value_operand; | 820 inputs[0] = value_operand; |
| 825 inputs[1] = default_operand; | 821 inputs[1] = default_operand; |
| 826 for (size_t index = 0; index < case_count; ++index) { | 822 for (size_t index = 0; index < case_count; ++index) { |
| 827 int32_t value = case_values[index]; | 823 int32_t value = case_values[index]; |
| 828 BasicBlock* branch = case_branches[index]; | 824 BasicBlock* branch = case_branches[index]; |
| 829 inputs[index * 2 + 2 + 0] = g.TempImmediate(value); | 825 inputs[index * 2 + 2 + 0] = g.TempImmediate(value); |
| 830 inputs[index * 2 + 2 + 1] = g.Label(branch); | 826 inputs[index * 2 + 2 + 1] = g.Label(branch); |
| 831 } | 827 } |
| 832 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr) | 828 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr); |
| 833 ->MarkAsControl(); | |
| 834 } | 829 } |
| 835 | 830 |
| 836 | 831 |
| 837 void InstructionSelector::VisitWord32Equal(Node* const node) { | 832 void InstructionSelector::VisitWord32Equal(Node* const node) { |
| 838 FlagsContinuation cont(kEqual, node); | 833 FlagsContinuation cont(kEqual, node); |
| 839 Int32BinopMatcher m(node); | 834 Int32BinopMatcher m(node); |
| 840 if (m.right().Is(0)) { | 835 if (m.right().Is(0)) { |
| 841 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); | 836 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); |
| 842 } | 837 } |
| 843 VisitWordCompare(this, node, &cont); | 838 VisitWordCompare(this, node, &cont); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) { | 939 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) { |
| 945 return MachineOperatorBuilder::kFloat64RoundDown | | 940 return MachineOperatorBuilder::kFloat64RoundDown | |
| 946 MachineOperatorBuilder::kFloat64RoundTruncate; | 941 MachineOperatorBuilder::kFloat64RoundTruncate; |
| 947 } | 942 } |
| 948 return MachineOperatorBuilder::kNoFlags; | 943 return MachineOperatorBuilder::kNoFlags; |
| 949 } | 944 } |
| 950 | 945 |
| 951 } // namespace compiler | 946 } // namespace compiler |
| 952 } // namespace internal | 947 } // namespace internal |
| 953 } // namespace v8 | 948 } // namespace v8 |
| OLD | NEW |