namespace internal {
namespace compiler {
-// TODO(titzer): factor this out to a common routine with js-typed-lowering.
-static void ReplaceEffectfulWithValue(Node* node, Node* value) {
- Node* effect = NULL;
- if (OperatorProperties::HasEffectInput(node->op())) {
- effect = NodeProperties::GetEffectInput(node);
- }
-
- // Requires distinguishing between value and effect edges.
- UseIter iter = node->uses().begin();
- while (iter != node->uses().end()) {
- if (NodeProperties::IsEffectEdge(iter.edge())) {
- DCHECK_NE(NULL, effect);
- iter = iter.UpdateToAndIncrement(effect);
- } else {
- iter = iter.UpdateToAndIncrement(value);
- }
- }
-}
-
-
class ContextSpecializationVisitor : public NullNodeVisitor {
public:
explicit ContextSpecializationVisitor(JSContextSpecializer* spec)
case IrOpcode::kJSLoadContext: {
Reduction r = spec_->ReduceJSLoadContext(node);
if (r.Changed() && r.replacement() != node) {
- ReplaceEffectfulWithValue(node, r.replacement());
+ NodeProperties::ReplaceWithValue(node, r.replacement());
+ node->RemoveAllInputs();
}
break;
}
case IrOpcode::kJSStoreContext: {
Reduction r = spec_->ReduceJSStoreContext(node);
if (r.Changed() && r.replacement() != node) {
- ReplaceEffectfulWithValue(node, r.replacement());
+ NodeProperties::ReplaceWithValue(node, r.replacement());
+ node->RemoveAllInputs();
}
break;
}
void JSContextSpecializer::SpecializeToContext() {
- ReplaceEffectfulWithValue(context_, jsgraph_->Constant(info_->context()));
+ NodeProperties::ReplaceWithValue(context_,
+ jsgraph_->Constant(info_->context()));
ContextSpecializationVisitor visitor(this);
jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor);
Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
- ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0));
+ HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
// If the context is not constant, no reduction can occur.
- if (!match.HasValue()) {
+ if (!m.HasValue()) {
return Reducer::NoChange();
}
ContextAccess access = OpParameter<ContextAccess>(node);
// Find the right parent context.
- Context* context = *match.Value();
+ Context* context = *m.Value().handle();
for (int i = access.depth(); i > 0; --i) {
context = context->previous();
}
if (access.depth() == 0) {
return Reducer::NoChange();
}
- Operator* op = jsgraph_->javascript()->LoadContext(0, access.index(),
- access.immutable());
+ const Operator* op = jsgraph_->javascript()->LoadContext(
+ 0, access.index(), access.immutable());
node->set_op(op);
Handle<Object> context_handle = Handle<Object>(context, info_->isolate());
node->ReplaceInput(0, jsgraph_->Constant(context_handle));
Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode());
- ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0));
+ HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
// If the context is not constant, no reduction can occur.
- if (!match.HasValue()) {
+ if (!m.HasValue()) {
return Reducer::NoChange();
}
}
// Find the right parent context.
- Context* context = *match.Value();
+ Context* context = *m.Value().handle();
for (int i = access.depth(); i > 0; --i) {
context = context->previous();
}
- Operator* op = jsgraph_->javascript()->StoreContext(0, access.index());
+ const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index());
node->set_op(op);
Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate());
node->ReplaceInput(0, jsgraph_->Constant(new_context_handle));
return Reducer::Changed(node);
}
-}
-}
-} // namespace v8::internal::compiler
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8