Commit d63c8e4d authored by titzer@chromium.org's avatar titzer@chromium.org

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

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/31943002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17299 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 19b2ee1c
......@@ -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);
......
......@@ -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);
......
......@@ -2576,6 +2576,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;
......
......@@ -648,10 +648,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;
}
......@@ -681,13 +692,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)
......@@ -3233,10 +3245,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());
......@@ -3250,6 +3258,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();
......
......@@ -342,10 +342,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();
......@@ -460,6 +457,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);
......@@ -479,7 +477,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_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment