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/simplified-lowering.h" | 5 #include "src/compiler/simplified-lowering.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/address-map.h" | 9 #include "src/address-map.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2104 if (lower()) DeferReplacement(node, node->InputAt(0)); | 2104 if (lower()) DeferReplacement(node, node->InputAt(0)); |
2105 return; | 2105 return; |
2106 } | 2106 } |
2107 case IrOpcode::kNumberToUint32: { | 2107 case IrOpcode::kNumberToUint32: { |
2108 // Just change representation if necessary. | 2108 // Just change representation if necessary. |
2109 VisitUnop(node, UseInfo::TruncatingWord32(), | 2109 VisitUnop(node, UseInfo::TruncatingWord32(), |
2110 MachineRepresentation::kWord32); | 2110 MachineRepresentation::kWord32); |
2111 if (lower()) DeferReplacement(node, node->InputAt(0)); | 2111 if (lower()) DeferReplacement(node, node->InputAt(0)); |
2112 return; | 2112 return; |
2113 } | 2113 } |
| 2114 case IrOpcode::kNumberToUint8Clamped: { |
| 2115 Type* const input_type = TypeOf(node->InputAt(0)); |
| 2116 if (input_type->Is(type_cache_.kUint8OrMinusZeroOrNaN)) { |
| 2117 VisitUnop(node, UseInfo::TruncatingWord32(), |
| 2118 MachineRepresentation::kWord32); |
| 2119 if (lower()) DeferReplacement(node, node->InputAt(0)); |
| 2120 } else if (input_type->Is(Type::Unsigned32OrMinusZeroOrNaN())) { |
| 2121 VisitUnop(node, UseInfo::TruncatingWord32(), |
| 2122 MachineRepresentation::kWord32); |
| 2123 if (lower()) lowering->DoUnsigned32ToUint8Clamped(node); |
| 2124 } else if (input_type->Is(Type::Signed32OrMinusZeroOrNaN())) { |
| 2125 VisitUnop(node, UseInfo::TruncatingWord32(), |
| 2126 MachineRepresentation::kWord32); |
| 2127 if (lower()) lowering->DoSigned32ToUint8Clamped(node); |
| 2128 } else if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { |
| 2129 VisitUnop(node, UseInfo::TruncatingFloat64(), |
| 2130 MachineRepresentation::kFloat64); |
| 2131 if (lower()) lowering->DoIntegerToUint8Clamped(node); |
| 2132 } else { |
| 2133 VisitUnop(node, UseInfo::TruncatingFloat64(), |
| 2134 MachineRepresentation::kFloat64); |
| 2135 if (lower()) lowering->DoNumberToUint8Clamped(node); |
| 2136 } |
| 2137 return; |
| 2138 } |
2114 case IrOpcode::kReferenceEqual: { | 2139 case IrOpcode::kReferenceEqual: { |
2115 VisitBinop(node, UseInfo::AnyTagged(), MachineRepresentation::kBit); | 2140 VisitBinop(node, UseInfo::AnyTagged(), MachineRepresentation::kBit); |
2116 if (lower()) { | 2141 if (lower()) { |
2117 NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); | 2142 NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); |
2118 } | 2143 } |
2119 return; | 2144 return; |
2120 } | 2145 } |
2121 case IrOpcode::kStringEqual: | 2146 case IrOpcode::kStringEqual: |
2122 case IrOpcode::kStringLessThan: | 2147 case IrOpcode::kStringLessThan: |
2123 case IrOpcode::kStringLessThanOrEqual: { | 2148 case IrOpcode::kStringLessThanOrEqual: { |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3287 | 3312 |
3288 void SimplifiedLowering::DoNumberToBit(Node* node) { | 3313 void SimplifiedLowering::DoNumberToBit(Node* node) { |
3289 Node* const input = node->InputAt(0); | 3314 Node* const input = node->InputAt(0); |
3290 | 3315 |
3291 node->ReplaceInput(0, jsgraph()->Float64Constant(0.0)); | 3316 node->ReplaceInput(0, jsgraph()->Float64Constant(0.0)); |
3292 node->AppendInput(graph()->zone(), | 3317 node->AppendInput(graph()->zone(), |
3293 graph()->NewNode(machine()->Float64Abs(), input)); | 3318 graph()->NewNode(machine()->Float64Abs(), input)); |
3294 NodeProperties::ChangeOp(node, machine()->Float64LessThan()); | 3319 NodeProperties::ChangeOp(node, machine()->Float64LessThan()); |
3295 } | 3320 } |
3296 | 3321 |
| 3322 void SimplifiedLowering::DoIntegerToUint8Clamped(Node* node) { |
| 3323 Node* const input = node->InputAt(0); |
| 3324 Node* const min = jsgraph()->Float64Constant(0.0); |
| 3325 Node* const max = jsgraph()->Float64Constant(255.0); |
| 3326 |
| 3327 node->ReplaceInput( |
| 3328 0, graph()->NewNode(machine()->Float64LessThan(), min, input)); |
| 3329 node->AppendInput( |
| 3330 graph()->zone(), |
| 3331 graph()->NewNode( |
| 3332 common()->Select(MachineRepresentation::kFloat64), |
| 3333 graph()->NewNode(machine()->Float64LessThan(), input, max), input, |
| 3334 max)); |
| 3335 node->AppendInput(graph()->zone(), min); |
| 3336 NodeProperties::ChangeOp(node, |
| 3337 common()->Select(MachineRepresentation::kFloat64)); |
| 3338 } |
| 3339 |
| 3340 void SimplifiedLowering::DoNumberToUint8Clamped(Node* node) { |
| 3341 Node* const input = node->InputAt(0); |
| 3342 Node* const min = jsgraph()->Float64Constant(0.0); |
| 3343 Node* const max = jsgraph()->Float64Constant(255.0); |
| 3344 |
| 3345 node->ReplaceInput( |
| 3346 0, graph()->NewNode( |
| 3347 common()->Select(MachineRepresentation::kFloat64), |
| 3348 graph()->NewNode(machine()->Float64LessThan(), min, input), |
| 3349 graph()->NewNode( |
| 3350 common()->Select(MachineRepresentation::kFloat64), |
| 3351 graph()->NewNode(machine()->Float64LessThan(), input, max), |
| 3352 input, max), |
| 3353 min)); |
| 3354 NodeProperties::ChangeOp(node, |
| 3355 machine()->Float64RoundTiesEven().placeholder()); |
| 3356 } |
| 3357 |
| 3358 void SimplifiedLowering::DoSigned32ToUint8Clamped(Node* node) { |
| 3359 Node* const input = node->InputAt(0); |
| 3360 Node* const min = jsgraph()->Int32Constant(0); |
| 3361 Node* const max = jsgraph()->Int32Constant(255); |
| 3362 |
| 3363 node->ReplaceInput( |
| 3364 0, graph()->NewNode(machine()->Int32LessThanOrEqual(), input, max)); |
| 3365 node->AppendInput( |
| 3366 graph()->zone(), |
| 3367 graph()->NewNode(common()->Select(MachineRepresentation::kWord32), |
| 3368 graph()->NewNode(machine()->Int32LessThan(), input, min), |
| 3369 min, input)); |
| 3370 node->AppendInput(graph()->zone(), max); |
| 3371 NodeProperties::ChangeOp(node, |
| 3372 common()->Select(MachineRepresentation::kWord32)); |
| 3373 } |
| 3374 |
| 3375 void SimplifiedLowering::DoUnsigned32ToUint8Clamped(Node* node) { |
| 3376 Node* const input = node->InputAt(0); |
| 3377 Node* const max = jsgraph()->Uint32Constant(255u); |
| 3378 |
| 3379 node->ReplaceInput( |
| 3380 0, graph()->NewNode(machine()->Uint32LessThanOrEqual(), input, max)); |
| 3381 node->AppendInput(graph()->zone(), input); |
| 3382 node->AppendInput(graph()->zone(), max); |
| 3383 NodeProperties::ChangeOp(node, |
| 3384 common()->Select(MachineRepresentation::kWord32)); |
| 3385 } |
| 3386 |
3297 Node* SimplifiedLowering::ToNumberCode() { | 3387 Node* SimplifiedLowering::ToNumberCode() { |
3298 if (!to_number_code_.is_set()) { | 3388 if (!to_number_code_.is_set()) { |
3299 Callable callable = CodeFactory::ToNumber(isolate()); | 3389 Callable callable = CodeFactory::ToNumber(isolate()); |
3300 to_number_code_.set(jsgraph()->HeapConstant(callable.code())); | 3390 to_number_code_.set(jsgraph()->HeapConstant(callable.code())); |
3301 } | 3391 } |
3302 return to_number_code_.get(); | 3392 return to_number_code_.get(); |
3303 } | 3393 } |
3304 | 3394 |
3305 Operator const* SimplifiedLowering::ToNumberOperator() { | 3395 Operator const* SimplifiedLowering::ToNumberOperator() { |
3306 if (!to_number_operator_.is_set()) { | 3396 if (!to_number_operator_.is_set()) { |
3307 Callable callable = CodeFactory::ToNumber(isolate()); | 3397 Callable callable = CodeFactory::ToNumber(isolate()); |
3308 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; | 3398 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; |
3309 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 3399 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
3310 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 3400 isolate(), graph()->zone(), callable.descriptor(), 0, flags, |
3311 Operator::kNoProperties); | 3401 Operator::kNoProperties); |
3312 to_number_operator_.set(common()->Call(desc)); | 3402 to_number_operator_.set(common()->Call(desc)); |
3313 } | 3403 } |
3314 return to_number_operator_.get(); | 3404 return to_number_operator_.get(); |
3315 } | 3405 } |
3316 | 3406 |
3317 } // namespace compiler | 3407 } // namespace compiler |
3318 } // namespace internal | 3408 } // namespace internal |
3319 } // namespace v8 | 3409 } // namespace v8 |
OLD | NEW |