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 } | |
Benedikt Meurer
2015/09/03 13:11:09
Nit: Add UNREACHABLE() at the end.
| |
1071 } | 1078 } |
1072 } | 1079 } |
1073 | 1080 |
1074 | 1081 |
1075 void InstructionSelector::AddFrameStateInputs( | 1082 void InstructionSelector::AddFrameStateInputs(Node* state, |
1076 Node* state, InstructionOperandVector* inputs, | 1083 InstructionOperandVector* inputs, |
1077 FrameStateDescriptor* descriptor) { | 1084 FrameStateDescriptor* descriptor, |
1085 FrameStateInputKind kind) { | |
1078 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); | 1086 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); |
1079 | 1087 |
1080 if (descriptor->outer_state()) { | 1088 if (descriptor->outer_state()) { |
1081 AddFrameStateInputs(state->InputAt(kFrameStateOuterStateInput), inputs, | 1089 AddFrameStateInputs(state->InputAt(kFrameStateOuterStateInput), inputs, |
1082 descriptor->outer_state()); | 1090 descriptor->outer_state(), kind); |
1083 } | 1091 } |
1084 | 1092 |
1085 Node* parameters = state->InputAt(kFrameStateParametersInput); | 1093 Node* parameters = state->InputAt(kFrameStateParametersInput); |
1086 Node* locals = state->InputAt(kFrameStateLocalsInput); | 1094 Node* locals = state->InputAt(kFrameStateLocalsInput); |
1087 Node* stack = state->InputAt(kFrameStateStackInput); | 1095 Node* stack = state->InputAt(kFrameStateStackInput); |
1088 Node* context = state->InputAt(kFrameStateContextInput); | 1096 Node* context = state->InputAt(kFrameStateContextInput); |
1089 Node* function = state->InputAt(kFrameStateFunctionInput); | 1097 Node* function = state->InputAt(kFrameStateFunctionInput); |
1090 | 1098 |
1091 DCHECK_EQ(descriptor->parameters_count(), | 1099 DCHECK_EQ(descriptor->parameters_count(), |
1092 StateValuesAccess(parameters).size()); | 1100 StateValuesAccess(parameters).size()); |
1093 DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size()); | 1101 DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size()); |
1094 DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size()); | 1102 DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size()); |
1095 | 1103 |
1096 ZoneVector<MachineType> types(instruction_zone()); | 1104 ZoneVector<MachineType> types(instruction_zone()); |
1097 types.reserve(descriptor->GetSize()); | 1105 types.reserve(descriptor->GetSize()); |
1098 | 1106 |
1099 OperandGenerator g(this); | 1107 OperandGenerator g(this); |
1100 size_t value_index = 0; | 1108 size_t value_index = 0; |
1101 inputs->push_back(SlotOrImmediate(&g, function)); | 1109 inputs->push_back(OperandForDeopt(&g, function, kind)); |
1102 descriptor->SetType(value_index++, kMachAnyTagged); | 1110 descriptor->SetType(value_index++, kMachAnyTagged); |
1103 for (StateValuesAccess::TypedNode input_node : | 1111 for (StateValuesAccess::TypedNode input_node : |
1104 StateValuesAccess(parameters)) { | 1112 StateValuesAccess(parameters)) { |
1105 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1113 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
1106 descriptor->SetType(value_index++, input_node.type); | 1114 descriptor->SetType(value_index++, input_node.type); |
1107 } | 1115 } |
1108 if (descriptor->HasContext()) { | 1116 if (descriptor->HasContext()) { |
1109 inputs->push_back(SlotOrImmediate(&g, context)); | 1117 inputs->push_back(OperandForDeopt(&g, context, kind)); |
1110 descriptor->SetType(value_index++, kMachAnyTagged); | 1118 descriptor->SetType(value_index++, kMachAnyTagged); |
1111 } | 1119 } |
1112 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) { | 1120 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) { |
1113 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1121 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
1114 descriptor->SetType(value_index++, input_node.type); | 1122 descriptor->SetType(value_index++, input_node.type); |
1115 } | 1123 } |
1116 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { | 1124 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { |
1117 inputs->push_back(SlotOrImmediate(&g, input_node.node)); | 1125 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
1118 descriptor->SetType(value_index++, input_node.type); | 1126 descriptor->SetType(value_index++, input_node.type); |
1119 } | 1127 } |
1120 DCHECK(value_index == descriptor->GetSize()); | 1128 DCHECK(value_index == descriptor->GetSize()); |
1121 } | 1129 } |
1122 | 1130 |
1123 } // namespace compiler | 1131 } // namespace compiler |
1124 } // namespace internal | 1132 } // namespace internal |
1125 } // namespace v8 | 1133 } // namespace v8 |
OLD | NEW |