Chromium Code Reviews| 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/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
| 6 #include "src/compiler/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
| 7 #include "src/compiler/js-typed-lowering.h" | 7 #include "src/compiler/js-typed-lowering.h" |
| 8 #include "src/compiler/node-aux-data-inl.h" | 8 #include "src/compiler/node-aux-data-inl.h" |
| 9 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
| 10 #include "src/types.h" | 10 #include "src/types.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 215 } |
| 216 | 216 |
| 217 void update_effect(Node* effect) { | 217 void update_effect(Node* effect) { |
| 218 NodeProperties::ReplaceEffectInput(node_, effect); | 218 NodeProperties::ReplaceEffectInput(node_, effect); |
| 219 } | 219 } |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 | 222 |
| 223 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 223 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
| 224 JSBinopReduction r(this, node); | 224 JSBinopReduction r(this, node); |
| 225 if (r.BothInputsAre(Type::Number())) { | |
| 226 // JSAdd(x:number, y:number) => NumberAdd(x, y) | |
| 227 return r.ChangeToPureOperator(simplified()->NumberAdd()); | |
| 228 } | |
| 229 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); | |
| 230 if (r.NeitherInputCanBe(maybe_string)) { | |
| 231 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) | |
|
Michael Starzinger
2014/09/11 14:25:44
I convinced myself that this is correct for ES5, c
rossberg
2014/09/11 14:50:19
It seems correct, as long as ToNumber(symbol) thro
| |
| 232 r.ConvertInputsToNumber(); | |
| 233 return r.ChangeToPureOperator(simplified()->NumberAdd()); | |
| 234 } | |
| 225 if (r.OneInputIs(Type::String())) { | 235 if (r.OneInputIs(Type::String())) { |
| 236 // JSAdd(x:string, y:string) => StringAdd(x, y) | |
| 237 // JSAdd(x:string, y) => StringAdd(x, ToString(y)) | |
| 238 // JSAdd(x, y:string) => StringAdd(ToString(x), y) | |
| 226 r.ConvertInputsToString(); | 239 r.ConvertInputsToString(); |
| 227 return r.ChangeToPureOperator(simplified()->StringAdd()); | 240 return r.ChangeToPureOperator(simplified()->StringAdd()); |
| 228 } | 241 } |
| 229 if (r.NeitherInputCanBe(Type::String())) { | |
| 230 r.ConvertInputsToNumber(); | |
| 231 return r.ChangeToPureOperator(simplified()->NumberAdd()); | |
| 232 } | |
| 233 return NoChange(); | 242 return NoChange(); |
| 234 } | 243 } |
| 235 | 244 |
| 236 | 245 |
| 237 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, | 246 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, |
| 238 const Operator* numberOp) { | 247 const Operator* numberOp) { |
| 239 JSBinopReduction r(this, node); | 248 JSBinopReduction r(this, node); |
| 240 if (r.OneInputIs(Type::Primitive())) { | 249 if (r.OneInputIs(Type::Primitive())) { |
| 241 // If at least one input is a primitive, then insert appropriate conversions | 250 // If at least one input is a primitive, then insert appropriate conversions |
| 242 // to number and reduce this operator to the given numeric one. | 251 // to number and reduce this operator to the given numeric one. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 return ReduceJSStoreProperty(node); | 668 return ReduceJSStoreProperty(node); |
| 660 default: | 669 default: |
| 661 break; | 670 break; |
| 662 } | 671 } |
| 663 return NoChange(); | 672 return NoChange(); |
| 664 } | 673 } |
| 665 | 674 |
| 666 } // namespace compiler | 675 } // namespace compiler |
| 667 } // namespace internal | 676 } // namespace internal |
| 668 } // namespace v8 | 677 } // namespace v8 |
| OLD | NEW |