Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 7273066: Simplify EmitCallIC. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8-counters.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 void EmitJumpIfSmi(Register reg, 73 void EmitJumpIfSmi(Register reg,
74 Label* target, 74 Label* target,
75 Label::Distance near_jump = Label::kFar) { 75 Label::Distance near_jump = Label::kFar) {
76 __ testb(reg, Immediate(kSmiTagMask)); 76 __ testb(reg, Immediate(kSmiTagMask));
77 EmitJump(carry, target, near_jump); // Never taken before patched. 77 EmitJump(carry, target, near_jump); // Never taken before patched.
78 } 78 }
79 79
80 void EmitPatchInfo() { 80 void EmitPatchInfo() {
81 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); 81 if (patch_site_.is_bound()) {
82 ASSERT(is_int8(delta_to_patch_site)); 82 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_);
83 __ testl(rax, Immediate(delta_to_patch_site)); 83 ASSERT(is_int8(delta_to_patch_site));
84 __ testl(rax, Immediate(delta_to_patch_site));
84 #ifdef DEBUG 85 #ifdef DEBUG
85 info_emitted_ = true; 86 info_emitted_ = true;
86 #endif 87 #endif
88 } else {
89 __ nop(); // Signals no inlined code.
90 }
87 } 91 }
88 92
89 bool is_bound() const { return patch_site_.is_bound(); }
90
91 private: 93 private:
92 // jc will be patched with jz, jnc will become jnz. 94 // jc will be patched with jz, jnc will become jnz.
93 void EmitJump(Condition cc, Label* target, Label::Distance near_jump) { 95 void EmitJump(Condition cc, Label* target, Label::Distance near_jump) {
94 ASSERT(!patch_site_.is_bound() && !info_emitted_); 96 ASSERT(!patch_site_.is_bound() && !info_emitted_);
95 ASSERT(cc == carry || cc == not_carry); 97 ASSERT(cc == carry || cc == not_carry);
96 __ bind(&patch_site_); 98 __ bind(&patch_site_);
97 __ j(cc, target, near_jump); 99 __ j(cc, target, near_jump);
98 } 100 }
99 101
100 MacroAssembler* masm_; 102 MacroAssembler* masm_;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 __ cmpq(rdx, rax); 817 __ cmpq(rdx, rax);
816 __ j(not_equal, &next_test); 818 __ j(not_equal, &next_test);
817 __ Drop(1); // Switch value is no longer needed. 819 __ Drop(1); // Switch value is no longer needed.
818 __ jmp(clause->body_target()); 820 __ jmp(clause->body_target());
819 __ bind(&slow_case); 821 __ bind(&slow_case);
820 } 822 }
821 823
822 // Record position before stub call for type feedback. 824 // Record position before stub call for type feedback.
823 SetSourcePosition(clause->position()); 825 SetSourcePosition(clause->position());
824 Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); 826 Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT);
825 EmitCallIC(ic, &patch_site, clause->CompareId()); 827 EmitCallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId());
828 patch_site.EmitPatchInfo();
826 829
827 __ testq(rax, rax); 830 __ testq(rax, rax);
828 __ j(not_equal, &next_test); 831 __ j(not_equal, &next_test);
829 __ Drop(1); // Switch value is no longer needed. 832 __ Drop(1); // Switch value is no longer needed.
830 __ jmp(clause->body_target()); 833 __ jmp(clause->body_target());
831 } 834 }
832 835
833 // Discard the test value and jump to the default if present, otherwise to 836 // Discard the test value and jump to the default if present, otherwise to
834 // the end of the statement. 837 // the end of the statement.
835 __ bind(&next_test); 838 __ bind(&next_test);
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 Label done, stub_call, smi_case; 1632 Label done, stub_call, smi_case;
1630 __ pop(rdx); 1633 __ pop(rdx);
1631 __ movq(rcx, rax); 1634 __ movq(rcx, rax);
1632 __ or_(rax, rdx); 1635 __ or_(rax, rdx);
1633 JumpPatchSite patch_site(masm_); 1636 JumpPatchSite patch_site(masm_);
1634 patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear); 1637 patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear);
1635 1638
1636 __ bind(&stub_call); 1639 __ bind(&stub_call);
1637 __ movq(rax, rcx); 1640 __ movq(rax, rcx);
1638 BinaryOpStub stub(op, mode); 1641 BinaryOpStub stub(op, mode);
1639 EmitCallIC(stub.GetCode(), &patch_site, expr->id()); 1642 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id());
1643 patch_site.EmitPatchInfo();
1640 __ jmp(&done, Label::kNear); 1644 __ jmp(&done, Label::kNear);
1641 1645
1642 __ bind(&smi_case); 1646 __ bind(&smi_case);
1643 switch (op) { 1647 switch (op) {
1644 case Token::SAR: 1648 case Token::SAR:
1645 __ SmiShiftArithmeticRight(rax, rdx, rcx); 1649 __ SmiShiftArithmeticRight(rax, rdx, rcx);
1646 break; 1650 break;
1647 case Token::SHL: 1651 case Token::SHL:
1648 __ SmiShiftLeft(rax, rdx, rcx); 1652 __ SmiShiftLeft(rax, rdx, rcx);
1649 break; 1653 break;
(...skipping 26 matching lines...) Expand all
1676 __ bind(&done); 1680 __ bind(&done);
1677 context()->Plug(rax); 1681 context()->Plug(rax);
1678 } 1682 }
1679 1683
1680 1684
1681 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, 1685 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr,
1682 Token::Value op, 1686 Token::Value op,
1683 OverwriteMode mode) { 1687 OverwriteMode mode) {
1684 __ pop(rdx); 1688 __ pop(rdx);
1685 BinaryOpStub stub(op, mode); 1689 BinaryOpStub stub(op, mode);
1686 // NULL signals no inlined smi code. 1690 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code.
1687 EmitCallIC(stub.GetCode(), NULL, expr->id()); 1691 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id());
1692 patch_site.EmitPatchInfo();
1688 context()->Plug(rax); 1693 context()->Plug(rax);
1689 } 1694 }
1690 1695
1691 1696
1692 void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { 1697 void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) {
1693 // Invalid left-hand sides are rewritten to have a 'throw 1698 // Invalid left-hand sides are rewritten to have a 'throw
1694 // ReferenceError' on the left-hand side. 1699 // ReferenceError' on the left-hand side.
1695 if (!expr->IsValidLeftHandSide()) { 1700 if (!expr->IsValidLeftHandSide()) {
1696 VisitForEffect(expr); 1701 VisitForEffect(expr);
1697 return; 1702 return;
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 SetSourcePosition(expr->position()); 3793 SetSourcePosition(expr->position());
3789 3794
3790 // Call stub for +1/-1. 3795 // Call stub for +1/-1.
3791 BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); 3796 BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE);
3792 if (expr->op() == Token::INC) { 3797 if (expr->op() == Token::INC) {
3793 __ Move(rdx, Smi::FromInt(1)); 3798 __ Move(rdx, Smi::FromInt(1));
3794 } else { 3799 } else {
3795 __ movq(rdx, rax); 3800 __ movq(rdx, rax);
3796 __ Move(rax, Smi::FromInt(1)); 3801 __ Move(rax, Smi::FromInt(1));
3797 } 3802 }
3798 EmitCallIC(stub.GetCode(), &patch_site, expr->CountId()); 3803 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->CountId());
3804 patch_site.EmitPatchInfo();
3799 __ bind(&done); 3805 __ bind(&done);
3800 3806
3801 // Store the value returned in rax. 3807 // Store the value returned in rax.
3802 switch (assign_type) { 3808 switch (assign_type) {
3803 case VARIABLE: 3809 case VARIABLE:
3804 if (expr->is_postfix()) { 3810 if (expr->is_postfix()) {
3805 // Perform the assignment as if via '='. 3811 // Perform the assignment as if via '='.
3806 { EffectContext context(this); 3812 { EffectContext context(this);
3807 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), 3813 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
3808 Token::ASSIGN); 3814 Token::ASSIGN);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4060 __ or_(rcx, rax); 4066 __ or_(rcx, rax);
4061 patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear); 4067 patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear);
4062 __ cmpq(rdx, rax); 4068 __ cmpq(rdx, rax);
4063 Split(cc, if_true, if_false, NULL); 4069 Split(cc, if_true, if_false, NULL);
4064 __ bind(&slow_case); 4070 __ bind(&slow_case);
4065 } 4071 }
4066 4072
4067 // Record position and call the compare IC. 4073 // Record position and call the compare IC.
4068 SetSourcePosition(expr->position()); 4074 SetSourcePosition(expr->position());
4069 Handle<Code> ic = CompareIC::GetUninitialized(op); 4075 Handle<Code> ic = CompareIC::GetUninitialized(op);
4070 EmitCallIC(ic, &patch_site, expr->id()); 4076 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
4077 patch_site.EmitPatchInfo();
4071 4078
4072 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); 4079 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4073 __ testq(rax, rax); 4080 __ testq(rax, rax);
4074 Split(cc, if_true, if_false, fall_through); 4081 Split(cc, if_true, if_false, fall_through);
4075 } 4082 }
4076 } 4083 }
4077 4084
4078 // Convert the result of the comparison into one expected for this 4085 // Convert the result of the comparison into one expected for this
4079 // expression's context. 4086 // expression's context.
4080 context()->Plug(if_true, if_false); 4087 context()->Plug(if_true, if_false);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4124 Register FullCodeGenerator::context_register() { 4131 Register FullCodeGenerator::context_register() {
4125 return rsi; 4132 return rsi;
4126 } 4133 }
4127 4134
4128 4135
4129 void FullCodeGenerator::EmitCallIC(Handle<Code> ic, 4136 void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4130 RelocInfo::Mode mode, 4137 RelocInfo::Mode mode,
4131 unsigned ast_id) { 4138 unsigned ast_id) {
4132 ASSERT(mode == RelocInfo::CODE_TARGET || 4139 ASSERT(mode == RelocInfo::CODE_TARGET ||
4133 mode == RelocInfo::CODE_TARGET_CONTEXT); 4140 mode == RelocInfo::CODE_TARGET_CONTEXT);
4134 Counters* counters = isolate()->counters();
4135 switch (ic->kind()) {
4136 case Code::LOAD_IC:
4137 __ IncrementCounter(counters->named_load_full(), 1);
4138 break;
4139 case Code::KEYED_LOAD_IC:
4140 __ IncrementCounter(counters->keyed_load_full(), 1);
4141 break;
4142 case Code::STORE_IC:
4143 __ IncrementCounter(counters->named_store_full(), 1);
4144 break;
4145 case Code::KEYED_STORE_IC:
4146 __ IncrementCounter(counters->keyed_store_full(), 1);
4147 default:
4148 break;
4149 }
4150 __ call(ic, mode, ast_id); 4141 __ call(ic, mode, ast_id);
4151 } 4142 }
4152 4143
4153 4144
4154 void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4155 JumpPatchSite* patch_site,
4156 unsigned ast_id) {
4157 Counters* counters = isolate()->counters();
4158 switch (ic->kind()) {
4159 case Code::LOAD_IC:
4160 __ IncrementCounter(counters->named_load_full(), 1);
4161 break;
4162 case Code::KEYED_LOAD_IC:
4163 __ IncrementCounter(counters->keyed_load_full(), 1);
4164 break;
4165 case Code::STORE_IC:
4166 __ IncrementCounter(counters->named_store_full(), 1);
4167 break;
4168 case Code::KEYED_STORE_IC:
4169 __ IncrementCounter(counters->keyed_store_full(), 1);
4170 default:
4171 break;
4172 }
4173 __ call(ic, RelocInfo::CODE_TARGET, ast_id);
4174 if (patch_site != NULL && patch_site->is_bound()) {
4175 patch_site->EmitPatchInfo();
4176 } else {
4177 __ nop(); // Signals no inlined code.
4178 }
4179 }
4180
4181
4182 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { 4145 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
4183 ASSERT(IsAligned(frame_offset, kPointerSize)); 4146 ASSERT(IsAligned(frame_offset, kPointerSize));
4184 __ movq(Operand(rbp, frame_offset), value); 4147 __ movq(Operand(rbp, frame_offset), value);
4185 } 4148 }
4186 4149
4187 4150
4188 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { 4151 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
4189 __ movq(dst, ContextOperand(rsi, context_index)); 4152 __ movq(dst, ContextOperand(rsi, context_index));
4190 } 4153 }
4191 4154
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4242 __ ret(0); 4205 __ ret(0);
4243 } 4206 }
4244 4207
4245 4208
4246 #undef __ 4209 #undef __
4247 4210
4248 4211
4249 } } // namespace v8::internal 4212 } } // namespace v8::internal
4250 4213
4251 #endif // V8_TARGET_ARCH_X64 4214 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/v8-counters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698