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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 | 330 |
331 | 331 |
332 bool LCodeGen::GenerateBody() { | 332 bool LCodeGen::GenerateBody() { |
333 ASSERT(is_generating()); | 333 ASSERT(is_generating()); |
334 bool emit_instructions = true; | 334 bool emit_instructions = true; |
335 for (current_instruction_ = 0; | 335 for (current_instruction_ = 0; |
336 !is_aborted() && current_instruction_ < instructions_->length(); | 336 !is_aborted() && current_instruction_ < instructions_->length(); |
337 current_instruction_++) { | 337 current_instruction_++) { |
338 LInstruction* instr = instructions_->at(current_instruction_); | 338 LInstruction* instr = instructions_->at(current_instruction_); |
| 339 |
| 340 // Don't emit code for basic blocks with a replacement. |
339 if (instr->IsLabel()) { | 341 if (instr->IsLabel()) { |
340 LLabel* label = LLabel::cast(instr); | 342 emit_instructions = !LLabel::cast(instr)->HasReplacement(); |
341 emit_instructions = !label->HasReplacement(); | 343 } |
| 344 if (!emit_instructions) continue; |
| 345 |
| 346 if (FLAG_code_comments && instr->HasInterestingComment(this)) { |
| 347 Comment(";;; <@%d,#%d> %s", |
| 348 current_instruction_, |
| 349 instr->hydrogen_value()->id(), |
| 350 instr->Mnemonic()); |
342 } | 351 } |
343 | 352 |
344 if (emit_instructions) { | 353 if (!CpuFeatures::IsSupported(SSE2)) FlushX87StackIfNecessary(instr); |
345 if (FLAG_code_comments) { | |
346 HValue* hydrogen = instr->hydrogen_value(); | |
347 if (hydrogen != NULL) { | |
348 if (hydrogen->IsChange()) { | |
349 HValue* changed_value = HChange::cast(hydrogen)->value(); | |
350 int use_id = 0; | |
351 const char* use_mnemo = "dead"; | |
352 if (hydrogen->UseCount() >= 1) { | |
353 HValue* use_value = hydrogen->uses().value(); | |
354 use_id = use_value->id(); | |
355 use_mnemo = use_value->Mnemonic(); | |
356 } | |
357 Comment(";;; @%d: %s. <of #%d %s for #%d %s>", | |
358 current_instruction_, instr->Mnemonic(), | |
359 changed_value->id(), changed_value->Mnemonic(), | |
360 use_id, use_mnemo); | |
361 } else { | |
362 Comment(";;; @%d: %s. <#%d>", current_instruction_, | |
363 instr->Mnemonic(), hydrogen->id()); | |
364 } | |
365 } else { | |
366 Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); | |
367 } | |
368 } | |
369 | 354 |
370 if (!CpuFeatures::IsSupported(SSE2)) { | 355 instr->CompileToNative(this); |
371 FlushX87StackIfNecessary(instr); | |
372 } | |
373 | 356 |
374 instr->CompileToNative(this); | 357 if (!CpuFeatures::IsSupported(SSE2)) { |
375 | 358 ASSERT(!instr->HasDoubleRegisterResult() || x87_stack_depth_ == 1); |
376 if (!CpuFeatures::IsSupported(SSE2)) { | 359 if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
377 ASSERT(!instr->HasDoubleRegisterResult() || x87_stack_depth_ == 1); | 360 __ VerifyX87StackDepth(x87_stack_depth_); |
378 | |
379 if (FLAG_debug_code && FLAG_enable_slow_asserts) { | |
380 __ VerifyX87StackDepth(x87_stack_depth_); | |
381 } | |
382 } | 361 } |
383 } | 362 } |
384 } | 363 } |
385 EnsureSpaceForLazyDeopt(); | 364 EnsureSpaceForLazyDeopt(); |
386 return !is_aborted(); | 365 return !is_aborted(); |
387 } | 366 } |
388 | 367 |
389 | 368 |
390 bool LCodeGen::GenerateJumpTable() { | 369 bool LCodeGen::GenerateJumpTable() { |
391 Label needs_frame_not_call; | 370 Label needs_frame_not_call; |
392 Label needs_frame_is_call; | 371 Label needs_frame_is_call; |
| 372 if (jump_table_.length() > 0) { |
| 373 Comment(";;; -------------------- Jump table --------------------"); |
| 374 } |
393 for (int i = 0; i < jump_table_.length(); i++) { | 375 for (int i = 0; i < jump_table_.length(); i++) { |
394 __ bind(&jump_table_[i].label); | 376 __ bind(&jump_table_[i].label); |
395 Address entry = jump_table_[i].address; | 377 Address entry = jump_table_[i].address; |
396 bool is_lazy_deopt = jump_table_[i].is_lazy_deopt; | 378 bool is_lazy_deopt = jump_table_[i].is_lazy_deopt; |
397 Deoptimizer::BailoutType type = | 379 Deoptimizer::BailoutType type = |
398 is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; | 380 is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
399 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); | 381 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
400 if (id == Deoptimizer::kNotDeoptimizationEntry) { | 382 if (id == Deoptimizer::kNotDeoptimizationEntry) { |
401 Comment(";;; jump table entry %d.", i); | 383 Comment(";;; jump table entry %d.", i); |
402 } else { | 384 } else { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 440 } |
459 return !is_aborted(); | 441 return !is_aborted(); |
460 } | 442 } |
461 | 443 |
462 | 444 |
463 bool LCodeGen::GenerateDeferredCode() { | 445 bool LCodeGen::GenerateDeferredCode() { |
464 ASSERT(is_generating()); | 446 ASSERT(is_generating()); |
465 if (deferred_.length() > 0) { | 447 if (deferred_.length() > 0) { |
466 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { | 448 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
467 LDeferredCode* code = deferred_[i]; | 449 LDeferredCode* code = deferred_[i]; |
| 450 Comment(";;; <@%d,#%d> " |
| 451 "-------------------- Deferred %s --------------------", |
| 452 code->instruction_index(), |
| 453 code->instr()->hydrogen_value()->id(), |
| 454 code->instr()->Mnemonic()); |
468 __ bind(code->entry()); | 455 __ bind(code->entry()); |
469 if (NeedsDeferredFrame()) { | 456 if (NeedsDeferredFrame()) { |
470 Comment(";;; Deferred build frame @%d: %s.", | 457 Comment(";;; Build frame"); |
471 code->instruction_index(), | |
472 code->instr()->Mnemonic()); | |
473 ASSERT(!frame_is_built_); | 458 ASSERT(!frame_is_built_); |
474 ASSERT(info()->IsStub()); | 459 ASSERT(info()->IsStub()); |
475 frame_is_built_ = true; | 460 frame_is_built_ = true; |
476 // Build the frame in such a way that esi isn't trashed. | 461 // Build the frame in such a way that esi isn't trashed. |
477 __ push(ebp); // Caller's frame pointer. | 462 __ push(ebp); // Caller's frame pointer. |
478 __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); | 463 __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); |
479 __ push(Immediate(Smi::FromInt(StackFrame::STUB))); | 464 __ push(Immediate(Smi::FromInt(StackFrame::STUB))); |
480 __ lea(ebp, Operand(esp, 2 * kPointerSize)); | 465 __ lea(ebp, Operand(esp, 2 * kPointerSize)); |
| 466 Comment(";;; Deferred code"); |
481 } | 467 } |
482 Comment(";;; Deferred code @%d: %s.", | |
483 code->instruction_index(), | |
484 code->instr()->Mnemonic()); | |
485 code->Generate(); | 468 code->Generate(); |
486 if (NeedsDeferredFrame()) { | 469 if (NeedsDeferredFrame()) { |
487 Comment(";;; Deferred destroy frame @%d: %s.", | 470 Comment(";;; Destroy frame"); |
488 code->instruction_index(), | |
489 code->instr()->Mnemonic()); | |
490 ASSERT(frame_is_built_); | 471 ASSERT(frame_is_built_); |
491 frame_is_built_ = false; | 472 frame_is_built_ = false; |
492 __ mov(esp, ebp); | 473 __ mov(esp, ebp); |
493 __ pop(ebp); | 474 __ pop(ebp); |
494 } | 475 } |
495 __ jmp(code->exit()); | 476 __ jmp(code->exit()); |
496 } | 477 } |
497 } | 478 } |
498 | 479 |
499 // Deferred code is the last part of the instruction sequence. Mark | 480 // Deferred code is the last part of the instruction sequence. Mark |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode); | 1099 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode); |
1119 } | 1100 } |
1120 | 1101 |
1121 | 1102 |
1122 void LCodeGen::RecordPosition(int position) { | 1103 void LCodeGen::RecordPosition(int position) { |
1123 if (position == RelocInfo::kNoPosition) return; | 1104 if (position == RelocInfo::kNoPosition) return; |
1124 masm()->positions_recorder()->RecordPosition(position); | 1105 masm()->positions_recorder()->RecordPosition(position); |
1125 } | 1106 } |
1126 | 1107 |
1127 | 1108 |
| 1109 static const char* LabelType(LLabel* label) { |
| 1110 if (label->is_loop_header()) return " (loop header)"; |
| 1111 if (label->is_osr_entry()) return " (OSR entry)"; |
| 1112 return ""; |
| 1113 } |
| 1114 |
| 1115 |
1128 void LCodeGen::DoLabel(LLabel* label) { | 1116 void LCodeGen::DoLabel(LLabel* label) { |
1129 Comment(";;; -------------------- B%d%s --------------------", | 1117 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1118 current_instruction_, |
| 1119 label->hydrogen_value()->id(), |
1130 label->block_id(), | 1120 label->block_id(), |
1131 label->is_loop_header() ? " (loop header)" : ""); | 1121 LabelType(label)); |
1132 __ bind(label->label()); | 1122 __ bind(label->label()); |
1133 current_block_ = label->block_id(); | 1123 current_block_ = label->block_id(); |
1134 DoGap(label); | 1124 DoGap(label); |
1135 } | 1125 } |
1136 | 1126 |
1137 | 1127 |
1138 void LCodeGen::DoParallelMove(LParallelMove* move) { | 1128 void LCodeGen::DoParallelMove(LParallelMove* move) { |
1139 resolver_.Resolve(move); | 1129 resolver_.Resolve(move); |
1140 } | 1130 } |
1141 | 1131 |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 ASSERT(ToRegister(instr->left()).is(edx)); | 2039 ASSERT(ToRegister(instr->left()).is(edx)); |
2050 ASSERT(ToRegister(instr->right()).is(eax)); | 2040 ASSERT(ToRegister(instr->right()).is(eax)); |
2051 ASSERT(ToRegister(instr->result()).is(eax)); | 2041 ASSERT(ToRegister(instr->result()).is(eax)); |
2052 | 2042 |
2053 BinaryOpStub stub(instr->op(), NO_OVERWRITE); | 2043 BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
2054 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); | 2044 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
2055 __ nop(); // Signals no inlined code. | 2045 __ nop(); // Signals no inlined code. |
2056 } | 2046 } |
2057 | 2047 |
2058 | 2048 |
2059 int LCodeGen::GetNextEmittedBlock() { | 2049 int LCodeGen::GetNextEmittedBlock() const { |
2060 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { | 2050 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
2061 if (!chunk_->GetLabel(i)->HasReplacement()) return i; | 2051 if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
2062 } | 2052 } |
2063 return -1; | 2053 return -1; |
2064 } | 2054 } |
2065 | 2055 |
2066 | 2056 |
2067 void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { | 2057 void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { |
2068 int next_block = GetNextEmittedBlock(); | 2058 int next_block = GetNextEmittedBlock(); |
2069 right_block = chunk_->LookupDestination(right_block); | 2059 right_block = chunk_->LookupDestination(right_block); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2196 } | 2186 } |
2197 | 2187 |
2198 // We've seen something for the first time -> deopt. | 2188 // We've seen something for the first time -> deopt. |
2199 DeoptimizeIf(no_condition, instr->environment()); | 2189 DeoptimizeIf(no_condition, instr->environment()); |
2200 } | 2190 } |
2201 } | 2191 } |
2202 } | 2192 } |
2203 | 2193 |
2204 | 2194 |
2205 void LCodeGen::EmitGoto(int block) { | 2195 void LCodeGen::EmitGoto(int block) { |
2206 int destination = chunk_->LookupDestination(block); | 2196 if (!IsNextEmittedBlock(block)) { |
2207 if (destination != GetNextEmittedBlock()) { | 2197 __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); |
2208 __ jmp(chunk_->GetAssemblyLabel(destination)); | |
2209 } | 2198 } |
2210 } | 2199 } |
2211 | 2200 |
2212 | 2201 |
2213 void LCodeGen::DoGoto(LGoto* instr) { | 2202 void LCodeGen::DoGoto(LGoto* instr) { |
2214 EmitGoto(instr->block_id()); | 2203 EmitGoto(instr->block_id()); |
2215 } | 2204 } |
2216 | 2205 |
2217 | 2206 |
2218 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { | 2207 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
(...skipping 4357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6576 FixedArray::kHeaderSize - kPointerSize)); | 6565 FixedArray::kHeaderSize - kPointerSize)); |
6577 __ bind(&done); | 6566 __ bind(&done); |
6578 } | 6567 } |
6579 | 6568 |
6580 | 6569 |
6581 #undef __ | 6570 #undef __ |
6582 | 6571 |
6583 } } // namespace v8::internal | 6572 } } // namespace v8::internal |
6584 | 6573 |
6585 #endif // V8_TARGET_ARCH_IA32 | 6574 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |