LCOV - code coverage report
Current view: top level - src/compiler - js-graph.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 125 130 96.2 %
Date: 2017-04-26 Functions: 36 38 94.7 %

          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-stubs.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 CACHED(name, expr) \
      17             :   cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr))
      18             : 
      19      182395 : Node* JSGraph::AllocateInNewSpaceStubConstant() {
      20      250313 :   return CACHED(kAllocateInNewSpaceStubConstant,
      21             :                 HeapConstant(isolate()->builtins()->AllocateInNewSpace()));
      22             : }
      23             : 
      24          52 : Node* JSGraph::AllocateInOldSpaceStubConstant() {
      25          70 :   return CACHED(kAllocateInOldSpaceStubConstant,
      26             :                 HeapConstant(isolate()->builtins()->AllocateInOldSpace()));
      27             : }
      28             : 
      29       10151 : Node* JSGraph::ToNumberBuiltinConstant() {
      30       12023 :   return CACHED(kToNumberBuiltinConstant,
      31             :                 HeapConstant(isolate()->builtins()->ToNumber()));
      32             : }
      33             : 
      34     2154967 : Node* JSGraph::CEntryStubConstant(int result_size, SaveFPRegsMode save_doubles,
      35     1247487 :                                   ArgvMode argv_mode, bool builtin_exit_frame) {
      36     2154967 :   if (save_doubles == kDontSaveFPRegs && argv_mode == kArgvOnStack) {
      37             :     DCHECK(result_size >= 1 && result_size <= 3);
      38     2154967 :     if (!builtin_exit_frame) {
      39             :       CachedNode key;
      40     2143296 :       if (result_size == 1) {
      41             :         key = kCEntryStub1Constant;
      42      791375 :       } else if (result_size == 2) {
      43             :         key = kCEntryStub2Constant;
      44             :       } else {
      45             :         DCHECK(result_size == 3);
      46             :         key = kCEntryStub3Constant;
      47             :       }
      48     4623582 :       return CACHED(
      49             :           key, HeapConstant(CEntryStub(isolate(), result_size, save_doubles,
      50             :                                        argv_mode, builtin_exit_frame)
      51             :                                 .GetCode()));
      52             :     }
      53             :     CachedNode key = builtin_exit_frame
      54             :                          ? kCEntryStub1WithBuiltinExitFrameConstant
      55       11671 :                          : kCEntryStub1Constant;
      56       26359 :     return CACHED(key,
      57             :                   HeapConstant(CEntryStub(isolate(), result_size, save_doubles,
      58             :                                           argv_mode, builtin_exit_frame)
      59             :                                    .GetCode()));
      60             :   }
      61             :   CEntryStub stub(isolate(), result_size, save_doubles, argv_mode,
      62             :                   builtin_exit_frame);
      63           0 :   return HeapConstant(stub.GetCode());
      64             : }
      65             : 
      66       42687 : Node* JSGraph::EmptyFixedArrayConstant() {
      67       54863 :   return CACHED(kEmptyFixedArrayConstant,
      68             :                 HeapConstant(factory()->empty_fixed_array()));
      69             : }
      70             : 
      71       79352 : Node* JSGraph::EmptyStringConstant() {
      72      109958 :   return CACHED(kEmptyStringConstant, HeapConstant(factory()->empty_string()));
      73             : }
      74             : 
      75         438 : Node* JSGraph::FixedArrayMapConstant() {
      76         818 :   return CACHED(kFixedArrayMapConstant,
      77             :                 HeapConstant(factory()->fixed_array_map()));
      78             : }
      79             : 
      80           0 : Node* JSGraph::FixedDoubleArrayMapConstant() {
      81           0 :   return CACHED(kFixedDoubleArrayMapConstant,
      82             :                 HeapConstant(factory()->fixed_double_array_map()));
      83             : }
      84             : 
      85      166336 : Node* JSGraph::HeapNumberMapConstant() {
      86      234136 :   return CACHED(kHeapNumberMapConstant,
      87             :                 HeapConstant(factory()->heap_number_map()));
      88             : }
      89             : 
      90        1936 : Node* JSGraph::OptimizedOutConstant() {
      91        2702 :   return CACHED(kOptimizedOutConstant,
      92             :                 HeapConstant(factory()->optimized_out()));
      93             : }
      94             : 
      95       30069 : Node* JSGraph::StaleRegisterConstant() {
      96       32292 :   return CACHED(kStaleRegisterConstant,
      97             :                 HeapConstant(factory()->stale_register()));
      98             : }
      99             : 
     100     1498894 : Node* JSGraph::UndefinedConstant() {
     101     1957132 :   return CACHED(kUndefinedConstant, HeapConstant(factory()->undefined_value()));
     102             : }
     103             : 
     104             : 
     105      335104 : Node* JSGraph::TheHoleConstant() {
     106      436152 :   return CACHED(kTheHoleConstant, HeapConstant(factory()->the_hole_value()));
     107             : }
     108             : 
     109             : 
     110     1125562 : Node* JSGraph::TrueConstant() {
     111     1520994 :   return CACHED(kTrueConstant, HeapConstant(factory()->true_value()));
     112             : }
     113             : 
     114             : 
     115     1085419 : Node* JSGraph::FalseConstant() {
     116     1480899 :   return CACHED(kFalseConstant, HeapConstant(factory()->false_value()));
     117             : }
     118             : 
     119             : 
     120       31749 : Node* JSGraph::NullConstant() {
     121       51136 :   return CACHED(kNullConstant, HeapConstant(factory()->null_value()));
     122             : }
     123             : 
     124             : 
     125     1130361 : Node* JSGraph::ZeroConstant() {
     126     1321214 :   return CACHED(kZeroConstant, NumberConstant(0.0));
     127             : }
     128             : 
     129      237537 : Node* JSGraph::OneConstant() {
     130      771644 :   return CACHED(kOneConstant, NumberConstant(1.0));
     131             : }
     132             : 
     133             : 
     134        2141 : Node* JSGraph::NaNConstant() {
     135        2141 :   return CACHED(kNaNConstant,
     136             :                 NumberConstant(std::numeric_limits<double>::quiet_NaN()));
     137             : }
     138             : 
     139             : 
     140    21018073 : Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
     141     8788207 :   Node** loc = cache_.FindHeapConstant(value);
     142     8788267 :   if (*loc == nullptr) {
     143    12229892 :     *loc = graph()->NewNode(common()->HeapConstant(value));
     144             :   }
     145     8788271 :   return *loc;
     146             : }
     147             : 
     148             : 
     149    11341792 : Node* JSGraph::Constant(Handle<Object> value) {
     150             :   // Dereference the handle to determine if a number constant or other
     151             :   // canonicalized node can be used.
     152     2053549 :   if (value->IsNumber()) {
     153      160963 :     return Constant(value->Number());
     154     1892586 :   } else if (value->IsUndefined(isolate())) {
     155       14803 :     return UndefinedConstant();
     156     1877783 :   } else if (value->IsTrue(isolate())) {
     157       14998 :     return TrueConstant();
     158     1862785 :   } else if (value->IsFalse(isolate())) {
     159       35064 :     return FalseConstant();
     160     1827721 :   } else if (value->IsNull(isolate())) {
     161         353 :     return NullConstant();
     162     1827368 :   } else if (value->IsTheHole(isolate())) {
     163           7 :     return TheHoleConstant();
     164             :   } else {
     165     1827361 :     return HeapConstant(Handle<HeapObject>::cast(value));
     166             :   }
     167             : }
     168             : 
     169             : 
     170      520096 : Node* JSGraph::Constant(double value) {
     171      578609 :   if (bit_cast<int64_t>(value) == bit_cast<int64_t>(0.0)) return ZeroConstant();
     172      472596 :   if (bit_cast<int64_t>(value) == bit_cast<int64_t>(1.0)) return OneConstant();
     173      450570 :   return NumberConstant(value);
     174             : }
     175             : 
     176             : 
     177     3876110 : Node* JSGraph::Constant(int32_t value) {
     178     4008229 :   if (value == 0) return ZeroConstant();
     179     4266969 :   if (value == 1) return OneConstant();
     180     3221013 :   return NumberConstant(value);
     181             : }
     182             : 
     183        3104 : Node* JSGraph::Constant(uint32_t value) {
     184        3325 :   if (value == 0) return ZeroConstant();
     185        2999 :   if (value == 1) return OneConstant();
     186        2767 :   return NumberConstant(value);
     187             : }
     188             : 
     189    16267729 : Node* JSGraph::Int32Constant(int32_t value) {
     190             :   Node** loc = cache_.FindInt32Constant(value);
     191     7568579 :   if (*loc == nullptr) {
     192     8699262 :     *loc = graph()->NewNode(common()->Int32Constant(value));
     193             :   }
     194     7568659 :   return *loc;
     195             : }
     196             : 
     197             : 
     198     8840778 : Node* JSGraph::Int64Constant(int64_t value) {
     199             :   Node** loc = cache_.FindInt64Constant(value);
     200     5450082 :   if (*loc == nullptr) {
     201     3390678 :     *loc = graph()->NewNode(common()->Int64Constant(value));
     202             :   }
     203     5450094 :   return *loc;
     204             : }
     205             : 
     206       35936 : Node* JSGraph::RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode) {
     207             :   Node** loc = cache_.FindRelocatableInt32Constant(
     208       15167 :       value, static_cast<RelocInfoMode>(rmode));
     209       15162 :   if (*loc == nullptr) {
     210       20770 :     *loc = graph()->NewNode(common()->RelocatableInt32Constant(value, rmode));
     211             :   }
     212       15164 :   return *loc;
     213             : }
     214             : 
     215       57883 : Node* JSGraph::RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode) {
     216             :   Node** loc = cache_.FindRelocatableInt64Constant(
     217       27713 :       value, static_cast<RelocInfoMode>(rmode));
     218       27712 :   if (*loc == nullptr) {
     219       30171 :     *loc = graph()->NewNode(common()->RelocatableInt64Constant(value, rmode));
     220             :   }
     221       27713 :   return *loc;
     222             : }
     223             : 
     224       27713 : Node* JSGraph::RelocatableIntPtrConstant(intptr_t value,
     225             :                                          RelocInfo::Mode rmode) {
     226             :   return kPointerSize == 8
     227             :              ? RelocatableInt64Constant(value, rmode)
     228       27713 :              : RelocatableInt32Constant(static_cast<int>(value), rmode);
     229             : }
     230             : 
     231    11979248 : Node* JSGraph::NumberConstant(double value) {
     232             :   Node** loc = cache_.FindNumberConstant(value);
     233     4537478 :   if (*loc == nullptr) {
     234     7441806 :     *loc = graph()->NewNode(common()->NumberConstant(value));
     235             :   }
     236     4537476 :   return *loc;
     237             : }
     238             : 
     239             : 
     240        6383 : Node* JSGraph::Float32Constant(float value) {
     241             :   Node** loc = cache_.FindFloat32Constant(value);
     242        2471 :   if (*loc == nullptr) {
     243        3912 :     *loc = graph()->NewNode(common()->Float32Constant(value));
     244             :   }
     245        2471 :   return *loc;
     246             : }
     247             : 
     248             : 
     249      910360 : Node* JSGraph::Float64Constant(double value) {
     250             :   Node** loc = cache_.FindFloat64Constant(value);
     251      451939 :   if (*loc == nullptr) {
     252      458422 :     *loc = graph()->NewNode(common()->Float64Constant(value));
     253             :   }
     254      451939 :   return *loc;
     255             : }
     256             : 
     257       16597 : Node* JSGraph::PointerConstant(intptr_t value) {
     258             :   Node** loc = cache_.FindPointerConstant(value);
     259       13801 :   if (*loc == nullptr) {
     260        2796 :     *loc = graph()->NewNode(common()->PointerConstant(value));
     261             :   }
     262       13801 :   return *loc;
     263             : }
     264             : 
     265     4316609 : Node* JSGraph::ExternalConstant(ExternalReference reference) {
     266     1810051 :   Node** loc = cache_.FindExternalConstant(reference);
     267     1810058 :   if (*loc == nullptr) {
     268     2506562 :     *loc = graph()->NewNode(common()->ExternalConstant(reference));
     269             :   }
     270     1810070 :   return *loc;
     271             : }
     272             : 
     273             : 
     274           0 : Node* JSGraph::ExternalConstant(Runtime::FunctionId function_id) {
     275           0 :   return ExternalConstant(ExternalReference(function_id, isolate()));
     276             : }
     277             : 
     278       14541 : Node* JSGraph::EmptyStateValues() {
     279       14541 :   return CACHED(kEmptyStateValues, graph()->NewNode(common()->StateValues(
     280             :                                        0, SparseInputMask::Dense())));
     281             : }
     282             : 
     283    10528653 : Node* JSGraph::Dead() {
     284    10528651 :   return CACHED(kDead, graph()->NewNode(common()->Dead()));
     285             : }
     286             : 
     287             : 
     288     2844161 : void JSGraph::GetCachedNodes(NodeVector* nodes) {
     289     2844161 :   cache_.GetCachedNodes(nodes);
     290    71102860 :   for (size_t i = 0; i < arraysize(cached_nodes_); i++) {
     291    68258704 :     if (Node* node = cached_nodes_[i]) {
     292    21052112 :       if (!node->IsDead()) nodes->push_back(node);
     293             :     }
     294             :   }
     295     2844156 : }
     296             : 
     297             : }  // namespace compiler
     298             : }  // namespace internal
     299             : }  // namespace v8

Generated by: LCOV version 1.10