| 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-graph.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-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 11 #include "src/compiler/node-properties-inl.h" | 11 #include "src/compiler/node-properties-inl.h" |
| 12 #include "src/types.h" | 12 #include "src/types.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 namespace compiler { | 16 namespace compiler { |
| 17 | 17 |
| 18 // TODO(turbofan): js-typed-lowering improvements possible | 18 // TODO(turbofan): js-typed-lowering improvements possible |
| 19 // - immediately put in type bounds for all new nodes | 19 // - immediately put in type bounds for all new nodes |
| 20 // - relax effects from generic but not-side-effecting operations | 20 // - relax effects from generic but not-side-effecting operations |
| 21 // - relax effects for ToNumber(mixed) | 21 // - relax effects for ToNumber(mixed) |
| 22 | 22 |
| 23 | 23 |
| 24 // Relax the effects of {node} by immediately replacing effect uses of {node} | 24 // Relax the effects of {node} by immediately replacing effect uses of {node} |
| 25 // with the effect input to {node}. | 25 // with the effect input to {node}. |
| 26 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. | 26 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. |
| 27 // TODO(titzer): move into a GraphEditor? | 27 // TODO(titzer): move into a GraphEditor? |
| 28 static void RelaxEffects(Node* node) { | 28 static void RelaxEffects(Node* node) { |
| 29 NodeProperties::ReplaceWithValue(node, node, NULL); | 29 NodeProperties::ReplaceWithValue(node, node, NULL); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 JSTypedLowering::JSTypedLowering(JSGraph* jsgraph) | 33 JSTypedLowering::JSTypedLowering(JSGraph* jsgraph) |
| 34 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) { | 34 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) { |
| 35 Factory* factory = zone()->isolate()->factory(); | 35 Handle<Object> zero = factory()->NewNumber(0.0); |
| 36 Handle<Object> zero = factory->NewNumber(0.0); | 36 Handle<Object> one = factory()->NewNumber(1.0); |
| 37 Handle<Object> one = factory->NewNumber(1.0); | 37 zero_range_ = Type::Range(zero, zero, graph()->zone()); |
| 38 zero_range_ = Type::Range(zero, zero, zone()); | 38 one_range_ = Type::Range(one, one, graph()->zone()); |
| 39 one_range_ = Type::Range(one, one, zone()); | 39 Handle<Object> thirtyone = factory()->NewNumber(31.0); |
| 40 Handle<Object> thirtyone = factory->NewNumber(31.0); | 40 zero_thirtyone_range_ = Type::Range(zero, thirtyone, graph()->zone()); |
| 41 zero_thirtyone_range_ = Type::Range(zero, thirtyone, zone()); | |
| 42 // TODO(jarin): Can we have a correctification of the stupid type system? | 41 // TODO(jarin): Can we have a correctification of the stupid type system? |
| 43 // These stupid work-arounds are just stupid! | 42 // These stupid work-arounds are just stupid! |
| 44 shifted_int32_ranges_[0] = Type::Signed32(); | 43 shifted_int32_ranges_[0] = Type::Signed32(); |
| 45 if (SmiValuesAre31Bits()) { | 44 if (SmiValuesAre31Bits()) { |
| 46 shifted_int32_ranges_[1] = Type::SignedSmall(); | 45 shifted_int32_ranges_[1] = Type::SignedSmall(); |
| 47 for (size_t k = 2; k < arraysize(shifted_int32_ranges_); ++k) { | 46 for (size_t k = 2; k < arraysize(shifted_int32_ranges_); ++k) { |
| 48 Handle<Object> min = factory->NewNumber(kMinInt / (1 << k)); | 47 Handle<Object> min = factory()->NewNumber(kMinInt / (1 << k)); |
| 49 Handle<Object> max = factory->NewNumber(kMaxInt / (1 << k)); | 48 Handle<Object> max = factory()->NewNumber(kMaxInt / (1 << k)); |
| 50 shifted_int32_ranges_[k] = Type::Range(min, max, zone()); | 49 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
| 51 } | 50 } |
| 52 } else { | 51 } else { |
| 53 for (size_t k = 1; k < arraysize(shifted_int32_ranges_); ++k) { | 52 for (size_t k = 1; k < arraysize(shifted_int32_ranges_); ++k) { |
| 54 Handle<Object> min = factory->NewNumber(kMinInt / (1 << k)); | 53 Handle<Object> min = factory()->NewNumber(kMinInt / (1 << k)); |
| 55 Handle<Object> max = factory->NewNumber(kMaxInt / (1 << k)); | 54 Handle<Object> max = factory()->NewNumber(kMaxInt / (1 << k)); |
| 56 shifted_int32_ranges_[k] = Type::Range(min, max, zone()); | 55 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
| 57 } | 56 } |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 | 60 |
| 62 Reduction JSTypedLowering::ReplaceEagerly(Node* old, Node* node) { | 61 Reduction JSTypedLowering::ReplaceEagerly(Node* old, Node* node) { |
| 63 NodeProperties::ReplaceWithValue(old, node, node); | 62 NodeProperties::ReplaceWithValue(old, node, node); |
| 64 return Changed(node); | 63 return Changed(node); |
| 65 } | 64 } |
| 66 | 65 |
| 67 | 66 |
| 68 // A helper class to simplify the process of reducing a single binop node with a | 67 // A helper class to simplify the process of reducing a single binop node with a |
| 69 // JSOperator. This class manages the rewriting of context, control, and effect | 68 // JSOperator. This class manages the rewriting of context, control, and effect |
| 70 // dependencies during lowering of a binop and contains numerous helper | 69 // dependencies during lowering of a binop and contains numerous helper |
| 71 // functions for matching the types of inputs to an operation. | 70 // functions for matching the types of inputs to an operation. |
| 72 class JSBinopReduction { | 71 class JSBinopReduction FINAL { |
| 73 public: | 72 public: |
| 74 JSBinopReduction(JSTypedLowering* lowering, Node* node) | 73 JSBinopReduction(JSTypedLowering* lowering, Node* node) |
| 75 : lowering_(lowering), | 74 : lowering_(lowering), |
| 76 node_(node), | 75 node_(node), |
| 77 left_type_(NodeProperties::GetBounds(node->InputAt(0)).upper), | 76 left_type_(NodeProperties::GetBounds(node->InputAt(0)).upper), |
| 78 right_type_(NodeProperties::GetBounds(node->InputAt(1)).upper) {} | 77 right_type_(NodeProperties::GetBounds(node->InputAt(1)).upper) {} |
| 79 | 78 |
| 80 void ConvertInputsToNumber() { | 79 void ConvertInputsToNumber() { |
| 81 node_->ReplaceInput(0, ConvertToNumber(left())); | 80 node_->ReplaceInput(0, ConvertToNumber(left())); |
| 82 node_->ReplaceInput(1, ConvertToNumber(right())); | 81 node_->ReplaceInput(1, ConvertToNumber(right())); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void ConvertInputsToInt32(bool left_signed, bool right_signed) { | 84 void ConvertInputsToUI32(Signedness left_signedness, |
| 86 node_->ReplaceInput(0, ConvertToI32(left_signed, left())); | 85 Signedness right_signedness) { |
| 87 node_->ReplaceInput(1, ConvertToI32(right_signed, right())); | 86 node_->ReplaceInput(0, ConvertToUI32(left(), left_signedness)); |
| 87 node_->ReplaceInput(1, ConvertToUI32(right(), right_signedness)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ConvertInputsToString() { | 90 void ConvertInputsToString() { |
| 91 node_->ReplaceInput(0, ConvertToString(left())); | 91 node_->ReplaceInput(0, ConvertToString(left())); |
| 92 node_->ReplaceInput(1, ConvertToString(right())); | 92 node_->ReplaceInput(1, ConvertToString(right())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Convert inputs for bitwise shift operation (ES5 spec 11.7). | 95 // Convert inputs for bitwise shift operation (ES5 spec 11.7). |
| 96 void ConvertInputsForShift(bool left_signed) { | 96 void ConvertInputsForShift(Signedness left_signedness) { |
| 97 node_->ReplaceInput(0, ConvertToI32(left_signed, left())); | 97 node_->ReplaceInput(0, ConvertToUI32(left(), left_signedness)); |
| 98 Node* rnum = ConvertToI32(false, right()); | 98 Node* rnum = ConvertToUI32(right(), kUnsigned); |
| 99 Type* rnum_type = NodeProperties::GetBounds(rnum).upper; | 99 Type* rnum_type = NodeProperties::GetBounds(rnum).upper; |
| 100 if (!rnum_type->Is(lowering_->zero_thirtyone_range_)) { | 100 if (!rnum_type->Is(lowering_->zero_thirtyone_range_)) { |
| 101 rnum = graph()->NewNode(machine()->Word32And(), rnum, | 101 rnum = graph()->NewNode(machine()->Word32And(), rnum, |
| 102 jsgraph()->Int32Constant(0x1F)); | 102 jsgraph()->Int32Constant(0x1F)); |
| 103 } | 103 } |
| 104 node_->ReplaceInput(1, rnum); | 104 node_->ReplaceInput(1, rnum); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void SwapInputs() { | 107 void SwapInputs() { |
| 108 Node* l = left(); | 108 Node* l = left(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 Node* ConvertToNumber(Node* node) { | 198 Node* ConvertToNumber(Node* node) { |
| 199 // Avoid introducing too many eager ToNumber() operations. | 199 // Avoid introducing too many eager ToNumber() operations. |
| 200 Reduction reduced = lowering_->ReduceJSToNumberInput(node); | 200 Reduction reduced = lowering_->ReduceJSToNumberInput(node); |
| 201 if (reduced.Changed()) return reduced.replacement(); | 201 if (reduced.Changed()) return reduced.replacement(); |
| 202 Node* n = graph()->NewNode(javascript()->ToNumber(), node, context(), | 202 Node* n = graph()->NewNode(javascript()->ToNumber(), node, context(), |
| 203 effect(), control()); | 203 effect(), control()); |
| 204 update_effect(n); | 204 update_effect(n); |
| 205 return n; | 205 return n; |
| 206 } | 206 } |
| 207 | 207 |
| 208 Node* ConvertToI32(bool is_signed, Node* node) { | 208 Node* ConvertToUI32(Node* node, Signedness signedness) { |
| 209 // Avoid introducing too many eager NumberToXXnt32() operations. | 209 // Avoid introducing too many eager NumberToXXnt32() operations. |
| 210 node = ConvertToNumber(node); | 210 node = ConvertToNumber(node); |
| 211 Type* type = is_signed ? Type::Signed32() : Type::Unsigned32(); | 211 Type* type = NodeProperties::GetBounds(node).upper; |
| 212 Type* input_type = NodeProperties::GetBounds(node).upper; | 212 if (signedness == kSigned) { |
| 213 | 213 if (!type->Is(Type::Signed32())) { |
| 214 if (input_type->Is(type)) return node; // already in the value range. | 214 node = graph()->NewNode(simplified()->NumberToInt32(), node); |
| 215 | 215 } |
| 216 const Operator* op = is_signed ? simplified()->NumberToInt32() | 216 } else { |
| 217 : simplified()->NumberToUint32(); | 217 DCHECK_EQ(kUnsigned, signedness); |
| 218 Node* n = graph()->NewNode(op, node); | 218 if (!type->Is(Type::Unsigned32())) { |
| 219 return n; | 219 node = graph()->NewNode(simplified()->NumberToUint32(), node); |
| 220 } |
| 221 } |
| 222 return node; |
| 220 } | 223 } |
| 221 | 224 |
| 222 void update_effect(Node* effect) { | 225 void update_effect(Node* effect) { |
| 223 NodeProperties::ReplaceEffectInput(node_, effect); | 226 NodeProperties::ReplaceEffectInput(node_, effect); |
| 224 } | 227 } |
| 225 }; | 228 }; |
| 226 | 229 |
| 227 | 230 |
| 228 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 231 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
| 229 JSBinopReduction r(this, node); | 232 JSBinopReduction r(this, node); |
| 230 if (r.BothInputsAre(Type::Number())) { | 233 if (r.BothInputsAre(Type::Number())) { |
| 231 // JSAdd(x:number, y:number) => NumberAdd(x, y) | 234 // JSAdd(x:number, y:number) => NumberAdd(x, y) |
| 232 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 235 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
| 233 } | 236 } |
| 234 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); | 237 if (r.BothInputsAre(Type::Primitive()) && |
| 235 if (r.BothInputsAre(Type::Primitive()) && r.NeitherInputCanBe(maybe_string)) { | 238 r.NeitherInputCanBe(Type::StringOrReceiver())) { |
| 236 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) | 239 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) |
| 237 r.ConvertInputsToNumber(); | 240 r.ConvertInputsToNumber(); |
| 238 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 241 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
| 239 } | 242 } |
| 240 #if 0 | 243 #if 0 |
| 241 // TODO(turbofan): General ToNumber disabled for now because: | 244 // TODO(turbofan): General ToNumber disabled for now because: |
| 242 // a) The inserted ToNumber operation screws up observability of valueOf. | 245 // a) The inserted ToNumber operation screws up observability of valueOf. |
| 243 // b) Deoptimization at ToNumber doesn't have corresponding bailout id. | 246 // b) Deoptimization at ToNumber doesn't have corresponding bailout id. |
| 244 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); | 247 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); |
| 245 if (r.NeitherInputCanBe(maybe_string)) { | 248 if (r.NeitherInputCanBe(maybe_string)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 266 Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) { | 269 Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) { |
| 267 JSBinopReduction r(this, node); | 270 JSBinopReduction r(this, node); |
| 268 if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(zero_range_)) { | 271 if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(zero_range_)) { |
| 269 // TODO(jarin): Propagate frame state input from non-primitive input node to | 272 // TODO(jarin): Propagate frame state input from non-primitive input node to |
| 270 // JSToNumber node. | 273 // JSToNumber node. |
| 271 // TODO(titzer): some Smi bitwise operations don't really require going | 274 // TODO(titzer): some Smi bitwise operations don't really require going |
| 272 // all the way to int32, which can save tagging/untagging for some | 275 // all the way to int32, which can save tagging/untagging for some |
| 273 // operations | 276 // operations |
| 274 // on some platforms. | 277 // on some platforms. |
| 275 // TODO(turbofan): make this heuristic configurable for code size. | 278 // TODO(turbofan): make this heuristic configurable for code size. |
| 276 r.ConvertInputsToInt32(true, true); | 279 r.ConvertInputsToUI32(kSigned, kSigned); |
| 277 return r.ChangeToPureOperator(machine()->Word32Or(), Type::Integral32()); | 280 return r.ChangeToPureOperator(machine()->Word32Or(), Type::Integral32()); |
| 278 } | 281 } |
| 279 return NoChange(); | 282 return NoChange(); |
| 280 } | 283 } |
| 281 | 284 |
| 282 | 285 |
| 283 Reduction JSTypedLowering::ReduceJSMultiply(Node* node) { | 286 Reduction JSTypedLowering::ReduceJSMultiply(Node* node) { |
| 284 JSBinopReduction r(this, node); | 287 JSBinopReduction r(this, node); |
| 285 if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(one_range_)) { | 288 if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(one_range_)) { |
| 286 // TODO(jarin): Propagate frame state input from non-primitive input node to | 289 // TODO(jarin): Propagate frame state input from non-primitive input node to |
| (...skipping 24 matching lines...) Expand all Loading... |
| 311 // TODO(turbofan): make this heuristic configurable for code size. | 314 // TODO(turbofan): make this heuristic configurable for code size. |
| 312 r.ConvertInputsToNumber(); | 315 r.ConvertInputsToNumber(); |
| 313 return r.ChangeToPureOperator(numberOp); | 316 return r.ChangeToPureOperator(numberOp); |
| 314 } | 317 } |
| 315 #endif | 318 #endif |
| 316 // TODO(turbofan): relax/remove the effects of this operator in other cases. | 319 // TODO(turbofan): relax/remove the effects of this operator in other cases. |
| 317 return NoChange(); | 320 return NoChange(); |
| 318 } | 321 } |
| 319 | 322 |
| 320 | 323 |
| 321 Reduction JSTypedLowering::ReduceI32Binop(Node* node, bool left_signed, | 324 Reduction JSTypedLowering::ReduceInt32Binop(Node* node, const Operator* intOp) { |
| 322 bool right_signed, | |
| 323 const Operator* intOp) { | |
| 324 JSBinopReduction r(this, node); | 325 JSBinopReduction r(this, node); |
| 325 if (r.BothInputsAre(Type::Primitive())) { | 326 if (r.BothInputsAre(Type::Primitive())) { |
| 326 // TODO(titzer): some Smi bitwise operations don't really require going | 327 // TODO(titzer): some Smi bitwise operations don't really require going |
| 327 // all the way to int32, which can save tagging/untagging for some | 328 // all the way to int32, which can save tagging/untagging for some |
| 328 // operations | 329 // operations |
| 329 // on some platforms. | 330 // on some platforms. |
| 330 // TODO(turbofan): make this heuristic configurable for code size. | 331 // TODO(turbofan): make this heuristic configurable for code size. |
| 331 r.ConvertInputsToInt32(left_signed, right_signed); | 332 r.ConvertInputsToUI32(kSigned, kSigned); |
| 332 return r.ChangeToPureOperator(intOp, Type::Integral32()); | 333 return r.ChangeToPureOperator(intOp, Type::Integral32()); |
| 333 } | 334 } |
| 334 return NoChange(); | 335 return NoChange(); |
| 335 } | 336 } |
| 336 | 337 |
| 337 | 338 |
| 338 Reduction JSTypedLowering::ReduceI32Shift(Node* node, bool left_signed, | 339 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, |
| 339 const Operator* shift_op) { | 340 Signedness left_signedness, |
| 341 const Operator* shift_op) { |
| 340 JSBinopReduction r(this, node); | 342 JSBinopReduction r(this, node); |
| 341 if (r.BothInputsAre(Type::Primitive())) { | 343 if (r.BothInputsAre(Type::Primitive())) { |
| 342 r.ConvertInputsForShift(left_signed); | 344 r.ConvertInputsForShift(left_signedness); |
| 343 return r.ChangeToPureOperator(shift_op, Type::Integral32()); | 345 return r.ChangeToPureOperator(shift_op, Type::Integral32()); |
| 344 } | 346 } |
| 345 return NoChange(); | 347 return NoChange(); |
| 346 } | 348 } |
| 347 | 349 |
| 348 | 350 |
| 349 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { | 351 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { |
| 350 JSBinopReduction r(this, node); | 352 JSBinopReduction r(this, node); |
| 351 if (r.BothInputsAre(Type::String())) { | 353 if (r.BothInputsAre(Type::String())) { |
| 352 // If both inputs are definitely strings, perform a string comparison. | 354 // If both inputs are definitely strings, perform a string comparison. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 374 #if 0 | 376 #if 0 |
| 375 // TODO(turbofan): General ToNumber disabled for now because: | 377 // TODO(turbofan): General ToNumber disabled for now because: |
| 376 // a) The inserted ToNumber operation screws up observability of valueOf. | 378 // a) The inserted ToNumber operation screws up observability of valueOf. |
| 377 // b) Deoptimization at ToNumber doesn't have corresponding bailout id. | 379 // b) Deoptimization at ToNumber doesn't have corresponding bailout id. |
| 378 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); | 380 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); |
| 379 if (r.OneInputCannotBe(maybe_string)) { | 381 if (r.OneInputCannotBe(maybe_string)) { |
| 380 // If one input cannot be a string, then emit a number comparison. | 382 // If one input cannot be a string, then emit a number comparison. |
| 381 ... | 383 ... |
| 382 } | 384 } |
| 383 #endif | 385 #endif |
| 384 Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); | 386 if (r.BothInputsAre(Type::Primitive()) && |
| 385 if (r.BothInputsAre(Type::Primitive()) && r.OneInputCannotBe(maybe_string)) { | 387 r.OneInputCannotBe(Type::StringOrReceiver())) { |
| 386 const Operator* less_than; | 388 const Operator* less_than; |
| 387 const Operator* less_than_or_equal; | 389 const Operator* less_than_or_equal; |
| 388 if (r.BothInputsAre(Type::Unsigned32())) { | 390 if (r.BothInputsAre(Type::Unsigned32())) { |
| 389 less_than = machine()->Uint32LessThan(); | 391 less_than = machine()->Uint32LessThan(); |
| 390 less_than_or_equal = machine()->Uint32LessThanOrEqual(); | 392 less_than_or_equal = machine()->Uint32LessThanOrEqual(); |
| 391 } else if (r.BothInputsAre(Type::Signed32())) { | 393 } else if (r.BothInputsAre(Type::Signed32())) { |
| 392 less_than = machine()->Int32LessThan(); | 394 less_than = machine()->Int32LessThan(); |
| 393 less_than_or_equal = machine()->Int32LessThanOrEqual(); | 395 less_than_or_equal = machine()->Int32LessThanOrEqual(); |
| 394 } else { | 396 } else { |
| 395 // TODO(turbofan): mixed signed/unsigned int32 comparisons. | 397 // TODO(turbofan): mixed signed/unsigned int32 comparisons. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 446 |
| 445 | 447 |
| 446 Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { | 448 Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { |
| 447 JSBinopReduction r(this, node); | 449 JSBinopReduction r(this, node); |
| 448 if (r.left() == r.right()) { | 450 if (r.left() == r.right()) { |
| 449 // x === x is always true if x != NaN | 451 // x === x is always true if x != NaN |
| 450 if (!r.left_type()->Maybe(Type::NaN())) { | 452 if (!r.left_type()->Maybe(Type::NaN())) { |
| 451 return ReplaceEagerly(node, jsgraph()->BooleanConstant(!invert)); | 453 return ReplaceEagerly(node, jsgraph()->BooleanConstant(!invert)); |
| 452 } | 454 } |
| 453 } | 455 } |
| 454 Type* string_or_number = Type::Union(Type::String(), Type::Number(), zone()); | 456 if (r.OneInputCannotBe(Type::NumberOrString())) { |
| 455 if (r.OneInputCannotBe(string_or_number)) { | |
| 456 // For values with canonical representation (i.e. not string nor number) an | 457 // For values with canonical representation (i.e. not string nor number) an |
| 457 // empty type intersection means the values cannot be strictly equal. | 458 // empty type intersection means the values cannot be strictly equal. |
| 458 if (!r.left_type()->Maybe(r.right_type())) { | 459 if (!r.left_type()->Maybe(r.right_type())) { |
| 459 return ReplaceEagerly(node, jsgraph()->BooleanConstant(invert)); | 460 return ReplaceEagerly(node, jsgraph()->BooleanConstant(invert)); |
| 460 } | 461 } |
| 461 } | 462 } |
| 462 if (r.OneInputIs(Type::Undefined())) { | 463 if (r.OneInputIs(Type::Undefined())) { |
| 463 return r.ChangeToPureOperator( | 464 return r.ChangeToPureOperator( |
| 464 simplified()->ReferenceEqual(Type::Undefined()), invert); | 465 simplified()->ReferenceEqual(Type::Undefined()), invert); |
| 465 } | 466 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 483 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); | 484 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); |
| 484 } | 485 } |
| 485 if (r.BothInputsAre(Type::Number())) { | 486 if (r.BothInputsAre(Type::Number())) { |
| 486 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); | 487 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); |
| 487 } | 488 } |
| 488 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types) | 489 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types) |
| 489 return NoChange(); | 490 return NoChange(); |
| 490 } | 491 } |
| 491 | 492 |
| 492 | 493 |
| 493 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { | |
| 494 if (input->opcode() == IrOpcode::kJSToNumber) { | |
| 495 // Recursively try to reduce the input first. | |
| 496 Reduction result = ReduceJSToNumber(input); | |
| 497 if (result.Changed()) return result; | |
| 498 return Changed(input); // JSToNumber(JSToNumber(x)) => JSToNumber(x) | |
| 499 } | |
| 500 Type* input_type = NodeProperties::GetBounds(input).upper; | |
| 501 if (input_type->Is(Type::Number())) { | |
| 502 // JSToNumber(x:number) => x | |
| 503 return Changed(input); | |
| 504 } | |
| 505 if (input_type->Is(Type::Undefined())) { | |
| 506 // JSToNumber(undefined) => #NaN | |
| 507 return Replace(jsgraph()->NaNConstant()); | |
| 508 } | |
| 509 if (input_type->Is(Type::Null())) { | |
| 510 // JSToNumber(null) => #0 | |
| 511 return Replace(jsgraph()->ZeroConstant()); | |
| 512 } | |
| 513 if (input_type->Is(Type::Boolean())) { | |
| 514 // JSToNumber(x:boolean) => BooleanToNumber(x) | |
| 515 return Replace(graph()->NewNode(simplified()->BooleanToNumber(), input)); | |
| 516 } | |
| 517 // TODO(turbofan): js-typed-lowering of ToNumber(x:string) | |
| 518 return NoChange(); | |
| 519 } | |
| 520 | |
| 521 | |
| 522 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { | |
| 523 // Try to reduce the input first. | |
| 524 Node* const input = node->InputAt(0); | |
| 525 Reduction reduction = ReduceJSToNumberInput(input); | |
| 526 if (reduction.Changed()) { | |
| 527 NodeProperties::ReplaceWithValue(node, reduction.replacement()); | |
| 528 return reduction; | |
| 529 } | |
| 530 Type* const input_type = NodeProperties::GetBounds(input).upper; | |
| 531 if (input_type->Is(Type::PlainPrimitive())) { | |
| 532 // Converting a plain primitive to a number has no observable side effects. | |
| 533 RelaxEffects(node); | |
| 534 // JSToNumber(phi(x1,...,xn,control):plain-primitive,context) | |
| 535 // => phi(JSToNumber(x1,no-context),...,JSToNumber(xn,no-context),control) | |
| 536 if (input->opcode() == IrOpcode::kPhi) { | |
| 537 int const input_count = input->InputCount() - 1; | |
| 538 Node* const control = input->InputAt(input_count); | |
| 539 DCHECK_LE(0, input_count); | |
| 540 DCHECK(NodeProperties::IsControl(control)); | |
| 541 DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number())); | |
| 542 DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number())); | |
| 543 node->set_op(common()->Phi(kMachAnyTagged, input_count)); | |
| 544 for (int i = 0; i < input_count; ++i) { | |
| 545 Node* value = input->InputAt(i); | |
| 546 // Recursively try to reduce the value first. | |
| 547 Reduction reduction = ReduceJSToNumberInput(value); | |
| 548 if (reduction.Changed()) { | |
| 549 value = reduction.replacement(); | |
| 550 } else { | |
| 551 value = graph()->NewNode(javascript()->ToNumber(), value, | |
| 552 jsgraph()->NoContextConstant(), | |
| 553 graph()->start(), graph()->start()); | |
| 554 } | |
| 555 if (i < node->InputCount()) { | |
| 556 node->ReplaceInput(i, value); | |
| 557 } else { | |
| 558 node->AppendInput(graph()->zone(), value); | |
| 559 } | |
| 560 } | |
| 561 if (input_count < node->InputCount()) { | |
| 562 node->ReplaceInput(input_count, control); | |
| 563 } else { | |
| 564 node->AppendInput(graph()->zone(), control); | |
| 565 } | |
| 566 node->TrimInputCount(input_count + 1); | |
| 567 } | |
| 568 return Changed(node); | |
| 569 } | |
| 570 return NoChange(); | |
| 571 } | |
| 572 | |
| 573 | |
| 574 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { | |
| 575 if (input->opcode() == IrOpcode::kJSToString) { | |
| 576 // Recursively try to reduce the input first. | |
| 577 Reduction result = ReduceJSToStringInput(input->InputAt(0)); | |
| 578 if (result.Changed()) { | |
| 579 RelaxEffects(input); | |
| 580 return result; | |
| 581 } | |
| 582 return Changed(input); // JSToString(JSToString(x)) => JSToString(x) | |
| 583 } | |
| 584 Type* input_type = NodeProperties::GetBounds(input).upper; | |
| 585 if (input_type->Is(Type::String())) { | |
| 586 return Changed(input); // JSToString(x:string) => x | |
| 587 } | |
| 588 if (input_type->Is(Type::Undefined())) { | |
| 589 return Replace(jsgraph()->HeapConstant( | |
| 590 graph()->zone()->isolate()->factory()->undefined_string())); | |
| 591 } | |
| 592 if (input_type->Is(Type::Null())) { | |
| 593 return Replace(jsgraph()->HeapConstant( | |
| 594 graph()->zone()->isolate()->factory()->null_string())); | |
| 595 } | |
| 596 // TODO(turbofan): js-typed-lowering of ToString(x:boolean) | |
| 597 // TODO(turbofan): js-typed-lowering of ToString(x:number) | |
| 598 return NoChange(); | |
| 599 } | |
| 600 | |
| 601 | |
| 602 Reduction JSTypedLowering::ReduceJSToBooleanInput(Node* input) { | 494 Reduction JSTypedLowering::ReduceJSToBooleanInput(Node* input) { |
| 603 if (input->opcode() == IrOpcode::kJSToBoolean) { | 495 if (input->opcode() == IrOpcode::kJSToBoolean) { |
| 604 // Recursively try to reduce the input first. | 496 // Recursively try to reduce the input first. |
| 605 Reduction result = ReduceJSToBoolean(input); | 497 Reduction result = ReduceJSToBoolean(input); |
| 606 if (result.Changed()) return result; | 498 if (result.Changed()) return result; |
| 607 return Changed(input); // JSToBoolean(JSToBoolean(x)) => JSToBoolean(x) | 499 return Changed(input); // JSToBoolean(JSToBoolean(x)) => JSToBoolean(x) |
| 608 } | 500 } |
| 609 Type* input_type = NodeProperties::GetBounds(input).upper; | 501 Type* input_type = NodeProperties::GetBounds(input).upper; |
| 610 if (input_type->Is(Type::Boolean())) { | 502 if (input_type->Is(Type::Boolean())) { |
| 611 return Changed(input); // JSToBoolean(x:boolean) => x | 503 return Changed(input); // JSToBoolean(x:boolean) => x |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 612 } |
| 721 node->ReplaceInput(i, value); | 613 node->ReplaceInput(i, value); |
| 722 } | 614 } |
| 723 DCHECK_EQ(3, node->InputCount()); | 615 DCHECK_EQ(3, node->InputCount()); |
| 724 return Changed(node); | 616 return Changed(node); |
| 725 } | 617 } |
| 726 return NoChange(); | 618 return NoChange(); |
| 727 } | 619 } |
| 728 | 620 |
| 729 | 621 |
| 622 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { |
| 623 if (input->opcode() == IrOpcode::kJSToNumber) { |
| 624 // Recursively try to reduce the input first. |
| 625 Reduction result = ReduceJSToNumber(input); |
| 626 if (result.Changed()) return result; |
| 627 return Changed(input); // JSToNumber(JSToNumber(x)) => JSToNumber(x) |
| 628 } |
| 629 Type* input_type = NodeProperties::GetBounds(input).upper; |
| 630 if (input_type->Is(Type::Number())) { |
| 631 // JSToNumber(x:number) => x |
| 632 return Changed(input); |
| 633 } |
| 634 if (input_type->Is(Type::Undefined())) { |
| 635 // JSToNumber(undefined) => #NaN |
| 636 return Replace(jsgraph()->NaNConstant()); |
| 637 } |
| 638 if (input_type->Is(Type::Null())) { |
| 639 // JSToNumber(null) => #0 |
| 640 return Replace(jsgraph()->ZeroConstant()); |
| 641 } |
| 642 if (input_type->Is(Type::Boolean())) { |
| 643 // JSToNumber(x:boolean) => BooleanToNumber(x) |
| 644 return Replace(graph()->NewNode(simplified()->BooleanToNumber(), input)); |
| 645 } |
| 646 // TODO(turbofan): js-typed-lowering of ToNumber(x:string) |
| 647 return NoChange(); |
| 648 } |
| 649 |
| 650 |
| 651 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { |
| 652 // Try to reduce the input first. |
| 653 Node* const input = node->InputAt(0); |
| 654 Reduction reduction = ReduceJSToNumberInput(input); |
| 655 if (reduction.Changed()) { |
| 656 NodeProperties::ReplaceWithValue(node, reduction.replacement()); |
| 657 return reduction; |
| 658 } |
| 659 Type* const input_type = NodeProperties::GetBounds(input).upper; |
| 660 if (input_type->Is(Type::PlainPrimitive())) { |
| 661 // Converting a plain primitive to a number has no observable side effects. |
| 662 RelaxEffects(node); |
| 663 if (input->opcode() == IrOpcode::kPhi) { |
| 664 // JSToNumber(phi(x1,...,xn,control):plain-primitive,context) |
| 665 // => phi(JSToNumber(x1,no-context), |
| 666 // ..., |
| 667 // JSToNumber(xn,no-context),control) |
| 668 int const input_count = input->InputCount() - 1; |
| 669 Node* const control = input->InputAt(input_count); |
| 670 DCHECK_LE(0, input_count); |
| 671 DCHECK(NodeProperties::IsControl(control)); |
| 672 DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number())); |
| 673 DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number())); |
| 674 node->set_op(common()->Phi(kMachAnyTagged, input_count)); |
| 675 for (int i = 0; i < input_count; ++i) { |
| 676 Node* value = input->InputAt(i); |
| 677 // Recursively try to reduce the value first. |
| 678 Reduction reduction = ReduceJSToNumberInput(value); |
| 679 if (reduction.Changed()) { |
| 680 value = reduction.replacement(); |
| 681 } else { |
| 682 // We must be very careful not to introduce cycles when pushing |
| 683 // operations into phis. It is safe for {value}, since it appears |
| 684 // as input to the phi that we are replacing, but it's not safe |
| 685 // to simply reuse the context of the {node}. However, ToNumber() |
| 686 // does not require a context anyways, so it's safe to discard it |
| 687 // here and pass the dummy context. |
| 688 value = graph()->NewNode(javascript()->ToNumber(), value, |
| 689 jsgraph()->NoContextConstant(), |
| 690 graph()->start(), graph()->start()); |
| 691 } |
| 692 if (i < node->InputCount()) { |
| 693 node->ReplaceInput(i, value); |
| 694 } else { |
| 695 node->AppendInput(graph()->zone(), value); |
| 696 } |
| 697 } |
| 698 if (input_count < node->InputCount()) { |
| 699 node->ReplaceInput(input_count, control); |
| 700 } else { |
| 701 node->AppendInput(graph()->zone(), control); |
| 702 } |
| 703 node->TrimInputCount(input_count + 1); |
| 704 } else if (input->opcode() == IrOpcode::kSelect) { |
| 705 // JSToNumber(select(c,x1,x2):plain-primitive,context) |
| 706 // => select(c,JSToNumber(x1,no-context),JSToNumber(x2,no-context)) |
| 707 int const input_count = input->InputCount(); |
| 708 BranchHint const input_hint = SelectParametersOf(input->op()).hint(); |
| 709 DCHECK_EQ(3, input_count); |
| 710 DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number())); |
| 711 DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number())); |
| 712 node->set_op(common()->Select(kMachAnyTagged, input_hint)); |
| 713 node->ReplaceInput(0, input->InputAt(0)); |
| 714 for (int i = 1; i < input_count; ++i) { |
| 715 Node* value = input->InputAt(i); |
| 716 // Recursively try to reduce the value first. |
| 717 Reduction reduction = ReduceJSToNumberInput(value); |
| 718 if (reduction.Changed()) { |
| 719 value = reduction.replacement(); |
| 720 } else { |
| 721 // We must be very careful not to introduce cycles when pushing |
| 722 // operations into selects. It is safe for {value}, since it appears |
| 723 // as input to the select that we are replacing, but it's not safe |
| 724 // to simply reuse the context of the {node}. However, ToNumber() |
| 725 // does not require a context anyways, so it's safe to discard it |
| 726 // here and pass the dummy context. |
| 727 value = graph()->NewNode(javascript()->ToNumber(), value, |
| 728 jsgraph()->NoContextConstant(), |
| 729 graph()->start(), graph()->start()); |
| 730 } |
| 731 node->ReplaceInput(i, value); |
| 732 } |
| 733 node->TrimInputCount(input_count); |
| 734 } |
| 735 return Changed(node); |
| 736 } |
| 737 return NoChange(); |
| 738 } |
| 739 |
| 740 |
| 741 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { |
| 742 if (input->opcode() == IrOpcode::kJSToString) { |
| 743 // Recursively try to reduce the input first. |
| 744 Reduction result = ReduceJSToString(input); |
| 745 if (result.Changed()) return result; |
| 746 return Changed(input); // JSToString(JSToString(x)) => JSToString(x) |
| 747 } |
| 748 Type* input_type = NodeProperties::GetBounds(input).upper; |
| 749 if (input_type->Is(Type::String())) { |
| 750 return Changed(input); // JSToString(x:string) => x |
| 751 } |
| 752 if (input_type->Is(Type::Undefined())) { |
| 753 return Replace(jsgraph()->HeapConstant(factory()->undefined_string())); |
| 754 } |
| 755 if (input_type->Is(Type::Null())) { |
| 756 return Replace(jsgraph()->HeapConstant(factory()->null_string())); |
| 757 } |
| 758 // TODO(turbofan): js-typed-lowering of ToString(x:boolean) |
| 759 // TODO(turbofan): js-typed-lowering of ToString(x:number) |
| 760 return NoChange(); |
| 761 } |
| 762 |
| 763 |
| 764 Reduction JSTypedLowering::ReduceJSToString(Node* node) { |
| 765 // Try to reduce the input first. |
| 766 Node* const input = node->InputAt(0); |
| 767 Reduction reduction = ReduceJSToStringInput(input); |
| 768 if (reduction.Changed()) { |
| 769 NodeProperties::ReplaceWithValue(node, reduction.replacement()); |
| 770 return reduction; |
| 771 } |
| 772 return NoChange(); |
| 773 } |
| 774 |
| 775 |
| 730 Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { | 776 Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { |
| 731 Node* key = NodeProperties::GetValueInput(node, 1); | 777 Node* key = NodeProperties::GetValueInput(node, 1); |
| 732 Node* base = NodeProperties::GetValueInput(node, 0); | 778 Node* base = NodeProperties::GetValueInput(node, 0); |
| 733 Type* key_type = NodeProperties::GetBounds(key).upper; | 779 Type* key_type = NodeProperties::GetBounds(key).upper; |
| 734 // TODO(mstarzinger): This lowering is not correct if: | 780 // TODO(mstarzinger): This lowering is not correct if: |
| 735 // a) The typed array or it's buffer is neutered. | 781 // a) The typed array or it's buffer is neutered. |
| 736 HeapObjectMatcher<Object> mbase(base); | 782 HeapObjectMatcher<Object> mbase(base); |
| 737 if (mbase.HasValue() && mbase.Value().handle()->IsJSTypedArray()) { | 783 if (mbase.HasValue() && mbase.Value().handle()->IsJSTypedArray()) { |
| 738 Handle<JSTypedArray> const array = | 784 Handle<JSTypedArray> const array = |
| 739 Handle<JSTypedArray>::cast(mbase.Value().handle()); | 785 Handle<JSTypedArray>::cast(mbase.Value().handle()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 NodeProperties::GetValueInput(node, 0), effect, control)); | 927 NodeProperties::GetValueInput(node, 0), effect, control)); |
| 882 } | 928 } |
| 883 node->set_op( | 929 node->set_op( |
| 884 simplified()->StoreField(AccessBuilder::ForContextSlot(access.index()))); | 930 simplified()->StoreField(AccessBuilder::ForContextSlot(access.index()))); |
| 885 node->RemoveInput(2); | 931 node->RemoveInput(2); |
| 886 DCHECK_EQ(4, node->InputCount()); | 932 DCHECK_EQ(4, node->InputCount()); |
| 887 return Changed(node); | 933 return Changed(node); |
| 888 } | 934 } |
| 889 | 935 |
| 890 | 936 |
| 891 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { | |
| 892 if (reduction.Changed()) { | |
| 893 NodeProperties::ReplaceWithValue(node, reduction.replacement()); | |
| 894 return reduction; | |
| 895 } | |
| 896 return Reducer::NoChange(); | |
| 897 } | |
| 898 | |
| 899 | |
| 900 Reduction JSTypedLowering::Reduce(Node* node) { | 937 Reduction JSTypedLowering::Reduce(Node* node) { |
| 901 // Check if the output type is a singleton. In that case we already know the | 938 // Check if the output type is a singleton. In that case we already know the |
| 902 // result value and can simply replace the node unless there are effects. | 939 // result value and can simply replace the node unless there are effects. |
| 903 if (NodeProperties::IsTyped(node) && | 940 if (NodeProperties::IsTyped(node) && |
| 904 NodeProperties::GetBounds(node).upper->IsConstant() && | 941 NodeProperties::GetBounds(node).upper->IsConstant() && |
| 905 !IrOpcode::IsLeafOpcode(node->opcode()) && | 942 !IrOpcode::IsLeafOpcode(node->opcode()) && |
| 906 node->op()->EffectOutputCount() == 0) { | 943 node->op()->EffectOutputCount() == 0) { |
| 907 return ReplaceEagerly(node, jsgraph()->Constant( | 944 return ReplaceEagerly(node, jsgraph()->Constant( |
| 908 NodeProperties::GetBounds(node).upper->AsConstant()->Value())); | 945 NodeProperties::GetBounds(node).upper->AsConstant()->Value())); |
| 909 // TODO(neis): Extend this to Range(x,x), NaN, MinusZero, ...? | 946 // TODO(neis): Extend this to Range(x,x), NaN, MinusZero, ...? |
| 910 } | 947 } |
| 911 switch (node->opcode()) { | 948 switch (node->opcode()) { |
| 912 case IrOpcode::kJSEqual: | 949 case IrOpcode::kJSEqual: |
| 913 return ReduceJSEqual(node, false); | 950 return ReduceJSEqual(node, false); |
| 914 case IrOpcode::kJSNotEqual: | 951 case IrOpcode::kJSNotEqual: |
| 915 return ReduceJSEqual(node, true); | 952 return ReduceJSEqual(node, true); |
| 916 case IrOpcode::kJSStrictEqual: | 953 case IrOpcode::kJSStrictEqual: |
| 917 return ReduceJSStrictEqual(node, false); | 954 return ReduceJSStrictEqual(node, false); |
| 918 case IrOpcode::kJSStrictNotEqual: | 955 case IrOpcode::kJSStrictNotEqual: |
| 919 return ReduceJSStrictEqual(node, true); | 956 return ReduceJSStrictEqual(node, true); |
| 920 case IrOpcode::kJSLessThan: // fall through | 957 case IrOpcode::kJSLessThan: // fall through |
| 921 case IrOpcode::kJSGreaterThan: // fall through | 958 case IrOpcode::kJSGreaterThan: // fall through |
| 922 case IrOpcode::kJSLessThanOrEqual: // fall through | 959 case IrOpcode::kJSLessThanOrEqual: // fall through |
| 923 case IrOpcode::kJSGreaterThanOrEqual: | 960 case IrOpcode::kJSGreaterThanOrEqual: |
| 924 return ReduceJSComparison(node); | 961 return ReduceJSComparison(node); |
| 925 case IrOpcode::kJSBitwiseOr: | 962 case IrOpcode::kJSBitwiseOr: |
| 926 return ReduceJSBitwiseOr(node); | 963 return ReduceJSBitwiseOr(node); |
| 927 case IrOpcode::kJSBitwiseXor: | 964 case IrOpcode::kJSBitwiseXor: |
| 928 return ReduceI32Binop(node, true, true, machine()->Word32Xor()); | 965 return ReduceInt32Binop(node, machine()->Word32Xor()); |
| 929 case IrOpcode::kJSBitwiseAnd: | 966 case IrOpcode::kJSBitwiseAnd: |
| 930 return ReduceI32Binop(node, true, true, machine()->Word32And()); | 967 return ReduceInt32Binop(node, machine()->Word32And()); |
| 931 case IrOpcode::kJSShiftLeft: | 968 case IrOpcode::kJSShiftLeft: |
| 932 return ReduceI32Shift(node, true, machine()->Word32Shl()); | 969 return ReduceUI32Shift(node, kSigned, machine()->Word32Shl()); |
| 933 case IrOpcode::kJSShiftRight: | 970 case IrOpcode::kJSShiftRight: |
| 934 return ReduceI32Shift(node, true, machine()->Word32Sar()); | 971 return ReduceUI32Shift(node, kSigned, machine()->Word32Sar()); |
| 935 case IrOpcode::kJSShiftRightLogical: | 972 case IrOpcode::kJSShiftRightLogical: |
| 936 return ReduceI32Shift(node, false, machine()->Word32Shr()); | 973 return ReduceUI32Shift(node, kUnsigned, machine()->Word32Shr()); |
| 937 case IrOpcode::kJSAdd: | 974 case IrOpcode::kJSAdd: |
| 938 return ReduceJSAdd(node); | 975 return ReduceJSAdd(node); |
| 939 case IrOpcode::kJSSubtract: | 976 case IrOpcode::kJSSubtract: |
| 940 return ReduceNumberBinop(node, simplified()->NumberSubtract()); | 977 return ReduceNumberBinop(node, simplified()->NumberSubtract()); |
| 941 case IrOpcode::kJSMultiply: | 978 case IrOpcode::kJSMultiply: |
| 942 return ReduceJSMultiply(node); | 979 return ReduceJSMultiply(node); |
| 943 case IrOpcode::kJSDivide: | 980 case IrOpcode::kJSDivide: |
| 944 return ReduceNumberBinop(node, simplified()->NumberDivide()); | 981 return ReduceNumberBinop(node, simplified()->NumberDivide()); |
| 945 case IrOpcode::kJSModulus: | 982 case IrOpcode::kJSModulus: |
| 946 return ReduceNumberBinop(node, simplified()->NumberModulus()); | 983 return ReduceNumberBinop(node, simplified()->NumberModulus()); |
| 947 case IrOpcode::kJSUnaryNot: { | 984 case IrOpcode::kJSUnaryNot: { |
| 948 Reduction result = ReduceJSToBooleanInput(node->InputAt(0)); | 985 Reduction result = ReduceJSToBooleanInput(node->InputAt(0)); |
| 949 if (result.Changed()) { | 986 if (result.Changed()) { |
| 950 // JSUnaryNot(x:boolean) => BooleanNot(x) | 987 // JSUnaryNot(x:boolean) => BooleanNot(x) |
| 951 node = result.replacement(); | 988 node = result.replacement(); |
| 952 } else { | 989 } else { |
| 953 // JSUnaryNot(x) => BooleanNot(JSToBoolean(x)) | 990 // JSUnaryNot(x) => BooleanNot(JSToBoolean(x)) |
| 954 node->set_op(javascript()->ToBoolean()); | 991 node->set_op(javascript()->ToBoolean()); |
| 955 } | 992 } |
| 956 Node* value = graph()->NewNode(simplified()->BooleanNot(), node); | 993 Node* value = graph()->NewNode(simplified()->BooleanNot(), node); |
| 957 return Replace(value); | 994 return Replace(value); |
| 958 } | 995 } |
| 959 case IrOpcode::kJSToBoolean: | 996 case IrOpcode::kJSToBoolean: |
| 960 return ReduceJSToBoolean(node); | 997 return ReduceJSToBoolean(node); |
| 961 case IrOpcode::kJSToNumber: | 998 case IrOpcode::kJSToNumber: |
| 962 return ReduceJSToNumber(node); | 999 return ReduceJSToNumber(node); |
| 963 case IrOpcode::kJSToString: | 1000 case IrOpcode::kJSToString: |
| 964 return ReplaceWithReduction(node, | 1001 return ReduceJSToString(node); |
| 965 ReduceJSToStringInput(node->InputAt(0))); | |
| 966 case IrOpcode::kJSLoadProperty: | 1002 case IrOpcode::kJSLoadProperty: |
| 967 return ReduceJSLoadProperty(node); | 1003 return ReduceJSLoadProperty(node); |
| 968 case IrOpcode::kJSStoreProperty: | 1004 case IrOpcode::kJSStoreProperty: |
| 969 return ReduceJSStoreProperty(node); | 1005 return ReduceJSStoreProperty(node); |
| 970 case IrOpcode::kJSLoadContext: | 1006 case IrOpcode::kJSLoadContext: |
| 971 return ReduceJSLoadContext(node); | 1007 return ReduceJSLoadContext(node); |
| 972 case IrOpcode::kJSStoreContext: | 1008 case IrOpcode::kJSStoreContext: |
| 973 return ReduceJSStoreContext(node); | 1009 return ReduceJSStoreContext(node); |
| 974 case IrOpcode::kJSCallFunction: | |
| 975 return JSBuiltinReducer(jsgraph()).Reduce(node); | |
| 976 default: | 1010 default: |
| 977 break; | 1011 break; |
| 978 } | 1012 } |
| 979 return NoChange(); | 1013 return NoChange(); |
| 980 } | 1014 } |
| 981 | 1015 |
| 982 | 1016 |
| 983 Node* JSTypedLowering::Word32Shl(Node* const lhs, int32_t const rhs) { | 1017 Node* JSTypedLowering::Word32Shl(Node* const lhs, int32_t const rhs) { |
| 984 if (rhs == 0) return lhs; | 1018 if (rhs == 0) return lhs; |
| 985 return graph()->NewNode(machine()->Word32Shl(), lhs, | 1019 return graph()->NewNode(machine()->Word32Shl(), lhs, |
| 986 jsgraph()->Int32Constant(rhs)); | 1020 jsgraph()->Int32Constant(rhs)); |
| 987 } | 1021 } |
| 988 | 1022 |
| 1023 |
| 1024 Factory* JSTypedLowering::factory() const { return jsgraph()->factory(); } |
| 1025 |
| 1026 |
| 1027 Graph* JSTypedLowering::graph() const { return jsgraph()->graph(); } |
| 1028 |
| 1029 |
| 1030 JSOperatorBuilder* JSTypedLowering::javascript() const { |
| 1031 return jsgraph()->javascript(); |
| 1032 } |
| 1033 |
| 1034 |
| 1035 CommonOperatorBuilder* JSTypedLowering::common() const { |
| 1036 return jsgraph()->common(); |
| 1037 } |
| 1038 |
| 1039 |
| 1040 MachineOperatorBuilder* JSTypedLowering::machine() const { |
| 1041 return jsgraph()->machine(); |
| 1042 } |
| 1043 |
| 989 } // namespace compiler | 1044 } // namespace compiler |
| 990 } // namespace internal | 1045 } // namespace internal |
| 991 } // namespace v8 | 1046 } // namespace v8 |
| OLD | NEW |