Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: src/compiler/js-intrinsic-lowering.cc

Issue 1848243002: [turbofan] Introduce JSToInteger and JSToLength operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/js-intrinsic-lowering.h ('k') | src/compiler/js-operator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/js-intrinsic-lowering.h" 5 #include "src/compiler/js-intrinsic-lowering.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/compiler/access-builder.h" 10 #include "src/compiler/access-builder.h"
11 #include "src/compiler/js-graph.h" 11 #include "src/compiler/js-graph.h"
12 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
13 #include "src/compiler/node-matchers.h" 13 #include "src/compiler/node-matchers.h"
14 #include "src/compiler/node-properties.h" 14 #include "src/compiler/node-properties.h"
15 #include "src/compiler/operator-properties.h" 15 #include "src/compiler/operator-properties.h"
16 #include "src/counters.h" 16 #include "src/counters.h"
17 #include "src/objects-inl.h" 17 #include "src/objects-inl.h"
18 #include "src/type-cache.h"
19 18
20 namespace v8 { 19 namespace v8 {
21 namespace internal { 20 namespace internal {
22 namespace compiler { 21 namespace compiler {
23 22
24 JSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph, 23 JSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph,
25 DeoptimizationMode mode) 24 DeoptimizationMode mode)
26 : AdvancedReducer(editor), 25 : AdvancedReducer(editor), jsgraph_(jsgraph), mode_(mode) {}
27 jsgraph_(jsgraph),
28 mode_(mode),
29 type_cache_(TypeCache::Get()) {}
30
31 26
32 Reduction JSIntrinsicLowering::Reduce(Node* node) { 27 Reduction JSIntrinsicLowering::Reduce(Node* node) {
33 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); 28 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange();
34 const Runtime::Function* const f = 29 const Runtime::Function* const f =
35 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); 30 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id());
36 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); 31 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange();
37 switch (f->function_id) { 32 switch (f->function_id) {
38 case Runtime::kInlineConstructDouble: 33 case Runtime::kInlineConstructDouble:
39 return ReduceConstructDouble(node); 34 return ReduceConstructDouble(node);
40 case Runtime::kInlineCreateIterResultObject: 35 case Runtime::kInlineCreateIterResultObject:
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 return Change(node, op, receiver, effect, control); 339 return Change(node, op, receiver, effect, control);
345 } 340 }
346 341
347 342
348 Reduction JSIntrinsicLowering::ReduceSubString(Node* node) { 343 Reduction JSIntrinsicLowering::ReduceSubString(Node* node) {
349 return Change(node, CodeFactory::SubString(isolate()), 3); 344 return Change(node, CodeFactory::SubString(isolate()), 3);
350 } 345 }
351 346
352 347
353 Reduction JSIntrinsicLowering::ReduceToInteger(Node* node) { 348 Reduction JSIntrinsicLowering::ReduceToInteger(Node* node) {
354 Node* value = NodeProperties::GetValueInput(node, 0); 349 NodeProperties::ChangeOp(node, javascript()->ToInteger());
355 350 return Changed(node);
356 // ToInteger is a no-op on integer values and -0.
357 Type* value_type = NodeProperties::GetType(value);
358 if (value_type->Is(type_cache().kIntegerOrMinusZero)) {
359 ReplaceWithValue(node, value);
360 return Replace(value);
361 }
362
363 return Change(node, CodeFactory::ToInteger(isolate()), 0);
364 } 351 }
365 352
366 353
367 Reduction JSIntrinsicLowering::ReduceToName(Node* node) { 354 Reduction JSIntrinsicLowering::ReduceToName(Node* node) {
368 NodeProperties::ChangeOp(node, javascript()->ToName()); 355 NodeProperties::ChangeOp(node, javascript()->ToName());
369 return Changed(node); 356 return Changed(node);
370 } 357 }
371 358
372 359
373 Reduction JSIntrinsicLowering::ReduceToNumber(Node* node) { 360 Reduction JSIntrinsicLowering::ReduceToNumber(Node* node) {
374 NodeProperties::ChangeOp(node, javascript()->ToNumber()); 361 NodeProperties::ChangeOp(node, javascript()->ToNumber());
375 return Changed(node); 362 return Changed(node);
376 } 363 }
377 364
378 365
379 Reduction JSIntrinsicLowering::ReduceToLength(Node* node) { 366 Reduction JSIntrinsicLowering::ReduceToLength(Node* node) {
380 Node* value = NodeProperties::GetValueInput(node, 0); 367 NodeProperties::ChangeOp(node, javascript()->ToLength());
381 Type* value_type = NodeProperties::GetType(value); 368 return Changed(node);
382 if (value_type->Is(type_cache().kIntegerOrMinusZero)) {
383 if (value_type->Max() <= 0.0) {
384 value = jsgraph()->ZeroConstant();
385 } else if (value_type->Min() >= kMaxSafeInteger) {
386 value = jsgraph()->Constant(kMaxSafeInteger);
387 } else {
388 if (value_type->Min() <= 0.0) {
389 value = graph()->NewNode(
390 common()->Select(MachineRepresentation::kTagged),
391 graph()->NewNode(simplified()->NumberLessThanOrEqual(), value,
392 jsgraph()->ZeroConstant()),
393 jsgraph()->ZeroConstant(), value);
394 value_type = Type::Range(0.0, value_type->Max(), graph()->zone());
395 NodeProperties::SetType(value, value_type);
396 }
397 if (value_type->Max() > kMaxSafeInteger) {
398 value = graph()->NewNode(
399 common()->Select(MachineRepresentation::kTagged),
400 graph()->NewNode(simplified()->NumberLessThanOrEqual(),
401 jsgraph()->Constant(kMaxSafeInteger), value),
402 jsgraph()->Constant(kMaxSafeInteger), value);
403 value_type =
404 Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone());
405 NodeProperties::SetType(value, value_type);
406 }
407 }
408 ReplaceWithValue(node, value);
409 return Replace(value);
410 }
411 return Change(node, CodeFactory::ToLength(isolate()), 0);
412 } 369 }
413 370
414 371
415 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) { 372 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) {
416 NodeProperties::ChangeOp(node, javascript()->ToObject()); 373 NodeProperties::ChangeOp(node, javascript()->ToObject());
417 return Changed(node); 374 return Changed(node);
418 } 375 }
419 376
420 377
421 Reduction JSIntrinsicLowering::ReduceToPrimitive(Node* node) { 378 Reduction JSIntrinsicLowering::ReduceToPrimitive(Node* node) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 498 }
542 499
543 500
544 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { 501 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const {
545 return jsgraph()->simplified(); 502 return jsgraph()->simplified();
546 } 503 }
547 504
548 } // namespace compiler 505 } // namespace compiler
549 } // namespace internal 506 } // namespace internal
550 } // namespace v8 507 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-intrinsic-lowering.h ('k') | src/compiler/js-operator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698