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

Side by Side Diff: src/hydrogen.cc

Issue 17229005: Convert UnaryOpStub to a HydrogenCodeStub (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 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/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 HValue* context = environment()->LookupContext(); 996 HValue* context = environment()->LookupContext();
997 int num_parameters = graph()->info()->num_parameters(); 997 int num_parameters = graph()->info()->num_parameters();
998 HValue* params = Add<HConstant>(num_parameters); 998 HValue* params = Add<HConstant>(num_parameters);
999 HReturn* return_instruction = new(graph()->zone()) 999 HReturn* return_instruction = new(graph()->zone())
1000 HReturn(value, context, params); 1000 HReturn(value, context, params);
1001 current_block()->FinishExit(return_instruction); 1001 current_block()->FinishExit(return_instruction);
1002 return return_instruction; 1002 return return_instruction;
1003 } 1003 }
1004 1004
1005 1005
1006 void HGraphBuilder::AddSoftDeoptimize() {
1007 isolate()->counters()->soft_deopts_requested()->Increment();
1008 if (FLAG_always_opt) return;
1009 if (current_block()->IsDeoptimizing()) return;
1010 Add<HSoftDeoptimize>();
1011 isolate()->counters()->soft_deopts_inserted()->Increment();
1012 current_block()->MarkAsDeoptimizing();
1013 graph()->set_has_soft_deoptimize(true);
1014 }
1015
1016
1006 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { 1017 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) {
1007 HBasicBlock* b = graph()->CreateBasicBlock(); 1018 HBasicBlock* b = graph()->CreateBasicBlock();
1008 b->SetInitialEnvironment(env); 1019 b->SetInitialEnvironment(env);
1009 return b; 1020 return b;
1010 } 1021 }
1011 1022
1012 1023
1013 HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() { 1024 HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() {
1014 HBasicBlock* header = graph()->CreateBasicBlock(); 1025 HBasicBlock* header = graph()->CreateBasicBlock();
1015 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header); 1026 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header);
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 HInstruction* value = Add<HLoadKeyed>(boilerplate_elements, key_constant, 1656 HInstruction* value = Add<HLoadKeyed>(boilerplate_elements, key_constant,
1646 static_cast<HValue*>(NULL), kind); 1657 static_cast<HValue*>(NULL), kind);
1647 Add<HStoreKeyed>(object_elements, key_constant, value, kind); 1658 Add<HStoreKeyed>(object_elements, key_constant, value, kind);
1648 } 1659 }
1649 } 1660 }
1650 1661
1651 return object; 1662 return object;
1652 } 1663 }
1653 1664
1654 1665
1666 HInstruction* HGraphBuilder::BuildUnaryMathOp(
1667 HValue* input, Handle<Type> type, Token::Value operation) {
1668 // We only handle the numeric cases here
1669 type = handle(
1670 Type::Intersect(type, handle(Type::Number(), isolate())), isolate());
1671
1672 switch (operation) {
1673 default:
1674 UNREACHABLE();
1675 case Token::SUB: {
1676 HInstruction* instr =
1677 HMul::New(zone(), environment()->LookupContext(),
1678 input, graph()->GetConstantMinus1());
1679 Representation rep = Representation::FromType(type);
1680 if (type->Is(Type::None())) {
1681 AddSoftDeoptimize();
1682 }
1683 if (instr->IsBinaryOperation()) {
1684 HBinaryOperation* binop = HBinaryOperation::cast(instr);
1685 binop->set_observed_input_representation(1, rep);
1686 binop->set_observed_input_representation(2, rep);
1687 }
1688 return instr;
1689 }
1690 case Token::BIT_NOT:
1691 if (type->Is(Type::None())) {
1692 AddSoftDeoptimize();
1693 }
1694 return new(zone()) HBitNot(input);
1695 }
1696 }
1697
1698
1655 void HGraphBuilder::BuildCompareNil( 1699 void HGraphBuilder::BuildCompareNil(
1656 HValue* value, 1700 HValue* value,
1657 Handle<Type> type, 1701 Handle<Type> type,
1658 int position, 1702 int position,
1659 HIfContinuation* continuation) { 1703 HIfContinuation* continuation) {
1660 IfBuilder if_nil(this, position); 1704 IfBuilder if_nil(this, position);
1661 bool needs_or = false; 1705 bool needs_or = false;
1662 if (type->Maybe(Type::Null())) { 1706 if (type->Maybe(Type::Null())) {
1663 if (needs_or) if_nil.Or(); 1707 if (needs_or) if_nil.Or();
1664 if_nil.If<HCompareObjectEqAndBranch>(value, graph()->GetConstantNull()); 1708 if_nil.If<HCompareObjectEqAndBranch>(value, graph()->GetConstantNull());
(...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 } 4268 }
4225 } 4269 }
4226 4270
4227 4271
4228 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { 4272 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) {
4229 Push(instr); 4273 Push(instr);
4230 AddInstruction(instr); 4274 AddInstruction(instr);
4231 } 4275 }
4232 4276
4233 4277
4234 void HOptimizedGraphBuilder::AddSoftDeoptimize() {
4235 isolate()->counters()->soft_deopts_requested()->Increment();
4236 if (FLAG_always_opt) return;
4237 if (current_block()->IsDeoptimizing()) return;
4238 Add<HSoftDeoptimize>();
4239 isolate()->counters()->soft_deopts_inserted()->Increment();
4240 current_block()->MarkAsDeoptimizing();
4241 graph()->set_has_soft_deoptimize(true);
4242 }
4243
4244
4245 template <class Instruction> 4278 template <class Instruction>
4246 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { 4279 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) {
4247 int count = call->argument_count(); 4280 int count = call->argument_count();
4248 ZoneList<HValue*> arguments(count, zone()); 4281 ZoneList<HValue*> arguments(count, zone());
4249 for (int i = 0; i < count; ++i) { 4282 for (int i = 0; i < count; ++i) {
4250 arguments.Add(Pop(), zone()); 4283 arguments.Add(Pop(), zone());
4251 } 4284 }
4252 4285
4253 while (!arguments.is_empty()) { 4286 while (!arguments.is_empty()) {
4254 Add<HPushArgument>(arguments.RemoveLast()); 4287 Add<HPushArgument>(arguments.RemoveLast());
(...skipping 4264 matching lines...) Expand 10 before | Expand all | Expand 10 after
8519 HValue* value = Pop(); 8552 HValue* value = Pop();
8520 HValue* context = environment()->LookupContext(); 8553 HValue* context = environment()->LookupContext();
8521 HInstruction* instr = new(zone()) HTypeof(context, value); 8554 HInstruction* instr = new(zone()) HTypeof(context, value);
8522 return ast_context()->ReturnInstruction(instr, expr->id()); 8555 return ast_context()->ReturnInstruction(instr, expr->id());
8523 } 8556 }
8524 8557
8525 8558
8526 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { 8559 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) {
8527 CHECK_ALIVE(VisitForValue(expr->expression())); 8560 CHECK_ALIVE(VisitForValue(expr->expression()));
8528 HValue* value = Pop(); 8561 HValue* value = Pop();
8529 HValue* context = environment()->LookupContext();
8530 HInstruction* instr =
8531 HMul::New(zone(), context, value, graph()->GetConstantMinus1());
8532 Handle<Type> operand_type = expr->expression()->lower_type(); 8562 Handle<Type> operand_type = expr->expression()->lower_type();
8533 Representation rep = ToRepresentation(operand_type); 8563 HInstruction* instr = BuildUnaryMathOp(value, operand_type, Token::SUB);
8534 if (operand_type->Is(Type::None())) {
8535 AddSoftDeoptimize();
8536 }
8537 if (instr->IsBinaryOperation()) {
8538 HBinaryOperation::cast(instr)->set_observed_input_representation(1, rep);
8539 HBinaryOperation::cast(instr)->set_observed_input_representation(2, rep);
8540 }
8541 return ast_context()->ReturnInstruction(instr, expr->id()); 8564 return ast_context()->ReturnInstruction(instr, expr->id());
8542 } 8565 }
8543 8566
8544 8567
8545 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { 8568 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) {
8546 CHECK_ALIVE(VisitForValue(expr->expression())); 8569 CHECK_ALIVE(VisitForValue(expr->expression()));
8547 HValue* value = Pop(); 8570 HValue* value = Pop();
8548 Handle<Type> operand_type = expr->expression()->lower_type(); 8571 Handle<Type> operand_type = expr->expression()->lower_type();
8549 if (operand_type->Is(Type::None())) { 8572 HInstruction* instr = BuildUnaryMathOp(value, operand_type, Token::BIT_NOT);
8550 AddSoftDeoptimize();
8551 }
8552 HInstruction* instr = new(zone()) HBitNot(value);
8553 return ast_context()->ReturnInstruction(instr, expr->id()); 8573 return ast_context()->ReturnInstruction(instr, expr->id());
8554 } 8574 }
8555 8575
8556 8576
8557 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) { 8577 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) {
8558 if (ast_context()->IsTest()) { 8578 if (ast_context()->IsTest()) {
8559 TestContext* context = TestContext::cast(ast_context()); 8579 TestContext* context = TestContext::cast(ast_context());
8560 VisitForControl(expr->expression(), 8580 VisitForControl(expr->expression(),
8561 context->if_false(), 8581 context->if_false(),
8562 context->if_true()); 8582 context->if_true());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
8596 set_current_block(join); 8616 set_current_block(join);
8597 if (join != NULL) return ast_context()->ReturnValue(Pop()); 8617 if (join != NULL) return ast_context()->ReturnValue(Pop());
8598 } 8618 }
8599 8619
8600 8620
8601 HInstruction* HOptimizedGraphBuilder::BuildIncrement( 8621 HInstruction* HOptimizedGraphBuilder::BuildIncrement(
8602 bool returns_original_input, 8622 bool returns_original_input,
8603 CountOperation* expr) { 8623 CountOperation* expr) {
8604 // The input to the count operation is on top of the expression stack. 8624 // The input to the count operation is on top of the expression stack.
8605 TypeInfo info = expr->type(); 8625 TypeInfo info = expr->type();
8606 Representation rep = ToRepresentation(info); 8626 Representation rep = Representation::FromType(info);
8607 if (rep.IsNone() || rep.IsTagged()) { 8627 if (rep.IsNone() || rep.IsTagged()) {
8608 rep = Representation::Smi(); 8628 rep = Representation::Smi();
8609 } 8629 }
8610 8630
8611 if (returns_original_input) { 8631 if (returns_original_input) {
8612 // We need an explicit HValue representing ToNumber(input). The 8632 // We need an explicit HValue representing ToNumber(input). The
8613 // actual HChange instruction we need is (sometimes) added in a later 8633 // actual HChange instruction we need is (sometimes) added in a later
8614 // phase, so it is not available now to be used as an input to HAdd and 8634 // phase, so it is not available now to be used as an input to HAdd and
8615 // as the return value. 8635 // as the return value.
8616 HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep); 8636 HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
8904 8924
8905 HInstruction* HOptimizedGraphBuilder::BuildBinaryOperation( 8925 HInstruction* HOptimizedGraphBuilder::BuildBinaryOperation(
8906 BinaryOperation* expr, 8926 BinaryOperation* expr,
8907 HValue* left, 8927 HValue* left,
8908 HValue* right) { 8928 HValue* right) {
8909 HValue* context = environment()->LookupContext(); 8929 HValue* context = environment()->LookupContext();
8910 Handle<Type> left_type = expr->left()->lower_type(); 8930 Handle<Type> left_type = expr->left()->lower_type();
8911 Handle<Type> right_type = expr->right()->lower_type(); 8931 Handle<Type> right_type = expr->right()->lower_type();
8912 Handle<Type> result_type = expr->result_type(); 8932 Handle<Type> result_type = expr->result_type();
8913 Maybe<int> fixed_right_arg = expr->fixed_right_arg(); 8933 Maybe<int> fixed_right_arg = expr->fixed_right_arg();
8914 Representation left_rep = ToRepresentation(left_type); 8934 Representation left_rep = Representation::FromType(left_type);
8915 Representation right_rep = ToRepresentation(right_type); 8935 Representation right_rep = Representation::FromType(right_type);
8916 Representation result_rep = ToRepresentation(result_type); 8936 Representation result_rep = Representation::FromType(result_type);
8937
8917 if (left_type->Is(Type::None())) { 8938 if (left_type->Is(Type::None())) {
8918 AddSoftDeoptimize(); 8939 AddSoftDeoptimize();
8919 // TODO(rossberg): we should be able to get rid of non-continuous defaults. 8940 // TODO(rossberg): we should be able to get rid of non-continuous defaults.
8920 left_type = handle(Type::Any(), isolate()); 8941 left_type = handle(Type::Any(), isolate());
8921 } 8942 }
8922 if (right_type->Is(Type::None())) { 8943 if (right_type->Is(Type::None())) {
8923 AddSoftDeoptimize(); 8944 AddSoftDeoptimize();
8924 right_type = handle(Type::Any(), isolate()); 8945 right_type = handle(Type::Any(), isolate());
8925 } 8946 }
8926 HInstruction* instr = NULL; 8947 HInstruction* instr = NULL;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
9134 CHECK_ALIVE(VisitForValue(expr->left())); 9155 CHECK_ALIVE(VisitForValue(expr->left()));
9135 CHECK_ALIVE(VisitForValue(expr->right())); 9156 CHECK_ALIVE(VisitForValue(expr->right()));
9136 HValue* right = Pop(); 9157 HValue* right = Pop();
9137 HValue* left = Pop(); 9158 HValue* left = Pop();
9138 HInstruction* instr = BuildBinaryOperation(expr, left, right); 9159 HInstruction* instr = BuildBinaryOperation(expr, left, right);
9139 instr->set_position(expr->position()); 9160 instr->set_position(expr->position());
9140 return ast_context()->ReturnInstruction(instr, expr->id()); 9161 return ast_context()->ReturnInstruction(instr, expr->id());
9141 } 9162 }
9142 9163
9143 9164
9144 // TODO(rossberg): this should die eventually.
9145 Representation HOptimizedGraphBuilder::ToRepresentation(TypeInfo info) {
9146 if (info.IsUninitialized()) return Representation::None();
9147 // TODO(verwaest): Return Smi rather than Integer32.
9148 if (info.IsSmi()) return Representation::Integer32();
9149 if (info.IsInteger32()) return Representation::Integer32();
9150 if (info.IsDouble()) return Representation::Double();
9151 if (info.IsNumber()) return Representation::Double();
9152 return Representation::Tagged();
9153 }
9154
9155
9156 Representation HOptimizedGraphBuilder::ToRepresentation(Handle<Type> type) {
9157 if (type->Is(Type::None())) return Representation::None();
9158 if (type->Is(Type::Signed32())) return Representation::Integer32();
9159 if (type->Is(Type::Number())) return Representation::Double();
9160 return Representation::Tagged();
9161 }
9162
9163
9164 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, 9165 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr,
9165 HTypeof* typeof_expr, 9166 HTypeof* typeof_expr,
9166 Handle<String> check) { 9167 Handle<String> check) {
9167 // Note: The HTypeof itself is removed during canonicalization, if possible. 9168 // Note: The HTypeof itself is removed during canonicalization, if possible.
9168 HValue* value = typeof_expr->value(); 9169 HValue* value = typeof_expr->value();
9169 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); 9170 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check);
9170 instr->set_position(expr->position()); 9171 instr->set_position(expr->position());
9171 return ast_context()->ReturnControl(instr, expr->id()); 9172 return ast_context()->ReturnControl(instr, expr->id());
9172 } 9173 }
9173 9174
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
9246 Handle<String> rhs = Handle<String>::cast(literal->value()); 9247 Handle<String> rhs = Handle<String>::cast(literal->value());
9247 HClassOfTestAndBranch* instr = 9248 HClassOfTestAndBranch* instr =
9248 new(zone()) HClassOfTestAndBranch(value, rhs); 9249 new(zone()) HClassOfTestAndBranch(value, rhs);
9249 instr->set_position(expr->position()); 9250 instr->set_position(expr->position());
9250 return ast_context()->ReturnControl(instr, expr->id()); 9251 return ast_context()->ReturnControl(instr, expr->id());
9251 } 9252 }
9252 9253
9253 Handle<Type> left_type = expr->left()->lower_type(); 9254 Handle<Type> left_type = expr->left()->lower_type();
9254 Handle<Type> right_type = expr->right()->lower_type(); 9255 Handle<Type> right_type = expr->right()->lower_type();
9255 Handle<Type> combined_type = expr->combined_type(); 9256 Handle<Type> combined_type = expr->combined_type();
9256 Representation combined_rep = ToRepresentation(combined_type); 9257 Representation combined_rep = Representation::FromType(combined_type);
9257 Representation left_rep = ToRepresentation(left_type); 9258 Representation left_rep = Representation::FromType(left_type);
9258 Representation right_rep = ToRepresentation(right_type); 9259 Representation right_rep = Representation::FromType(right_type);
9259 9260
9260 CHECK_ALIVE(VisitForValue(expr->left())); 9261 CHECK_ALIVE(VisitForValue(expr->left()));
9261 CHECK_ALIVE(VisitForValue(expr->right())); 9262 CHECK_ALIVE(VisitForValue(expr->right()));
9262 9263
9263 HValue* context = environment()->LookupContext(); 9264 HValue* context = environment()->LookupContext();
9264 HValue* right = Pop(); 9265 HValue* right = Pop();
9265 HValue* left = Pop(); 9266 HValue* left = Pop();
9266 Token::Value op = expr->op(); 9267 Token::Value op = expr->op();
9267 9268
9268 HTypeof* typeof_expr = NULL; 9269 HTypeof* typeof_expr = NULL;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
9377 return ast_context()->ReturnControl(result, expr->id()); 9378 return ast_context()->ReturnControl(result, expr->id());
9378 } else { 9379 } else {
9379 if (combined_rep.IsTagged() || combined_rep.IsNone()) { 9380 if (combined_rep.IsTagged() || combined_rep.IsNone()) {
9380 HCompareGeneric* result = 9381 HCompareGeneric* result =
9381 new(zone()) HCompareGeneric(context, left, right, op); 9382 new(zone()) HCompareGeneric(context, left, right, op);
9382 result->set_observed_input_representation(1, left_rep); 9383 result->set_observed_input_representation(1, left_rep);
9383 result->set_observed_input_representation(2, right_rep); 9384 result->set_observed_input_representation(2, right_rep);
9384 result->set_position(expr->position()); 9385 result->set_position(expr->position());
9385 return ast_context()->ReturnInstruction(result, expr->id()); 9386 return ast_context()->ReturnInstruction(result, expr->id());
9386 } else { 9387 } else {
9387 // TODO(verwaest): Remove once ToRepresentation properly returns Smi when 9388 // TODO(verwaest): Remove once Representation::FromType properly
9388 // the IC measures Smi. 9389 // returns Smi when the IC measures Smi.
9389 if (left_type->Is(Type::Smi())) left_rep = Representation::Smi(); 9390 if (left_type->Is(Type::Smi())) left_rep = Representation::Smi();
9390 if (right_type->Is(Type::Smi())) right_rep = Representation::Smi(); 9391 if (right_type->Is(Type::Smi())) right_rep = Representation::Smi();
9391 HCompareIDAndBranch* result = 9392 HCompareIDAndBranch* result =
9392 new(zone()) HCompareIDAndBranch(left, right, op); 9393 new(zone()) HCompareIDAndBranch(left, right, op);
9393 result->set_observed_input_representation(left_rep, right_rep); 9394 result->set_observed_input_representation(left_rep, right_rep);
9394 result->set_position(expr->position()); 9395 result->set_position(expr->position());
9395 return ast_context()->ReturnControl(result, expr->id()); 9396 return ast_context()->ReturnControl(result, expr->id());
9396 } 9397 }
9397 } 9398 }
9398 } 9399 }
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after
11038 if (ShouldProduceTraceOutput()) { 11039 if (ShouldProduceTraceOutput()) {
11039 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11040 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11040 } 11041 }
11041 11042
11042 #ifdef DEBUG 11043 #ifdef DEBUG
11043 graph_->Verify(false); // No full verify. 11044 graph_->Verify(false); // No full verify.
11044 #endif 11045 #endif
11045 } 11046 }
11046 11047
11047 } } // namespace v8::internal 11048 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698