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

Side by Side Diff: src/hydrogen.cc

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