OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/graph.h" | 6 #include "src/compiler/graph.h" |
7 #include "src/compiler/node.h" | 7 #include "src/compiler/node.h" |
| 8 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
9 #include "test/unittests/compiler/graph-reducer-unittest.h" | 10 #include "test/unittests/compiler/graph-reducer-unittest.h" |
10 #include "test/unittests/test-utils.h" | 11 #include "test/unittests/test-utils.h" |
11 | 12 |
12 using testing::_; | 13 using testing::_; |
13 using testing::DefaultValue; | 14 using testing::DefaultValue; |
14 using testing::ElementsAre; | 15 using testing::ElementsAre; |
15 using testing::Return; | 16 using testing::Return; |
16 using testing::Sequence; | 17 using testing::Sequence; |
17 using testing::StrictMock; | 18 using testing::StrictMock; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }; | 57 }; |
57 | 58 |
58 | 59 |
59 // Replaces all "A" operators with "B" operators without creating new nodes. | 60 // Replaces all "A" operators with "B" operators without creating new nodes. |
60 class InPlaceABReducer final : public Reducer { | 61 class InPlaceABReducer final : public Reducer { |
61 public: | 62 public: |
62 Reduction Reduce(Node* node) final { | 63 Reduction Reduce(Node* node) final { |
63 switch (node->op()->opcode()) { | 64 switch (node->op()->opcode()) { |
64 case kOpcodeA0: | 65 case kOpcodeA0: |
65 EXPECT_EQ(0, node->InputCount()); | 66 EXPECT_EQ(0, node->InputCount()); |
66 node->set_op(&kOpB0); | 67 NodeProperties::ChangeOp(node, &kOpB0); |
67 return Replace(node); | 68 return Replace(node); |
68 case kOpcodeA1: | 69 case kOpcodeA1: |
69 EXPECT_EQ(1, node->InputCount()); | 70 EXPECT_EQ(1, node->InputCount()); |
70 node->set_op(&kOpB1); | 71 NodeProperties::ChangeOp(node, &kOpB1); |
71 return Replace(node); | 72 return Replace(node); |
72 case kOpcodeA2: | 73 case kOpcodeA2: |
73 EXPECT_EQ(2, node->InputCount()); | 74 EXPECT_EQ(2, node->InputCount()); |
74 node->set_op(&kOpB2); | 75 NodeProperties::ChangeOp(node, &kOpB2); |
75 return Replace(node); | 76 return Replace(node); |
76 } | 77 } |
77 return NoChange(); | 78 return NoChange(); |
78 } | 79 } |
79 }; | 80 }; |
80 | 81 |
81 | 82 |
82 // Replaces all "A" operators with "B" operators by allocating new nodes. | 83 // Replaces all "A" operators with "B" operators by allocating new nodes. |
83 class NewABReducer final : public Reducer { | 84 class NewABReducer final : public Reducer { |
84 public: | 85 public: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 }; | 172 }; |
172 | 173 |
173 | 174 |
174 // Replaces all "B" operators with "C" operators without creating new nodes. | 175 // Replaces all "B" operators with "C" operators without creating new nodes. |
175 class InPlaceBCReducer final : public Reducer { | 176 class InPlaceBCReducer final : public Reducer { |
176 public: | 177 public: |
177 Reduction Reduce(Node* node) final { | 178 Reduction Reduce(Node* node) final { |
178 switch (node->op()->opcode()) { | 179 switch (node->op()->opcode()) { |
179 case kOpcodeB0: | 180 case kOpcodeB0: |
180 EXPECT_EQ(0, node->InputCount()); | 181 EXPECT_EQ(0, node->InputCount()); |
181 node->set_op(&kOpC0); | 182 NodeProperties::ChangeOp(node, &kOpC0); |
182 return Replace(node); | 183 return Replace(node); |
183 case kOpcodeB1: | 184 case kOpcodeB1: |
184 EXPECT_EQ(1, node->InputCount()); | 185 EXPECT_EQ(1, node->InputCount()); |
185 node->set_op(&kOpC1); | 186 NodeProperties::ChangeOp(node, &kOpC1); |
186 return Replace(node); | 187 return Replace(node); |
187 case kOpcodeB2: | 188 case kOpcodeB2: |
188 EXPECT_EQ(2, node->InputCount()); | 189 EXPECT_EQ(2, node->InputCount()); |
189 node->set_op(&kOpC2); | 190 NodeProperties::ChangeOp(node, &kOpC2); |
190 return Replace(node); | 191 return Replace(node); |
191 } | 192 } |
192 return NoChange(); | 193 return NoChange(); |
193 } | 194 } |
194 }; | 195 }; |
195 | 196 |
196 | 197 |
197 // Swaps the inputs to "kOp2A" and "kOp2B" nodes based on ids. | 198 // Swaps the inputs to "kOp2A" and "kOp2B" nodes based on ids. |
198 class AB2Sorter final : public Reducer { | 199 class AB2Sorter final : public Reducer { |
199 public: | 200 public: |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 EXPECT_EQ(&kOpC0, n1->op()); | 852 EXPECT_EQ(&kOpC0, n1->op()); |
852 EXPECT_EQ(&kOpC1, end->op()); | 853 EXPECT_EQ(&kOpC1, end->op()); |
853 EXPECT_EQ(n1, end->InputAt(0)); | 854 EXPECT_EQ(n1, end->InputAt(0)); |
854 } | 855 } |
855 } | 856 } |
856 } | 857 } |
857 | 858 |
858 } // namespace compiler | 859 } // namespace compiler |
859 } // namespace internal | 860 } // namespace internal |
860 } // namespace v8 | 861 } // namespace v8 |
OLD | NEW |