| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 bool LCodeGen::GenerateBody() { | 253 bool LCodeGen::GenerateBody() { |
| 254 ASSERT(is_generating()); | 254 ASSERT(is_generating()); |
| 255 bool emit_instructions = true; | 255 bool emit_instructions = true; |
| 256 for (current_instruction_ = 0; | 256 for (current_instruction_ = 0; |
| 257 !is_aborted() && current_instruction_ < instructions_->length(); | 257 !is_aborted() && current_instruction_ < instructions_->length(); |
| 258 current_instruction_++) { | 258 current_instruction_++) { |
| 259 LInstruction* instr = instructions_->at(current_instruction_); | 259 LInstruction* instr = instructions_->at(current_instruction_); |
| 260 |
| 261 // Don't emit code for basic blocks with a replacement. |
| 260 if (instr->IsLabel()) { | 262 if (instr->IsLabel()) { |
| 261 LLabel* label = LLabel::cast(instr); | 263 emit_instructions = !LLabel::cast(instr)->HasReplacement(); |
| 262 emit_instructions = !label->HasReplacement(); | 264 } |
| 265 if (!emit_instructions) continue; |
| 266 |
| 267 if (FLAG_code_comments && instr->HasInterestingComment(this)) { |
| 268 Comment(";;; <@%d,#%d> %s", |
| 269 current_instruction_, |
| 270 instr->hydrogen_value()->id(), |
| 271 instr->Mnemonic()); |
| 263 } | 272 } |
| 264 | 273 |
| 265 if (emit_instructions) { | 274 instr->CompileToNative(this); |
| 266 if (FLAG_code_comments) { | |
| 267 HValue* hydrogen = instr->hydrogen_value(); | |
| 268 if (hydrogen != NULL) { | |
| 269 if (hydrogen->IsChange()) { | |
| 270 HValue* changed_value = HChange::cast(hydrogen)->value(); | |
| 271 int use_id = 0; | |
| 272 const char* use_mnemo = "dead"; | |
| 273 if (hydrogen->UseCount() >= 1) { | |
| 274 HValue* use_value = hydrogen->uses().value(); | |
| 275 use_id = use_value->id(); | |
| 276 use_mnemo = use_value->Mnemonic(); | |
| 277 } | |
| 278 Comment(";;; @%d: %s. <of #%d %s for #%d %s>", | |
| 279 current_instruction_, instr->Mnemonic(), | |
| 280 changed_value->id(), changed_value->Mnemonic(), | |
| 281 use_id, use_mnemo); | |
| 282 } else { | |
| 283 Comment(";;; @%d: %s. <#%d>", current_instruction_, | |
| 284 instr->Mnemonic(), hydrogen->id()); | |
| 285 } | |
| 286 } else { | |
| 287 Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); | |
| 288 } | |
| 289 } | |
| 290 instr->CompileToNative(this); | |
| 291 } | |
| 292 } | 275 } |
| 293 return !is_aborted(); | 276 return !is_aborted(); |
| 294 } | 277 } |
| 295 | 278 |
| 296 | 279 |
| 297 bool LCodeGen::GenerateDeferredCode() { | 280 bool LCodeGen::GenerateDeferredCode() { |
| 298 ASSERT(is_generating()); | 281 ASSERT(is_generating()); |
| 299 if (deferred_.length() > 0) { | 282 if (deferred_.length() > 0) { |
| 300 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { | 283 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 301 LDeferredCode* code = deferred_[i]; | 284 LDeferredCode* code = deferred_[i]; |
| 285 Comment(";;; <@%d,#%d> " |
| 286 "-------------------- Deferred %s --------------------", |
| 287 code->instruction_index(), |
| 288 code->instr()->hydrogen_value()->id(), |
| 289 code->instr()->Mnemonic()); |
| 302 __ bind(code->entry()); | 290 __ bind(code->entry()); |
| 303 if (NeedsDeferredFrame()) { | 291 if (NeedsDeferredFrame()) { |
| 304 Comment(";;; Deferred build frame @%d: %s.", | 292 Comment(";;; Build frame"); |
| 305 code->instruction_index(), | |
| 306 code->instr()->Mnemonic()); | |
| 307 ASSERT(!frame_is_built_); | 293 ASSERT(!frame_is_built_); |
| 308 ASSERT(info()->IsStub()); | 294 ASSERT(info()->IsStub()); |
| 309 frame_is_built_ = true; | 295 frame_is_built_ = true; |
| 310 __ MultiPush(cp.bit() | fp.bit() | ra.bit()); | 296 __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 311 __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); | 297 __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 312 __ push(scratch0()); | 298 __ push(scratch0()); |
| 313 __ Addu(fp, sp, Operand(2 * kPointerSize)); | 299 __ Addu(fp, sp, Operand(2 * kPointerSize)); |
| 300 Comment(";;; Deferred code"); |
| 314 } | 301 } |
| 315 Comment(";;; Deferred code @%d: %s.", | |
| 316 code->instruction_index(), | |
| 317 code->instr()->Mnemonic()); | |
| 318 code->Generate(); | 302 code->Generate(); |
| 319 if (NeedsDeferredFrame()) { | 303 if (NeedsDeferredFrame()) { |
| 320 Comment(";;; Deferred destroy frame @%d: %s.", | 304 Comment(";;; Destroy frame"); |
| 321 code->instruction_index(), | |
| 322 code->instr()->Mnemonic()); | |
| 323 ASSERT(frame_is_built_); | 305 ASSERT(frame_is_built_); |
| 324 __ pop(at); | 306 __ pop(at); |
| 325 __ MultiPop(cp.bit() | fp.bit() | ra.bit()); | 307 __ MultiPop(cp.bit() | fp.bit() | ra.bit()); |
| 326 frame_is_built_ = false; | 308 frame_is_built_ = false; |
| 327 } | 309 } |
| 328 __ jmp(code->exit()); | 310 __ jmp(code->exit()); |
| 329 } | 311 } |
| 330 } | 312 } |
| 331 // Deferred code is the last part of the instruction sequence. Mark | 313 // Deferred code is the last part of the instruction sequence. Mark |
| 332 // the generated code as done unless we bailed out. | 314 // the generated code as done unless we bailed out. |
| 333 if (!is_aborted()) status_ = DONE; | 315 if (!is_aborted()) status_ = DONE; |
| 334 return !is_aborted(); | 316 return !is_aborted(); |
| 335 } | 317 } |
| 336 | 318 |
| 337 | 319 |
| 338 bool LCodeGen::GenerateDeoptJumpTable() { | 320 bool LCodeGen::GenerateDeoptJumpTable() { |
| 339 // Check that the jump table is accessible from everywhere in the function | 321 // Check that the jump table is accessible from everywhere in the function |
| 340 // code, i.e. that offsets to the table can be encoded in the 16bit signed | 322 // code, i.e. that offsets to the table can be encoded in the 16bit signed |
| 341 // immediate of a branch instruction. | 323 // immediate of a branch instruction. |
| 342 // To simplify we consider the code size from the first instruction to the | 324 // To simplify we consider the code size from the first instruction to the |
| 343 // end of the jump table. | 325 // end of the jump table. |
| 344 if (!is_int16((masm()->pc_offset() / Assembler::kInstrSize) + | 326 if (!is_int16((masm()->pc_offset() / Assembler::kInstrSize) + |
| 345 deopt_jump_table_.length() * 12)) { | 327 deopt_jump_table_.length() * 12)) { |
| 346 Abort("Generated code is too large"); | 328 Abort("Generated code is too large"); |
| 347 } | 329 } |
| 348 | 330 |
| 331 if (deopt_jump_table_.length() > 0) { |
| 332 Comment(";;; -------------------- Jump table --------------------"); |
| 333 } |
| 349 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); | 334 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 350 __ RecordComment("[ Deoptimization jump table"); | |
| 351 Label table_start; | 335 Label table_start; |
| 352 __ bind(&table_start); | 336 __ bind(&table_start); |
| 353 Label needs_frame_not_call; | 337 Label needs_frame_not_call; |
| 354 Label needs_frame_is_call; | 338 Label needs_frame_is_call; |
| 355 for (int i = 0; i < deopt_jump_table_.length(); i++) { | 339 for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 356 __ bind(&deopt_jump_table_[i].label); | 340 __ bind(&deopt_jump_table_[i].label); |
| 357 Address entry = deopt_jump_table_[i].address; | 341 Address entry = deopt_jump_table_[i].address; |
| 358 bool is_lazy_deopt = deopt_jump_table_[i].is_lazy_deopt; | 342 bool is_lazy_deopt = deopt_jump_table_[i].is_lazy_deopt; |
| 359 Deoptimizer::BailoutType type = | 343 Deoptimizer::BailoutType type = |
| 360 is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; | 344 is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); | 1000 pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
| 1017 } | 1001 } |
| 1018 | 1002 |
| 1019 | 1003 |
| 1020 void LCodeGen::RecordPosition(int position) { | 1004 void LCodeGen::RecordPosition(int position) { |
| 1021 if (position == RelocInfo::kNoPosition) return; | 1005 if (position == RelocInfo::kNoPosition) return; |
| 1022 masm()->positions_recorder()->RecordPosition(position); | 1006 masm()->positions_recorder()->RecordPosition(position); |
| 1023 } | 1007 } |
| 1024 | 1008 |
| 1025 | 1009 |
| 1010 static const char* LabelType(LLabel* label) { |
| 1011 if (label->is_loop_header()) return " (loop header)"; |
| 1012 if (label->is_osr_entry()) return " (OSR entry)"; |
| 1013 return ""; |
| 1014 } |
| 1015 |
| 1016 |
| 1026 void LCodeGen::DoLabel(LLabel* label) { | 1017 void LCodeGen::DoLabel(LLabel* label) { |
| 1027 Comment(";;; -------------------- B%d%s --------------------", | 1018 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1019 current_instruction_, |
| 1020 label->hydrogen_value()->id(), |
| 1028 label->block_id(), | 1021 label->block_id(), |
| 1029 label->is_loop_header() ? " (loop header)" : ""); | 1022 LabelType(label)); |
| 1030 __ bind(label->label()); | 1023 __ bind(label->label()); |
| 1031 current_block_ = label->block_id(); | 1024 current_block_ = label->block_id(); |
| 1032 DoGap(label); | 1025 DoGap(label); |
| 1033 } | 1026 } |
| 1034 | 1027 |
| 1035 | 1028 |
| 1036 void LCodeGen::DoParallelMove(LParallelMove* move) { | 1029 void LCodeGen::DoParallelMove(LParallelMove* move) { |
| 1037 resolver_.Resolve(move); | 1030 resolver_.Resolve(move); |
| 1038 } | 1031 } |
| 1039 | 1032 |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 ASSERT(ToRegister(instr->result()).is(v0)); | 1742 ASSERT(ToRegister(instr->result()).is(v0)); |
| 1750 | 1743 |
| 1751 BinaryOpStub stub(instr->op(), NO_OVERWRITE); | 1744 BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
| 1752 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); | 1745 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 1753 // Other arch use a nop here, to signal that there is no inlined | 1746 // Other arch use a nop here, to signal that there is no inlined |
| 1754 // patchable code. Mips does not need the nop, since our marker | 1747 // patchable code. Mips does not need the nop, since our marker |
| 1755 // instruction (andi zero_reg) will never be used in normal code. | 1748 // instruction (andi zero_reg) will never be used in normal code. |
| 1756 } | 1749 } |
| 1757 | 1750 |
| 1758 | 1751 |
| 1759 int LCodeGen::GetNextEmittedBlock() { | 1752 int LCodeGen::GetNextEmittedBlock() const { |
| 1760 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { | 1753 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
| 1761 if (!chunk_->GetLabel(i)->HasReplacement()) return i; | 1754 if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
| 1762 } | 1755 } |
| 1763 return -1; | 1756 return -1; |
| 1764 } | 1757 } |
| 1765 | 1758 |
| 1766 | 1759 |
| 1767 void LCodeGen::EmitBranch(int left_block, int right_block, | 1760 void LCodeGen::EmitBranch(int left_block, int right_block, |
| 1768 Condition cc, Register src1, const Operand& src2) { | 1761 Condition cc, Register src1, const Operand& src2) { |
| 1769 int next_block = GetNextEmittedBlock(); | 1762 int next_block = GetNextEmittedBlock(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 } | 1901 } |
| 1909 | 1902 |
| 1910 // We've seen something for the first time -> deopt. | 1903 // We've seen something for the first time -> deopt. |
| 1911 DeoptimizeIf(al, instr->environment(), zero_reg, Operand(zero_reg)); | 1904 DeoptimizeIf(al, instr->environment(), zero_reg, Operand(zero_reg)); |
| 1912 } | 1905 } |
| 1913 } | 1906 } |
| 1914 } | 1907 } |
| 1915 | 1908 |
| 1916 | 1909 |
| 1917 void LCodeGen::EmitGoto(int block) { | 1910 void LCodeGen::EmitGoto(int block) { |
| 1918 int destination = chunk_->LookupDestination(block); | 1911 if (!IsNextEmittedBlock(block)) { |
| 1919 if (destination != GetNextEmittedBlock()) { | 1912 __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); |
| 1920 __ jmp(chunk_->GetAssemblyLabel(destination)); | |
| 1921 } | 1913 } |
| 1922 } | 1914 } |
| 1923 | 1915 |
| 1924 | 1916 |
| 1925 void LCodeGen::DoGoto(LGoto* instr) { | 1917 void LCodeGen::DoGoto(LGoto* instr) { |
| 1926 EmitGoto(instr->block_id()); | 1918 EmitGoto(instr->block_id()); |
| 1927 } | 1919 } |
| 1928 | 1920 |
| 1929 | 1921 |
| 1930 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { | 1922 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| (...skipping 3787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5718 __ Subu(scratch, result, scratch); | 5710 __ Subu(scratch, result, scratch); |
| 5719 __ lw(result, FieldMemOperand(scratch, | 5711 __ lw(result, FieldMemOperand(scratch, |
| 5720 FixedArray::kHeaderSize - kPointerSize)); | 5712 FixedArray::kHeaderSize - kPointerSize)); |
| 5721 __ bind(&done); | 5713 __ bind(&done); |
| 5722 } | 5714 } |
| 5723 | 5715 |
| 5724 | 5716 |
| 5725 #undef __ | 5717 #undef __ |
| 5726 | 5718 |
| 5727 } } // namespace v8::internal | 5719 } } // namespace v8::internal |
| OLD | NEW |