| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_PPC | 7 #if V8_TARGET_ARCH_PPC |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // o fp: our caller's frame pointer (aka r31) | 97 // o fp: our caller's frame pointer (aka r31) |
| 98 // o sp: stack pointer | 98 // o sp: stack pointer |
| 99 // o lr: return address | 99 // o lr: return address |
| 100 // o ip: our own function entry (required by the prologue) | 100 // o ip: our own function entry (required by the prologue) |
| 101 // | 101 // |
| 102 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 102 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 103 // frames-ppc.h for its layout. | 103 // frames-ppc.h for its layout. |
| 104 void FullCodeGenerator::Generate() { | 104 void FullCodeGenerator::Generate() { |
| 105 CompilationInfo* info = info_; | 105 CompilationInfo* info = info_; |
| 106 handler_table_ = | 106 handler_table_ = |
| 107 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 107 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( |
| 108 HandlerTable::LengthForRange(function()->handler_count()), TENURED)); |
| 108 | 109 |
| 109 profiling_counter_ = isolate()->factory()->NewCell( | 110 profiling_counter_ = isolate()->factory()->NewCell( |
| 110 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); | 111 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
| 111 SetFunctionPosition(function()); | 112 SetFunctionPosition(function()); |
| 112 Comment cmnt(masm_, "[ function compiled by full code generator"); | 113 Comment cmnt(masm_, "[ function compiled by full code generator"); |
| 113 | 114 |
| 114 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | 115 ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 115 | 116 |
| 116 #ifdef DEBUG | 117 #ifdef DEBUG |
| 117 if (strlen(FLAG_stop_at) > 0 && | 118 if (strlen(FLAG_stop_at) > 0 && |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 | 357 |
| 357 // Always emit a 'return undefined' in case control fell off the end of | 358 // Always emit a 'return undefined' in case control fell off the end of |
| 358 // the body. | 359 // the body. |
| 359 { | 360 { |
| 360 Comment cmnt(masm_, "[ return <undefined>;"); | 361 Comment cmnt(masm_, "[ return <undefined>;"); |
| 361 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex); | 362 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex); |
| 362 } | 363 } |
| 363 EmitReturnSequence(); | 364 EmitReturnSequence(); |
| 365 |
| 366 masm_->EmitConstantPool(); |
| 364 } | 367 } |
| 365 | 368 |
| 366 | 369 |
| 367 void FullCodeGenerator::ClearAccumulator() { | 370 void FullCodeGenerator::ClearAccumulator() { |
| 368 __ LoadSmiLiteral(r3, Smi::FromInt(0)); | 371 __ LoadSmiLiteral(r3, Smi::FromInt(0)); |
| 369 } | 372 } |
| 370 | 373 |
| 371 | 374 |
| 372 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { | 375 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 373 __ mov(r5, Operand(profiling_counter_)); | 376 __ mov(r5, Operand(profiling_counter_)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 394 Comment cmnt(masm_, "[ Back edge bookkeeping"); | 397 Comment cmnt(masm_, "[ Back edge bookkeeping"); |
| 395 Label ok; | 398 Label ok; |
| 396 | 399 |
| 397 DCHECK(back_edge_target->is_bound()); | 400 DCHECK(back_edge_target->is_bound()); |
| 398 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target) + | 401 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target) + |
| 399 kCodeSizeMultiplier / 2; | 402 kCodeSizeMultiplier / 2; |
| 400 int weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier)); | 403 int weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier)); |
| 401 EmitProfilingCounterDecrement(weight); | 404 EmitProfilingCounterDecrement(weight); |
| 402 { | 405 { |
| 403 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); | 406 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 407 Assembler::BlockConstantPoolEntrySharingScope prevent_entry_sharing(masm_); |
| 404 // BackEdgeTable::PatchAt manipulates this sequence. | 408 // BackEdgeTable::PatchAt manipulates this sequence. |
| 405 __ cmpi(r6, Operand::Zero()); | 409 __ cmpi(r6, Operand::Zero()); |
| 406 __ bc_short(ge, &ok); | 410 __ bc_short(ge, &ok); |
| 407 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); | 411 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
| 408 | 412 |
| 409 // Record a mapping of this PC offset to the OSR id. This is used to find | 413 // Record a mapping of this PC offset to the OSR id. This is used to find |
| 410 // the AST id from the unoptimized code in order to use it as a key into | 414 // the AST id from the unoptimized code in order to use it as a key into |
| 411 // the deoptimization input data found in the optimized code. | 415 // the deoptimization input data found in the optimized code. |
| 412 RecordBackEdge(stmt->OsrEntryId()); | 416 RecordBackEdge(stmt->OsrEntryId()); |
| 413 } | 417 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 arg_count++; | 470 arg_count++; |
| 467 } | 471 } |
| 468 int32_t sp_delta = arg_count * kPointerSize; | 472 int32_t sp_delta = arg_count * kPointerSize; |
| 469 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); | 473 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
| 470 __ RecordJSReturn(); | 474 __ RecordJSReturn(); |
| 471 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT, sp_delta); | 475 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT, sp_delta); |
| 472 #if V8_TARGET_ARCH_PPC64 | 476 #if V8_TARGET_ARCH_PPC64 |
| 473 // With 64bit we may need nop() instructions to ensure we have | 477 // With 64bit we may need nop() instructions to ensure we have |
| 474 // enough space to SetDebugBreakAtReturn() | 478 // enough space to SetDebugBreakAtReturn() |
| 475 if (is_int16(sp_delta)) { | 479 if (is_int16(sp_delta)) { |
| 476 masm_->nop(); | 480 if (!FLAG_enable_embedded_constant_pool) masm_->nop(); |
| 477 masm_->nop(); | 481 masm_->nop(); |
| 478 } | 482 } |
| 479 #endif | 483 #endif |
| 480 __ blr(); | 484 __ blr(); |
| 481 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); | 485 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 482 } | 486 } |
| 483 | 487 |
| 484 #ifdef DEBUG | 488 #ifdef DEBUG |
| 485 // Check that the size of the code used for returning is large enough | 489 // Check that the size of the code used for returning is large enough |
| 486 // for the debugger's requirements. | 490 // for the debugger's requirements. |
| (...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 Label l_next, l_call; | 2140 Label l_next, l_call; |
| 2137 Register load_receiver = LoadDescriptor::ReceiverRegister(); | 2141 Register load_receiver = LoadDescriptor::ReceiverRegister(); |
| 2138 Register load_name = LoadDescriptor::NameRegister(); | 2142 Register load_name = LoadDescriptor::NameRegister(); |
| 2139 | 2143 |
| 2140 // Initial send value is undefined. | 2144 // Initial send value is undefined. |
| 2141 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex); | 2145 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex); |
| 2142 __ b(&l_next); | 2146 __ b(&l_next); |
| 2143 | 2147 |
| 2144 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | 2148 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
| 2145 __ bind(&l_catch); | 2149 __ bind(&l_catch); |
| 2146 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); | |
| 2147 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" | 2150 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" |
| 2148 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter | 2151 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter |
| 2149 __ Push(load_name, r6, r3); // "throw", iter, except | 2152 __ Push(load_name, r6, r3); // "throw", iter, except |
| 2150 __ b(&l_call); | 2153 __ b(&l_call); |
| 2151 | 2154 |
| 2152 // try { received = %yield result } | 2155 // try { received = %yield result } |
| 2153 // Shuffle the received result above a try handler and yield it without | 2156 // Shuffle the received result above a try handler and yield it without |
| 2154 // re-boxing. | 2157 // re-boxing. |
| 2155 __ bind(&l_try); | 2158 __ bind(&l_try); |
| 2156 __ pop(r3); // result | 2159 __ pop(r3); // result |
| 2157 __ PushTryHandler(StackHandler::CATCH, expr->index()); | 2160 EnterTryBlock(expr->index(), &l_catch); |
| 2158 const int handler_size = StackHandlerConstants::kSize; | 2161 const int try_block_size = TryCatch::kElementCount * kPointerSize; |
| 2159 __ push(r3); // result | 2162 __ push(r3); // result |
| 2160 __ b(&l_suspend); | 2163 __ b(&l_suspend); |
| 2161 __ bind(&l_continuation); | 2164 __ bind(&l_continuation); |
| 2162 __ b(&l_resume); | 2165 __ b(&l_resume); |
| 2163 __ bind(&l_suspend); | 2166 __ bind(&l_suspend); |
| 2164 const int generator_object_depth = kPointerSize + handler_size; | 2167 const int generator_object_depth = kPointerSize + try_block_size; |
| 2165 __ LoadP(r3, MemOperand(sp, generator_object_depth)); | 2168 __ LoadP(r3, MemOperand(sp, generator_object_depth)); |
| 2166 __ push(r3); // g | 2169 __ push(r3); // g |
| 2170 __ Push(Smi::FromInt(expr->index())); // handler-index |
| 2167 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | 2171 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2168 __ LoadSmiLiteral(r4, Smi::FromInt(l_continuation.pos())); | 2172 __ LoadSmiLiteral(r4, Smi::FromInt(l_continuation.pos())); |
| 2169 __ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kContinuationOffset), | 2173 __ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kContinuationOffset), |
| 2170 r0); | 2174 r0); |
| 2171 __ StoreP(cp, FieldMemOperand(r3, JSGeneratorObject::kContextOffset), r0); | 2175 __ StoreP(cp, FieldMemOperand(r3, JSGeneratorObject::kContextOffset), r0); |
| 2172 __ mr(r4, cp); | 2176 __ mr(r4, cp); |
| 2173 __ RecordWriteField(r3, JSGeneratorObject::kContextOffset, r4, r5, | 2177 __ RecordWriteField(r3, JSGeneratorObject::kContextOffset, r4, r5, |
| 2174 kLRHasBeenSaved, kDontSaveFPRegs); | 2178 kLRHasBeenSaved, kDontSaveFPRegs); |
| 2175 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 2179 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); |
| 2176 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 2180 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2177 __ pop(r3); // result | 2181 __ pop(r3); // result |
| 2178 EmitReturnSequence(); | 2182 EmitReturnSequence(); |
| 2179 __ bind(&l_resume); // received in r3 | 2183 __ bind(&l_resume); // received in r3 |
| 2180 __ PopTryHandler(); | 2184 ExitTryBlock(expr->index()); |
| 2181 | 2185 |
| 2182 // receiver = iter; f = 'next'; arg = received; | 2186 // receiver = iter; f = 'next'; arg = received; |
| 2183 __ bind(&l_next); | 2187 __ bind(&l_next); |
| 2184 | 2188 |
| 2185 __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next" | 2189 __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next" |
| 2186 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter | 2190 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter |
| 2187 __ Push(load_name, r6, r3); // "next", iter, received | 2191 __ Push(load_name, r6, r3); // "next", iter, received |
| 2188 | 2192 |
| 2189 // result = receiver[f](arg); | 2193 // result = receiver[f](arg); |
| 2190 __ bind(&l_call); | 2194 __ bind(&l_call); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 __ SmiUntag(r6, SetRC); | 2296 __ SmiUntag(r6, SetRC); |
| 2293 | 2297 |
| 2294 // If we are sending a value and there is no operand stack, we can jump back | 2298 // If we are sending a value and there is no operand stack, we can jump back |
| 2295 // in directly. | 2299 // in directly. |
| 2296 Label call_resume; | 2300 Label call_resume; |
| 2297 if (resume_mode == JSGeneratorObject::NEXT) { | 2301 if (resume_mode == JSGeneratorObject::NEXT) { |
| 2298 Label slow_resume; | 2302 Label slow_resume; |
| 2299 __ bne(&slow_resume, cr0); | 2303 __ bne(&slow_resume, cr0); |
| 2300 __ LoadP(ip, FieldMemOperand(r7, JSFunction::kCodeEntryOffset)); | 2304 __ LoadP(ip, FieldMemOperand(r7, JSFunction::kCodeEntryOffset)); |
| 2301 { | 2305 { |
| 2306 ConstantPoolUnavailableScope constant_pool_unavailable(masm_); |
| 2307 if (FLAG_enable_embedded_constant_pool) { |
| 2308 __ LoadTargetConstantPoolPointerRegister(ip); |
| 2309 } |
| 2302 __ LoadP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset)); | 2310 __ LoadP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset)); |
| 2303 __ SmiUntag(r5); | 2311 __ SmiUntag(r5); |
| 2304 __ add(ip, ip, r5); | 2312 __ add(ip, ip, r5); |
| 2305 __ LoadSmiLiteral(r5, | 2313 __ LoadSmiLiteral(r5, |
| 2306 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); | 2314 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); |
| 2307 __ StoreP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset), | 2315 __ StoreP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset), |
| 2308 r0); | 2316 r0); |
| 2309 __ Jump(ip); | 2317 __ Jump(ip); |
| 2310 __ bind(&slow_resume); | 2318 __ bind(&slow_resume); |
| 2311 } | 2319 } |
| (...skipping 3044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5356 __ SmiUntag(r4); | 5364 __ SmiUntag(r4); |
| 5357 __ mov(ip, Operand(masm_->CodeObject())); | 5365 __ mov(ip, Operand(masm_->CodeObject())); |
| 5358 __ add(ip, ip, r4); | 5366 __ add(ip, ip, r4); |
| 5359 __ mtctr(ip); | 5367 __ mtctr(ip); |
| 5360 __ bctr(); | 5368 __ bctr(); |
| 5361 } | 5369 } |
| 5362 | 5370 |
| 5363 | 5371 |
| 5364 #undef __ | 5372 #undef __ |
| 5365 | 5373 |
| 5366 #define __ ACCESS_MASM(masm()) | |
| 5367 | |
| 5368 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( | |
| 5369 int* stack_depth, int* context_length) { | |
| 5370 // The macros used here must preserve the result register. | |
| 5371 | |
| 5372 // Because the handler block contains the context of the finally | |
| 5373 // code, we can restore it directly from there for the finally code | |
| 5374 // rather than iteratively unwinding contexts via their previous | |
| 5375 // links. | |
| 5376 __ Drop(*stack_depth); // Down to the handler block. | |
| 5377 if (*context_length > 0) { | |
| 5378 // Restore the context to its dedicated register and the stack. | |
| 5379 __ LoadP(cp, MemOperand(sp, StackHandlerConstants::kContextOffset)); | |
| 5380 __ StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 5381 } | |
| 5382 __ PopTryHandler(); | |
| 5383 __ b(finally_entry_, SetLK); | |
| 5384 | |
| 5385 *stack_depth = 0; | |
| 5386 *context_length = 0; | |
| 5387 return previous_; | |
| 5388 } | |
| 5389 | |
| 5390 #undef __ | |
| 5391 | |
| 5392 | 5374 |
| 5393 void BackEdgeTable::PatchAt(Code* unoptimized_code, Address pc, | 5375 void BackEdgeTable::PatchAt(Code* unoptimized_code, Address pc, |
| 5394 BackEdgeState target_state, | 5376 BackEdgeState target_state, |
| 5395 Code* replacement_code) { | 5377 Code* replacement_code) { |
| 5396 Address mov_address = Assembler::target_address_from_return_address(pc); | 5378 Address mov_address = Assembler::target_address_from_return_address(pc); |
| 5397 Address cmp_address = mov_address - 2 * Assembler::kInstrSize; | 5379 Address cmp_address = mov_address - 2 * Assembler::kInstrSize; |
| 5398 CodePatcher patcher(cmp_address, 1); | 5380 CodePatcher patcher(cmp_address, 1); |
| 5399 | 5381 |
| 5400 switch (target_state) { | 5382 switch (target_state) { |
| 5401 case INTERRUPT: { | 5383 case INTERRUPT: { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5454 return ON_STACK_REPLACEMENT; | 5436 return ON_STACK_REPLACEMENT; |
| 5455 } | 5437 } |
| 5456 | 5438 |
| 5457 DCHECK(interrupt_address == | 5439 DCHECK(interrupt_address == |
| 5458 isolate->builtins()->OsrAfterStackCheck()->entry()); | 5440 isolate->builtins()->OsrAfterStackCheck()->entry()); |
| 5459 return OSR_AFTER_STACK_CHECK; | 5441 return OSR_AFTER_STACK_CHECK; |
| 5460 } | 5442 } |
| 5461 } | 5443 } |
| 5462 } // namespace v8::internal | 5444 } // namespace v8::internal |
| 5463 #endif // V8_TARGET_ARCH_PPC | 5445 #endif // V8_TARGET_ARCH_PPC |
| OLD | NEW |