LCOV - code coverage report
Current view: top level - src/interpreter - control-flow-builders.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 99 104 95.2 %
Date: 2019-04-17 Functions: 28 36 77.8 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/interpreter/control-flow-builders.h"
       6             : #include "src/objects-inl.h"
       7             : 
       8             : namespace v8 {
       9             : namespace internal {
      10             : namespace interpreter {
      11             : 
      12             : 
      13    11116843 : BreakableControlFlowBuilder::~BreakableControlFlowBuilder() {
      14             :   BindBreakTarget();
      15             :   DCHECK(break_labels_.empty() || break_labels_.is_bound());
      16     5558407 :   if (block_coverage_builder_ != nullptr) {
      17             :     block_coverage_builder_->IncrementBlockCounter(
      18        1532 :         node_, SourceRangeKind::kContinuation);
      19             :   }
      20     5558444 : }
      21             : 
      22           0 : void BreakableControlFlowBuilder::BindBreakTarget() {
      23     5558399 :   break_labels_.Bind(builder());
      24           0 : }
      25             : 
      26       52992 : void BreakableControlFlowBuilder::EmitJump(BytecodeLabels* sites) {
      27       52992 :   builder()->Jump(sites->New());
      28       52992 : }
      29             : 
      30       38412 : void BreakableControlFlowBuilder::EmitJumpIfTrue(
      31             :     BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
      32       38412 :   builder()->JumpIfTrue(mode, sites->New());
      33       38417 : }
      34             : 
      35        4753 : void BreakableControlFlowBuilder::EmitJumpIfFalse(
      36             :     BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
      37        4753 :   builder()->JumpIfFalse(mode, sites->New());
      38        4753 : }
      39             : 
      40        4753 : void BreakableControlFlowBuilder::EmitJumpIfUndefined(BytecodeLabels* sites) {
      41        4753 :   builder()->JumpIfUndefined(sites->New());
      42        4753 : }
      43             : 
      44           0 : void BreakableControlFlowBuilder::EmitJumpIfNull(BytecodeLabels* sites) {
      45           0 :   builder()->JumpIfNull(sites->New());
      46           0 : }
      47             : 
      48      558664 : LoopBuilder::~LoopBuilder() {
      49             :   DCHECK(continue_labels_.empty() || continue_labels_.is_bound());
      50      279337 : }
      51             : 
      52      263397 : void LoopBuilder::LoopHeader() {
      53             :   // Jumps from before the loop header into the loop violate ordering
      54             :   // requirements of bytecode basic blocks. The only entry into a loop
      55             :   // must be the loop header. Surely breaks is okay? Not if nested
      56             :   // and misplaced between the headers.
      57             :   DCHECK(break_labels_.empty() && continue_labels_.empty());
      58      263397 :   builder()->Bind(&loop_header_);
      59      263406 : }
      60             : 
      61      263548 : void LoopBuilder::LoopBody() {
      62      263548 :   if (block_coverage_builder_ != nullptr) {
      63         228 :     block_coverage_builder_->IncrementBlockCounter(block_coverage_body_slot_);
      64             :   }
      65      263548 : }
      66             : 
      67      263408 : void LoopBuilder::JumpToHeader(int loop_depth) {
      68             :   // Pass the proper loop nesting level to the backwards branch, to trigger
      69             :   // on-stack replacement when armed for the given loop nesting depth.
      70             :   int level = Min(loop_depth, AbstractCode::kMaxLoopNestingMarker - 1);
      71             :   // Loop must have closed form, i.e. all loop elements are within the loop,
      72             :   // the loop header precedes the body and next elements in the loop.
      73      263408 :   builder()->JumpLoop(&loop_header_, level);
      74      263411 : }
      75             : 
      76      263754 : void LoopBuilder::BindContinueTarget() { continue_labels_.Bind(builder()); }
      77             : 
      78       21318 : SwitchBuilder::~SwitchBuilder() {
      79             : #ifdef DEBUG
      80             :   for (auto site : case_sites_) {
      81             :     DCHECK(!site.has_referrer_jump() || site.is_bound());
      82             :   }
      83             : #endif
      84       10659 : }
      85             : 
      86       80554 : void SwitchBuilder::SetCaseTarget(int index, CaseClause* clause) {
      87       80554 :   BytecodeLabel& site = case_sites_.at(index);
      88       80554 :   builder()->Bind(&site);
      89       80554 :   if (block_coverage_builder_) {
      90             :     block_coverage_builder_->IncrementBlockCounter(clause,
      91          24 :                                                    SourceRangeKind::kBody);
      92             :   }
      93       80554 : }
      94             : 
      95      227688 : TryCatchBuilder::~TryCatchBuilder() {
      96      113844 :   if (block_coverage_builder_ != nullptr) {
      97             :     block_coverage_builder_->IncrementBlockCounter(
      98          68 :         statement_, SourceRangeKind::kContinuation);
      99             :   }
     100      113844 : }
     101             : 
     102      113848 : void TryCatchBuilder::BeginTry(Register context) {
     103      113848 :   builder()->MarkTryBegin(handler_id_, context);
     104      113853 : }
     105             : 
     106             : 
     107      113851 : void TryCatchBuilder::EndTry() {
     108      113851 :   builder()->MarkTryEnd(handler_id_);
     109      113852 :   builder()->Jump(&exit_);
     110      113856 :   builder()->MarkHandler(handler_id_, catch_prediction_);
     111             : 
     112      113853 :   if (block_coverage_builder_ != nullptr) {
     113          68 :     block_coverage_builder_->IncrementBlockCounter(statement_,
     114          68 :                                                    SourceRangeKind::kCatch);
     115             :   }
     116      113853 : }
     117             : 
     118      113853 : void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); }
     119             : 
     120       84504 : TryFinallyBuilder::~TryFinallyBuilder() {
     121       42252 :   if (block_coverage_builder_ != nullptr) {
     122             :     block_coverage_builder_->IncrementBlockCounter(
     123          28 :         statement_, SourceRangeKind::kContinuation);
     124             :   }
     125       42252 : }
     126             : 
     127       42252 : void TryFinallyBuilder::BeginTry(Register context) {
     128       42252 :   builder()->MarkTryBegin(handler_id_, context);
     129       42256 : }
     130             : 
     131             : 
     132       53385 : void TryFinallyBuilder::LeaveTry() {
     133       53385 :   builder()->Jump(finalization_sites_.New());
     134       53388 : }
     135             : 
     136             : 
     137       42256 : void TryFinallyBuilder::EndTry() {
     138       42256 :   builder()->MarkTryEnd(handler_id_);
     139       42255 : }
     140             : 
     141             : 
     142       42257 : void TryFinallyBuilder::BeginHandler() {
     143       42257 :   builder()->Bind(&handler_);
     144       42257 :   builder()->MarkHandler(handler_id_, catch_prediction_);
     145       42256 : }
     146             : 
     147       42254 : void TryFinallyBuilder::BeginFinally() {
     148       42254 :   finalization_sites_.Bind(builder());
     149             : 
     150       42257 :   if (block_coverage_builder_ != nullptr) {
     151          28 :     block_coverage_builder_->IncrementBlockCounter(statement_,
     152          28 :                                                    SourceRangeKind::kFinally);
     153             :   }
     154       42257 : }
     155             : 
     156       42256 : void TryFinallyBuilder::EndFinally() {
     157             :   // Nothing to be done here.
     158       42256 : }
     159             : 
     160     1231650 : ConditionalControlFlowBuilder::~ConditionalControlFlowBuilder() {
     161      615820 :   if (!else_labels_.is_bound()) else_labels_.Bind(builder());
     162      615826 :   end_labels_.Bind(builder());
     163             : 
     164             :   DCHECK(end_labels_.empty() || end_labels_.is_bound());
     165             :   DCHECK(then_labels_.empty() || then_labels_.is_bound());
     166             :   DCHECK(else_labels_.empty() || else_labels_.is_bound());
     167             : 
     168             :   // IfStatement requires a continuation counter, Conditional does not (as it
     169             :   // can only contain expressions).
     170      616354 :   if (block_coverage_builder_ != nullptr && node_->IsIfStatement()) {
     171             :     block_coverage_builder_->IncrementBlockCounter(
     172         444 :         node_, SourceRangeKind::kContinuation);
     173             :   }
     174      615830 : }
     175             : 
     176       73002 : void ConditionalControlFlowBuilder::JumpToEnd() {
     177             :   DCHECK(end_labels_.empty());  // May only be called once.
     178       73002 :   builder()->Jump(end_labels_.New());
     179       73004 : }
     180             : 
     181      607405 : void ConditionalControlFlowBuilder::Then() {
     182      607405 :   then_labels()->Bind(builder());
     183      607408 :   if (block_coverage_builder_ != nullptr) {
     184         504 :     block_coverage_builder_->IncrementBlockCounter(block_coverage_then_slot_);
     185             :   }
     186      607408 : }
     187             : 
     188       80162 : void ConditionalControlFlowBuilder::Else() {
     189       80162 :   else_labels()->Bind(builder());
     190       80161 :   if (block_coverage_builder_ != nullptr) {
     191         124 :     block_coverage_builder_->IncrementBlockCounter(block_coverage_else_slot_);
     192             :   }
     193       80161 : }
     194             : 
     195             : }  // namespace interpreter
     196             : }  // namespace internal
     197      122004 : }  // namespace v8

Generated by: LCOV version 1.10