LCOV - code coverage report
Current view: top level - src/compiler - diamond.h (source / functions) Hit Total Coverage
Test: app.info Lines: 21 21 100.0 %
Date: 2019-04-17 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2013 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             : #ifndef V8_COMPILER_DIAMOND_H_
       6             : #define V8_COMPILER_DIAMOND_H_
       7             : 
       8             : #include "src/compiler/common-operator.h"
       9             : #include "src/compiler/graph.h"
      10             : #include "src/compiler/node.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : namespace compiler {
      15             : 
      16             : // A helper to make it easier to build diamond-shaped control patterns.
      17             : struct Diamond {
      18             :   Graph* graph;
      19             :   CommonOperatorBuilder* common;
      20             :   Node* branch;
      21             :   Node* if_true;
      22             :   Node* if_false;
      23             :   Node* merge;
      24             : 
      25      432978 :   Diamond(Graph* g, CommonOperatorBuilder* b, Node* cond,
      26             :           BranchHint hint = BranchHint::kNone) {
      27      432978 :     graph = g;
      28      432978 :     common = b;
      29      866122 :     branch = graph->NewNode(common->Branch(hint), cond, graph->start());
      30      866364 :     if_true = graph->NewNode(common->IfTrue(), branch);
      31      866482 :     if_false = graph->NewNode(common->IfFalse(), branch);
      32      866405 :     merge = graph->NewNode(common->Merge(2), if_true, if_false);
      33      433143 :   }
      34             : 
      35             :   // Place {this} after {that} in control flow order.
      36           5 :   void Chain(Diamond& that) { branch->ReplaceInput(1, that.merge); }
      37             : 
      38             :   // Place {this} after {that} in control flow order.
      39      325356 :   void Chain(Node* that) { branch->ReplaceInput(1, that); }
      40             : 
      41             :   // Nest {this} into either the if_true or if_false branch of {that}.
      42       83373 :   void Nest(Diamond& that, bool if_true) {
      43       83373 :     if (if_true) {
      44       83308 :       branch->ReplaceInput(1, that.if_true);
      45       83308 :       that.merge->ReplaceInput(0, merge);
      46             :     } else {
      47          65 :       branch->ReplaceInput(1, that.if_false);
      48          65 :       that.merge->ReplaceInput(1, merge);
      49             :     }
      50       83373 :   }
      51             : 
      52      244302 :   Node* Phi(MachineRepresentation rep, Node* tv, Node* fv) {
      53      488605 :     return graph->NewNode(common->Phi(rep, 2), tv, fv, merge);
      54             :   }
      55             : 
      56      393256 :   Node* EffectPhi(Node* tv, Node* fv) {
      57      786472 :     return graph->NewNode(common->EffectPhi(2), tv, fv, merge);
      58             :   }
      59             : };
      60             : 
      61             : }  // namespace compiler
      62             : }  // namespace internal
      63             : }  // namespace v8
      64             : 
      65             : #endif  // V8_COMPILER_DIAMOND_H_

Generated by: LCOV version 1.10