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

Unified Diff: src/compiler/graph-reducer.h

Issue 1122423003: [turbofan] Add support for advanced reducers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move comment Created 5 years, 7 months 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/control-reducer.cc ('k') | src/compiler/graph-reducer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/graph-reducer.h
diff --git a/src/compiler/graph-reducer.h b/src/compiler/graph-reducer.h
index a6cc1f2d94b0b14974907cd37b83ac7d8d81a448..1c90b3018babceb2fe657307a9d3b341d35dd86f 100644
--- a/src/compiler/graph-reducer.h
+++ b/src/compiler/graph-reducer.h
@@ -17,13 +17,18 @@ class Graph;
class Node;
+// NodeIds are identifying numbers for nodes that can be used to index auxiliary
+// out-of-line data associated with each node.
+typedef int32_t NodeId;
+
+
// Represents the result of trying to reduce a node in the graph.
class Reduction final {
public:
- explicit Reduction(Node* replacement = NULL) : replacement_(replacement) {}
+ explicit Reduction(Node* replacement = nullptr) : replacement_(replacement) {}
Node* replacement() const { return replacement_; }
- bool Changed() const { return replacement() != NULL; }
+ bool Changed() const { return replacement() != nullptr; }
private:
Node* replacement_;
@@ -37,26 +42,66 @@ class Reduction final {
// phase.
class Reducer {
public:
- Reducer() {}
virtual ~Reducer() {}
// Try to reduce a node if possible.
virtual Reduction Reduce(Node* node) = 0;
+ // Ask this reducer to finish operation, returns {true} if the reducer is
+ // done, while {false} indicates that the graph might need to be reduced
+ // again.
+ // TODO(turbofan): Remove this once the dead node trimming is in the
+ // GraphReducer.
+ virtual bool Finish();
+
// Helper functions for subclasses to produce reductions for a node.
static Reduction NoChange() { return Reduction(); }
static Reduction Replace(Node* node) { return Reduction(node); }
static Reduction Changed(Node* node) { return Reduction(node); }
+};
+
+
+// An advanced reducer can also edit the graphs by changing and replacing nodes
+// other than the one currently being reduced.
+class AdvancedReducer : public Reducer {
+ public:
+ // Observe the actions of this reducer.
+ class Editor {
+ public:
+ virtual ~Editor() {}
+
+ // Replace {node} with {replacement}.
+ virtual void Replace(Node* node, Node* replacement) = 0;
+ // Revisit the {node} again later.
+ virtual void Revisit(Node* node) = 0;
+ };
+
+ explicit AdvancedReducer(Editor* editor) : editor_(editor) {}
+
+ protected:
+ // Helper functions for subclasses to produce reductions for a node.
+ static Reduction Replace(Node* node) { return Reducer::Replace(node); }
+
+ // Helper functions for subclasses to edit the graph.
+ void Replace(Node* node, Node* replacement) {
+ DCHECK_NOT_NULL(editor_);
+ editor_->Replace(node, replacement);
+ }
+ void Revisit(Node* node) {
+ DCHECK_NOT_NULL(editor_);
+ editor_->Revisit(node);
+ }
private:
- DISALLOW_COPY_AND_ASSIGN(Reducer);
+ Editor* const editor_;
};
// Performs an iterative reduction of a node graph.
-class GraphReducer final {
+class GraphReducer final : public AdvancedReducer::Editor {
public:
GraphReducer(Graph* graph, Zone* zone);
+ ~GraphReducer() final;
Graph* graph() const { return graph_; }
@@ -79,15 +124,22 @@ class GraphReducer final {
// Reduce the node on top of the stack.
void ReduceTop();
+ // Replace {node} with {replacement}.
+ void Replace(Node* node, Node* replacement) final;
+ // Replace all uses of {node} with {replacement} if the id of {replacement} is
+ // less than or equal to {max_id}. Otherwise, replace all uses of {node} whose
+ // id is less than or equal to {max_id} with the {replacement}.
+ void Replace(Node* node, Node* replacement, NodeId max_id);
+
// Node stack operations.
void Pop();
void Push(Node* node);
// Revisit queue operations.
bool Recurse(Node* node);
- void Revisit(Node* node);
+ void Revisit(Node* node) final;
- Graph* graph_;
+ Graph* const graph_;
NodeMarker<State> state_;
ZoneVector<Reducer*> reducers_;
ZoneStack<Node*> revisit_;
« no previous file with comments | « src/compiler/control-reducer.cc ('k') | src/compiler/graph-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698