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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler/value-numbering-reducer.h"
6
7 #include "src/compiler/node.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace compiler {
12
13 namespace {
14
15 size_t HashCode(Node* node) { return node->op()->HashCode(); }
16
17
18 bool Equals(Node* a, Node* b) {
19 DCHECK_NOT_NULL(a);
20 DCHECK_NOT_NULL(b);
21 DCHECK_NOT_NULL(a->op());
22 DCHECK_NOT_NULL(b->op());
23 if (!a->op()->Equals(b->op())) return false;
24 if (a->InputCount() != b->InputCount()) return false;
25 for (int j = 0; j < a->InputCount(); ++j) {
26 DCHECK_NOT_NULL(a->InputAt(j));
27 DCHECK_NOT_NULL(b->InputAt(j));
28 if (a->InputAt(j)->id() != b->InputAt(j)->id()) return false;
29 }
30 return true;
31 }
32
33 } // namespace
34
35
36 class ValueNumberingReducer::Entry FINAL : public ZoneObject {
37 public:
38 Entry(Node* node, Entry* next) : node_(node), next_(next) {}
39
40 Node* node() const { return node_; }
41 Entry* next() const { return next_; }
42
43 private:
44 Node* node_;
45 Entry* next_;
46 };
47
48
49 ValueNumberingReducer::ValueNumberingReducer(Zone* zone) : zone_(zone) {
50 for (size_t i = 0; i < arraysize(buckets_); ++i) {
51 buckets_[i] = NULL;
52 }
53 }
54
55
56 ValueNumberingReducer::~ValueNumberingReducer() {}
57
58
59 Reduction ValueNumberingReducer::Reduce(Node* node) {
60 Entry** head = &buckets_[HashCode(node) % arraysize(buckets_)];
61 for (Entry* entry = *head; entry; entry = entry->next()) {
62 if (entry->node()->op() == NULL) continue;
63 if (Equals(node, entry->node())) {
64 return Replace(entry->node());
65 }
66 }
67 *head = new (zone()) Entry(node, *head);
68 return NoChange();
69 }
70
71 } // namespace compiler
72 } // namespace internal
73 } // namespace v8
OLDNEW
« 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