OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 #define DEFINE_GET_CONSTANT(Name, name, htype, boolean_value) \ | 640 #define DEFINE_GET_CONSTANT(Name, name, htype, boolean_value) \ |
641 HConstant* HGraph::GetConstant##Name() { \ | 641 HConstant* HGraph::GetConstant##Name() { \ |
642 if (!constant_##name##_.is_set()) { \ | 642 if (!constant_##name##_.is_set()) { \ |
643 HConstant* constant = new(zone()) HConstant( \ | 643 HConstant* constant = new(zone()) HConstant( \ |
644 isolate()->factory()->name##_value(), \ | 644 isolate()->factory()->name##_value(), \ |
645 UniqueValueId(isolate()->heap()->name##_value()), \ | 645 UniqueValueId(isolate()->heap()->name##_value()), \ |
646 Representation::Tagged(), \ | 646 Representation::Tagged(), \ |
647 htype, \ | 647 htype, \ |
648 false, \ | 648 false, \ |
649 true, \ | 649 true, \ |
| 650 false, \ |
650 boolean_value); \ | 651 boolean_value); \ |
651 constant->InsertAfter(GetConstantUndefined()); \ | 652 constant->InsertAfter(GetConstantUndefined()); \ |
652 constant_##name##_.set(constant); \ | 653 constant_##name##_.set(constant); \ |
653 } \ | 654 } \ |
654 return constant_##name##_.get(); \ | 655 return constant_##name##_.get(); \ |
655 } | 656 } |
656 | 657 |
657 | 658 |
658 DEFINE_GET_CONSTANT(True, true, HType::Boolean(), true) | 659 DEFINE_GET_CONSTANT(True, true, HType::Boolean(), true) |
659 DEFINE_GET_CONSTANT(False, false, HType::Boolean(), false) | 660 DEFINE_GET_CONSTANT(False, false, HType::Boolean(), false) |
660 DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false) | 661 DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false) |
661 DEFINE_GET_CONSTANT(Null, null, HType::Tagged(), false) | 662 DEFINE_GET_CONSTANT(Null, null, HType::Tagged(), false) |
662 | 663 |
663 | 664 |
664 #undef DEFINE_GET_CONSTANT | 665 #undef DEFINE_GET_CONSTANT |
665 | 666 |
666 | 667 |
667 HConstant* HGraph::GetInvalidContext() { | 668 HConstant* HGraph::GetInvalidContext() { |
668 return GetConstant(&constant_invalid_context_, 0xFFFFC0C7); | 669 return GetConstant(&constant_invalid_context_, 0xFFFFC0C7); |
669 } | 670 } |
670 | 671 |
671 | 672 |
| 673 bool HGraph::IsStandardConstant(HConstant* constant) { |
| 674 if (constant == GetConstantUndefined()) return true; |
| 675 if (constant == GetConstant0()) return true; |
| 676 if (constant == GetConstant1()) return true; |
| 677 if (constant == GetConstantMinus1()) return true; |
| 678 if (constant == GetConstantTrue()) return true; |
| 679 if (constant == GetConstantFalse()) return true; |
| 680 if (constant == GetConstantHole()) return true; |
| 681 if (constant == GetConstantNull()) return true; |
| 682 return false; |
| 683 } |
| 684 |
| 685 |
672 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, int position) | 686 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, int position) |
673 : builder_(builder), | 687 : builder_(builder), |
674 position_(position), | 688 position_(position), |
675 finished_(false), | 689 finished_(false), |
676 did_then_(false), | 690 did_then_(false), |
677 did_else_(false), | 691 did_else_(false), |
678 did_and_(false), | 692 did_and_(false), |
679 did_or_(false), | 693 did_or_(false), |
680 captured_(false), | 694 captured_(false), |
681 needs_compare_(true), | 695 needs_compare_(true), |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 HValue* context = environment()->LookupContext(); | 1010 HValue* context = environment()->LookupContext(); |
997 int num_parameters = graph()->info()->num_parameters(); | 1011 int num_parameters = graph()->info()->num_parameters(); |
998 HValue* params = Add<HConstant>(num_parameters); | 1012 HValue* params = Add<HConstant>(num_parameters); |
999 HReturn* return_instruction = new(graph()->zone()) | 1013 HReturn* return_instruction = new(graph()->zone()) |
1000 HReturn(value, context, params); | 1014 HReturn(value, context, params); |
1001 current_block()->FinishExit(return_instruction); | 1015 current_block()->FinishExit(return_instruction); |
1002 return return_instruction; | 1016 return return_instruction; |
1003 } | 1017 } |
1004 | 1018 |
1005 | 1019 |
1006 void HGraphBuilder::AddSoftDeoptimize() { | 1020 void HGraphBuilder::AddSoftDeoptimize(SoftDeoptimizeMode mode) { |
1007 isolate()->counters()->soft_deopts_requested()->Increment(); | 1021 isolate()->counters()->soft_deopts_requested()->Increment(); |
1008 if (FLAG_always_opt) return; | 1022 if (FLAG_always_opt && mode == CAN_OMIT_SOFT_DEOPT) return; |
1009 if (current_block()->IsDeoptimizing()) return; | 1023 if (current_block()->IsDeoptimizing()) return; |
1010 Add<HSoftDeoptimize>(); | 1024 Add<HSoftDeoptimize>(); |
1011 isolate()->counters()->soft_deopts_inserted()->Increment(); | 1025 isolate()->counters()->soft_deopts_inserted()->Increment(); |
1012 current_block()->MarkAsDeoptimizing(); | 1026 current_block()->MarkAsDeoptimizing(); |
1013 graph()->set_has_soft_deoptimize(true); | 1027 graph()->set_has_soft_deoptimize(true); |
1014 } | 1028 } |
1015 | 1029 |
1016 | 1030 |
1017 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { | 1031 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { |
1018 HBasicBlock* b = graph()->CreateBasicBlock(); | 1032 HBasicBlock* b = graph()->CreateBasicBlock(); |
(...skipping 4193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5212 LookupGlobalProperty(variable, &lookup, false); | 5226 LookupGlobalProperty(variable, &lookup, false); |
5213 | 5227 |
5214 if (type == kUseCell && | 5228 if (type == kUseCell && |
5215 current_info()->global_object()->IsAccessCheckNeeded()) { | 5229 current_info()->global_object()->IsAccessCheckNeeded()) { |
5216 type = kUseGeneric; | 5230 type = kUseGeneric; |
5217 } | 5231 } |
5218 | 5232 |
5219 if (type == kUseCell) { | 5233 if (type == kUseCell) { |
5220 Handle<GlobalObject> global(current_info()->global_object()); | 5234 Handle<GlobalObject> global(current_info()->global_object()); |
5221 Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); | 5235 Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); |
5222 HLoadGlobalCell* instr = | 5236 if (cell->type()->IsConstant()) { |
5223 new(zone()) HLoadGlobalCell(cell, lookup.GetPropertyDetails()); | 5237 cell->AddDependentCompilationInfo(top_info()); |
5224 return ast_context()->ReturnInstruction(instr, expr->id()); | 5238 Handle<Object> constant_object = cell->type()->AsConstant(); |
| 5239 if (constant_object->IsConsString()) { |
| 5240 constant_object = |
| 5241 FlattenGetString(Handle<String>::cast(constant_object)); |
| 5242 } |
| 5243 HConstant* constant = new(zone()) HConstant(constant_object); |
| 5244 return ast_context()->ReturnInstruction(constant, expr->id()); |
| 5245 } else { |
| 5246 HLoadGlobalCell* instr = |
| 5247 new(zone()) HLoadGlobalCell(cell, lookup.GetPropertyDetails()); |
| 5248 return ast_context()->ReturnInstruction(instr, expr->id()); |
| 5249 } |
5225 } else { | 5250 } else { |
5226 HValue* context = environment()->LookupContext(); | 5251 HValue* context = environment()->LookupContext(); |
5227 HGlobalObject* global_object = new(zone()) HGlobalObject(context); | 5252 HGlobalObject* global_object = new(zone()) HGlobalObject(context); |
5228 AddInstruction(global_object); | 5253 AddInstruction(global_object); |
5229 HLoadGlobalGeneric* instr = | 5254 HLoadGlobalGeneric* instr = |
5230 new(zone()) HLoadGlobalGeneric(context, | 5255 new(zone()) HLoadGlobalGeneric(context, |
5231 global_object, | 5256 global_object, |
5232 variable->name(), | 5257 variable->name(), |
5233 ast_context()->is_for_typeof()); | 5258 ast_context()->is_for_typeof()); |
5234 instr->set_position(expr->position()); | 5259 instr->set_position(expr->position()); |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6125 void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( | 6150 void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( |
6126 Variable* var, | 6151 Variable* var, |
6127 HValue* value, | 6152 HValue* value, |
6128 int position, | 6153 int position, |
6129 BailoutId ast_id) { | 6154 BailoutId ast_id) { |
6130 LookupResult lookup(isolate()); | 6155 LookupResult lookup(isolate()); |
6131 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, true); | 6156 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, true); |
6132 if (type == kUseCell) { | 6157 if (type == kUseCell) { |
6133 Handle<GlobalObject> global(current_info()->global_object()); | 6158 Handle<GlobalObject> global(current_info()->global_object()); |
6134 Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); | 6159 Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); |
6135 HInstruction* instr = Add<HStoreGlobalCell>(value, cell, | 6160 if (cell->type()->IsConstant()) { |
6136 lookup.GetPropertyDetails()); | 6161 IfBuilder builder(this); |
| 6162 HValue* constant = Add<HConstant>(cell->type()->AsConstant()); |
| 6163 if (cell->type()->AsConstant()->IsNumber()) { |
| 6164 builder.IfCompare(value, constant, Token::EQ); |
| 6165 } else { |
| 6166 builder.If<HCompareObjectEqAndBranch>(value, constant); |
| 6167 } |
| 6168 builder.Then(); |
| 6169 builder.Else(); |
| 6170 AddSoftDeoptimize(MUST_EMIT_SOFT_DEOPT); |
| 6171 builder.End(); |
| 6172 } |
| 6173 HInstruction* instr = |
| 6174 Add<HStoreGlobalCell>(value, cell, lookup.GetPropertyDetails()); |
6137 instr->set_position(position); | 6175 instr->set_position(position); |
6138 if (instr->HasObservableSideEffects()) { | 6176 if (instr->HasObservableSideEffects()) { |
6139 AddSimulate(ast_id, REMOVABLE_SIMULATE); | 6177 AddSimulate(ast_id, REMOVABLE_SIMULATE); |
6140 } | 6178 } |
6141 } else { | 6179 } else { |
6142 HValue* context = environment()->LookupContext(); | 6180 HValue* context = environment()->LookupContext(); |
6143 HGlobalObject* global_object = Add<HGlobalObject>(context); | 6181 HGlobalObject* global_object = Add<HGlobalObject>(context); |
6144 HStoreGlobalGeneric* instr = | 6182 HStoreGlobalGeneric* instr = |
6145 Add<HStoreGlobalGeneric>(context, global_object, var->name(), | 6183 Add<HStoreGlobalGeneric>(context, global_object, var->name(), |
6146 value, function_strict_mode_flag()); | 6184 value, function_strict_mode_flag()); |
(...skipping 4892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11039 if (ShouldProduceTraceOutput()) { | 11077 if (ShouldProduceTraceOutput()) { |
11040 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 11078 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
11041 } | 11079 } |
11042 | 11080 |
11043 #ifdef DEBUG | 11081 #ifdef DEBUG |
11044 graph_->Verify(false); // No full verify. | 11082 graph_->Verify(false); // No full verify. |
11045 #endif | 11083 #endif |
11046 } | 11084 } |
11047 | 11085 |
11048 } } // namespace v8::internal | 11086 } } // namespace v8::internal |
OLD | NEW |