Reviewers: Jakob,

Description:
Allow constants to be deleted by reinserting them into the graph as needed.

BUG=

Please review this at https://codereview.chromium.org/31943002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+22, -22 lines):
  M src/code-stubs-hydrogen.cc
  M src/hydrogen-dce.cc
  M src/hydrogen-instructions.cc
  M src/hydrogen.h
  M src/hydrogen.cc


Index: src/code-stubs-hydrogen.cc
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc
index a695161801999b29da4342e3f9b86a92a600c409..a273c1b19a185f8081926a6777477ff9a76420a1 100644
--- a/src/code-stubs-hydrogen.cc
+++ b/src/code-stubs-hydrogen.cc
@@ -150,10 +150,6 @@ bool CodeStubGraphBuilderBase::BuildGraph() {
   next_block->SetJoinId(BailoutId::StubEntry());
   set_current_block(next_block);

-  HConstant* undefined_constant =
-      Add<HConstant>(isolate()->factory()->undefined_value());
-  graph()->set_undefined_constant(undefined_constant);
-
   for (int i = 0; i < param_count; ++i) {
     HParameter* param =
         Add<HParameter>(i, HParameter::REGISTER_PARAMETER);
Index: src/hydrogen-dce.cc
diff --git a/src/hydrogen-dce.cc b/src/hydrogen-dce.cc
index 3b64107fa119fe1c0245bd33313b80c1809c33d4..e101ee5bcc58bd624358005a54b96d23237d3d21 100644
--- a/src/hydrogen-dce.cc
+++ b/src/hydrogen-dce.cc
@@ -98,11 +98,7 @@ void HDeadCodeEliminationPhase::RemoveDeadInstructions() {
       HInstruction* instr = it.Current();
       if (!instr->CheckFlag(HValue::kIsLive)) {
         // Instruction has not been marked live, so remove it.
-        if (!instr->IsConstant() || instr->block()->block_id() != 0) {
-          // TODO(titzer): Some global constants in block 0 can be used
-          // again later, and can't currently be removed. Fix that.
-          instr->DeleteAndReplaceWith(NULL);
-        }
+        instr->DeleteAndReplaceWith(NULL);
       } else {
// Clear the liveness flag to leave the graph clean for the next DCE.
         instr->ClearFlag(HValue::kIsLive);
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 867fa50fca25aa30e5508edc5368d76b23c7a576..3a367e2e43155248501bd6718fc52d81ae9b21c8 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -2563,6 +2563,7 @@ bool HConstant::EmitAtUses() {
   ASSERT(IsLinked());
   if (block()->graph()->has_osr() &&
       block()->graph()->IsStandardConstant(this)) {
+ // TODO(titzer): this seems like a hack that should be fixed by custom OSR.
     return true;
   }
   if (UseCount() == 0) return true;
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 14ac329575680c20e6cbac81e6298a9f6ef914da..92e99755e7079ffc73e913b56f607fda4cc991e6 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -634,10 +634,21 @@ HConstant* HGraph::GetConstant(SetOncePointer<HConstant>* pointer,
     // Can't pass GetInvalidContext() to HConstant::New, because that will
     // recursively call GetConstant
     HConstant* constant = HConstant::New(zone(), NULL, value);
-    constant->InsertAfter(GetConstantUndefined());
+    constant->InsertAfter(entry_block()->first());
     pointer->set(constant);
+    return constant;
   }
-  return pointer->get();
+  return ReinsertConstantIfNecessary(pointer->get());
+}
+
+
+HConstant* HGraph::ReinsertConstantIfNecessary(HConstant* constant) {
+  if (!constant->IsLinked()) {
+    // The constant was removed from the graph. Reinsert.
+    constant->ClearFlag(HValue::kIsDead);
+    constant->InsertAfter(entry_block()->first());
+  }
+  return constant;
 }


@@ -667,13 +678,14 @@ HConstant* HGraph::GetConstant##Name() { \ true, \ false, \ boolean_value); \ - constant->InsertAfter(GetConstantUndefined()); \ + constant->InsertAfter(entry_block()->first()); \ constant_##name##_.set(constant); \ } \ - return constant_##name##_.get(); \ + return ReinsertConstantIfNecessary(constant_##name##_.get()); \
 }


+DEFINE_GET_CONSTANT(Undefined, undefined, HType::Tagged(), false)
 DEFINE_GET_CONSTANT(True, true, HType::Boolean(), true)
 DEFINE_GET_CONSTANT(False, false, HType::Boolean(), false)
 DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false)
@@ -3206,10 +3218,6 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) {
   HInstruction* context = Add<HContext>();
   environment()->BindContext(context);

-  HConstant* undefined_constant = HConstant::cast(Add<HConstant>(
-      isolate()->factory()->undefined_value()));
-  graph()->set_undefined_constant(undefined_constant);
-
   // Create an arguments object containing the initial parameters.  Set the
// initial values of parameters including "this" having parameter index 0.
   ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count());
@@ -3223,6 +3231,7 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) {
   AddInstruction(arguments_object);
   graph()->SetArgumentsObject(arguments_object);

+  HConstant* undefined_constant = graph()->GetConstantUndefined();
   // Initialize specials and locals to undefined.
   for (int i = environment()->parameter_count() + 1;
        i < environment()->length();
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index bd28ba1b74d55da9df2dd5c11cc615a6c4ba4f0b..5eb5c9e1c45a03431492dc84bc63e691a98fcf38 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -338,10 +338,7 @@ class HGraph V8_FINAL : public ZoneObject {

   void CollectPhis();

-  void set_undefined_constant(HConstant* constant) {
-    undefined_constant_.set(constant);
-  }
- HConstant* GetConstantUndefined() const { return undefined_constant_.get(); }
+  HConstant* GetConstantUndefined();
   HConstant* GetConstant0();
   HConstant* GetConstant1();
   HConstant* GetConstantMinus1();
@@ -456,6 +453,7 @@ class HGraph V8_FINAL : public ZoneObject {
bool IsInsideNoSideEffectsScope() { return no_side_effects_scope_count_
0; }

  private:
+  HConstant* ReinsertConstantIfNecessary(HConstant* constant);
   HConstant* GetConstant(SetOncePointer<HConstant>* pointer,
                          int32_t integer_value);

@@ -475,7 +473,7 @@ class HGraph V8_FINAL : public ZoneObject {
   ZoneList<HValue*> values_;
   ZoneList<HPhi*>* phi_list_;
   ZoneList<HInstruction*>* uint32_instructions_;
-  SetOncePointer<HConstant> undefined_constant_;
+  SetOncePointer<HConstant> constant_undefined_;
   SetOncePointer<HConstant> constant_0_;
   SetOncePointer<HConstant> constant_1_;
   SetOncePointer<HConstant> constant_minus1_;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to