LCOV - code coverage report
Current view: top level - src/compiler - type-narrowing-reducer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 22 24 91.7 %
Date: 2019-04-17 Functions: 3 5 60.0 %

          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             : 
       9             : namespace v8 {
      10             : namespace internal {
      11             : namespace compiler {
      12             : 
      13      464155 : TypeNarrowingReducer::TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph,
      14             :                                            JSHeapBroker* broker)
      15      464155 :     : AdvancedReducer(editor), jsgraph_(jsgraph), op_typer_(broker, zone()) {}
      16             : 
      17             : TypeNarrowingReducer::~TypeNarrowingReducer() = default;
      18             : 
      19    36467649 : Reduction TypeNarrowingReducer::Reduce(Node* node) {
      20             :   DisallowHeapAccess no_heap_access;
      21             : 
      22    36467649 :   Type new_type = Type::Any();
      23             : 
      24    36467649 :   switch (node->opcode()) {
      25             :     case IrOpcode::kNumberLessThan: {
      26             :       // TODO(turbofan) Reuse the logic from typer.cc (by integrating relational
      27             :       // comparisons with the operation typer).
      28       45184 :       Type left_type = NodeProperties::GetType(node->InputAt(0));
      29       45184 :       Type right_type = NodeProperties::GetType(node->InputAt(1));
      30       90291 :       if (left_type.Is(Type::PlainNumber()) &&
      31             :           right_type.Is(Type::PlainNumber())) {
      32       44983 :         if (left_type.Max() < right_type.Min()) {
      33        7338 :           new_type = op_typer_.singleton_true();
      34       37644 :         } else if (left_type.Min() >= right_type.Max()) {
      35         775 :           new_type = op_typer_.singleton_false();
      36             :         }
      37             :       }
      38             :       break;
      39             :     }
      40             : 
      41             :     case IrOpcode::kTypeGuard: {
      42             :       new_type = op_typer_.TypeTypeGuard(
      43       39564 :           node->op(), NodeProperties::GetType(node->InputAt(0)));
      44       39566 :       break;
      45             :     }
      46             : 
      47             : #define DECLARE_CASE(Name)                                                \
      48             :   case IrOpcode::k##Name: {                                               \
      49             :     new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0)),  \
      50             :                               NodeProperties::GetType(node->InputAt(1))); \
      51             :     break;                                                                \
      52             :   }
      53      192344 :       SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_CASE)
      54          78 :       DECLARE_CASE(SameValue)
      55             : #undef DECLARE_CASE
      56             : 
      57             : #define DECLARE_CASE(Name)                                                \
      58             :   case IrOpcode::k##Name: {                                               \
      59             :     new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0))); \
      60             :     break;                                                                \
      61             :   }
      62       55049 :       SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_CASE)
      63       72545 :       DECLARE_CASE(ToBoolean)
      64             : #undef DECLARE_CASE
      65             : 
      66             :     default:
      67             :       return NoChange();
      68             :   }
      69             : 
      70      404781 :   Type original_type = NodeProperties::GetType(node);
      71      404781 :   Type restricted = Type::Intersect(new_type, original_type, zone());
      72      404781 :   if (!original_type.Is(restricted)) {
      73             :     NodeProperties::SetType(node, restricted);
      74             :     return Changed(node);
      75             :   }
      76             :   return NoChange();
      77             : }
      78             : 
      79           0 : Graph* TypeNarrowingReducer::graph() const { return jsgraph()->graph(); }
      80             : 
      81           0 : Zone* TypeNarrowingReducer::zone() const { return graph()->zone(); }
      82             : 
      83             : }  // namespace compiler
      84             : }  // namespace internal
      85      122004 : }  // namespace v8

Generated by: LCOV version 1.10