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

Unified Diff: src/compiler/value-numbering-reducer.cc

Issue 539503002: [turbofan] Initial version of ValueNumberingReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Nit and clang-format. Created 6 years, 3 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/value-numbering-reducer.h ('k') | src/compiler/value-numbering-reducer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/value-numbering-reducer.cc
diff --git a/src/compiler/value-numbering-reducer.cc b/src/compiler/value-numbering-reducer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fe4b39c389ffa69bcec22f196730b1b862630bb
--- /dev/null
+++ b/src/compiler/value-numbering-reducer.cc
@@ -0,0 +1,73 @@
+// 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/value-numbering-reducer.h"
+
+#include "src/compiler/node.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+namespace {
+
+size_t HashCode(Node* node) { return node->op()->HashCode(); }
+
+
+bool Equals(Node* a, Node* b) {
+ DCHECK_NOT_NULL(a);
+ DCHECK_NOT_NULL(b);
+ DCHECK_NOT_NULL(a->op());
+ DCHECK_NOT_NULL(b->op());
+ if (!a->op()->Equals(b->op())) return false;
+ if (a->InputCount() != b->InputCount()) return false;
+ for (int j = 0; j < a->InputCount(); ++j) {
+ DCHECK_NOT_NULL(a->InputAt(j));
+ DCHECK_NOT_NULL(b->InputAt(j));
+ if (a->InputAt(j)->id() != b->InputAt(j)->id()) return false;
+ }
+ return true;
+}
+
+} // namespace
+
+
+class ValueNumberingReducer::Entry FINAL : public ZoneObject {
+ public:
+ Entry(Node* node, Entry* next) : node_(node), next_(next) {}
+
+ Node* node() const { return node_; }
+ Entry* next() const { return next_; }
+
+ private:
+ Node* node_;
+ Entry* next_;
+};
+
+
+ValueNumberingReducer::ValueNumberingReducer(Zone* zone) : zone_(zone) {
+ for (size_t i = 0; i < arraysize(buckets_); ++i) {
+ buckets_[i] = NULL;
+ }
+}
+
+
+ValueNumberingReducer::~ValueNumberingReducer() {}
+
+
+Reduction ValueNumberingReducer::Reduce(Node* node) {
+ Entry** head = &buckets_[HashCode(node) % arraysize(buckets_)];
+ for (Entry* entry = *head; entry; entry = entry->next()) {
+ if (entry->node()->op() == NULL) continue;
+ if (Equals(node, entry->node())) {
+ return Replace(entry->node());
+ }
+ }
+ *head = new (zone()) Entry(node, *head);
+ return NoChange();
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/compiler/value-numbering-reducer.h ('k') | src/compiler/value-numbering-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698