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-reducer.h" | 5 #include "src/compiler/common-operator-reducer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 return NoChange(); | 102 return NoChange(); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 Reduction CommonOperatorReducer::ReduceSelect(Node* node) { | 106 Reduction CommonOperatorReducer::ReduceSelect(Node* node) { |
107 DCHECK_EQ(IrOpcode::kSelect, node->opcode()); | 107 DCHECK_EQ(IrOpcode::kSelect, node->opcode()); |
108 Node* cond = NodeProperties::GetValueInput(node, 0); | 108 Node* cond = NodeProperties::GetValueInput(node, 0); |
109 Node* vtrue = NodeProperties::GetValueInput(node, 1); | 109 Node* vtrue = NodeProperties::GetValueInput(node, 1); |
110 Node* vfalse = NodeProperties::GetValueInput(node, 2); | 110 Node* vfalse = NodeProperties::GetValueInput(node, 2); |
111 if (vtrue == vfalse) return Replace(vtrue); | 111 if (vtrue == vfalse) return Replace(vtrue); |
112 if (cond->opcode() == IrOpcode::kFloat32LessThan) { | 112 switch (cond->opcode()) { |
113 Float32BinopMatcher mcond(cond); | 113 case IrOpcode::kHeapConstant: { |
114 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 114 HeapObjectMatcher<HeapObject> mcond(cond); |
115 vfalse->opcode() == IrOpcode::kFloat32Sub && | 115 if (mcond.Is( |
Michael Starzinger
2015/04/10 09:32:39
We should be able to use the following here ...
H
Benedikt Meurer
2015/04/10 09:39:38
Done.
| |
116 machine()->HasFloat32Abs()) { | 116 Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { |
117 Float32BinopMatcher mvfalse(vfalse); | 117 return Replace(vtrue); |
118 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | |
119 return Change(node, machine()->Float32Abs(), vtrue); | |
120 } | 118 } |
119 if (mcond.Is( | |
120 Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { | |
121 return Replace(vfalse); | |
122 } | |
123 break; | |
121 } | 124 } |
122 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 125 case IrOpcode::kFloat32LessThan: { |
123 machine()->HasFloat32Min()) { | 126 Float32BinopMatcher mcond(cond); |
124 return Change(node, machine()->Float32Min(), vtrue, vfalse); | 127 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
125 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | 128 vfalse->opcode() == IrOpcode::kFloat32Sub && |
126 machine()->HasFloat32Max()) { | 129 machine()->HasFloat32Abs()) { |
127 return Change(node, machine()->Float32Max(), vtrue, vfalse); | 130 Float32BinopMatcher mvfalse(vfalse); |
131 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | |
132 return Change(node, machine()->Float32Abs(), vtrue); | |
133 } | |
134 } | |
135 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | |
136 machine()->HasFloat32Min()) { | |
137 return Change(node, machine()->Float32Min(), vtrue, vfalse); | |
138 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | |
139 machine()->HasFloat32Max()) { | |
140 return Change(node, machine()->Float32Max(), vtrue, vfalse); | |
141 } | |
142 break; | |
128 } | 143 } |
129 } else if (cond->opcode() == IrOpcode::kFloat64LessThan) { | 144 case IrOpcode::kFloat64LessThan: { |
130 Float64BinopMatcher mcond(cond); | 145 Float64BinopMatcher mcond(cond); |
131 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 146 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
132 vfalse->opcode() == IrOpcode::kFloat64Sub && | 147 vfalse->opcode() == IrOpcode::kFloat64Sub && |
133 machine()->HasFloat64Abs()) { | 148 machine()->HasFloat64Abs()) { |
134 Float64BinopMatcher mvfalse(vfalse); | 149 Float64BinopMatcher mvfalse(vfalse); |
135 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | 150 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
136 return Change(node, machine()->Float64Abs(), vtrue); | 151 return Change(node, machine()->Float64Abs(), vtrue); |
152 } | |
137 } | 153 } |
154 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | |
155 machine()->HasFloat64Min()) { | |
156 return Change(node, machine()->Float64Min(), vtrue, vfalse); | |
157 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | |
158 machine()->HasFloat64Max()) { | |
159 return Change(node, machine()->Float64Max(), vtrue, vfalse); | |
160 } | |
161 break; | |
138 } | 162 } |
139 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 163 default: |
140 machine()->HasFloat64Min()) { | 164 break; |
141 return Change(node, machine()->Float64Min(), vtrue, vfalse); | |
142 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | |
143 machine()->HasFloat64Max()) { | |
144 return Change(node, machine()->Float64Max(), vtrue, vfalse); | |
145 } | |
146 } | 165 } |
147 return NoChange(); | 166 return NoChange(); |
148 } | 167 } |
149 | 168 |
150 | 169 |
151 Reduction CommonOperatorReducer::Change(Node* node, Operator const* op, | 170 Reduction CommonOperatorReducer::Change(Node* node, Operator const* op, |
152 Node* a) { | 171 Node* a) { |
153 node->set_op(op); | 172 node->set_op(op); |
154 node->ReplaceInput(0, a); | 173 node->ReplaceInput(0, a); |
155 node->TrimInputCount(1); | 174 node->TrimInputCount(1); |
(...skipping 12 matching lines...) Expand all Loading... | |
168 | 187 |
169 | 188 |
170 CommonOperatorBuilder* CommonOperatorReducer::common() const { | 189 CommonOperatorBuilder* CommonOperatorReducer::common() const { |
171 return jsgraph()->common(); | 190 return jsgraph()->common(); |
172 } | 191 } |
173 | 192 |
174 | 193 |
175 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } | 194 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } |
176 | 195 |
177 | 196 |
197 Factory* CommonOperatorReducer::factory() const { | |
Michael Starzinger
2015/04/10 09:32:39
If the above suggestion works, then the factory ge
Benedikt Meurer
2015/04/10 09:39:38
Done.
| |
198 return jsgraph()->isolate()->factory(); | |
199 } | |
200 | |
201 | |
178 MachineOperatorBuilder* CommonOperatorReducer::machine() const { | 202 MachineOperatorBuilder* CommonOperatorReducer::machine() const { |
179 return jsgraph()->machine(); | 203 return jsgraph()->machine(); |
180 } | 204 } |
181 | 205 |
182 } // namespace compiler | 206 } // namespace compiler |
183 } // namespace internal | 207 } // namespace internal |
184 } // namespace v8 | 208 } // namespace v8 |
OLD | NEW |