blob: b75bacb6ea761cdf43318bc4164478f446550a6b [file] [log] [blame]
Nicolas Geoffray724c9632014-09-22 12:27:27 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "nodes.h"
18#include "utils/arena_allocator.h"
19
20#include "gtest/gtest.h"
21
22namespace art {
23
24/**
25 * Test that removing instruction from the graph removes itself from user lists
26 * and environment lists.
27 */
28TEST(Node, RemoveInstruction) {
29 ArenaPool pool;
30 ArenaAllocator allocator(&pool);
31
32 HGraph* graph = new (&allocator) HGraph(&allocator);
33 HBasicBlock* entry = new (&allocator) HBasicBlock(graph);
34 graph->AddBlock(entry);
35 graph->SetEntryBlock(entry);
36 HInstruction* parameter = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
37 entry->AddInstruction(parameter);
38 entry->AddInstruction(new (&allocator) HGoto());
39
40 HBasicBlock* first_block = new (&allocator) HBasicBlock(graph);
41 graph->AddBlock(first_block);
42 entry->AddSuccessor(first_block);
43 HInstruction* null_check = new (&allocator) HNullCheck(parameter, 0);
44 first_block->AddInstruction(null_check);
45 first_block->AddInstruction(new (&allocator) HReturnVoid());
46
47 HBasicBlock* exit_block = new (&allocator) HBasicBlock(graph);
48 graph->AddBlock(exit_block);
49 first_block->AddSuccessor(exit_block);
50 exit_block->AddInstruction(new (&allocator) HExit());
51
52 HEnvironment* environment = new (&allocator) HEnvironment(&allocator, 1);
53 null_check->SetEnvironment(environment);
54 environment->SetRawEnvAt(0, parameter);
55 parameter->AddEnvUseAt(null_check->GetEnvironment(), 0);
56
57 ASSERT_TRUE(parameter->HasEnvironmentUses());
58 ASSERT_TRUE(parameter->HasUses());
59
60 first_block->RemoveInstruction(null_check);
61
62 ASSERT_FALSE(parameter->HasEnvironmentUses());
63 ASSERT_FALSE(parameter->HasUses());
64}
65
66} // namespace art