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

Side by Side Diff: src/compiler/simplified-operator-reducer.cc

Issue 1162563002: [turbofan] Remove the useless SimplifiedOperatorReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
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/simplified-operator-reducer.h"
6
7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator.h"
9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/operator-properties.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph)
17 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
18
19
20 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {}
21
22
23 Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
24 switch (node->opcode()) {
25 case IrOpcode::kBooleanNot: {
26 HeapObjectMatcher<HeapObject> m(node->InputAt(0));
27 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) {
28 return Replace(jsgraph()->TrueConstant());
29 }
30 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) {
31 return Replace(jsgraph()->FalseConstant());
32 }
33 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0));
34 break;
35 }
36 case IrOpcode::kChangeBitToBool: {
37 Int32Matcher m(node->InputAt(0));
38 if (m.Is(0)) return Replace(jsgraph()->FalseConstant());
39 if (m.Is(1)) return Replace(jsgraph()->TrueConstant());
40 if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0));
41 break;
42 }
43 case IrOpcode::kChangeBoolToBit: {
44 HeapObjectMatcher<HeapObject> m(node->InputAt(0));
45 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) {
46 return ReplaceInt32(0);
47 }
48 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) {
49 return ReplaceInt32(1);
50 }
51 if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0));
52 break;
53 }
54 case IrOpcode::kChangeFloat64ToTagged: {
55 Float64Matcher m(node->InputAt(0));
56 if (m.HasValue()) return ReplaceNumber(m.Value());
57 break;
58 }
59 case IrOpcode::kChangeInt32ToTagged: {
60 Int32Matcher m(node->InputAt(0));
61 if (m.HasValue()) return ReplaceNumber(m.Value());
62 break;
63 }
64 case IrOpcode::kChangeTaggedToFloat64: {
65 NumberMatcher m(node->InputAt(0));
66 if (m.HasValue()) return ReplaceFloat64(m.Value());
67 if (m.IsChangeFloat64ToTagged()) return Replace(m.node()->InputAt(0));
68 if (m.IsChangeInt32ToTagged()) {
69 return Change(node, machine()->ChangeInt32ToFloat64(),
70 m.node()->InputAt(0));
71 }
72 if (m.IsChangeUint32ToTagged()) {
73 return Change(node, machine()->ChangeUint32ToFloat64(),
74 m.node()->InputAt(0));
75 }
76 break;
77 }
78 case IrOpcode::kChangeTaggedToInt32: {
79 NumberMatcher m(node->InputAt(0));
80 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
81 if (m.IsChangeFloat64ToTagged()) {
82 return Change(node, machine()->ChangeFloat64ToInt32(),
83 m.node()->InputAt(0));
84 }
85 if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0));
86 break;
87 }
88 case IrOpcode::kChangeTaggedToUint32: {
89 NumberMatcher m(node->InputAt(0));
90 if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value()));
91 if (m.IsChangeFloat64ToTagged()) {
92 return Change(node, machine()->ChangeFloat64ToUint32(),
93 m.node()->InputAt(0));
94 }
95 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0));
96 break;
97 }
98 case IrOpcode::kChangeUint32ToTagged: {
99 Uint32Matcher m(node->InputAt(0));
100 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value()));
101 break;
102 }
103 case IrOpcode::kStoreField: {
104 // TODO(turbofan): Poor man's store elimination, remove this once we have
105 // a fully featured store elimination in place.
106 Node* const effect = node->InputAt(2);
107 if (effect->op()->Equals(node->op()) && effect->OwnedBy(node) &&
108 effect->InputAt(0) == node->InputAt(0)) {
109 // The {effect} is a store to the same field in the same object, and
110 // {node} is the only effect observer, so we can kill {effect} and
111 // instead make {node} depend on the incoming effect to {effect}.
112 node->ReplaceInput(2, effect->InputAt(2));
113 effect->Kill();
114 return Changed(node);
115 }
116 break;
117 }
118 default:
119 break;
120 }
121 return NoChange();
122 }
123
124
125 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op,
126 Node* a) {
127 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op));
128 DCHECK_LE(1, node->InputCount());
129 node->set_op(op);
130 node->ReplaceInput(0, a);
131 return Changed(node);
132 }
133
134
135 Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) {
136 return Replace(jsgraph()->Float64Constant(value));
137 }
138
139
140 Reduction SimplifiedOperatorReducer::ReplaceInt32(int32_t value) {
141 return Replace(jsgraph()->Int32Constant(value));
142 }
143
144
145 Reduction SimplifiedOperatorReducer::ReplaceNumber(double value) {
146 return Replace(jsgraph()->Constant(value));
147 }
148
149
150 Reduction SimplifiedOperatorReducer::ReplaceNumber(int32_t value) {
151 return Replace(jsgraph()->Constant(value));
152 }
153
154
155 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); }
156
157
158 Factory* SimplifiedOperatorReducer::factory() const {
159 return jsgraph()->isolate()->factory();
160 }
161
162
163 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const {
164 return jsgraph()->machine();
165 }
166
167 } // namespace compiler
168 } // namespace internal
169 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | test/unittests/compiler/simplified-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698