blob: 15cd4e8a08d20f7f95333047d72677aa02a87108 [file] [log] [blame]
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001/*
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 "builder.h"
18#include "dex_instruction.h"
19#include "nodes.h"
20#include "optimizing_unit_test.h"
David Brazdilbadd8262016-02-02 16:28:56 +000021#include "pretty_printer.h"
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000022
23#include "gtest/gtest.h"
24
25namespace art {
26
27/**
28 * Check that the HGraphBuilder adds suspend checks to backward branches.
29 */
30
31static void TestCode(const uint16_t* data) {
32 ArenaPool pool;
33 ArenaAllocator allocator(&pool);
David Brazdilbadd8262016-02-02 16:28:56 +000034 HGraph* graph = CreateCFG(&allocator, data);
35 HBasicBlock* first_block = graph->GetEntryBlock()->GetSingleSuccessor();
36 HBasicBlock* loop_header = first_block->GetSingleSuccessor();
37 ASSERT_TRUE(loop_header->IsLoopHeader());
38 ASSERT_EQ(loop_header->GetLoopInformation()->GetPreHeader(), first_block);
39 ASSERT_TRUE(loop_header->GetFirstInstruction()->IsSuspendCheck());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000040}
41
David Brazdilbadd8262016-02-02 16:28:56 +000042class SuspendCheckTest : public CommonCompilerTest {};
43
44TEST_F(SuspendCheckTest, CFG1) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000045 const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
46 Instruction::NOP,
47 Instruction::GOTO | 0xFF00);
48
49 TestCode(data);
50}
51
David Brazdilbadd8262016-02-02 16:28:56 +000052TEST_F(SuspendCheckTest, CFG2) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000053 const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
54 Instruction::GOTO_32, 0, 0);
55
56 TestCode(data);
57}
58
David Brazdilbadd8262016-02-02 16:28:56 +000059TEST_F(SuspendCheckTest, CFG3) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000060 const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
61 Instruction::CONST_4 | 0 | 0,
62 Instruction::IF_EQ, 0xFFFF,
63 Instruction::RETURN_VOID);
64
65 TestCode(data);
66}
67
David Brazdilbadd8262016-02-02 16:28:56 +000068TEST_F(SuspendCheckTest, CFG4) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000069 const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
70 Instruction::CONST_4 | 0 | 0,
71 Instruction::IF_NE, 0xFFFF,
72 Instruction::RETURN_VOID);
73
74 TestCode(data);
75}
76
David Brazdilbadd8262016-02-02 16:28:56 +000077TEST_F(SuspendCheckTest, CFG5) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000078 const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
79 Instruction::CONST_4 | 0 | 0,
80 Instruction::IF_EQZ, 0xFFFF,
81 Instruction::RETURN_VOID);
82
83 TestCode(data);
84}
85
David Brazdilbadd8262016-02-02 16:28:56 +000086TEST_F(SuspendCheckTest, CFG6) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000087 const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
88 Instruction::CONST_4 | 0 | 0,
89 Instruction::IF_NEZ, 0xFFFF,
90 Instruction::RETURN_VOID);
91
92 TestCode(data);
93}
94} // namespace art