1fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray/* 2fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * 4fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * you may not use this file except in compliance with the License. 6fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * You may obtain a copy of the License at 7fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * 8fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * 10fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * See the License for the specific language governing permissions and 14fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * limitations under the License. 15fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray */ 16fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 17fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray#include "builder.h" 189e734c7ab4599d7747a05db0dc73c7b668cb6683David Sehr#include "dex/dex_instruction.h" 19fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray#include "nodes.h" 20fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray#include "optimizing_unit_test.h" 21badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil#include "pretty_printer.h" 22fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 23fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray#include "gtest/gtest.h" 24fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 25fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffraynamespace art { 26fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 27fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray/** 28fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray * Check that the HGraphBuilder adds suspend checks to backward branches. 29fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray */ 30fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 31ca6fff898afcb62491458ae8bcd428bfb3043da1Vladimir Markoclass SuspendCheckTest : public OptimizingUnitTest { 32ca6fff898afcb62491458ae8bcd428bfb3043da1Vladimir Marko protected: 33fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier void TestCode(const std::vector<uint16_t>& data); 34ca6fff898afcb62491458ae8bcd428bfb3043da1Vladimir Marko}; 35ca6fff898afcb62491458ae8bcd428bfb3043da1Vladimir Marko 36fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartiervoid SuspendCheckTest::TestCode(const std::vector<uint16_t>& data) { 37ca6fff898afcb62491458ae8bcd428bfb3043da1Vladimir Marko HGraph* graph = CreateCFG(data); 38badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil HBasicBlock* first_block = graph->GetEntryBlock()->GetSingleSuccessor(); 39badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil HBasicBlock* loop_header = first_block->GetSingleSuccessor(); 40badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil ASSERT_TRUE(loop_header->IsLoopHeader()); 41badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil ASSERT_EQ(loop_header->GetLoopInformation()->GetPreHeader(), first_block); 42badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil ASSERT_TRUE(loop_header->GetFirstInstruction()->IsSuspendCheck()); 43fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 44fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 45badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG1) { 46fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( 47fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::NOP, 48fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::GOTO | 0xFF00); 49fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 50fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 51fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 52fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 53badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG2) { 54fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( 55fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::GOTO_32, 0, 0); 56fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 57fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 58fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 59fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 60badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG3) { 61fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( 62fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::CONST_4 | 0 | 0, 63fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::IF_EQ, 0xFFFF, 64fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::RETURN_VOID); 65fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 66fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 67fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 68fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 69badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG4) { 70fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( 71fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::CONST_4 | 0 | 0, 72fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::IF_NE, 0xFFFF, 73fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::RETURN_VOID); 74fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 75fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 76fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 77fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 78badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG5) { 79fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( 80fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::CONST_4 | 0 | 0, 81fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::IF_EQZ, 0xFFFF, 82fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::RETURN_VOID); 83fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 84fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 85fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 86fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 87badd826664896d4a9628a5a89b78016894aa414bDavid BrazdilTEST_F(SuspendCheckTest, CFG6) { 88fa3db3d377bfaceb51c9a97864b17ce02538b7e0Mathieu Chartier const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( 89fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::CONST_4 | 0 | 0, 90fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::IF_NEZ, 0xFFFF, 91fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray Instruction::RETURN_VOID); 92fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray 93fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray TestCode(data); 94fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} 95fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray} // namespace art 96