Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index d3b9aa86750973cf71bd4bbf7bcbdbd24e505268..6fff1459bbca3b7bfd1d75d6f217341e8e0ca134 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -1,4 +1,4 @@ |
-// Copyright 2012 the V8 project authors. All rights reserved. |
+// Copyright 2013 the V8 project authors. All rights reserved. |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
// met: |
@@ -667,6 +667,19 @@ HConstant* HGraph::GetInvalidContext() { |
} |
+bool HGraph::IsStandardConstant(HConstant* constant) { |
+ if (constant == GetConstantUndefined()) return true; |
+ if (constant == GetConstant0()) return true; |
+ if (constant == GetConstant1()) return true; |
+ if (constant == GetConstantMinus1()) return true; |
+ if (constant == GetConstantTrue()) return true; |
+ if (constant == GetConstantFalse()) return true; |
+ if (constant == GetConstantHole()) return true; |
+ if (constant == GetConstantNull()) return true; |
+ return false; |
+} |
+ |
+ |
HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, int position) |
: builder_(builder), |
position_(position), |
@@ -4453,9 +4466,9 @@ void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { |
} |
-void HOptimizedGraphBuilder::AddSoftDeoptimize() { |
+void HOptimizedGraphBuilder::AddSoftDeoptimize(SoftDeoptimizeMode mode) { |
isolate()->counters()->soft_deopts_requested()->Increment(); |
- if (FLAG_always_opt) return; |
+ if (FLAG_always_opt && mode == CAN_OMIT_SOFT_DEOPT) return; |
if (current_block()->IsDeoptimizing()) return; |
Add<HSoftDeoptimize>(); |
isolate()->counters()->soft_deopts_inserted()->Increment(); |
@@ -5408,9 +5421,20 @@ void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
if (type == kUseCell) { |
Handle<GlobalObject> global(current_info()->global_object()); |
Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); |
- HLoadGlobalCell* instr = |
- new(zone()) HLoadGlobalCell(cell, lookup.GetPropertyDetails()); |
- return ast_context()->ReturnInstruction(instr, expr->id()); |
+ if (cell->type()->IsConstant()) { |
+ cell->AddDependentCompilationInfo(top_info()); |
+ Handle<Object> constant_object = cell->type()->AsConstant(); |
+ if (constant_object->IsConsString()) { |
+ constant_object = |
+ FlattenGetString(Handle<String>::cast(constant_object)); |
+ } |
+ HConstant* constant = new(zone()) HConstant(constant_object); |
+ return ast_context()->ReturnInstruction(constant, expr->id()); |
+ } else { |
+ HLoadGlobalCell* instr = |
+ new(zone()) HLoadGlobalCell(cell, lookup.GetPropertyDetails()); |
+ return ast_context()->ReturnInstruction(instr, expr->id()); |
+ } |
} else { |
HValue* context = environment()->LookupContext(); |
HGlobalObject* global_object = new(zone()) HGlobalObject(context); |
@@ -6317,8 +6341,21 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( |
if (type == kUseCell) { |
Handle<GlobalObject> global(current_info()->global_object()); |
Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); |
- HInstruction* instr = Add<HStoreGlobalCell>(value, cell, |
- lookup.GetPropertyDetails()); |
+ if (cell->type()->IsConstant()) { |
+ IfBuilder builder(this); |
+ HValue* constant = Add<HConstant>(cell->type()->AsConstant()); |
+ if (cell->type()->AsConstant()->IsNumber()) { |
+ builder.IfCompare(value, constant, Token::EQ); |
+ } else { |
+ builder.If<HCompareObjectEqAndBranch>(value, constant); |
+ } |
+ builder.Then(); |
+ builder.Else(); |
+ AddSoftDeoptimize(MUST_EMIT_SOFT_DEOPT); |
+ builder.End(); |
+ } |
+ HInstruction* instr = |
+ Add<HStoreGlobalCell>(value, cell, lookup.GetPropertyDetails()); |
instr->set_position(position); |
if (instr->HasObservableSideEffects()) { |
AddSimulate(ast_id, REMOVABLE_SIMULATE); |