OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 value()->PrintTo(stream); | 400 value()->PrintTo(stream); |
401 } | 401 } |
402 | 402 |
403 | 403 |
404 void LTransitionElementsKind::PrintDataTo(StringStream* stream) { | 404 void LTransitionElementsKind::PrintDataTo(StringStream* stream) { |
405 object()->PrintTo(stream); | 405 object()->PrintTo(stream); |
406 stream->Add(" %p -> %p", *original_map(), *transitioned_map()); | 406 stream->Add(" %p -> %p", *original_map(), *transitioned_map()); |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 LChunk::LChunk(CompilationInfo* info, HGraph* graph) | |
411 : spill_slot_count_(0), | |
412 info_(info), | |
413 graph_(graph), | |
414 instructions_(32, graph->zone()), | |
415 pointer_maps_(8, graph->zone()), | |
416 inlined_closures_(1, graph->zone()) { | |
417 } | |
418 | |
419 | |
420 int LChunk::GetNextSpillIndex(bool is_double) { | 410 int LChunk::GetNextSpillIndex(bool is_double) { |
421 // Skip a slot if for a double-width slot. | 411 // Skip a slot if for a double-width slot. |
422 if (is_double) spill_slot_count_++; | 412 if (is_double) spill_slot_count_++; |
423 return spill_slot_count_++; | 413 return spill_slot_count_++; |
424 } | 414 } |
425 | 415 |
426 | 416 |
427 LOperand* LChunk::GetNextSpillSlot(bool is_double) { | 417 LOperand* LChunk::GetNextSpillSlot(bool is_double) { |
428 int index = GetNextSpillIndex(is_double); | 418 int index = GetNextSpillIndex(is_double); |
429 if (is_double) { | 419 if (is_double) { |
430 return LDoubleStackSlot::Create(index, zone()); | 420 return LDoubleStackSlot::Create(index, zone()); |
431 } else { | 421 } else { |
432 return LStackSlot::Create(index, zone()); | 422 return LStackSlot::Create(index, zone()); |
433 } | 423 } |
434 } | 424 } |
435 | 425 |
436 | 426 |
437 void LChunk::MarkEmptyBlocks() { | |
438 HPhase phase("L_Mark empty blocks", this); | |
439 for (int i = 0; i < graph()->blocks()->length(); ++i) { | |
440 HBasicBlock* block = graph()->blocks()->at(i); | |
441 int first = block->first_instruction_index(); | |
442 int last = block->last_instruction_index(); | |
443 LInstruction* first_instr = instructions()->at(first); | |
444 LInstruction* last_instr = instructions()->at(last); | |
445 | |
446 LLabel* label = LLabel::cast(first_instr); | |
447 if (last_instr->IsGoto()) { | |
448 LGoto* goto_instr = LGoto::cast(last_instr); | |
449 if (label->IsRedundant() && | |
450 !label->is_loop_header()) { | |
451 bool can_eliminate = true; | |
452 for (int i = first + 1; i < last && can_eliminate; ++i) { | |
453 LInstruction* cur = instructions()->at(i); | |
454 if (cur->IsGap()) { | |
455 LGap* gap = LGap::cast(cur); | |
456 if (!gap->IsRedundant()) { | |
457 can_eliminate = false; | |
458 } | |
459 } else { | |
460 can_eliminate = false; | |
461 } | |
462 } | |
463 | |
464 if (can_eliminate) { | |
465 label->set_replacement(GetLabel(goto_instr->block_id())); | |
466 } | |
467 } | |
468 } | |
469 } | |
470 } | |
471 | |
472 | |
473 void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { | |
474 LInstructionGap* gap = new(graph_->zone()) LInstructionGap(block); | |
475 int index = -1; | |
476 if (instr->IsControl()) { | |
477 instructions_.Add(gap, zone()); | |
478 index = instructions_.length(); | |
479 instructions_.Add(instr, zone()); | |
480 } else { | |
481 index = instructions_.length(); | |
482 instructions_.Add(instr, zone()); | |
483 instructions_.Add(gap, zone()); | |
484 } | |
485 if (instr->HasPointerMap()) { | |
486 pointer_maps_.Add(instr->pointer_map(), zone()); | |
487 instr->pointer_map()->set_lithium_position(index); | |
488 } | |
489 } | |
490 | |
491 | |
492 LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) { | |
493 return LConstantOperand::Create(constant->id(), zone()); | |
494 } | |
495 | |
496 | |
497 int LChunk::GetParameterStackSlot(int index) const { | |
498 // The receiver is at index 0, the first parameter at index 1, so we | |
499 // shift all parameter indexes down by the number of parameters, and | |
500 // make sure they end up negative so they are distinguishable from | |
501 // spill slots. | |
502 int result = index - info()->scope()->num_parameters() - 1; | |
503 ASSERT(result < 0); | |
504 return result; | |
505 } | |
506 | |
507 // A parameter relative to ebp in the arguments stub. | |
508 int LChunk::ParameterAt(int index) { | |
509 ASSERT(-1 <= index); // -1 is the receiver. | |
510 return (1 + info()->scope()->num_parameters() - index) * | |
511 kPointerSize; | |
512 } | |
513 | |
514 | |
515 LGap* LChunk::GetGapAt(int index) const { | |
516 return LGap::cast(instructions_[index]); | |
517 } | |
518 | |
519 | |
520 bool LChunk::IsGapAt(int index) const { | |
521 return instructions_[index]->IsGap(); | |
522 } | |
523 | |
524 | |
525 int LChunk::NearestGapPos(int index) const { | |
526 while (!IsGapAt(index)) index--; | |
527 return index; | |
528 } | |
529 | |
530 | |
531 void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) { | |
532 GetGapAt(index)->GetOrCreateParallelMove( | |
533 LGap::START, zone())->AddMove(from, to, zone()); | |
534 } | |
535 | |
536 | |
537 Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const { | |
538 return HConstant::cast(graph_->LookupValue(operand->index()))->handle(); | |
539 } | |
540 | |
541 | |
542 Representation LChunk::LookupLiteralRepresentation( | |
543 LConstantOperand* operand) const { | |
544 return graph_->LookupValue(operand->index())->representation(); | |
545 } | |
546 | |
547 | |
548 LChunk* LChunkBuilder::Build() { | 427 LChunk* LChunkBuilder::Build() { |
549 ASSERT(is_unused()); | 428 ASSERT(is_unused()); |
550 chunk_ = new(zone()) LChunk(info(), graph()); | 429 chunk_ = new(zone()) LChunk(info(), graph()); |
551 HPhase phase("L_Building chunk", chunk_); | 430 HPhase phase("L_Building chunk", chunk_); |
552 status_ = BUILDING; | 431 status_ = BUILDING; |
553 const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); | 432 const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
554 for (int i = 0; i < blocks->length(); i++) { | 433 for (int i = 0; i < blocks->length(); i++) { |
555 HBasicBlock* next = NULL; | 434 HBasicBlock* next = NULL; |
556 if (i < blocks->length() - 1) next = blocks->at(i + 1); | 435 if (i < blocks->length() - 1) next = blocks->at(i + 1); |
557 DoBasicBlock(blocks->at(i), next); | 436 DoBasicBlock(blocks->at(i), next); |
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 | 2273 |
2395 | 2274 |
2396 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2275 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2397 LOperand* object = UseRegister(instr->object()); | 2276 LOperand* object = UseRegister(instr->object()); |
2398 LOperand* index = UseRegister(instr->index()); | 2277 LOperand* index = UseRegister(instr->index()); |
2399 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2278 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
2400 } | 2279 } |
2401 | 2280 |
2402 | 2281 |
2403 } } // namespace v8::internal | 2282 } } // namespace v8::internal |
OLD | NEW |