Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: src/compiler/js-context-specialization.cc

Issue 771713002: [turbofan] Make context specialization into a reducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/js-context-specialization.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-context-specialization.cc
diff --git a/src/compiler/js-context-specialization.cc b/src/compiler/js-context-specialization.cc
index d11bc6671188e5a6de74ee678fc02f48e46b069b..b2a234be4103966d7ce3eee623f6ed0be4039b53 100644
--- a/src/compiler/js-context-specialization.cc
+++ b/src/compiler/js-context-specialization.cc
@@ -6,7 +6,6 @@
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-context-specialization.h"
#include "src/compiler/js-operator.h"
-#include "src/compiler/node-aux-data-inl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
@@ -14,45 +13,20 @@ namespace v8 {
namespace internal {
namespace compiler {
-class ContextSpecializationVisitor : public NullNodeVisitor {
- public:
- explicit ContextSpecializationVisitor(JSContextSpecializer* spec)
- : spec_(spec) {}
-
- void Post(Node* node) {
- switch (node->opcode()) {
- case IrOpcode::kJSLoadContext: {
- Reduction r = spec_->ReduceJSLoadContext(node);
- if (r.Changed() && r.replacement() != node) {
- NodeProperties::ReplaceWithValue(node, r.replacement());
- node->RemoveAllInputs();
- }
- break;
- }
- case IrOpcode::kJSStoreContext: {
- Reduction r = spec_->ReduceJSStoreContext(node);
- if (r.Changed() && r.replacement() != node) {
- NodeProperties::ReplaceWithValue(node, r.replacement());
- node->RemoveAllInputs();
- }
- break;
- }
- default:
- break;
- }
- }
-
- private:
- JSContextSpecializer* spec_;
-};
-
-void JSContextSpecializer::SpecializeToContext() {
- NodeProperties::ReplaceWithValue(context_,
- jsgraph_->Constant(info_->context()));
-
- ContextSpecializationVisitor visitor(this);
- jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor);
+Reduction JSContextSpecializer::Reduce(Node* node) {
+ if (node == context_) {
+ Node* constant = jsgraph_->Constant(info_->context());
+ NodeProperties::ReplaceWithValue(node, constant);
+ return Replace(constant);
+ }
+ if (node->opcode() == IrOpcode::kJSLoadContext) {
+ return ReduceJSLoadContext(node);
+ }
+ if (node->opcode() == IrOpcode::kJSStoreContext) {
+ return ReduceJSStoreContext(node);
+ }
+ return NoChange();
}
@@ -62,7 +36,7 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
// If the context is not constant, no reduction can occur.
if (!m.HasValue()) {
- return Reducer::NoChange();
+ return NoChange();
}
const ContextAccess& access = ContextAccessOf(node->op());
@@ -77,14 +51,14 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
if (!access.immutable()) {
// The access does not have to look up a parent, nothing to fold.
if (access.depth() == 0) {
- return Reducer::NoChange();
+ return NoChange();
}
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));
- return Reducer::Changed(node);
+ return Changed(node);
}
Handle<Object> value = Handle<Object>(
context->get(static_cast<int>(access.index())), info_->isolate());
@@ -94,13 +68,15 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
// We must be conservative and check if the value in the slot is currently the
// hole or undefined. If it is neither of these, then it must be initialized.
if (value->IsUndefined() || value->IsTheHole()) {
- return Reducer::NoChange();
+ return NoChange();
}
// Success. The context load can be replaced with the constant.
// TODO(titzer): record the specialization for sharing code across multiple
// contexts that have the same value in the corresponding context slot.
- return Reducer::Replace(jsgraph_->Constant(value));
+ Node* constant = jsgraph_->Constant(value);
+ NodeProperties::ReplaceWithValue(node, constant);
+ return Replace(constant);
}
@@ -110,14 +86,14 @@ Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) {
HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
// If the context is not constant, no reduction can occur.
if (!m.HasValue()) {
- return Reducer::NoChange();
+ return NoChange();
}
const ContextAccess& access = ContextAccessOf(node->op());
// The access does not have to look up a parent, nothing to fold.
if (access.depth() == 0) {
- return Reducer::NoChange();
+ return NoChange();
}
// Find the right parent context.
@@ -131,7 +107,7 @@ Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) {
Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate());
node->ReplaceInput(0, jsgraph_->Constant(new_context_handle));
- return Reducer::Changed(node);
+ return Changed(node);
}
} // namespace compiler
« no previous file with comments | « src/compiler/js-context-specialization.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698