LCOV - code coverage report
Current view: top level - src/compiler - type-narrowing-reducer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 24 24 100.0 %
Date: 2019-01-20 Functions: 4 6 66.7 %

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/compiler/type-narrowing-reducer.h"
       6             : 
       7             : #include "src/compiler/js-graph.h"
       8             : #include "src/objects-inl.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : namespace compiler {
      13             : 
      14      456095 : TypeNarrowingReducer::TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph,
      15             :                                            JSHeapBroker* broker)
      16      912190 :     : AdvancedReducer(editor), jsgraph_(jsgraph), op_typer_(broker, zone()) {}
      17             : 
      18             : TypeNarrowingReducer::~TypeNarrowingReducer() = default;
      19             : 
      20    67287476 : Reduction TypeNarrowingReducer::Reduce(Node* node) {
      21             :   DisallowHeapAccess no_heap_access;
      22             : 
      23    33643738 :   Type new_type = Type::Any();
      24             : 
      25    33643738 :   switch (node->opcode()) {
      26             :     case IrOpcode::kNumberLessThan: {
      27             :       // TODO(turbofan) Reuse the logic from typer.cc (by integrating relational
      28             :       // comparisons with the operation typer).
      29       50330 :       Type left_type = NodeProperties::GetType(node->InputAt(0));
      30       50330 :       Type right_type = NodeProperties::GetType(node->InputAt(1));
      31      100557 :       if (left_type.Is(Type::PlainNumber()) &&
      32             :           right_type.Is(Type::PlainNumber())) {
      33       50089 :         if (left_type.Max() < right_type.Min()) {
      34        7933 :           new_type = op_typer_.singleton_true();
      35       42156 :         } else if (left_type.Min() >= right_type.Max()) {
      36         938 :           new_type = op_typer_.singleton_false();
      37             :         }
      38             :       }
      39             :       break;
      40             :     }
      41             : 
      42             :     case IrOpcode::kTypeGuard: {
      43             :       new_type = op_typer_.TypeTypeGuard(
      44       38261 :           node->op(), NodeProperties::GetType(node->InputAt(0)));
      45       38263 :       break;
      46             :     }
      47             : 
      48             : #define DECLARE_CASE(Name)                                                \
      49             :   case IrOpcode::k##Name: {                                               \
      50             :     new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0)),  \
      51             :                               NodeProperties::GetType(node->InputAt(1))); \
      52             :     break;                                                                \
      53             :   }
      54      205093 :       SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_CASE)
      55          12 :       DECLARE_CASE(SameValue)
      56             : #undef DECLARE_CASE
      57             : 
      58             : #define DECLARE_CASE(Name)                                                \
      59             :   case IrOpcode::k##Name: {                                               \
      60             :     new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0))); \
      61             :     break;                                                                \
      62             :   }
      63       64489 :       SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_CASE)
      64       65807 :       DECLARE_CASE(ToBoolean)
      65             : #undef DECLARE_CASE
      66             : 
      67             :     default:
      68             :       return NoChange();
      69             :   }
      70             : 
      71      423998 :   Type original_type = NodeProperties::GetType(node);
      72      423998 :   Type restricted = Type::Intersect(new_type, original_type, zone());
      73      424001 :   if (!original_type.Is(restricted)) {
      74             :     NodeProperties::SetType(node, restricted);
      75             :     return Changed(node);
      76             :   }
      77             :   return NoChange();
      78             : }
      79             : 
      80      880093 : Graph* TypeNarrowingReducer::graph() const { return jsgraph()->graph(); }
      81             : 
      82      880093 : Zone* TypeNarrowingReducer::zone() const { return graph()->zone(); }
      83             : 
      84             : }  // namespace compiler
      85             : }  // namespace internal
      86      183867 : }  // namespace v8

Generated by: LCOV version 1.10