Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1 | /* |
| 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 Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 21 | #include "pretty_printer.h" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 22 | |
| 23 | #include "gtest/gtest.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | /** |
| 28 | * Check that the HGraphBuilder adds suspend checks to backward branches. |
| 29 | */ |
| 30 | |
| 31 | static void TestCode(const uint16_t* data) { |
| 32 | ArenaPool pool; |
| 33 | ArenaAllocator allocator(&pool); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 34 | 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 Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 40 | } |
| 41 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 42 | class SuspendCheckTest : public CommonCompilerTest {}; |
| 43 | |
| 44 | TEST_F(SuspendCheckTest, CFG1) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 45 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
| 46 | Instruction::NOP, |
| 47 | Instruction::GOTO | 0xFF00); |
| 48 | |
| 49 | TestCode(data); |
| 50 | } |
| 51 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 52 | TEST_F(SuspendCheckTest, CFG2) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 53 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
| 54 | Instruction::GOTO_32, 0, 0); |
| 55 | |
| 56 | TestCode(data); |
| 57 | } |
| 58 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 59 | TEST_F(SuspendCheckTest, CFG3) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 60 | 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 Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 68 | TEST_F(SuspendCheckTest, CFG4) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 69 | 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 Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 77 | TEST_F(SuspendCheckTest, CFG5) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 78 | 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 Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 86 | TEST_F(SuspendCheckTest, CFG6) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 87 | 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 |