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" |
| 21 | |
| 22 | #include "gtest/gtest.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | /** |
| 27 | * Check that the HGraphBuilder adds suspend checks to backward branches. |
| 28 | */ |
| 29 | |
| 30 | static void TestCode(const uint16_t* data) { |
| 31 | ArenaPool pool; |
| 32 | ArenaAllocator allocator(&pool); |
| 33 | HGraphBuilder builder(&allocator); |
| 34 | const DexFile::CodeItem* item = reinterpret_cast<const DexFile::CodeItem*>(data); |
| 35 | HGraph* graph = builder.BuildGraph(*item); |
| 36 | ASSERT_NE(graph, nullptr); |
| 37 | |
| 38 | HBasicBlock* first_block = graph->GetEntryBlock()->GetSuccessors().Get(0); |
| 39 | HInstruction* first_instruction = first_block->GetFirstInstruction(); |
| 40 | // Account for some tests having a store local as first instruction. |
| 41 | ASSERT_TRUE(first_instruction->IsSuspendCheck() |
| 42 | || first_instruction->GetNext()->IsSuspendCheck()); |
| 43 | } |
| 44 | |
| 45 | TEST(CodegenTest, CFG1) { |
| 46 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
| 47 | Instruction::NOP, |
| 48 | Instruction::GOTO | 0xFF00); |
| 49 | |
| 50 | TestCode(data); |
| 51 | } |
| 52 | |
| 53 | TEST(CodegenTest, CFG2) { |
| 54 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
| 55 | Instruction::GOTO_32, 0, 0); |
| 56 | |
| 57 | TestCode(data); |
| 58 | } |
| 59 | |
| 60 | TEST(CodegenTest, CFG3) { |
| 61 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 62 | Instruction::CONST_4 | 0 | 0, |
| 63 | Instruction::IF_EQ, 0xFFFF, |
| 64 | Instruction::RETURN_VOID); |
| 65 | |
| 66 | TestCode(data); |
| 67 | } |
| 68 | |
| 69 | TEST(CodegenTest, CFG4) { |
| 70 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 71 | Instruction::CONST_4 | 0 | 0, |
| 72 | Instruction::IF_NE, 0xFFFF, |
| 73 | Instruction::RETURN_VOID); |
| 74 | |
| 75 | TestCode(data); |
| 76 | } |
| 77 | |
| 78 | TEST(CodegenTest, CFG5) { |
| 79 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 80 | Instruction::CONST_4 | 0 | 0, |
| 81 | Instruction::IF_EQZ, 0xFFFF, |
| 82 | Instruction::RETURN_VOID); |
| 83 | |
| 84 | TestCode(data); |
| 85 | } |
| 86 | |
| 87 | TEST(CodegenTest, CFG6) { |
| 88 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 89 | Instruction::CONST_4 | 0 | 0, |
| 90 | Instruction::IF_NEZ, 0xFFFF, |
| 91 | Instruction::RETURN_VOID); |
| 92 | |
| 93 | TestCode(data); |
| 94 | } |
| 95 | } // namespace art |