blob: a201fc9a5591db3755068769706c76dfd7133a39 [file] [log] [blame]
Ben Murdoch61f157c2016-09-16 13:49:30 +01001// Copyright 2016 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/checkpoint-elimination.h"
6#include "src/compiler/common-operator.h"
7#include "src/compiler/operator.h"
8#include "test/unittests/compiler/graph-reducer-unittest.h"
9#include "test/unittests/compiler/graph-unittest.h"
10#include "test/unittests/compiler/node-test-utils.h"
11
12using testing::StrictMock;
13
14namespace v8 {
15namespace internal {
16namespace compiler {
17
18class CheckpointEliminationTest : public GraphTest {
19 public:
20 CheckpointEliminationTest() : GraphTest() {}
21 ~CheckpointEliminationTest() override {}
22
23 protected:
24 Reduction Reduce(AdvancedReducer::Editor* editor, Node* node) {
25 CheckpointElimination reducer(editor);
26 return reducer.Reduce(node);
27 }
28
29 Reduction Reduce(Node* node) {
30 StrictMock<MockAdvancedReducerEditor> editor;
31 return Reduce(&editor, node);
32 }
33};
34
35namespace {
36
37const Operator kOpNoWrite(0, Operator::kNoWrite, "OpNoWrite", 0, 1, 0, 0, 1, 0);
38
39} // namespace
40
41// -----------------------------------------------------------------------------
42// Checkpoint
43
44TEST_F(CheckpointEliminationTest, CheckpointChain) {
45 Node* const control = graph()->start();
46 Node* frame_state = EmptyFrameState();
47 Node* checkpoint1 = graph()->NewNode(common()->Checkpoint(), frame_state,
48 graph()->start(), control);
49 Node* effect_link = graph()->NewNode(&kOpNoWrite, checkpoint1);
50 Node* checkpoint2 = graph()->NewNode(common()->Checkpoint(), frame_state,
51 effect_link, control);
52 Reduction r = Reduce(checkpoint2);
53 ASSERT_TRUE(r.Changed());
54 EXPECT_EQ(effect_link, r.replacement());
55}
56
57} // namespace compiler
58} // namespace internal
59} // namespace v8