Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/compiler/instruction-selector.cc

Issue 522873002: Removal of the deoptimization block from Turbofan (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Change constant capitalization Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/instruction-selector.h ('k') | src/compiler/instruction-selector-impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/compiler/instruction-selector-impl.h" 7 #include "src/compiler/instruction-selector-impl.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties-inl.h" 9 #include "src/compiler/node-properties-inl.h"
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 FrameStateDescriptor* frame_desc) 264 FrameStateDescriptor* frame_desc)
265 : descriptor(d), 265 : descriptor(d),
266 frame_state_descriptor(frame_desc), 266 frame_state_descriptor(frame_desc),
267 output_nodes(zone), 267 output_nodes(zone),
268 outputs(zone), 268 outputs(zone),
269 instruction_args(zone), 269 instruction_args(zone),
270 pushed_nodes(zone) { 270 pushed_nodes(zone) {
271 output_nodes.reserve(d->ReturnCount()); 271 output_nodes.reserve(d->ReturnCount());
272 outputs.reserve(d->ReturnCount()); 272 outputs.reserve(d->ReturnCount());
273 pushed_nodes.reserve(input_count()); 273 pushed_nodes.reserve(input_count());
274 instruction_args.reserve(input_count() + control_count() + 274 instruction_args.reserve(input_count() + frame_state_value_count());
275 frame_state_value_count());
276 } 275 }
277 276
278 277
279 // TODO(bmeurer): Get rid of the CallBuffer business and make 278 // TODO(bmeurer): Get rid of the CallBuffer business and make
280 // InstructionSelector::VisitCall platform independent instead. 279 // InstructionSelector::VisitCall platform independent instead.
281 void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer, 280 void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
282 bool call_code_immediate, 281 bool call_code_immediate,
283 bool call_address_immediate, 282 bool call_address_immediate) {
284 BasicBlock* cont_node,
285 BasicBlock* deopt_node) {
286 OperandGenerator g(this); 283 OperandGenerator g(this);
287 DCHECK_EQ(call->op()->OutputCount(), buffer->descriptor->ReturnCount()); 284 DCHECK_EQ(call->op()->OutputCount(), buffer->descriptor->ReturnCount());
288 DCHECK_EQ(OperatorProperties::GetValueInputCount(call->op()), 285 DCHECK_EQ(OperatorProperties::GetValueInputCount(call->op()),
289 buffer->input_count() + buffer->frame_state_count()); 286 buffer->input_count() + buffer->frame_state_count());
290 287
291 if (buffer->descriptor->ReturnCount() > 0) { 288 if (buffer->descriptor->ReturnCount() > 0) {
292 // Collect the projections that represent multiple outputs from this call. 289 // Collect the projections that represent multiple outputs from this call.
293 if (buffer->descriptor->ReturnCount() == 1) { 290 if (buffer->descriptor->ReturnCount() == 1) {
294 buffer->output_nodes.push_back(call); 291 buffer->output_nodes.push_back(call);
295 } else { 292 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 g.UseLocation(callee, buffer->descriptor->GetInputLocation(0))); 328 g.UseLocation(callee, buffer->descriptor->GetInputLocation(0)));
332 break; 329 break;
333 } 330 }
334 DCHECK_EQ(1, buffer->instruction_args.size()); 331 DCHECK_EQ(1, buffer->instruction_args.size());
335 332
336 // If the call needs a frame state, we insert the state information as 333 // If the call needs a frame state, we insert the state information as
337 // follows (n is the number of value inputs to the frame state): 334 // follows (n is the number of value inputs to the frame state):
338 // arg 1 : deoptimization id. 335 // arg 1 : deoptimization id.
339 // arg 2 - arg (n + 1) : value inputs to the frame state. 336 // arg 2 - arg (n + 1) : value inputs to the frame state.
340 if (buffer->frame_state_descriptor != NULL) { 337 if (buffer->frame_state_descriptor != NULL) {
341 int deoptimization_id = 338 InstructionSequence::StateId state_id =
342 sequence()->AddDeoptimizationEntry(buffer->frame_state_descriptor); 339 sequence()->AddFrameStateDescriptor(buffer->frame_state_descriptor);
343 buffer->instruction_args.push_back(g.TempImmediate(deoptimization_id)); 340 buffer->instruction_args.push_back(g.TempImmediate(state_id.ToInt()));
344 341
345 Node* frame_state = call->InputAt(buffer->descriptor->InputCount()); 342 Node* frame_state = call->InputAt(buffer->descriptor->InputCount());
346 AddFrameStateInputs(frame_state, &buffer->instruction_args, 343 AddFrameStateInputs(frame_state, &buffer->instruction_args,
347 buffer->frame_state_descriptor); 344 buffer->frame_state_descriptor);
348 } 345 }
349 DCHECK_EQ(1 + buffer->frame_state_value_count(), 346 DCHECK_EQ(1 + buffer->frame_state_value_count(),
350 buffer->instruction_args.size()); 347 buffer->instruction_args.size());
351 348
352 int input_count = buffer->input_count(); 349 int input_count = buffer->input_count();
353 350
(...skipping 16 matching lines...) Expand all
370 buffer->pushed_nodes.resize(stack_index + 1, NULL); 367 buffer->pushed_nodes.resize(stack_index + 1, NULL);
371 } 368 }
372 DCHECK_EQ(NULL, buffer->pushed_nodes[stack_index]); 369 DCHECK_EQ(NULL, buffer->pushed_nodes[stack_index]);
373 buffer->pushed_nodes[stack_index] = *iter; 370 buffer->pushed_nodes[stack_index] = *iter;
374 pushed_count++; 371 pushed_count++;
375 } else { 372 } else {
376 buffer->instruction_args.push_back(op); 373 buffer->instruction_args.push_back(op);
377 } 374 }
378 } 375 }
379 CHECK_EQ(pushed_count, static_cast<int>(buffer->pushed_nodes.size())); 376 CHECK_EQ(pushed_count, static_cast<int>(buffer->pushed_nodes.size()));
380
381 // If the call can deoptimize, we add the continuation and deoptimization
382 // block labels.
383 if (buffer->descriptor->CanLazilyDeoptimize()) {
384 DCHECK(cont_node != NULL);
385 DCHECK(deopt_node != NULL);
386 buffer->instruction_args.push_back(g.Label(cont_node));
387 buffer->instruction_args.push_back(g.Label(deopt_node));
388 } else {
389 DCHECK(cont_node == NULL);
390 DCHECK(deopt_node == NULL);
391 }
392
393 DCHECK(static_cast<size_t>(input_count) == 377 DCHECK(static_cast<size_t>(input_count) ==
394 (buffer->instruction_args.size() - buffer->control_count() + 378 (buffer->instruction_args.size() + buffer->pushed_nodes.size() -
395 buffer->pushed_nodes.size() - buffer->frame_state_value_count())); 379 buffer->frame_state_value_count()));
396 } 380 }
397 381
398 382
399 void InstructionSelector::VisitBlock(BasicBlock* block) { 383 void InstructionSelector::VisitBlock(BasicBlock* block) {
400 DCHECK_EQ(NULL, current_block_); 384 DCHECK_EQ(NULL, current_block_);
401 current_block_ = block; 385 current_block_ = block;
402 int current_block_end = static_cast<int>(instructions_.size()); 386 int current_block_end = static_cast<int>(instructions_.size());
403 387
404 // Generate code for the block control "top down", but schedule the code 388 // Generate code for the block control "top down", but schedule the code
405 // "bottom up". 389 // "bottom up".
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 442 }
459 case BasicBlockData::kReturn: { 443 case BasicBlockData::kReturn: {
460 // If the result itself is a return, return its input. 444 // If the result itself is a return, return its input.
461 Node* value = (input != NULL && input->opcode() == IrOpcode::kReturn) 445 Node* value = (input != NULL && input->opcode() == IrOpcode::kReturn)
462 ? input->InputAt(0) 446 ? input->InputAt(0)
463 : input; 447 : input;
464 return VisitReturn(value); 448 return VisitReturn(value);
465 } 449 }
466 case BasicBlockData::kThrow: 450 case BasicBlockData::kThrow:
467 return VisitThrow(input); 451 return VisitThrow(input);
468 case BasicBlockData::kDeoptimize:
469 return VisitDeoptimize(input);
470 case BasicBlockData::kCall: {
471 BasicBlock* deoptimization = block->SuccessorAt(0);
472 BasicBlock* continuation = block->SuccessorAt(1);
473 VisitCall(input, continuation, deoptimization);
474 break;
475 }
476 case BasicBlockData::kNone: { 452 case BasicBlockData::kNone: {
477 // TODO(titzer): exit block doesn't have control. 453 // TODO(titzer): exit block doesn't have control.
478 DCHECK(input == NULL); 454 DCHECK(input == NULL);
479 break; 455 break;
480 } 456 }
481 default: 457 default:
482 UNREACHABLE(); 458 UNREACHABLE();
483 break; 459 break;
484 } 460 }
485 } 461 }
(...skipping 10 matching lines...) Expand all
496 } 472 }
497 switch (node->opcode()) { 473 switch (node->opcode()) {
498 case IrOpcode::kStart: 474 case IrOpcode::kStart:
499 case IrOpcode::kLoop: 475 case IrOpcode::kLoop:
500 case IrOpcode::kEnd: 476 case IrOpcode::kEnd:
501 case IrOpcode::kBranch: 477 case IrOpcode::kBranch:
502 case IrOpcode::kIfTrue: 478 case IrOpcode::kIfTrue:
503 case IrOpcode::kIfFalse: 479 case IrOpcode::kIfFalse:
504 case IrOpcode::kEffectPhi: 480 case IrOpcode::kEffectPhi:
505 case IrOpcode::kMerge: 481 case IrOpcode::kMerge:
506 case IrOpcode::kLazyDeoptimization:
507 case IrOpcode::kContinuation:
508 // No code needed for these graph artifacts. 482 // No code needed for these graph artifacts.
509 return; 483 return;
510 case IrOpcode::kFinish: 484 case IrOpcode::kFinish:
511 return VisitFinish(node); 485 return VisitFinish(node);
512 case IrOpcode::kParameter: { 486 case IrOpcode::kParameter: {
513 LinkageLocation location = 487 LinkageLocation location =
514 linkage()->GetParameterLocation(OpParameter<int>(node)); 488 linkage()->GetParameterLocation(OpParameter<int>(node));
515 MarkAsRepresentation(location.representation(), node); 489 MarkAsRepresentation(location.representation(), node);
516 return VisitParameter(node); 490 return VisitParameter(node);
517 } 491 }
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 995
1022 996
1023 void InstructionSelector::VisitThrow(Node* value) { 997 void InstructionSelector::VisitThrow(Node* value) {
1024 UNIMPLEMENTED(); // TODO(titzer) 998 UNIMPLEMENTED(); // TODO(titzer)
1025 } 999 }
1026 1000
1027 1001
1028 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor( 1002 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
1029 Node* state) { 1003 Node* state) {
1030 DCHECK(state->op()->opcode() == IrOpcode::kFrameState); 1004 DCHECK(state->op()->opcode() == IrOpcode::kFrameState);
1031 BailoutId ast_id = OpParameter<BailoutId>(state); 1005 FrameStateCallInfo state_info = OpParameter<FrameStateCallInfo>(state);
1032 Node* parameters = state->InputAt(0); 1006 Node* parameters = state->InputAt(0);
1033 Node* locals = state->InputAt(1); 1007 Node* locals = state->InputAt(1);
1034 Node* stack = state->InputAt(2); 1008 Node* stack = state->InputAt(2);
1035 1009
1036 return new (instruction_zone()) 1010 return new (instruction_zone())
1037 FrameStateDescriptor(ast_id, OpParameter<int>(parameters), 1011 FrameStateDescriptor(state_info, OpParameter<int>(parameters),
1038 OpParameter<int>(locals), OpParameter<int>(stack)); 1012 OpParameter<int>(locals), OpParameter<int>(stack));
1039 } 1013 }
1040 1014
1041 1015
1042 static InstructionOperand* UseOrImmediate(OperandGenerator* g, Node* input) { 1016 static InstructionOperand* UseOrImmediate(OperandGenerator* g, Node* input) {
1043 switch (input->opcode()) { 1017 switch (input->opcode()) {
1044 case IrOpcode::kInt32Constant: 1018 case IrOpcode::kInt32Constant:
1045 case IrOpcode::kNumberConstant: 1019 case IrOpcode::kNumberConstant:
1046 case IrOpcode::kFloat64Constant: 1020 case IrOpcode::kFloat64Constant:
1047 case IrOpcode::kHeapConstant: 1021 case IrOpcode::kHeapConstant:
1048 return g->UseImmediate(input); 1022 return g->UseImmediate(input);
1049 default: 1023 default:
1050 return g->UseUnique(input); 1024 return g->UseUnique(input);
1051 } 1025 }
1052 } 1026 }
1053 1027
1054 1028
1055 void InstructionSelector::AddFrameStateInputs( 1029 void InstructionSelector::AddFrameStateInputs(
1056 Node* state, InstructionOperandVector* inputs, 1030 Node* state, InstructionOperandVector* inputs,
1057 FrameStateDescriptor* descriptor) { 1031 FrameStateDescriptor* descriptor) {
1058 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); 1032 DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode());
1059 1033
1060 Node* parameters = state->InputAt(0); 1034 Node* parameters = state->InputAt(0);
1061 Node* locals = state->InputAt(1); 1035 Node* locals = state->InputAt(1);
1062 Node* stack = state->InputAt(2); 1036 Node* stack = state->InputAt(2);
1037 Node* context = state->InputAt(3);
1038
1039 DCHECK_EQ(IrOpcode::kStateValues, parameters->op()->opcode());
1040 DCHECK_EQ(IrOpcode::kStateValues, locals->op()->opcode());
1041 DCHECK_EQ(IrOpcode::kStateValues, stack->op()->opcode());
1063 1042
1064 DCHECK_EQ(descriptor->parameters_count(), parameters->InputCount()); 1043 DCHECK_EQ(descriptor->parameters_count(), parameters->InputCount());
1065 DCHECK_EQ(descriptor->locals_count(), locals->InputCount()); 1044 DCHECK_EQ(descriptor->locals_count(), locals->InputCount());
1066 DCHECK_EQ(descriptor->stack_count(), stack->InputCount()); 1045 DCHECK_EQ(descriptor->stack_count(), stack->InputCount());
1067 1046
1068 OperandGenerator g(this); 1047 OperandGenerator g(this);
1069 for (int i = 0; i < descriptor->parameters_count(); i++) { 1048 for (int i = 0; i < descriptor->parameters_count(); i++) {
1070 inputs->push_back(UseOrImmediate(&g, parameters->InputAt(i))); 1049 inputs->push_back(UseOrImmediate(&g, parameters->InputAt(i)));
1071 } 1050 }
1051 inputs->push_back(UseOrImmediate(&g, context));
1072 for (int i = 0; i < descriptor->locals_count(); i++) { 1052 for (int i = 0; i < descriptor->locals_count(); i++) {
1073 inputs->push_back(UseOrImmediate(&g, locals->InputAt(i))); 1053 inputs->push_back(UseOrImmediate(&g, locals->InputAt(i)));
1074 } 1054 }
1075 for (int i = 0; i < descriptor->stack_count(); i++) { 1055 for (int i = 0; i < descriptor->stack_count(); i++) {
1076 inputs->push_back(UseOrImmediate(&g, stack->InputAt(i))); 1056 inputs->push_back(UseOrImmediate(&g, stack->InputAt(i)));
1077 } 1057 }
1078 } 1058 }
1079 1059
1080 1060
1081 void InstructionSelector::VisitDeoptimize(Node* deopt) {
1082 DCHECK(deopt->op()->opcode() == IrOpcode::kDeoptimize);
1083 Node* state = deopt->InputAt(0);
1084 FrameStateDescriptor* descriptor = GetFrameStateDescriptor(state);
1085 int deoptimization_id = sequence()->AddDeoptimizationEntry(descriptor);
1086
1087 InstructionOperandVector inputs(zone());
1088 inputs.reserve(descriptor->size() + 1);
1089
1090 OperandGenerator g(this);
1091 inputs.push_back(g.TempImmediate(deoptimization_id));
1092
1093 AddFrameStateInputs(state, &inputs, descriptor);
1094
1095 DCHECK_EQ(descriptor->size() + 1, inputs.size());
1096
1097 Emit(kArchDeoptimize, 0, NULL, inputs.size(), &inputs.front(), 0, NULL);
1098 }
1099
1100
1101 #if !V8_TURBOFAN_BACKEND 1061 #if !V8_TURBOFAN_BACKEND
1102 1062
1103 #define DECLARE_UNIMPLEMENTED_SELECTOR(x) \ 1063 #define DECLARE_UNIMPLEMENTED_SELECTOR(x) \
1104 void InstructionSelector::Visit##x(Node* node) { UNIMPLEMENTED(); } 1064 void InstructionSelector::Visit##x(Node* node) { UNIMPLEMENTED(); }
1105 MACHINE_OP_LIST(DECLARE_UNIMPLEMENTED_SELECTOR) 1065 MACHINE_OP_LIST(DECLARE_UNIMPLEMENTED_SELECTOR)
1106 #undef DECLARE_UNIMPLEMENTED_SELECTOR 1066 #undef DECLARE_UNIMPLEMENTED_SELECTOR
1107 1067
1108 1068
1109 void InstructionSelector::VisitInt32AddWithOverflow(Node* node, 1069 void InstructionSelector::VisitInt32AddWithOverflow(Node* node,
1110 FlagsContinuation* cont) { 1070 FlagsContinuation* cont) {
(...skipping 25 matching lines...) Expand all
1136 1096
1137 1097
1138 void InstructionSelector::VisitCall(Node* call, BasicBlock* continuation, 1098 void InstructionSelector::VisitCall(Node* call, BasicBlock* continuation,
1139 BasicBlock* deoptimization) {} 1099 BasicBlock* deoptimization) {}
1140 1100
1141 #endif // !V8_TURBOFAN_BACKEND 1101 #endif // !V8_TURBOFAN_BACKEND
1142 1102
1143 } // namespace compiler 1103 } // namespace compiler
1144 } // namespace internal 1104 } // namespace internal
1145 } // namespace v8 1105 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/instruction-selector.h ('k') | src/compiler/instruction-selector-impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698