From: haitao.feng@intel.com Date: Fri, 2 Aug 2013 13:42:02 +0000 (+0000) Subject: Introduce PopReturnAddressTo and PushReturnAddressFrom macro-assembler instructions... X-Git-Tag: upstream/4.7.83~13067 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dfda85a91aa7f528f34516b38354c5b815101054;p=platform%2Fupstream%2Fv8.git Introduce PopReturnAddressTo and PushReturnAddressFrom macro-assembler instructions for X64 R=danno@chromium.org Review URL: https://codereview.chromium.org/21477002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16034 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc index fe867ea..18a6e56 100644 --- a/src/x64/builtins-x64.cc +++ b/src/x64/builtins-x64.cc @@ -59,9 +59,9 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, int num_extra_args = 0; if (extra_args == NEEDS_CALLED_FUNCTION) { num_extra_args = 1; - __ pop(kScratchRegister); // Save return address. + __ PopReturnAddressTo(kScratchRegister); __ push(rdi); - __ push(kScratchRegister); // Restore return address. + __ PushReturnAddressFrom(kScratchRegister); } else { ASSERT(extra_args == NO_EXTRA_ARGUMENTS); } @@ -429,10 +429,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, } // Remove caller arguments from the stack and return. - __ pop(rcx); + __ PopReturnAddressTo(rcx); SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); - __ push(rcx); + __ PushReturnAddressFrom(rcx); Counters* counters = masm->isolate()->counters(); __ IncrementCounter(counters->constructed_objects(), 1); __ ret(0); @@ -772,9 +772,9 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) { { Label done; __ testq(rax, rax); __ j(not_zero, &done); - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ Push(masm->isolate()->factory()->undefined_value()); - __ push(rbx); + __ PushReturnAddressFrom(rbx); __ incq(rax); __ bind(&done); } @@ -895,9 +895,9 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) { __ cmpq(rdx, Immediate(1)); __ j(not_equal, &non_proxy); - __ pop(rdx); // return address + __ PopReturnAddressTo(rdx); __ push(rdi); // re-add proxy object as additional argument - __ push(rdx); + __ PushReturnAddressFrom(rdx); __ incq(rax); __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), @@ -1182,9 +1182,9 @@ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { __ testq(rax, rax); __ j(zero, &no_arguments); __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0)); - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ lea(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); - __ push(rcx); + __ PushReturnAddressFrom(rcx); __ movq(rax, rbx); // Lookup the argument in the number to string cache. @@ -1268,9 +1268,9 @@ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { // stack, and jump back to the case where the argument is a string. __ bind(&no_arguments); __ LoadRoot(rbx, Heap::kempty_stringRootIndex); - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ lea(rsp, Operand(rsp, kPointerSize)); - __ push(rcx); + __ PushReturnAddressFrom(rcx); __ jmp(&argument_is_string); // At this point the argument is already a string. Call runtime to @@ -1313,10 +1313,10 @@ static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { __ pop(rbp); // Remove caller arguments from the stack. - __ pop(rcx); + __ PopReturnAddressTo(rcx); SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); - __ push(rcx); + __ PushReturnAddressFrom(rcx); } diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index 83c9e38..76479d3 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -430,12 +430,12 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) { // Create a new closure through the slower runtime call. __ bind(&gc); - __ pop(rcx); // Temporarily remove return address. + __ PopReturnAddressTo(rcx); __ pop(rdx); __ push(rsi); __ push(rdx); __ PushRoot(Heap::kFalseValueRootIndex); - __ push(rcx); // Restore return address. + __ PushReturnAddressFrom(rcx); __ TailCallRuntime(Runtime::kNewClosure, 3, 1); } @@ -694,13 +694,13 @@ void BinaryOpStub::Initialize() {} void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { - __ pop(rcx); // Save return address. + __ PopReturnAddressTo(rcx); __ push(rdx); __ push(rax); // Left and right arguments are now on top. __ Push(Smi::FromInt(MinorKey())); - __ push(rcx); // Push return address. + __ PushReturnAddressFrom(rcx); // Patch the caller to an appropriate specialized stub and return the // operation result to the caller of the stub. @@ -982,10 +982,10 @@ static void BinaryOpStub_GenerateRegisterArgsPushUnderReturn( MacroAssembler* masm) { // Push arguments, but ensure they are under the return address // for a tail call. - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ push(rdx); __ push(rax); - __ push(rcx); + __ PushReturnAddressFrom(rcx); } @@ -2153,10 +2153,10 @@ void StoreArrayLengthStub::Generate(MacroAssembler* masm) { __ JumpIfNotSmi(value, &miss); // Prepare tail call to StoreIC_ArrayLength. - __ pop(scratch); + __ PopReturnAddressTo(scratch); __ push(receiver); __ push(value); - __ push(scratch); // return address + __ PushReturnAddressFrom(scratch); ExternalReference ref = ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); @@ -2222,9 +2222,9 @@ void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { // Slow-case: Handle non-smi or out-of-bounds access to arguments // by calling the runtime system. __ bind(&slow); - __ pop(rbx); // Return address. + __ PopReturnAddressTo(rbx); __ push(rdx); - __ push(rbx); + __ PushReturnAddressFrom(rbx); __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); } @@ -3484,7 +3484,7 @@ void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { } // Push arguments below the return address to prepare jump to builtin. - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ push(rdx); __ push(rax); @@ -3497,8 +3497,7 @@ void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { __ Push(Smi::FromInt(NegativeComparisonResult(cc))); } - // Restore return address on the stack. - __ push(rcx); + __ PushReturnAddressFrom(rcx); // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) // tagged as a small integer. @@ -3667,9 +3666,9 @@ void CallFunctionStub::Generate(MacroAssembler* masm) { // Check for function proxy. __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); __ j(not_equal, &non_function); - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ push(rdi); // put proxy as additional argument under return address - __ push(rcx); + __ PushReturnAddressFrom(rcx); __ Set(rax, argc_ + 1); __ Set(rbx, 0); __ SetCallKind(rcx, CALL_AS_METHOD); @@ -4347,9 +4346,9 @@ void InstanceofStub::Generate(MacroAssembler* masm) { __ bind(&slow); if (HasCallSiteInlineCheck()) { // Remove extra value from the stack. - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ pop(rax); - __ push(rcx); + __ PushReturnAddressFrom(rcx); } __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); } @@ -4820,10 +4819,10 @@ void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, Register temp) { - __ pop(temp); + __ PopReturnAddressTo(temp); __ pop(rdx); __ pop(rax); - __ push(temp); + __ PushReturnAddressFrom(temp); } @@ -5527,9 +5526,9 @@ void StringCompareStub::Generate(MacroAssembler* masm) { // Inline comparison of ASCII strings. __ IncrementCounter(counters->string_compare_native(), 1); // Drop arguments from the stack - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ addq(rsp, Immediate(2 * kPointerSize)); - __ push(rcx); + __ PushReturnAddressFrom(rcx); GenerateCompareFlatAsciiStrings(masm, rdx, rax, rcx, rbx, rdi, r8); // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) @@ -5798,10 +5797,10 @@ void ICCompareStub::GenerateStrings(MacroAssembler* masm) { // Handle more complex cases in runtime. __ bind(&runtime); - __ pop(tmp1); // Return address. + __ PopReturnAddressTo(tmp1); __ push(left); __ push(right); - __ push(tmp1); + __ PushReturnAddressFrom(tmp1); if (equality) { __ TailCallRuntime(Runtime::kStringEquals, 2, 1); } else { @@ -6409,16 +6408,14 @@ void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { // the runtime. __ bind(&slow_elements); - __ pop(rdi); // Pop return address and remember to put back later for tail - // call. + __ PopReturnAddressTo(rdi); __ push(rbx); __ push(rcx); __ push(rax); __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); __ push(rdx); - __ push(rdi); // Return return address so that tail call returns to right - // place. + __ PushReturnAddressFrom(rdi); __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object. @@ -6465,7 +6462,7 @@ void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; __ movq(rbx, MemOperand(rbp, parameter_count_offset)); masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); - __ pop(rcx); + __ PopReturnAddressTo(rcx); int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 68301ec..f3e5a50 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -4816,7 +4816,7 @@ void FullCodeGenerator::EnterFinallyBlock() { ASSERT(!result_register().is(rdx)); ASSERT(!result_register().is(rcx)); // Cook return address on top of stack (smi encoded Code* delta) - __ pop(rdx); + __ PopReturnAddressTo(rdx); __ Move(rcx, masm_->CodeObject()); __ subq(rdx, rcx); __ Integer32ToSmi(rdx, rdx); diff --git a/src/x64/ic-x64.cc b/src/x64/ic-x64.cc index 6e238c7..4837b9a 100644 --- a/src/x64/ic-x64.cc +++ b/src/x64/ic-x64.cc @@ -570,10 +570,10 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) { __ j(not_zero, &slow); // Everything is fine, call runtime. - __ pop(rcx); + __ PopReturnAddressTo(rcx); __ push(rdx); // receiver __ push(rax); // key - __ push(rcx); // return address + __ PushReturnAddressFrom(rcx); // Perform tail call to the entry. __ TailCallExternalReference( @@ -1369,10 +1369,10 @@ void LoadIC::GenerateMiss(MacroAssembler* masm) { Counters* counters = masm->isolate()->counters(); __ IncrementCounter(counters->load_miss(), 1); - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rax); // receiver __ push(rcx); // name - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Perform tail call to the entry. ExternalReference ref = @@ -1388,10 +1388,10 @@ void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rax); // receiver __ push(rcx); // name - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Perform tail call to the entry. __ TailCallRuntime(Runtime::kGetProperty, 2, 1); @@ -1408,10 +1408,10 @@ void KeyedLoadIC::GenerateMiss(MacroAssembler* masm, ICMissMode miss_mode) { Counters* counters = masm->isolate()->counters(); __ IncrementCounter(counters->keyed_load_miss(), 1); - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rax); // name - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Perform tail call to the entry. ExternalReference ref = miss_mode == MISS_FORCE_GENERIC @@ -1429,10 +1429,10 @@ void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rax); // name - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Perform tail call to the entry. __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1); @@ -1468,11 +1468,11 @@ void StoreIC::GenerateMiss(MacroAssembler* masm) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rcx); // name __ push(rax); // value - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Perform tail call to the entry. ExternalReference ref = @@ -1512,13 +1512,13 @@ void StoreIC::GenerateRuntimeSetProperty(MacroAssembler* masm, // -- rdx : receiver // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); __ push(rcx); __ push(rax); __ Push(Smi::FromInt(NONE)); // PropertyAttributes __ Push(Smi::FromInt(strict_mode)); - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Do tail-call to runtime routine. __ TailCallRuntime(Runtime::kSetProperty, 5, 1); @@ -1534,13 +1534,13 @@ void KeyedStoreIC::GenerateRuntimeSetProperty(MacroAssembler* masm, // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rcx); // key __ push(rax); // value __ Push(Smi::FromInt(NONE)); // PropertyAttributes __ Push(Smi::FromInt(strict_mode)); // Strict mode. - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Do tail-call to runtime routine. __ TailCallRuntime(Runtime::kSetProperty, 5, 1); @@ -1555,11 +1555,11 @@ void StoreIC::GenerateSlow(MacroAssembler* masm) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rcx); // key __ push(rax); // value - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Do tail-call to runtime routine. ExternalReference ref(IC_Utility(kStoreIC_Slow), masm->isolate()); @@ -1575,11 +1575,11 @@ void KeyedStoreIC::GenerateSlow(MacroAssembler* masm) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rcx); // key __ push(rax); // value - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Do tail-call to runtime routine. ExternalReference ref(IC_Utility(kKeyedStoreIC_Slow), masm->isolate()); @@ -1595,11 +1595,11 @@ void KeyedStoreIC::GenerateMiss(MacroAssembler* masm, ICMissMode miss_mode) { // -- rsp[0] : return address // ----------------------------------- - __ pop(rbx); + __ PopReturnAddressTo(rbx); __ push(rdx); // receiver __ push(rcx); // key __ push(rax); // value - __ push(rbx); // return address + __ PushReturnAddressFrom(rbx); // Do tail-call to runtime routine. ExternalReference ref = miss_mode == MISS_FORCE_GENERIC diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 5682ae8..dbdc12e 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -2568,7 +2568,7 @@ void LCodeGen::DoReturn(LReturn* instr) { // The argument count parameter is a smi __ SmiToInteger32(reg, reg); Register return_addr_reg = reg.is(rcx) ? rbx : rcx; - __ pop(return_addr_reg); + __ PopReturnAddressTo(return_addr_reg); __ shl(reg, Immediate(kPointerSizeLog2)); __ addq(rsp, reg); __ jmp(return_addr_reg); diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index 762bc35..68f0613 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -2799,9 +2799,9 @@ void MacroAssembler::Ret(int bytes_dropped, Register scratch) { if (is_uint16(bytes_dropped)) { ret(bytes_dropped); } else { - pop(scratch); + PopReturnAddressTo(scratch); addq(rsp, Immediate(bytes_dropped)); - push(scratch); + PushReturnAddressFrom(scratch); ret(0); } } @@ -3568,8 +3568,7 @@ void MacroAssembler::LeaveExitFrame(bool save_doubles) { // from the caller stack. lea(rsp, Operand(r15, 1 * kPointerSize)); - // Push the return address to get ready to return. - push(rcx); + PushReturnAddressFrom(rcx); LeaveExitFrameEpilogue(); } diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h index b07e08c..ca13ca3 100644 --- a/src/x64/macro-assembler-x64.h +++ b/src/x64/macro-assembler-x64.h @@ -823,6 +823,8 @@ class MacroAssembler: public Assembler { void Drop(int stack_elements); void Call(Label* target) { call(target); } + void PushReturnAddressFrom(Register src) { push(src); } + void PopReturnAddressTo(Register dst) { pop(dst); } // Control Flow void Jump(Address destination, RelocInfo::Mode rmode); diff --git a/src/x64/stub-cache-x64.cc b/src/x64/stub-cache-x64.cc index 0f72add..7ad250a 100644 --- a/src/x64/stub-cache-x64.cc +++ b/src/x64/stub-cache-x64.cc @@ -830,11 +830,11 @@ void BaseStoreStubCompiler::GenerateStoreTransition(MacroAssembler* masm, object->map()->unused_property_fields() == 0) { // The properties must be extended before we can store the value. // We jump to a runtime call that extends the properties array. - __ pop(scratch1); // Return address. + __ PopReturnAddressTo(scratch1); __ push(receiver_reg); __ Push(transition); __ push(value_reg); - __ push(scratch1); + __ PushReturnAddressFrom(scratch1); __ TailCallExternalReference( ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage), masm->isolate()), @@ -1284,7 +1284,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback( Handle callback) { // Insert additional parameters into the stack frame above return address. ASSERT(!scratch4().is(reg)); - __ pop(scratch4()); // Get return address to place it below. + __ PopReturnAddressTo(scratch4()); __ push(receiver()); // receiver __ push(reg); // holder @@ -1324,7 +1324,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback( ASSERT(!name_arg.is(scratch4())); __ movq(name_arg, rsp); - __ push(scratch4()); // Restore return address. + __ PushReturnAddressFrom(scratch4()); // v8::Arguments::values_ and handler for name. const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1; @@ -1444,10 +1444,10 @@ void BaseLoadStubCompiler::GenerateLoadInterceptor( } else { // !compile_followup_inline // Call the runtime system to load the interceptor. // Check that the maps haven't changed. - __ pop(scratch2()); // save old return address + __ PopReturnAddressTo(scratch2()); PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(), interceptor_holder); - __ push(scratch2()); // restore old return address + __ PushReturnAddressFrom(scratch2()); ExternalReference ref = ExternalReference( IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), isolate()); @@ -2650,12 +2650,12 @@ Handle StoreStubCompiler::CompileStoreCallback( HandlerFrontend(object, receiver(), holder, name, &success); __ bind(&success); - __ pop(scratch1()); // remove the return address + __ PopReturnAddressTo(scratch1()); __ push(receiver()); __ Push(callback); // callback info __ Push(name); __ push(value()); - __ push(scratch1()); // restore return address + __ PushReturnAddressFrom(scratch1()); // Do tail-call to the runtime system. ExternalReference store_callback_property = @@ -2717,12 +2717,12 @@ void StoreStubCompiler::GenerateStoreViaSetter( Handle StoreStubCompiler::CompileStoreInterceptor( Handle object, Handle name) { - __ pop(scratch1()); // remove the return address + __ PopReturnAddressTo(scratch1()); __ push(receiver()); __ push(this->name()); __ push(value()); __ Push(Smi::FromInt(strict_mode())); - __ push(scratch1()); // restore return address + __ PushReturnAddressFrom(scratch1()); // Do tail-call to the runtime system. ExternalReference store_ic_property =