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