OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/simd-scalar-lowering.h" | 5 #include "src/compiler/simd-scalar-lowering.h" |
6 #include "src/compiler/diamond.h" | 6 #include "src/compiler/diamond.h" |
7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } else { | 51 } else { |
52 // Push the next input onto the stack. | 52 // Push the next input onto the stack. |
53 Node* input = top.node->InputAt(top.input_index++); | 53 Node* input = top.node->InputAt(top.input_index++); |
54 if (state_.Get(input) == State::kUnvisited) { | 54 if (state_.Get(input) == State::kUnvisited) { |
55 SetLoweredType(input, top.node); | 55 SetLoweredType(input, top.node); |
56 if (input->opcode() == IrOpcode::kPhi) { | 56 if (input->opcode() == IrOpcode::kPhi) { |
57 // To break cycles with phi nodes we push phis on a separate stack so | 57 // To break cycles with phi nodes we push phis on a separate stack so |
58 // that they are processed after all other nodes. | 58 // that they are processed after all other nodes. |
59 PreparePhiReplacement(input); | 59 PreparePhiReplacement(input); |
60 stack_.push_front({input, 0}); | 60 stack_.push_front({input, 0}); |
| 61 } else if (input->opcode() == IrOpcode::kEffectPhi || |
| 62 input->opcode() == IrOpcode::kLoop) { |
| 63 stack_.push_front({input, 0}); |
61 } else { | 64 } else { |
62 stack_.push_back({input, 0}); | 65 stack_.push_back({input, 0}); |
63 } | 66 } |
64 state_.Set(input, State::kOnStack); | 67 state_.Set(input, State::kOnStack); |
65 } | 68 } |
66 } | 69 } |
67 } | 70 } |
68 } | 71 } |
69 | 72 |
70 #define FOREACH_INT32X4_OPCODE(V) \ | 73 #define FOREACH_INT32X4_OPCODE(V) \ |
(...skipping 24 matching lines...) Expand all Loading... |
95 default: | 98 default: |
96 replacements_[node->id()].type = replacements_[output->id()].type; | 99 replacements_[node->id()].type = replacements_[output->id()].type; |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 static int GetParameterIndexAfterLowering( | 103 static int GetParameterIndexAfterLowering( |
101 Signature<MachineRepresentation>* signature, int old_index) { | 104 Signature<MachineRepresentation>* signature, int old_index) { |
102 // In function calls, the simd128 types are passed as 4 Int32 types. The | 105 // In function calls, the simd128 types are passed as 4 Int32 types. The |
103 // parameters are typecast to the types as needed for various operations. | 106 // parameters are typecast to the types as needed for various operations. |
104 int result = old_index; | 107 int result = old_index; |
105 for (int i = 0; i < old_index; i++) { | 108 for (int i = 0; i < old_index; ++i) { |
106 if (signature->GetParam(i) == MachineRepresentation::kSimd128) { | 109 if (signature->GetParam(i) == MachineRepresentation::kSimd128) { |
107 result += 3; | 110 result += 3; |
108 } | 111 } |
109 } | 112 } |
110 return result; | 113 return result; |
111 } | 114 } |
112 | 115 |
113 int SimdScalarLowering::GetParameterCountAfterLowering() { | 116 int SimdScalarLowering::GetParameterCountAfterLowering() { |
114 if (parameter_count_after_lowering_ == -1) { | 117 if (parameter_count_after_lowering_ == -1) { |
115 // GetParameterIndexAfterLowering(parameter_count) returns the parameter | 118 // GetParameterIndexAfterLowering(parameter_count) returns the parameter |
116 // count after lowering. | 119 // count after lowering. |
117 parameter_count_after_lowering_ = GetParameterIndexAfterLowering( | 120 parameter_count_after_lowering_ = GetParameterIndexAfterLowering( |
118 signature(), static_cast<int>(signature()->parameter_count())); | 121 signature(), static_cast<int>(signature()->parameter_count())); |
119 } | 122 } |
120 return parameter_count_after_lowering_; | 123 return parameter_count_after_lowering_; |
121 } | 124 } |
122 | 125 |
123 static int GetReturnCountAfterLowering( | 126 static int GetReturnCountAfterLowering( |
124 Signature<MachineRepresentation>* signature) { | 127 Signature<MachineRepresentation>* signature) { |
125 int result = static_cast<int>(signature->return_count()); | 128 int result = static_cast<int>(signature->return_count()); |
126 for (int i = 0; i < static_cast<int>(signature->return_count()); i++) { | 129 for (int i = 0; i < static_cast<int>(signature->return_count()); ++i) { |
127 if (signature->GetReturn(i) == MachineRepresentation::kSimd128) { | 130 if (signature->GetReturn(i) == MachineRepresentation::kSimd128) { |
128 result += 3; | 131 result += 3; |
129 } | 132 } |
130 } | 133 } |
131 return result; | 134 return result; |
132 } | 135 } |
133 | 136 |
| 137 void SimdScalarLowering::GetIndexNodes(Node* index, Node** new_indices) { |
| 138 new_indices[0] = index; |
| 139 for (size_t i = 1; i < kMaxLanes; ++i) { |
| 140 new_indices[i] = graph()->NewNode( |
| 141 machine()->Int32Add(), index, |
| 142 graph()->NewNode( |
| 143 common()->Int32Constant(static_cast<int>(i) * 16 / kMaxLanes))); |
| 144 } |
| 145 } |
| 146 |
| 147 void SimdScalarLowering::LowerLoadOp(MachineRepresentation rep, Node* node, |
| 148 const Operator* load_op) { |
| 149 if (rep == MachineRepresentation::kSimd128) { |
| 150 Node* base = node->InputAt(0); |
| 151 Node* index = node->InputAt(1); |
| 152 Node* indices[kMaxLanes]; |
| 153 GetIndexNodes(index, indices); |
| 154 Node* rep_nodes[kMaxLanes]; |
| 155 rep_nodes[0] = node; |
| 156 NodeProperties::ChangeOp(rep_nodes[0], load_op); |
| 157 if (node->InputCount() > 2) { |
| 158 DCHECK(node->InputCount() > 3); |
| 159 Node* effect_high = node->InputAt(2); |
| 160 Node* control_high = node->InputAt(3); |
| 161 rep_nodes[3] = graph()->NewNode(load_op, base, indices[3], effect_high, |
| 162 control_high); |
| 163 rep_nodes[2] = graph()->NewNode(load_op, base, indices[2], rep_nodes[3], |
| 164 control_high); |
| 165 rep_nodes[1] = graph()->NewNode(load_op, base, indices[1], rep_nodes[2], |
| 166 control_high); |
| 167 rep_nodes[0]->ReplaceInput(2, rep_nodes[1]); |
| 168 } else { |
| 169 for (size_t i = 1; i < kMaxLanes; ++i) { |
| 170 rep_nodes[i] = graph()->NewNode(load_op, base, indices[i]); |
| 171 } |
| 172 } |
| 173 ReplaceNode(node, rep_nodes); |
| 174 } else { |
| 175 DefaultLowering(node); |
| 176 } |
| 177 } |
| 178 |
| 179 void SimdScalarLowering::LowerStoreOp(MachineRepresentation rep, Node* node, |
| 180 const Operator* store_op, |
| 181 SimdType rep_type) { |
| 182 if (rep == MachineRepresentation::kSimd128) { |
| 183 Node* base = node->InputAt(0); |
| 184 Node* index = node->InputAt(1); |
| 185 Node* indices[kMaxLanes]; |
| 186 GetIndexNodes(index, indices); |
| 187 DCHECK(node->InputCount() > 2); |
| 188 Node* value = node->InputAt(2); |
| 189 DCHECK(HasReplacement(1, value)); |
| 190 Node* rep_nodes[kMaxLanes]; |
| 191 rep_nodes[0] = node; |
| 192 Node** rep_inputs = GetReplacementsWithType(value, rep_type); |
| 193 rep_nodes[0]->ReplaceInput(2, rep_inputs[0]); |
| 194 NodeProperties::ChangeOp(node, store_op); |
| 195 if (node->InputCount() > 3) { |
| 196 DCHECK(node->InputCount() > 4); |
| 197 Node* effect_high = node->InputAt(3); |
| 198 Node* control_high = node->InputAt(4); |
| 199 rep_nodes[3] = graph()->NewNode(store_op, base, indices[3], rep_inputs[3], |
| 200 effect_high, control_high); |
| 201 rep_nodes[2] = graph()->NewNode(store_op, base, indices[2], rep_inputs[2], |
| 202 rep_nodes[3], control_high); |
| 203 rep_nodes[1] = graph()->NewNode(store_op, base, indices[1], rep_inputs[1], |
| 204 rep_nodes[2], control_high); |
| 205 rep_nodes[0]->ReplaceInput(3, rep_nodes[1]); |
| 206 |
| 207 } else { |
| 208 for (size_t i = 1; i < kMaxLanes; ++i) { |
| 209 rep_nodes[i] = |
| 210 graph()->NewNode(store_op, base, indices[i], rep_inputs[i]); |
| 211 } |
| 212 } |
| 213 |
| 214 ReplaceNode(node, rep_nodes); |
| 215 } else { |
| 216 DefaultLowering(node); |
| 217 } |
| 218 } |
| 219 |
| 220 void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType rep_type, |
| 221 const Operator* op) { |
| 222 DCHECK(node->InputCount() == 2); |
| 223 Node** rep_left = GetReplacementsWithType(node->InputAt(0), rep_type); |
| 224 Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type); |
| 225 Node* rep_node[kMaxLanes]; |
| 226 for (int i = 0; i < kMaxLanes; ++i) { |
| 227 rep_node[i] = graph()->NewNode(op, rep_left[i], rep_right[i]); |
| 228 } |
| 229 ReplaceNode(node, rep_node); |
| 230 } |
| 231 |
134 void SimdScalarLowering::LowerNode(Node* node) { | 232 void SimdScalarLowering::LowerNode(Node* node) { |
135 SimdType rep_type = ReplacementType(node); | 233 SimdType rep_type = ReplacementType(node); |
136 switch (node->opcode()) { | 234 switch (node->opcode()) { |
137 case IrOpcode::kStart: { | 235 case IrOpcode::kStart: { |
138 int parameter_count = GetParameterCountAfterLowering(); | 236 int parameter_count = GetParameterCountAfterLowering(); |
139 // Only exchange the node if the parameter count actually changed. | 237 // Only exchange the node if the parameter count actually changed. |
140 if (parameter_count != static_cast<int>(signature()->parameter_count())) { | 238 if (parameter_count != static_cast<int>(signature()->parameter_count())) { |
141 int delta = | 239 int delta = |
142 parameter_count - static_cast<int>(signature()->parameter_count()); | 240 parameter_count - static_cast<int>(signature()->parameter_count()); |
143 int new_output_count = node->op()->ValueOutputCount() + delta; | 241 int new_output_count = node->op()->ValueOutputCount() + delta; |
144 NodeProperties::ChangeOp(node, common()->Start(new_output_count)); | 242 NodeProperties::ChangeOp(node, common()->Start(new_output_count)); |
145 } | 243 } |
146 break; | 244 break; |
147 } | 245 } |
148 case IrOpcode::kParameter: { | 246 case IrOpcode::kParameter: { |
149 DCHECK(node->InputCount() == 1); | 247 DCHECK(node->InputCount() == 1); |
150 // Only exchange the node if the parameter count actually changed. We do | 248 // Only exchange the node if the parameter count actually changed. We do |
151 // not even have to do the default lowering because the the start node, | 249 // not even have to do the default lowering because the the start node, |
152 // the only input of a parameter node, only changes if the parameter count | 250 // the only input of a parameter node, only changes if the parameter count |
153 // changes. | 251 // changes. |
154 if (GetParameterCountAfterLowering() != | 252 if (GetParameterCountAfterLowering() != |
155 static_cast<int>(signature()->parameter_count())) { | 253 static_cast<int>(signature()->parameter_count())) { |
156 int old_index = ParameterIndexOf(node->op()); | 254 int old_index = ParameterIndexOf(node->op()); |
157 int new_index = GetParameterIndexAfterLowering(signature(), old_index); | 255 int new_index = GetParameterIndexAfterLowering(signature(), old_index); |
158 if (old_index == new_index) { | 256 if (old_index == new_index) { |
159 NodeProperties::ChangeOp(node, common()->Parameter(new_index)); | 257 NodeProperties::ChangeOp(node, common()->Parameter(new_index)); |
160 | 258 |
161 Node* new_node[kMaxLanes]; | 259 Node* new_node[kMaxLanes]; |
162 for (int i = 0; i < kMaxLanes; i++) { | 260 for (int i = 0; i < kMaxLanes; ++i) { |
163 new_node[i] = nullptr; | 261 new_node[i] = nullptr; |
164 } | 262 } |
165 new_node[0] = node; | 263 new_node[0] = node; |
166 if (signature()->GetParam(old_index) == | 264 if (signature()->GetParam(old_index) == |
167 MachineRepresentation::kSimd128) { | 265 MachineRepresentation::kSimd128) { |
168 for (int i = 1; i < kMaxLanes; i++) { | 266 for (int i = 1; i < kMaxLanes; ++i) { |
169 new_node[i] = graph()->NewNode(common()->Parameter(new_index + i), | 267 new_node[i] = graph()->NewNode(common()->Parameter(new_index + i), |
170 graph()->start()); | 268 graph()->start()); |
171 } | 269 } |
172 } | 270 } |
173 ReplaceNode(node, new_node); | 271 ReplaceNode(node, new_node); |
174 } | 272 } |
175 } | 273 } |
176 break; | 274 break; |
177 } | 275 } |
| 276 case IrOpcode::kLoad: { |
| 277 MachineRepresentation rep = |
| 278 LoadRepresentationOf(node->op()).representation(); |
| 279 const Operator* load_op; |
| 280 if (rep_type == SimdType::kInt32) { |
| 281 load_op = machine()->Load(MachineType::Int32()); |
| 282 } else if (rep_type == SimdType::kFloat32) { |
| 283 load_op = machine()->Load(MachineType::Float32()); |
| 284 } |
| 285 LowerLoadOp(rep, node, load_op); |
| 286 break; |
| 287 } |
| 288 case IrOpcode::kUnalignedLoad: { |
| 289 MachineRepresentation rep = |
| 290 UnalignedLoadRepresentationOf(node->op()).representation(); |
| 291 const Operator* load_op; |
| 292 if (rep_type == SimdType::kInt32) { |
| 293 load_op = machine()->UnalignedLoad(MachineType::Int32()); |
| 294 } else if (rep_type == SimdType::kFloat32) { |
| 295 load_op = machine()->UnalignedLoad(MachineType::Float32()); |
| 296 } |
| 297 LowerLoadOp(rep, node, load_op); |
| 298 break; |
| 299 } |
| 300 case IrOpcode::kStore: { |
| 301 MachineRepresentation rep = |
| 302 StoreRepresentationOf(node->op()).representation(); |
| 303 WriteBarrierKind write_barrier_kind = |
| 304 StoreRepresentationOf(node->op()).write_barrier_kind(); |
| 305 const Operator* store_op; |
| 306 if (rep_type == SimdType::kInt32) { |
| 307 store_op = machine()->Store(StoreRepresentation( |
| 308 MachineRepresentation::kWord32, write_barrier_kind)); |
| 309 } else { |
| 310 store_op = machine()->Store(StoreRepresentation( |
| 311 MachineRepresentation::kFloat32, write_barrier_kind)); |
| 312 } |
| 313 LowerStoreOp(rep, node, store_op, rep_type); |
| 314 break; |
| 315 } |
| 316 case IrOpcode::kUnalignedStore: { |
| 317 MachineRepresentation rep = UnalignedStoreRepresentationOf(node->op()); |
| 318 const Operator* store_op; |
| 319 if (rep_type == SimdType::kInt32) { |
| 320 store_op = machine()->UnalignedStore(MachineRepresentation::kWord32); |
| 321 } else { |
| 322 store_op = machine()->UnalignedStore(MachineRepresentation::kFloat32); |
| 323 } |
| 324 LowerStoreOp(rep, node, store_op, rep_type); |
| 325 break; |
| 326 } |
178 case IrOpcode::kReturn: { | 327 case IrOpcode::kReturn: { |
179 DefaultLowering(node); | 328 DefaultLowering(node); |
180 int new_return_count = GetReturnCountAfterLowering(signature()); | 329 int new_return_count = GetReturnCountAfterLowering(signature()); |
181 if (static_cast<int>(signature()->return_count()) != new_return_count) { | 330 if (static_cast<int>(signature()->return_count()) != new_return_count) { |
182 NodeProperties::ChangeOp(node, common()->Return(new_return_count)); | 331 NodeProperties::ChangeOp(node, common()->Return(new_return_count)); |
183 } | 332 } |
184 break; | 333 break; |
185 } | 334 } |
186 case IrOpcode::kCall: { | 335 case IrOpcode::kCall: { |
187 // TODO(turbofan): Make WASM code const-correct wrt. CallDescriptor. | 336 // TODO(turbofan): Make WASM code const-correct wrt. CallDescriptor. |
188 CallDescriptor* descriptor = | 337 CallDescriptor* descriptor = |
189 const_cast<CallDescriptor*>(CallDescriptorOf(node->op())); | 338 const_cast<CallDescriptor*>(CallDescriptorOf(node->op())); |
190 if (DefaultLowering(node) || | 339 if (DefaultLowering(node) || |
191 (descriptor->ReturnCount() == 1 && | 340 (descriptor->ReturnCount() == 1 && |
192 descriptor->GetReturnType(0) == MachineType::Simd128())) { | 341 descriptor->GetReturnType(0) == MachineType::Simd128())) { |
193 // We have to adjust the call descriptor. | 342 // We have to adjust the call descriptor. |
194 const Operator* op = | 343 const Operator* op = |
195 common()->Call(wasm::ModuleEnv::GetI32WasmCallDescriptorForSimd( | 344 common()->Call(wasm::ModuleEnv::GetI32WasmCallDescriptorForSimd( |
196 zone(), descriptor)); | 345 zone(), descriptor)); |
197 NodeProperties::ChangeOp(node, op); | 346 NodeProperties::ChangeOp(node, op); |
198 } | 347 } |
199 if (descriptor->ReturnCount() == 1 && | 348 if (descriptor->ReturnCount() == 1 && |
200 descriptor->GetReturnType(0) == MachineType::Simd128()) { | 349 descriptor->GetReturnType(0) == MachineType::Simd128()) { |
201 // We access the additional return values through projections. | 350 // We access the additional return values through projections. |
202 Node* rep_node[kMaxLanes]; | 351 Node* rep_node[kMaxLanes]; |
203 for (int i = 0; i < kMaxLanes; i++) { | 352 for (int i = 0; i < kMaxLanes; ++i) { |
204 rep_node[i] = | 353 rep_node[i] = |
205 graph()->NewNode(common()->Projection(i), node, graph()->start()); | 354 graph()->NewNode(common()->Projection(i), node, graph()->start()); |
206 } | 355 } |
207 ReplaceNode(node, rep_node); | 356 ReplaceNode(node, rep_node); |
208 } | 357 } |
209 break; | 358 break; |
210 } | 359 } |
211 case IrOpcode::kPhi: { | 360 case IrOpcode::kPhi: { |
212 MachineRepresentation rep = PhiRepresentationOf(node->op()); | 361 MachineRepresentation rep = PhiRepresentationOf(node->op()); |
213 if (rep == MachineRepresentation::kSimd128) { | 362 if (rep == MachineRepresentation::kSimd128) { |
214 // The replacement nodes have already been created, we only have to | 363 // The replacement nodes have already been created, we only have to |
215 // replace placeholder nodes. | 364 // replace placeholder nodes. |
216 Node** rep_node = GetReplacements(node); | 365 Node** rep_node = GetReplacements(node); |
217 for (int i = 0; i < node->op()->ValueInputCount(); i++) { | 366 for (int i = 0; i < node->op()->ValueInputCount(); ++i) { |
218 Node** rep_input = | 367 Node** rep_input = |
219 GetReplacementsWithType(node->InputAt(i), rep_type); | 368 GetReplacementsWithType(node->InputAt(i), rep_type); |
220 for (int j = 0; j < kMaxLanes; j++) { | 369 for (int j = 0; j < kMaxLanes; j++) { |
221 rep_node[j]->ReplaceInput(i, rep_input[j]); | 370 rep_node[j]->ReplaceInput(i, rep_input[j]); |
222 } | 371 } |
223 } | 372 } |
224 } else { | 373 } else { |
225 DefaultLowering(node); | 374 DefaultLowering(node); |
226 } | 375 } |
227 break; | 376 break; |
228 } | 377 } |
229 | |
230 case IrOpcode::kInt32x4Add: { | 378 case IrOpcode::kInt32x4Add: { |
231 DCHECK(node->InputCount() == 2); | 379 LowerBinaryOp(node, rep_type, machine()->Int32Add()); |
232 Node** rep_left = GetReplacementsWithType(node->InputAt(0), rep_type); | 380 break; |
233 Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type); | 381 } |
| 382 case IrOpcode::kFloat32x4Add: { |
| 383 LowerBinaryOp(node, rep_type, machine()->Float32Add()); |
| 384 break; |
| 385 } |
| 386 case IrOpcode::kCreateInt32x4: |
| 387 case IrOpcode::kCreateFloat32x4: { |
234 Node* rep_node[kMaxLanes]; | 388 Node* rep_node[kMaxLanes]; |
235 for (int i = 0; i < kMaxLanes; i++) { | 389 for (int i = 0; i < kMaxLanes; ++i) { |
236 rep_node[i] = | 390 if (HasReplacement(0, node->InputAt(i))) { |
237 graph()->NewNode(machine()->Int32Add(), rep_left[i], rep_right[i]); | 391 rep_node[i] = GetReplacements(node->InputAt(i))[0]; |
| 392 } else { |
| 393 rep_node[i] = node->InputAt(i); |
| 394 } |
238 } | 395 } |
239 ReplaceNode(node, rep_node); | 396 ReplaceNode(node, rep_node); |
240 break; | 397 break; |
241 } | 398 } |
242 | 399 case IrOpcode::kInt32x4ExtractLane: |
243 case IrOpcode::kCreateInt32x4: { | 400 case IrOpcode::kFloat32x4ExtractLane: { |
244 Node* rep_node[kMaxLanes]; | |
245 for (int i = 0; i < kMaxLanes; i++) { | |
246 DCHECK(!HasReplacement(1, node->InputAt(i))); | |
247 rep_node[i] = node->InputAt(i); | |
248 } | |
249 ReplaceNode(node, rep_node); | |
250 break; | |
251 } | |
252 | |
253 case IrOpcode::kInt32x4ExtractLane: { | |
254 Node* laneNode = node->InputAt(1); | 401 Node* laneNode = node->InputAt(1); |
255 DCHECK_EQ(laneNode->opcode(), IrOpcode::kInt32Constant); | 402 DCHECK_EQ(laneNode->opcode(), IrOpcode::kInt32Constant); |
256 int32_t lane = OpParameter<int32_t>(laneNode); | 403 int32_t lane = OpParameter<int32_t>(laneNode); |
257 Node* rep_node[kMaxLanes] = { | 404 Node* rep_node[kMaxLanes] = { |
258 GetReplacementsWithType(node->InputAt(0), rep_type)[lane], nullptr, | 405 GetReplacementsWithType(node->InputAt(0), rep_type)[lane], nullptr, |
259 nullptr, nullptr}; | 406 nullptr, nullptr}; |
260 ReplaceNode(node, rep_node); | 407 ReplaceNode(node, rep_node); |
261 break; | 408 break; |
262 } | 409 } |
263 | 410 case IrOpcode::kInt32x4ReplaceLane: |
264 case IrOpcode::kFloat32x4Add: { | 411 case IrOpcode::kFloat32x4ReplaceLane: { |
265 DCHECK(node->InputCount() == 2); | 412 DCHECK_EQ(3, node->InputCount()); |
266 Node** rep_left = GetReplacementsWithType(node->InputAt(0), rep_type); | 413 Node* laneNode = node->InputAt(1); |
267 Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type); | 414 Node* repNode = node->InputAt(2); |
268 Node* rep_node[kMaxLanes]; | 415 DCHECK_EQ(laneNode->opcode(), IrOpcode::kInt32Constant); |
269 for (int i = 0; i < kMaxLanes; i++) { | 416 int32_t lane = OpParameter<int32_t>(laneNode); |
270 rep_node[i] = graph()->NewNode(machine()->Float32Add(), rep_left[i], | 417 DCHECK(lane >= 0 && lane <= 3); |
271 rep_right[i]); | 418 Node** rep_node = GetReplacementsWithType(node->InputAt(0), rep_type); |
| 419 if (HasReplacement(0, repNode)) { |
| 420 rep_node[lane] = GetReplacements(repNode)[0]; |
| 421 } else { |
| 422 rep_node[lane] = repNode; |
272 } | 423 } |
273 ReplaceNode(node, rep_node); | 424 ReplaceNode(node, rep_node); |
274 break; | 425 break; |
275 } | 426 } |
276 | |
277 case IrOpcode::kCreateFloat32x4: { | |
278 Node* rep_node[kMaxLanes]; | |
279 for (int i = 0; i < kMaxLanes; i++) { | |
280 DCHECK(!HasReplacement(1, node->InputAt(i))); | |
281 rep_node[i] = node->InputAt(i); | |
282 } | |
283 ReplaceNode(node, rep_node); | |
284 break; | |
285 } | |
286 | |
287 case IrOpcode::kFloat32x4ExtractLane: { | |
288 Node* laneNode = node->InputAt(1); | |
289 DCHECK_EQ(laneNode->opcode(), IrOpcode::kInt32Constant); | |
290 int32_t lane = OpParameter<int32_t>(laneNode); | |
291 Node* rep_node[kMaxLanes] = { | |
292 GetReplacementsWithType(node->InputAt(0), rep_type)[lane], nullptr, | |
293 nullptr, nullptr}; | |
294 ReplaceNode(node, rep_node); | |
295 break; | |
296 } | |
297 | |
298 default: { DefaultLowering(node); } | 427 default: { DefaultLowering(node); } |
299 } | 428 } |
300 } | 429 } |
301 | 430 |
302 bool SimdScalarLowering::DefaultLowering(Node* node) { | 431 bool SimdScalarLowering::DefaultLowering(Node* node) { |
303 bool something_changed = false; | 432 bool something_changed = false; |
304 for (int i = NodeProperties::PastValueIndex(node) - 1; i >= 0; i--) { | 433 for (int i = NodeProperties::PastValueIndex(node) - 1; i >= 0; i--) { |
305 Node* input = node->InputAt(i); | 434 Node* input = node->InputAt(i); |
306 if (HasReplacement(0, input)) { | 435 if (HasReplacement(0, input)) { |
307 something_changed = true; | 436 something_changed = true; |
308 node->ReplaceInput(i, GetReplacements(input)[0]); | 437 node->ReplaceInput(i, GetReplacements(input)[0]); |
309 } | 438 } |
310 if (HasReplacement(1, input)) { | 439 if (HasReplacement(1, input)) { |
311 something_changed = true; | 440 something_changed = true; |
312 for (int j = 1; j < kMaxLanes; j++) { | 441 for (int j = 1; j < kMaxLanes; j++) { |
313 node->InsertInput(zone(), i + j, GetReplacements(input)[j]); | 442 node->InsertInput(zone(), i + j, GetReplacements(input)[j]); |
314 } | 443 } |
315 } | 444 } |
316 } | 445 } |
317 return something_changed; | 446 return something_changed; |
318 } | 447 } |
319 | 448 |
320 void SimdScalarLowering::ReplaceNode(Node* old, Node** new_node) { | 449 void SimdScalarLowering::ReplaceNode(Node* old, Node** new_node) { |
321 // if new_low == nullptr, then also new_high == nullptr. | 450 // if new_low == nullptr, then also new_high == nullptr. |
322 DCHECK(new_node[0] != nullptr || | 451 DCHECK(new_node[0] != nullptr || |
323 (new_node[1] == nullptr && new_node[2] == nullptr && | 452 (new_node[1] == nullptr && new_node[2] == nullptr && |
324 new_node[3] == nullptr)); | 453 new_node[3] == nullptr)); |
325 for (int i = 0; i < kMaxLanes; i++) { | 454 for (int i = 0; i < kMaxLanes; ++i) { |
326 replacements_[old->id()].node[i] = new_node[i]; | 455 replacements_[old->id()].node[i] = new_node[i]; |
327 } | 456 } |
328 } | 457 } |
329 | 458 |
330 bool SimdScalarLowering::HasReplacement(size_t index, Node* node) { | 459 bool SimdScalarLowering::HasReplacement(size_t index, Node* node) { |
331 return replacements_[node->id()].node[index] != nullptr; | 460 return replacements_[node->id()].node[index] != nullptr; |
332 } | 461 } |
333 | 462 |
334 SimdScalarLowering::SimdType SimdScalarLowering::ReplacementType(Node* node) { | 463 SimdScalarLowering::SimdType SimdScalarLowering::ReplacementType(Node* node) { |
335 return replacements_[node->id()].type; | 464 return replacements_[node->id()].type; |
336 } | 465 } |
337 | 466 |
338 Node** SimdScalarLowering::GetReplacements(Node* node) { | 467 Node** SimdScalarLowering::GetReplacements(Node* node) { |
339 Node** result = replacements_[node->id()].node; | 468 Node** result = replacements_[node->id()].node; |
340 DCHECK(result); | 469 DCHECK(result); |
341 return result; | 470 return result; |
342 } | 471 } |
343 | 472 |
344 Node** SimdScalarLowering::GetReplacementsWithType(Node* node, SimdType type) { | 473 Node** SimdScalarLowering::GetReplacementsWithType(Node* node, SimdType type) { |
345 Node** replacements = GetReplacements(node); | 474 Node** replacements = GetReplacements(node); |
346 if (ReplacementType(node) == type) { | 475 if (ReplacementType(node) == type) { |
347 return GetReplacements(node); | 476 return GetReplacements(node); |
348 } | 477 } |
349 Node** result = zone()->NewArray<Node*>(kMaxLanes); | 478 Node** result = zone()->NewArray<Node*>(kMaxLanes); |
350 if (ReplacementType(node) == SimdType::kInt32 && type == SimdType::kFloat32) { | 479 if (ReplacementType(node) == SimdType::kInt32 && type == SimdType::kFloat32) { |
351 for (int i = 0; i < kMaxLanes; i++) { | 480 for (int i = 0; i < kMaxLanes; ++i) { |
352 if (replacements[i] != nullptr) { | 481 if (replacements[i] != nullptr) { |
353 result[i] = graph()->NewNode(machine()->BitcastInt32ToFloat32(), | 482 result[i] = graph()->NewNode(machine()->BitcastInt32ToFloat32(), |
354 replacements[i]); | 483 replacements[i]); |
355 } else { | 484 } else { |
356 result[i] = nullptr; | 485 result[i] = nullptr; |
357 } | 486 } |
358 } | 487 } |
359 } else { | 488 } else { |
360 for (int i = 0; i < kMaxLanes; i++) { | 489 for (int i = 0; i < kMaxLanes; ++i) { |
361 if (replacements[i] != nullptr) { | 490 if (replacements[i] != nullptr) { |
362 result[i] = graph()->NewNode(machine()->BitcastFloat32ToInt32(), | 491 result[i] = graph()->NewNode(machine()->BitcastFloat32ToInt32(), |
363 replacements[i]); | 492 replacements[i]); |
364 } else { | 493 } else { |
365 result[i] = nullptr; | 494 result[i] = nullptr; |
366 } | 495 } |
367 } | 496 } |
368 } | 497 } |
369 return result; | 498 return result; |
370 } | 499 } |
371 | 500 |
372 void SimdScalarLowering::PreparePhiReplacement(Node* phi) { | 501 void SimdScalarLowering::PreparePhiReplacement(Node* phi) { |
373 MachineRepresentation rep = PhiRepresentationOf(phi->op()); | 502 MachineRepresentation rep = PhiRepresentationOf(phi->op()); |
374 if (rep == MachineRepresentation::kSimd128) { | 503 if (rep == MachineRepresentation::kSimd128) { |
375 // We have to create the replacements for a phi node before we actually | 504 // We have to create the replacements for a phi node before we actually |
376 // lower the phi to break potential cycles in the graph. The replacements of | 505 // lower the phi to break potential cycles in the graph. The replacements of |
377 // input nodes do not exist yet, so we use a placeholder node to pass the | 506 // input nodes do not exist yet, so we use a placeholder node to pass the |
378 // graph verifier. | 507 // graph verifier. |
379 int value_count = phi->op()->ValueInputCount(); | 508 int value_count = phi->op()->ValueInputCount(); |
380 SimdType type = ReplacementType(phi); | 509 SimdType type = ReplacementType(phi); |
381 Node** inputs_rep[kMaxLanes]; | 510 Node** inputs_rep[kMaxLanes]; |
382 for (int i = 0; i < kMaxLanes; i++) { | 511 for (int i = 0; i < kMaxLanes; ++i) { |
383 inputs_rep[i] = zone()->NewArray<Node*>(value_count + 1); | 512 inputs_rep[i] = zone()->NewArray<Node*>(value_count + 1); |
384 inputs_rep[i][value_count] = NodeProperties::GetControlInput(phi, 0); | 513 inputs_rep[i][value_count] = NodeProperties::GetControlInput(phi, 0); |
385 } | 514 } |
386 for (int i = 0; i < value_count; i++) { | 515 for (int i = 0; i < value_count; ++i) { |
387 for (int j = 0; j < kMaxLanes; j++) { | 516 for (int j = 0; j < kMaxLanes; j++) { |
388 inputs_rep[j][i] = placeholder_; | 517 inputs_rep[j][i] = placeholder_; |
389 } | 518 } |
390 } | 519 } |
391 Node* rep_nodes[kMaxLanes]; | 520 Node* rep_nodes[kMaxLanes]; |
392 for (int i = 0; i < kMaxLanes; i++) { | 521 for (int i = 0; i < kMaxLanes; ++i) { |
393 if (type == SimdType::kInt32) { | 522 if (type == SimdType::kInt32) { |
394 rep_nodes[i] = graph()->NewNode( | 523 rep_nodes[i] = graph()->NewNode( |
395 common()->Phi(MachineRepresentation::kWord32, value_count), | 524 common()->Phi(MachineRepresentation::kWord32, value_count), |
396 value_count + 1, inputs_rep[i], false); | 525 value_count + 1, inputs_rep[i], false); |
397 } else if (type == SimdType::kFloat32) { | 526 } else if (type == SimdType::kFloat32) { |
398 rep_nodes[i] = graph()->NewNode( | 527 rep_nodes[i] = graph()->NewNode( |
399 common()->Phi(MachineRepresentation::kFloat32, value_count), | 528 common()->Phi(MachineRepresentation::kFloat32, value_count), |
400 value_count + 1, inputs_rep[i], false); | 529 value_count + 1, inputs_rep[i], false); |
401 } else { | 530 } else { |
402 UNREACHABLE(); | 531 UNREACHABLE(); |
403 } | 532 } |
404 } | 533 } |
405 ReplaceNode(phi, rep_nodes); | 534 ReplaceNode(phi, rep_nodes); |
406 } | 535 } |
407 } | 536 } |
408 } // namespace compiler | 537 } // namespace compiler |
409 } // namespace internal | 538 } // namespace internal |
410 } // namespace v8 | 539 } // namespace v8 |
OLD | NEW |