LCOV - code coverage report
Current view: top level - test/unittests/compiler - graph-trimmer-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 43 43 100.0 %
Date: 2019-03-21 Functions: 12 16 75.0 %

          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/compiler/graph-trimmer.h"
       6             : #include "test/unittests/compiler/graph-unittest.h"
       7             : #include "testing/gmock-support.h"
       8             : 
       9             : using testing::ElementsAre;
      10             : using testing::UnorderedElementsAre;
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : namespace compiler {
      15             : 
      16           4 : class GraphTrimmerTest : public GraphTest {
      17             :  public:
      18           4 :   GraphTrimmerTest() : GraphTest(1) {}
      19             : 
      20             :  protected:
      21           1 :   void TrimGraph(Node* root) {
      22           1 :     Node* const roots[1] = {root};
      23           2 :     GraphTrimmer trimmer(zone(), graph());
      24           1 :     trimmer.TrimGraph(&roots[0], &roots[arraysize(roots)]);
      25           1 :   }
      26           3 :   void TrimGraph() {
      27           6 :     GraphTrimmer trimmer(zone(), graph());
      28           3 :     trimmer.TrimGraph();
      29           3 :   }
      30             : };
      31             : 
      32             : 
      33             : namespace {
      34             : 
      35        6148 : const Operator kDead0(IrOpcode::kDead, Operator::kNoProperties, "Dead0", 0, 0,
      36        3074 :                       1, 0, 0, 0);
      37        6148 : const Operator kLive0(IrOpcode::kDead, Operator::kNoProperties, "Live0", 0, 0,
      38        3074 :                       1, 0, 0, 1);
      39             : 
      40             : }  // namespace
      41             : 
      42             : 
      43       15374 : TEST_F(GraphTrimmerTest, Empty) {
      44           2 :   Node* const start = graph()->NewNode(common()->Start(0));
      45           2 :   Node* const end = graph()->NewNode(common()->End(1), start);
      46           1 :   graph()->SetStart(start);
      47             :   graph()->SetEnd(end);
      48           1 :   TrimGraph();
      49           2 :   EXPECT_EQ(end, graph()->end());
      50           2 :   EXPECT_EQ(start, graph()->start());
      51           3 :   EXPECT_EQ(start, end->InputAt(0));
      52           1 : }
      53             : 
      54             : 
      55       15374 : TEST_F(GraphTrimmerTest, DeadUseOfStart) {
      56             :   Node* const dead0 = graph()->NewNode(&kDead0, graph()->start());
      57           1 :   graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start()));
      58           1 :   TrimGraph();
      59           2 :   EXPECT_THAT(dead0->inputs(), ElementsAre(nullptr));
      60           2 :   EXPECT_THAT(graph()->start()->uses(), ElementsAre(graph()->end()));
      61           1 : }
      62             : 
      63             : 
      64       15374 : TEST_F(GraphTrimmerTest, DeadAndLiveUsesOfStart) {
      65             :   Node* const dead0 = graph()->NewNode(&kDead0, graph()->start());
      66             :   Node* const live0 = graph()->NewNode(&kLive0, graph()->start());
      67           1 :   graph()->SetEnd(graph()->NewNode(common()->End(1), live0));
      68           1 :   TrimGraph();
      69           2 :   EXPECT_THAT(dead0->inputs(), ElementsAre(nullptr));
      70           2 :   EXPECT_THAT(graph()->start()->uses(), ElementsAre(live0));
      71           2 :   EXPECT_THAT(live0->uses(), ElementsAre(graph()->end()));
      72           1 : }
      73             : 
      74             : 
      75       15374 : TEST_F(GraphTrimmerTest, Roots) {
      76             :   Node* const live0 = graph()->NewNode(&kLive0, graph()->start());
      77             :   Node* const live1 = graph()->NewNode(&kLive0, graph()->start());
      78           1 :   graph()->SetEnd(graph()->NewNode(common()->End(1), live0));
      79           1 :   TrimGraph(live1);
      80           2 :   EXPECT_THAT(graph()->start()->uses(), UnorderedElementsAre(live0, live1));
      81           1 : }
      82             : 
      83             : }  // namespace compiler
      84             : }  // namespace internal
      85        9222 : }  // namespace v8

Generated by: LCOV version 1.10