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

Unified Diff: src/compiler/select-lowering.cc

Issue 702463002: [turbofan] Introduce separate SelectLowering reducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix windows Created 6 years, 1 month 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/select-lowering.h ('k') | test/unittests/compiler/select-lowering-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/select-lowering.cc
diff --git a/src/compiler/select-lowering.cc b/src/compiler/select-lowering.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4e553d1dc1334fed5264e1b1b9a7497f2adea629
--- /dev/null
+++ b/src/compiler/select-lowering.cc
@@ -0,0 +1,54 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/compiler/select-lowering.h"
+
+#include "src/compiler/common-operator.h"
+#include "src/compiler/generic-node-inl.h"
+#include "src/compiler/graph.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common)
+ : common_(common),
+ graph_(graph),
+ merges_(Merges::key_compare(), Merges::allocator_type(graph->zone())) {}
+
+
+SelectLowering::~SelectLowering() {}
+
+
+Reduction SelectLowering::Reduce(Node* node) {
+ if (node->opcode() != IrOpcode::kSelect) return NoChange();
+ SelectParameters const p = SelectParametersOf(node->op());
+
+ Node* const cond = node->InputAt(0);
+ Node* const control = graph()->start();
+
+ // Check if we already have a diamond for this condition.
+ auto i = merges_.find(cond);
+ if (i == merges_.end()) {
+ // Create a new diamond for this condition and remember its merge node.
+ Node* branch = graph()->NewNode(common()->Branch(p.hint()), cond, control);
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ i = merges_.insert(std::make_pair(cond, merge)).first;
+ }
+
+ DCHECK_EQ(cond, i->first);
+
+ // Create a Phi hanging off the previously determined merge.
+ node->set_op(common()->Phi(p.type(), 2));
+ node->ReplaceInput(0, node->InputAt(1));
+ node->ReplaceInput(1, node->InputAt(2));
+ node->ReplaceInput(2, i->second);
+ return Changed(node);
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/compiler/select-lowering.h ('k') | test/unittests/compiler/select-lowering-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698