LCOV - code coverage report
Current view: top level - src/compiler - js-graph.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 84 86 97.7 %
Date: 2019-01-20 Functions: 33 33 100.0 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/compiler/js-graph.h"
       6             : 
       7             : #include "src/code-factory.h"
       8             : #include "src/compiler/node-properties.h"
       9             : #include "src/compiler/typer.h"
      10             : #include "src/objects-inl.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : namespace compiler {
      15             : 
      16             : #define GET_CACHED_FIELD(ptr, expr) (*(ptr)) ? *(ptr) : (*(ptr) = (expr))
      17             : 
      18             : #define DEFINE_GETTER(name, expr) \
      19             :   Node* JSGraph::name() { return GET_CACHED_FIELD(&name##_, expr); }
      20             : 
      21      855413 : Node* JSGraph::CEntryStubConstant(int result_size, SaveFPRegsMode save_doubles,
      22      458760 :                                   ArgvMode argv_mode, bool builtin_exit_frame) {
      23      855413 :   if (save_doubles == kDontSaveFPRegs && argv_mode == kArgvOnStack) {
      24             :     DCHECK(result_size >= 1 && result_size <= 3);
      25      855413 :     if (!builtin_exit_frame) {
      26             :       Node** ptr = nullptr;
      27      851886 :       if (result_size == 1) {
      28      850950 :         ptr = &CEntryStub1Constant_;
      29         936 :       } else if (result_size == 2) {
      30         936 :         ptr = &CEntryStub2Constant_;
      31             :       } else {
      32             :         DCHECK_EQ(3, result_size);
      33           0 :         ptr = &CEntryStub3Constant_;
      34             :       }
      35     1765013 :       return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
      36             :                                        isolate(), result_size, save_doubles,
      37             :                                        argv_mode, builtin_exit_frame)));
      38             :     }
      39             :     Node** ptr = builtin_exit_frame ? &CEntryStub1WithBuiltinExitFrameConstant_
      40        3527 :                                     : &CEntryStub1Constant_;
      41        7925 :     return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
      42             :                                      isolate(), result_size, save_doubles,
      43             :                                      argv_mode, builtin_exit_frame)));
      44             :   }
      45             :   return HeapConstant(CodeFactory::CEntry(isolate(), result_size, save_doubles,
      46           0 :                                           argv_mode, builtin_exit_frame));
      47             : }
      48             : 
      49     8210621 : Node* JSGraph::Constant(Handle<Object> value) {
      50             :   // Dereference the handle to determine if a number constant or other
      51             :   // canonicalized node can be used.
      52     2933477 :   if (value->IsNumber()) {
      53      107085 :     return Constant(value->Number());
      54     2719310 :   } else if (value->IsUndefined(isolate())) {
      55       12548 :     return UndefinedConstant();
      56     2694214 :   } else if (value->IsTrue(isolate())) {
      57         673 :     return TrueConstant();
      58     2692868 :   } else if (value->IsFalse(isolate())) {
      59        1007 :     return FalseConstant();
      60     2690854 :   } else if (value->IsNull(isolate())) {
      61         165 :     return NullConstant();
      62     2690524 :   } else if (value->IsTheHole(isolate())) {
      63           5 :     return TheHoleConstant();
      64             :   } else {
      65     1345257 :     return HeapConstant(Handle<HeapObject>::cast(value));
      66             :   }
      67             : }
      68             : 
      69     1156853 : Node* JSGraph::Constant(const ObjectRef& ref) {
      70      987263 :   if (ref.IsSmi()) return Constant(ref.AsSmi());
      71             :   OddballType oddball_type =
      72      975716 :       ref.AsHeapObject().GetHeapObjectType().oddball_type();
      73      975715 :   if (ref.IsHeapNumber()) {
      74         409 :     return Constant(ref.AsHeapNumber().value());
      75      975305 :   } else if (oddball_type == OddballType::kUndefined) {
      76             :     DCHECK(ref.object().equals(isolate()->factory()->undefined_value()));
      77        1513 :     return UndefinedConstant();
      78      973792 :   } else if (oddball_type == OddballType::kNull) {
      79             :     DCHECK(ref.object().equals(isolate()->factory()->null_value()));
      80         309 :     return NullConstant();
      81      973483 :   } else if (oddball_type == OddballType::kHole) {
      82             :     DCHECK(ref.object().equals(isolate()->factory()->the_hole_value()));
      83        2491 :     return TheHoleConstant();
      84      970992 :   } else if (oddball_type == OddballType::kBoolean) {
      85      339179 :     if (ref.object().equals(isolate()->factory()->true_value())) {
      86       64568 :       return TrueConstant();
      87             :     } else {
      88             :       DCHECK(ref.object().equals(isolate()->factory()->false_value()));
      89      105021 :       return FalseConstant();
      90             :     }
      91             :   } else {
      92      801402 :     return HeapConstant(ref.AsHeapObject().object());
      93             :   }
      94             : }
      95             : 
      96     3015732 : Node* JSGraph::Constant(double value) {
      97     3232163 :   if (bit_cast<int64_t>(value) == bit_cast<int64_t>(0.0)) return ZeroConstant();
      98     3073101 :   if (bit_cast<int64_t>(value) == bit_cast<int64_t>(1.0)) return OneConstant();
      99     2525501 :   return NumberConstant(value);
     100             : }
     101             : 
     102     3242824 : Node* JSGraph::NumberConstant(double value) {
     103             :   Node** loc = cache_.FindNumberConstant(value);
     104     3242827 :   if (*loc == nullptr) {
     105     4505719 :     *loc = graph()->NewNode(common()->NumberConstant(value));
     106             :   }
     107     3242842 :   return *loc;
     108             : }
     109             : 
     110    12988096 : Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
     111    12988096 :   Node** loc = cache_.FindHeapConstant(value);
     112    12988133 :   if (*loc == nullptr) {
     113    13820491 :     *loc = graph()->NewNode(common()->HeapConstant(value));
     114             :   }
     115    12988152 :   return *loc;
     116             : }
     117             : 
     118     4855512 : void JSGraph::GetCachedNodes(NodeVector* nodes) {
     119     4855512 :   cache_.GetCachedNodes(nodes);
     120             : #define DO_CACHED_FIELD(name) \
     121             :   if (name##_) nodes->push_back(name##_);
     122             : 
     123     4855542 :   CACHED_GLOBAL_LIST(DO_CACHED_FIELD)
     124     4855509 :   CACHED_CENTRY_LIST(DO_CACHED_FIELD)
     125             : #undef DO_CACHED_FIELD
     126     4855513 : }
     127             : 
     128      306198 : DEFINE_GETTER(AllocateInNewSpaceStubConstant,
     129             :               HeapConstant(BUILTIN_CODE(isolate(), AllocateInNewSpace)))
     130             : 
     131         842 : DEFINE_GETTER(AllocateInOldSpaceStubConstant,
     132             :               HeapConstant(BUILTIN_CODE(isolate(), AllocateInOldSpace)))
     133             : 
     134         226 : DEFINE_GETTER(ArrayConstructorStubConstant,
     135             :               HeapConstant(BUILTIN_CODE(isolate(), ArrayConstructorImpl)))
     136             : 
     137         148 : DEFINE_GETTER(BooleanMapConstant, HeapConstant(factory()->boolean_map()))
     138             : 
     139          64 : DEFINE_GETTER(ToNumberBuiltinConstant,
     140             :               HeapConstant(BUILTIN_CODE(isolate(), ToNumber)))
     141             : 
     142      160748 : DEFINE_GETTER(EmptyFixedArrayConstant,
     143             :               HeapConstant(factory()->empty_fixed_array()))
     144             : 
     145       67436 : DEFINE_GETTER(EmptyStringConstant, HeapConstant(factory()->empty_string()))
     146             : 
     147        3499 : DEFINE_GETTER(FixedArrayMapConstant, HeapConstant(factory()->fixed_array_map()))
     148             : 
     149        1145 : DEFINE_GETTER(PropertyArrayMapConstant,
     150             :               HeapConstant(factory()->property_array_map()))
     151             : 
     152          56 : DEFINE_GETTER(FixedDoubleArrayMapConstant,
     153             :               HeapConstant(factory()->fixed_double_array_map()))
     154             : 
     155      243788 : DEFINE_GETTER(HeapNumberMapConstant, HeapConstant(factory()->heap_number_map()))
     156             : 
     157    17266557 : DEFINE_GETTER(OptimizedOutConstant, HeapConstant(factory()->optimized_out()))
     158             : 
     159       17016 : DEFINE_GETTER(StaleRegisterConstant, HeapConstant(factory()->stale_register()))
     160             : 
     161     2376253 : DEFINE_GETTER(UndefinedConstant, HeapConstant(factory()->undefined_value()))
     162             : 
     163      485155 : DEFINE_GETTER(TheHoleConstant, HeapConstant(factory()->the_hole_value()))
     164             : 
     165     1482774 : DEFINE_GETTER(TrueConstant, HeapConstant(factory()->true_value()))
     166             : 
     167     1551952 : DEFINE_GETTER(FalseConstant, HeapConstant(factory()->false_value()))
     168             : 
     169       43311 : DEFINE_GETTER(NullConstant, HeapConstant(factory()->null_value()))
     170             : 
     171     1317293 : DEFINE_GETTER(ZeroConstant, NumberConstant(0.0))
     172             : 
     173      457672 : DEFINE_GETTER(OneConstant, NumberConstant(1.0))
     174             : 
     175         323 : DEFINE_GETTER(MinusOneConstant, NumberConstant(-1.0))
     176             : 
     177        1314 : DEFINE_GETTER(NaNConstant,
     178             :               NumberConstant(std::numeric_limits<double>::quiet_NaN()))
     179             : 
     180       25229 : DEFINE_GETTER(EmptyStateValues,
     181             :               graph()->NewNode(common()->StateValues(0,
     182             :                                                      SparseInputMask::Dense())))
     183             : 
     184     5374917 : DEFINE_GETTER(SingleDeadTypedStateValues,
     185             :               graph()->NewNode(common()->TypedStateValues(
     186             :                   new (graph()->zone()->New(sizeof(ZoneVector<MachineType>)))
     187             :                       ZoneVector<MachineType>(0, graph()->zone()),
     188             :                   SparseInputMask(SparseInputMask::kEndMarker << 1))))
     189             : 
     190             : #undef DEFINE_GETTER
     191             : #undef GET_CACHED_FIELD
     192             : 
     193             : }  // namespace compiler
     194             : }  // namespace internal
     195      183867 : }  // namespace v8

Generated by: LCOV version 1.10