| 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/compiler/instruction-selector.h" | 5 #include "src/compiler/instruction-selector.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/base/adapters.h" | 9 #include "src/base/adapters.h" |
| 10 #include "src/compiler/instruction-selector-impl.h" | 10 #include "src/compiler/instruction-selector-impl.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // arg 1 : deoptimization id. | 353 // arg 1 : deoptimization id. |
| 354 // arg 2 - arg (n + 1) : value inputs to the frame state. | 354 // arg 2 - arg (n + 1) : value inputs to the frame state. |
| 355 if (buffer->frame_state_descriptor != NULL) { | 355 if (buffer->frame_state_descriptor != NULL) { |
| 356 InstructionSequence::StateId state_id = | 356 InstructionSequence::StateId state_id = |
| 357 sequence()->AddFrameStateDescriptor(buffer->frame_state_descriptor); | 357 sequence()->AddFrameStateDescriptor(buffer->frame_state_descriptor); |
| 358 buffer->instruction_args.push_back(g.TempImmediate(state_id.ToInt())); | 358 buffer->instruction_args.push_back(g.TempImmediate(state_id.ToInt())); |
| 359 | 359 |
| 360 Node* frame_state = | 360 Node* frame_state = |
| 361 call->InputAt(static_cast<int>(buffer->descriptor->InputCount())); | 361 call->InputAt(static_cast<int>(buffer->descriptor->InputCount())); |
| 362 AddFrameStateInputs(frame_state, &buffer->instruction_args, | 362 AddFrameStateInputs(frame_state, &buffer->instruction_args, |
| 363 buffer->frame_state_descriptor); | 363 buffer->frame_state_descriptor, |
| 364 FrameStateInputKind::kStackSlot); |
| 364 } | 365 } |
| 365 DCHECK(1 + buffer->frame_state_value_count() == | 366 DCHECK(1 + buffer->frame_state_value_count() == |
| 366 buffer->instruction_args.size()); | 367 buffer->instruction_args.size()); |
| 367 | 368 |
| 368 size_t input_count = static_cast<size_t>(buffer->input_count()); | 369 size_t input_count = static_cast<size_t>(buffer->input_count()); |
| 369 | 370 |
| 370 // Split the arguments into pushed_nodes and instruction_args. Pushed | 371 // Split the arguments into pushed_nodes and instruction_args. Pushed |
| 371 // arguments require an explicit push instruction before the call and do | 372 // arguments require an explicit push instruction before the call and do |
| 372 // not appear as arguments to the call. Everything else ends up | 373 // not appear as arguments to the call. Everything else ends up |
| 373 // as an InstructionOperand argument to the call. | 374 // as an InstructionOperand argument to the call. |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 FrameStateDescriptor* desc = GetFrameStateDescriptor(value); | 1010 FrameStateDescriptor* desc = GetFrameStateDescriptor(value); |
| 1010 size_t arg_count = desc->GetTotalSize() + 1; // Include deopt id. | 1011 size_t arg_count = desc->GetTotalSize() + 1; // Include deopt id. |
| 1011 | 1012 |
| 1012 InstructionOperandVector args(instruction_zone()); | 1013 InstructionOperandVector args(instruction_zone()); |
| 1013 args.reserve(arg_count); | 1014 args.reserve(arg_count); |
| 1014 | 1015 |
| 1015 InstructionSequence::StateId state_id = | 1016 InstructionSequence::StateId state_id = |
| 1016 sequence()->AddFrameStateDescriptor(desc); | 1017 sequence()->AddFrameStateDescriptor(desc); |
| 1017 args.push_back(g.TempImmediate(state_id.ToInt())); | 1018 args.push_back(g.TempImmediate(state_id.ToInt())); |
| 1018 | 1019 |
| 1019 AddFrameStateInputs(value, &args, desc); | 1020 AddFrameStateInputs(value, &args, desc, FrameStateInputKind::kAny); |
| 1020 | 1021 |
| 1021 DCHECK_EQ(args.size(), arg_count); | 1022 DCHECK_EQ(args.size(), arg_count); |
| 1022 | 1023 |
| 1023 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr); | 1024 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr); |
| 1024 } | 1025 } |
| 1025 | 1026 |
| 1026 | 1027 |
| 1027 void InstructionSelector::VisitThrow(Node* value) { | 1028 void InstructionSelector::VisitThrow(Node* value) { |
| 1028 OperandGenerator g(this); | 1029 OperandGenerator g(this); |
| 1029 Emit(kArchNop, g.NoOutput()); // TODO(titzer) | 1030 Emit(kArchNop, g.NoOutput()); // TODO(titzer) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1052 outer_state = GetFrameStateDescriptor(outer_node); | 1053 outer_state = GetFrameStateDescriptor(outer_node); |
| 1053 } | 1054 } |
| 1054 | 1055 |
| 1055 return new (instruction_zone()) FrameStateDescriptor( | 1056 return new (instruction_zone()) FrameStateDescriptor( |
| 1056 instruction_zone(), state_info.type(), state_info.bailout_id(), | 1057 instruction_zone(), state_info.type(), state_info.bailout_id(), |
| 1057 state_info.state_combine(), parameters, locals, stack, | 1058 state_info.state_combine(), parameters, locals, stack, |
| 1058 state_info.shared_info(), outer_state); | 1059 state_info.shared_info(), outer_state); |
| 1059 } | 1060 } |
| 1060 | 1061 |
| 1061 | 1062 |
| 1062 static InstructionOperand SlotOrImmediate(OperandGenerator* g, Node* input) { | 1063 InstructionOperand InstructionSelector::OperandForDeopt( |
| 1064 OperandGenerator* g, Node* input, FrameStateInputKind kind) { |
| 1063 switch (input->opcode()) { | 1065 switch (input->opcode()) { |
| 1064 case IrOpcode::kInt32Constant: | 1066 case IrOpcode::kInt32Constant: |
| 1065 case IrOpcode::kNumberConstant: | 1067 case IrOpcode::kNumberConstant: |
| 1066 case IrOpcode::kFloat64Constant: | 1068 case IrOpcode::kFloat64Constant: |
| 1067 case IrOpcode::kHeapConstant: | 1069 case IrOpcode::kHeapConstant: |
| 1068 return g->UseImmediate(input); | 1070 return g->UseImmediate(input); |
| 1069 default: | 1071 default: |
| 1070 return g->UseUniqueSlot(input); | 1072 switch (kind) { |
| 1073 case FrameStateInputKind::kStackSlot: |
| 1074 return g->UseUniqueSlot(input); |
| 1075 case FrameStateInputKind::kAny: |
| 1076 return g->Use(input); |
| 1077 } |
| 1078 UNREACHABLE(); |
| 1079 return InstructionOperand(); |
| 1071 } | 1080 } |
| 1072 } | 1081 } |
| 1073 | 1082 |
| 1074 | 1083 |
| 1075 void InstructionSelector::AddFrameStateInputs( | 1084 void InstructionSelector::AddFrameStateInputs(Node* state, |
| 1076 Node* state, InstructionOperandVector* inputs, | 1085 InstructionOperandVector* inputs, |
| 1077 FrameStateDescriptor* descriptor) { | 1086 FrameStateDescriptor* descriptor, |
| 1087 FrameStateInputKind kind) { |
| 1078 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); | 1088 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); |
| 1079 | 1089 |
| 1080 if (descriptor->outer_state()) { | 1090 if (descriptor->outer_state()) { |
| 1081 AddFrameStateInputs(state->InputAt(kFrameStateOuterStateInput), inputs, | 1091 AddFrameStateInputs(state->InputAt(kFrameStateOuterStateInput), inputs, |
| 1082 descriptor->outer_state()); | 1092 descriptor->outer_state(), kind); |
| 1083 } | 1093 } |
| 1084 | 1094 |
| 1085 Node* parameters = state->InputAt(kFrameStateParametersInput); | 1095 Node* parameters = state->InputAt(kFrameStateParametersInput); |
| 1086 Node* locals = state->InputAt(kFrameStateLocalsInput); | 1096 Node* locals = state->InputAt(kFrameStateLocalsInput); |
| 1087 Node* stack = state->InputAt(kFrameStateStackInput); | 1097 Node* stack = state->InputAt(kFrameStateStackInput); |
| 1088 Node* context = state->InputAt(kFrameStateContextInput); | 1098 Node* context = state->InputAt(kFrameStateContextInput); |
| 1089 Node* function = state->InputAt(kFrameStateFunctionInput); | 1099 Node* function = state->InputAt(kFrameStateFunctionInput); |
| 1090 | 1100 |
| 1091 DCHECK_EQ(descriptor->parameters_count(), | 1101 DCHECK_EQ(descriptor->parameters_count(), |
| 1092 StateValuesAccess(parameters).size()); | 1102 StateValuesAccess(parameters).size()); |
| 1093 DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size()); | 1103 DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size()); |
| 1094 DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size()); | 1104 DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size()); |
| 1095 | 1105 |
| 1096 ZoneVector<MachineType> types(instruction_zone()); | 1106 ZoneVector<MachineType> types(instruction_zone()); |
| 1097 types.reserve(descriptor->GetSize()); | 1107 types.reserve(descriptor->GetSize()); |
| 1098 | 1108 |
| 1099 OperandGenerator g(this); | 1109 OperandGenerator g(this); |
| 1100 size_t value_index = 0; | 1110 size_t value_index = 0; |
| 1101 inputs->push_back(SlotOrImmediate(&g, function)); | 1111 inputs->push_back(OperandForDeopt(&g, function, kind)); |
| 1102 descriptor->SetType(value_index++, kMachAnyTagged); | 1112 descriptor->SetType(value_index++, kMachAnyTagged); |
| 1103 for (StateValuesAccess::TypedNode input_node : | 1113 for (StateValuesAccess::TypedNode input_node : |
| 1104 StateValuesAccess(parameters)) { | 1114 StateValuesAccess(parameters)) { |
| 1105 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1115 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
| 1106 descriptor->SetType(value_index++, input_node.type); | 1116 descriptor->SetType(value_index++, input_node.type); |
| 1107 } | 1117 } |
| 1108 if (descriptor->HasContext()) { | 1118 if (descriptor->HasContext()) { |
| 1109 inputs->push_back(SlotOrImmediate(&g, context)); | 1119 inputs->push_back(OperandForDeopt(&g, context, kind)); |
| 1110 descriptor->SetType(value_index++, kMachAnyTagged); | 1120 descriptor->SetType(value_index++, kMachAnyTagged); |
| 1111 } | 1121 } |
| 1112 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) { | 1122 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) { |
| 1113 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1123 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
| 1114 descriptor->SetType(value_index++, input_node.type); | 1124 descriptor->SetType(value_index++, input_node.type); |
| 1115 } | 1125 } |
| 1116 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { | 1126 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { |
| 1117 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1127 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
| 1118 descriptor->SetType(value_index++, input_node.type); | 1128 descriptor->SetType(value_index++, input_node.type); |
| 1119 } | 1129 } |
| 1120 DCHECK(value_index == descriptor->GetSize()); | 1130 DCHECK(value_index == descriptor->GetSize()); |
| 1121 } | 1131 } |
| 1122 | 1132 |
| 1123 } // namespace compiler | 1133 } // namespace compiler |
| 1124 } // namespace internal | 1134 } // namespace internal |
| 1125 } // namespace v8 | 1135 } // namespace v8 |
| OLD | NEW |