| 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-builtin-reducer.h" | 7 #include "src/compiler/js-builtin-reducer.h" | 
| 8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" | 
| 9 #include "src/compiler/node-aux-data-inl.h" | 9 #include "src/compiler/node-aux-data-inl.h" | 
| 10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22 | 22 | 
| 23 // Relax the effects of {node} by immediately replacing effect uses of {node} | 23 // Relax the effects of {node} by immediately replacing effect uses of {node} | 
| 24 // with the effect input to {node}. | 24 // with the effect input to {node}. | 
| 25 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. | 25 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. | 
| 26 // TODO(titzer): move into a GraphEditor? | 26 // TODO(titzer): move into a GraphEditor? | 
| 27 static void RelaxEffects(Node* node) { | 27 static void RelaxEffects(Node* node) { | 
| 28   NodeProperties::ReplaceWithValue(node, node, NULL); | 28   NodeProperties::ReplaceWithValue(node, node, NULL); | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 | 31 | 
|  | 32 JSTypedLowering::JSTypedLowering(JSGraph* jsgraph) | 
|  | 33     : jsgraph_(jsgraph), simplified_(jsgraph->zone()) { | 
|  | 34   Factory* factory = zone()->isolate()->factory(); | 
|  | 35   Handle<Object> zero = factory->NewNumber(0.0); | 
|  | 36   Handle<Object> one = factory->NewNumber(1.0); | 
|  | 37   zero_range_ = Type::Range(zero, zero, zone()); | 
|  | 38   one_range_ = Type::Range(one, one, zone()); | 
|  | 39 } | 
|  | 40 | 
|  | 41 | 
| 32 JSTypedLowering::~JSTypedLowering() {} | 42 JSTypedLowering::~JSTypedLowering() {} | 
| 33 | 43 | 
| 34 | 44 | 
| 35 Reduction JSTypedLowering::ReplaceEagerly(Node* old, Node* node) { | 45 Reduction JSTypedLowering::ReplaceEagerly(Node* old, Node* node) { | 
| 36   NodeProperties::ReplaceWithValue(old, node, node); | 46   NodeProperties::ReplaceWithValue(old, node, node); | 
| 37   return Changed(node); | 47   return Changed(node); | 
| 38 } | 48 } | 
| 39 | 49 | 
| 40 | 50 | 
| 41 // A helper class to simplify the process of reducing a single binop node with a | 51 // A helper class to simplify the process of reducing a single binop node with a | 
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252     // JSAdd(x:string, y) => StringAdd(x, ToString(y)) | 262     // JSAdd(x:string, y) => StringAdd(x, ToString(y)) | 
| 253     // JSAdd(x, y:string) => StringAdd(ToString(x), y) | 263     // JSAdd(x, y:string) => StringAdd(ToString(x), y) | 
| 254     r.ConvertInputsToString(); | 264     r.ConvertInputsToString(); | 
| 255     return r.ChangeToPureOperator(simplified()->StringAdd()); | 265     return r.ChangeToPureOperator(simplified()->StringAdd()); | 
| 256   } | 266   } | 
| 257 #endif | 267 #endif | 
| 258   return NoChange(); | 268   return NoChange(); | 
| 259 } | 269 } | 
| 260 | 270 | 
| 261 | 271 | 
|  | 272 Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) { | 
|  | 273   JSBinopReduction r(this, node); | 
|  | 274   if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(zero_range_)) { | 
|  | 275     // TODO(jarin): Propagate frame state input from non-primitive input node to | 
|  | 276     // JSToNumber node. | 
|  | 277     // TODO(titzer): some Smi bitwise operations don't really require going | 
|  | 278     // all the way to int32, which can save tagging/untagging for some | 
|  | 279     // operations | 
|  | 280     // on some platforms. | 
|  | 281     // TODO(turbofan): make this heuristic configurable for code size. | 
|  | 282     r.ConvertInputsToInt32(true, true); | 
|  | 283     return r.ChangeToPureOperator(machine()->Word32Or()); | 
|  | 284   } | 
|  | 285   return NoChange(); | 
|  | 286 } | 
|  | 287 | 
|  | 288 | 
|  | 289 Reduction JSTypedLowering::ReduceJSMultiply(Node* node) { | 
|  | 290   JSBinopReduction r(this, node); | 
|  | 291   if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(one_range_)) { | 
|  | 292     // TODO(jarin): Propagate frame state input from non-primitive input node to | 
|  | 293     // JSToNumber node. | 
|  | 294     r.ConvertInputsToNumber(); | 
|  | 295     return r.ChangeToPureOperator(simplified()->NumberMultiply()); | 
|  | 296   } | 
|  | 297   // TODO(turbofan): relax/remove the effects of this operator in other cases. | 
|  | 298   return NoChange(); | 
|  | 299 } | 
|  | 300 | 
|  | 301 | 
| 262 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, | 302 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, | 
| 263                                              const Operator* numberOp) { | 303                                              const Operator* numberOp) { | 
| 264   JSBinopReduction r(this, node); | 304   JSBinopReduction r(this, node); | 
| 265   if (r.BothInputsAre(Type::Primitive())) { | 305   if (r.BothInputsAre(Type::Primitive())) { | 
| 266     r.ConvertInputsToNumber(); | 306     r.ConvertInputsToNumber(); | 
| 267     return r.ChangeToPureOperator(numberOp); | 307     return r.ChangeToPureOperator(numberOp); | 
| 268   } | 308   } | 
| 269 #if 0 | 309 #if 0 | 
| 270   // TODO(turbofan): General ToNumber disabled for now because: | 310   // TODO(turbofan): General ToNumber disabled for now because: | 
| 271   //   a) The inserted ToNumber operation screws up observability of valueOf. | 311   //   a) The inserted ToNumber operation screws up observability of valueOf. | 
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 690     case IrOpcode::kJSStrictEqual: | 730     case IrOpcode::kJSStrictEqual: | 
| 691       return ReduceJSStrictEqual(node, false); | 731       return ReduceJSStrictEqual(node, false); | 
| 692     case IrOpcode::kJSStrictNotEqual: | 732     case IrOpcode::kJSStrictNotEqual: | 
| 693       return ReduceJSStrictEqual(node, true); | 733       return ReduceJSStrictEqual(node, true); | 
| 694     case IrOpcode::kJSLessThan:         // fall through | 734     case IrOpcode::kJSLessThan:         // fall through | 
| 695     case IrOpcode::kJSGreaterThan:      // fall through | 735     case IrOpcode::kJSGreaterThan:      // fall through | 
| 696     case IrOpcode::kJSLessThanOrEqual:  // fall through | 736     case IrOpcode::kJSLessThanOrEqual:  // fall through | 
| 697     case IrOpcode::kJSGreaterThanOrEqual: | 737     case IrOpcode::kJSGreaterThanOrEqual: | 
| 698       return ReduceJSComparison(node); | 738       return ReduceJSComparison(node); | 
| 699     case IrOpcode::kJSBitwiseOr: | 739     case IrOpcode::kJSBitwiseOr: | 
| 700       return ReduceI32Binop(node, true, true, machine()->Word32Or()); | 740       return ReduceJSBitwiseOr(node); | 
| 701     case IrOpcode::kJSBitwiseXor: | 741     case IrOpcode::kJSBitwiseXor: | 
| 702       return ReduceI32Binop(node, true, true, machine()->Word32Xor()); | 742       return ReduceI32Binop(node, true, true, machine()->Word32Xor()); | 
| 703     case IrOpcode::kJSBitwiseAnd: | 743     case IrOpcode::kJSBitwiseAnd: | 
| 704       return ReduceI32Binop(node, true, true, machine()->Word32And()); | 744       return ReduceI32Binop(node, true, true, machine()->Word32And()); | 
| 705     case IrOpcode::kJSShiftLeft: | 745     case IrOpcode::kJSShiftLeft: | 
| 706       return ReduceI32Shift(node, true, machine()->Word32Shl()); | 746       return ReduceI32Shift(node, true, machine()->Word32Shl()); | 
| 707     case IrOpcode::kJSShiftRight: | 747     case IrOpcode::kJSShiftRight: | 
| 708       return ReduceI32Shift(node, true, machine()->Word32Sar()); | 748       return ReduceI32Shift(node, true, machine()->Word32Sar()); | 
| 709     case IrOpcode::kJSShiftRightLogical: | 749     case IrOpcode::kJSShiftRightLogical: | 
| 710       return ReduceI32Shift(node, false, machine()->Word32Shr()); | 750       return ReduceI32Shift(node, false, machine()->Word32Shr()); | 
| 711     case IrOpcode::kJSAdd: | 751     case IrOpcode::kJSAdd: | 
| 712       return ReduceJSAdd(node); | 752       return ReduceJSAdd(node); | 
| 713     case IrOpcode::kJSSubtract: | 753     case IrOpcode::kJSSubtract: | 
| 714       return ReduceNumberBinop(node, simplified()->NumberSubtract()); | 754       return ReduceNumberBinop(node, simplified()->NumberSubtract()); | 
| 715     case IrOpcode::kJSMultiply: | 755     case IrOpcode::kJSMultiply: | 
| 716       return ReduceNumberBinop(node, simplified()->NumberMultiply()); | 756       return ReduceJSMultiply(node); | 
| 717     case IrOpcode::kJSDivide: | 757     case IrOpcode::kJSDivide: | 
| 718       return ReduceNumberBinop(node, simplified()->NumberDivide()); | 758       return ReduceNumberBinop(node, simplified()->NumberDivide()); | 
| 719     case IrOpcode::kJSModulus: | 759     case IrOpcode::kJSModulus: | 
| 720       return ReduceNumberBinop(node, simplified()->NumberModulus()); | 760       return ReduceNumberBinop(node, simplified()->NumberModulus()); | 
| 721     case IrOpcode::kJSUnaryNot: { | 761     case IrOpcode::kJSUnaryNot: { | 
| 722       Reduction result = ReduceJSToBooleanInput(node->InputAt(0)); | 762       Reduction result = ReduceJSToBooleanInput(node->InputAt(0)); | 
| 723       Node* value; | 763       Node* value; | 
| 724       if (result.Changed()) { | 764       if (result.Changed()) { | 
| 725         // JSUnaryNot(x:boolean) => BooleanNot(x) | 765         // JSUnaryNot(x:boolean) => BooleanNot(x) | 
| 726         value = | 766         value = | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 754       return JSBuiltinReducer(jsgraph()).Reduce(node); | 794       return JSBuiltinReducer(jsgraph()).Reduce(node); | 
| 755     default: | 795     default: | 
| 756       break; | 796       break; | 
| 757   } | 797   } | 
| 758   return NoChange(); | 798   return NoChange(); | 
| 759 } | 799 } | 
| 760 | 800 | 
| 761 }  // namespace compiler | 801 }  // namespace compiler | 
| 762 }  // namespace internal | 802 }  // namespace internal | 
| 763 }  // namespace v8 | 803 }  // namespace v8 | 
| OLD | NEW | 
|---|