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

Unified Diff: src/compiler/control-equivalence.h

Issue 1056093005: [turbofan] Split ControlEquivalence implementation and add trace flag. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 | « BUILD.gn ('k') | src/compiler/control-equivalence.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/control-equivalence.h
diff --git a/src/compiler/control-equivalence.h b/src/compiler/control-equivalence.h
index 354d6cfceb8ad0d83e491a5f9326872a63390cba..4130c88002efd524e7a3de90ad1f0e281bc14e26 100644
--- a/src/compiler/control-equivalence.h
+++ b/src/compiler/control-equivalence.h
@@ -7,18 +7,12 @@
#include "src/compiler/graph.h"
#include "src/compiler/node.h"
-#include "src/compiler/node-properties.h"
#include "src/zone-containers.h"
namespace v8 {
namespace internal {
namespace compiler {
-#define TRACE(...) \
- do { \
- if (FLAG_trace_turbo_scheduler) PrintF(__VA_ARGS__); \
- } while (false)
-
// Determines control dependence equivalence classes for control nodes. Any two
// nodes having the same set of control dependences land in one class. These
// classes can in turn be used to:
@@ -34,7 +28,7 @@ namespace compiler {
// control regions in linear time" by Johnson, Pearson & Pingali (PLDI94) which
// also contains proofs for the aforementioned equivalence. References to line
// numbers in the algorithm from figure 4 have been added [line:x].
-class ControlEquivalence : public ZoneObject {
+class ControlEquivalence FINAL : public ZoneObject {
public:
ControlEquivalence(Zone* zone, Graph* graph)
: zone_(zone),
@@ -49,15 +43,11 @@ class ControlEquivalence : public ZoneObject {
// participate in the next step. Takes O(E) time and O(N) space.
// 2) An undirected depth-first backwards traversal that determines class
// numbers for all participating nodes. Takes O(E) time and O(N) space.
- void Run(Node* exit) {
- if (GetClass(exit) != kInvalidClass) return;
- DetermineParticipation(exit);
- RunUndirectedDFS(exit);
- }
+ void Run(Node* exit);
// Retrieves a previously computed class number.
size_t ClassOf(Node* node) {
- DCHECK(GetClass(node) != kInvalidClass);
+ DCHECK_NE(kInvalidClass, GetClass(node));
return GetClass(node);
}
@@ -100,65 +90,16 @@ class ControlEquivalence : public ZoneObject {
typedef ZoneVector<NodeData> Data;
// Called at pre-visit during DFS walk.
- void VisitPre(Node* node) {
- TRACE("CEQ: Pre-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
-
- // Dispense a new pre-order number.
- SetNumber(node, NewDFSNumber());
- TRACE(" Assigned DFS number is %zu\n", GetNumber(node));
- }
+ void VisitPre(Node* node);
// Called at mid-visit during DFS walk.
- void VisitMid(Node* node, DFSDirection direction) {
- TRACE("CEQ: Mid-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
- BracketList& blist = GetBracketList(node);
-
- // Remove brackets pointing to this node [line:19].
- BracketListDelete(blist, node, direction);
-
- // Potentially introduce artificial dependency from start to end.
- if (blist.empty()) {
- DCHECK_EQ(kInputDirection, direction);
- VisitBackedge(node, graph_->end(), kInputDirection);
- }
-
- // Potentially start a new equivalence class [line:37].
- BracketListTRACE(blist);
- Bracket* recent = &blist.back();
- if (recent->recent_size != blist.size()) {
- recent->recent_size = blist.size();
- recent->recent_class = NewClassNumber();
- }
-
- // Assign equivalence class to node.
- SetClass(node, recent->recent_class);
- TRACE(" Assigned class number is %zu\n", GetClass(node));
- }
+ void VisitMid(Node* node, DFSDirection direction);
// Called at post-visit during DFS walk.
- void VisitPost(Node* node, Node* parent_node, DFSDirection direction) {
- TRACE("CEQ: Post-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
- BracketList& blist = GetBracketList(node);
-
- // Remove brackets pointing to this node [line:19].
- BracketListDelete(blist, node, direction);
-
- // Propagate bracket list up the DFS tree [line:13].
- if (parent_node != NULL) {
- BracketList& parent_blist = GetBracketList(parent_node);
- parent_blist.splice(parent_blist.end(), blist);
- }
- }
+ void VisitPost(Node* node, Node* parent_node, DFSDirection direction);
// Called when hitting a back edge in the DFS walk.
- void VisitBackedge(Node* from, Node* to, DFSDirection direction) {
- TRACE("CEQ: Backedge from #%d:%s to #%d:%s\n", from->id(),
- from->op()->mnemonic(), to->id(), to->op()->mnemonic());
-
- // Push backedge onto the bracket list [line:25].
- Bracket bracket = {direction, kInvalidClass, 0, from, to};
- GetBracketList(from).push_back(bracket);
- }
+ void VisitBackedge(Node* from, Node* to, DFSDirection direction);
// Performs and undirected DFS walk of the graph. Conceptually all nodes are
// expanded, splitting "input" and "use" out into separate nodes. During the
@@ -174,102 +115,10 @@ class ControlEquivalence : public ZoneObject {
//
// This will yield a true spanning tree (without cross or forward edges) and
// also discover proper back edges in both directions.
- void RunUndirectedDFS(Node* exit) {
- ZoneStack<DFSStackEntry> stack(zone_);
- DFSPush(stack, exit, NULL, kInputDirection);
- VisitPre(exit);
+ void RunUndirectedDFS(Node* exit);
- while (!stack.empty()) { // Undirected depth-first backwards traversal.
- DFSStackEntry& entry = stack.top();
- Node* node = entry.node;
-
- if (entry.direction == kInputDirection) {
- if (entry.input != node->input_edges().end()) {
- Edge edge = *entry.input;
- Node* input = edge.to();
- ++(entry.input);
- if (NodeProperties::IsControlEdge(edge)) {
- // Visit next control input.
- if (!GetData(input)->participates) continue;
- if (GetData(input)->visited) continue;
- if (GetData(input)->on_stack) {
- // Found backedge if input is on stack.
- if (input != entry.parent_node) {
- VisitBackedge(node, input, kInputDirection);
- }
- } else {
- // Push input onto stack.
- DFSPush(stack, input, node, kInputDirection);
- VisitPre(input);
- }
- }
- continue;
- }
- if (entry.use != node->use_edges().end()) {
- // Switch direction to uses.
- entry.direction = kUseDirection;
- VisitMid(node, kInputDirection);
- continue;
- }
- }
-
- if (entry.direction == kUseDirection) {
- if (entry.use != node->use_edges().end()) {
- Edge edge = *entry.use;
- Node* use = edge.from();
- ++(entry.use);
- if (NodeProperties::IsControlEdge(edge)) {
- // Visit next control use.
- if (!GetData(use)->participates) continue;
- if (GetData(use)->visited) continue;
- if (GetData(use)->on_stack) {
- // Found backedge if use is on stack.
- if (use != entry.parent_node) {
- VisitBackedge(node, use, kUseDirection);
- }
- } else {
- // Push use onto stack.
- DFSPush(stack, use, node, kUseDirection);
- VisitPre(use);
- }
- }
- continue;
- }
- if (entry.input != node->input_edges().end()) {
- // Switch direction to inputs.
- entry.direction = kInputDirection;
- VisitMid(node, kUseDirection);
- continue;
- }
- }
-
- // Pop node from stack when done with all inputs and uses.
- DCHECK(entry.input == node->input_edges().end());
- DCHECK(entry.use == node->use_edges().end());
- DFSPop(stack, node);
- VisitPost(node, entry.parent_node, entry.direction);
- }
- }
-
- void DetermineParticipationEnqueue(ZoneQueue<Node*>& queue, Node* node) {
- if (!GetData(node)->participates) {
- GetData(node)->participates = true;
- queue.push(node);
- }
- }
-
- void DetermineParticipation(Node* exit) {
- ZoneQueue<Node*> queue(zone_);
- DetermineParticipationEnqueue(queue, exit);
- while (!queue.empty()) { // Breadth-first backwards traversal.
- Node* node = queue.front();
- queue.pop();
- int max = NodeProperties::PastControlIndex(node);
- for (int i = NodeProperties::FirstControlIndex(node); i < max; i++) {
- DetermineParticipationEnqueue(queue, node->InputAt(i));
- }
- }
- }
+ void DetermineParticipationEnqueue(ZoneQueue<Node*>& queue, Node* node);
+ void DetermineParticipation(Node* exit);
private:
NodeData* GetData(Node* node) { return &node_data_[node->id()]; }
@@ -300,54 +149,21 @@ class ControlEquivalence : public ZoneObject {
}
// Mutates the DFS stack by pushing an entry.
- void DFSPush(DFSStack& stack, Node* node, Node* from, DFSDirection dir) {
- DCHECK(GetData(node)->participates);
- DCHECK(!GetData(node)->visited);
- GetData(node)->on_stack = true;
- Node::InputEdges::iterator input = node->input_edges().begin();
- Node::UseEdges::iterator use = node->use_edges().begin();
- stack.push({dir, input, use, from, node});
- }
+ void DFSPush(DFSStack& stack, Node* node, Node* from, DFSDirection dir);
// Mutates the DFS stack by popping an entry.
- void DFSPop(DFSStack& stack, Node* node) {
- DCHECK_EQ(stack.top().node, node);
- GetData(node)->on_stack = false;
- GetData(node)->visited = true;
- stack.pop();
- }
+ void DFSPop(DFSStack& stack, Node* node);
- // TODO(mstarzinger): Optimize this to avoid linear search.
- void BracketListDelete(BracketList& blist, Node* to, DFSDirection direction) {
- for (BracketList::iterator i = blist.begin(); i != blist.end(); /*nop*/) {
- if (i->to == to && i->direction != direction) {
- TRACE(" BList erased: {%d->%d}\n", i->from->id(), i->to->id());
- i = blist.erase(i);
- } else {
- ++i;
- }
- }
- }
+ void BracketListDelete(BracketList& blist, Node* to, DFSDirection direction);
+ void BracketListTRACE(BracketList& blist);
- void BracketListTRACE(BracketList& blist) {
- if (FLAG_trace_turbo_scheduler) {
- TRACE(" BList: ");
- for (Bracket bracket : blist) {
- TRACE("{%d->%d} ", bracket.from->id(), bracket.to->id());
- }
- TRACE("\n");
- }
- }
-
- Zone* zone_;
- Graph* graph_;
+ Zone* const zone_;
+ Graph* const graph_;
int dfs_number_; // Generates new DFS pre-order numbers on demand.
int class_number_; // Generates new equivalence class numbers on demand.
Data node_data_; // Per-node data stored as a side-table.
};
-#undef TRACE
-
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « BUILD.gn ('k') | src/compiler/control-equivalence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698