Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +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 | |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 17 | #include "base/arena_allocator.h" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 18 | #include "builder.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 19 | #include "dex/dex_instruction.h" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 20 | #include "nodes.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 21 | #include "optimizing_unit_test.h" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 22 | |
| 23 | #include "gtest/gtest.h" |
| 24 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 25 | namespace art { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 26 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 27 | class OptimizerTest : public OptimizingUnitTest { |
| 28 | protected: |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 29 | void TestCode(const std::vector<uint16_t>& data, const uint32_t* blocks, size_t blocks_length); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 30 | }; |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 31 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 32 | void OptimizerTest::TestCode(const std::vector<uint16_t>& data, |
| 33 | const uint32_t* blocks, |
| 34 | size_t blocks_length) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 35 | HGraph* graph = CreateCFG(data); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 36 | ASSERT_EQ(graph->GetBlocks().size(), blocks_length); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 37 | for (size_t i = 0, e = blocks_length; i < e; ++i) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 38 | if (blocks[i] == kInvalidBlockId) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 39 | if (graph->GetBlocks()[i] == nullptr) { |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 40 | // Dead block. |
| 41 | } else { |
| 42 | // Only the entry block has no dominator. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 43 | ASSERT_EQ(nullptr, graph->GetBlocks()[i]->GetDominator()); |
| 44 | ASSERT_TRUE(graph->GetBlocks()[i]->IsEntryBlock()); |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 45 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 46 | } else { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 47 | ASSERT_NE(nullptr, graph->GetBlocks()[i]->GetDominator()); |
| 48 | ASSERT_EQ(blocks[i], graph->GetBlocks()[i]->GetDominator()->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 53 | TEST_F(OptimizerTest, ReturnVoid) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 54 | const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 55 | Instruction::RETURN_VOID); // Block number 1 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 56 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 57 | const uint32_t dominators[] = { |
| 58 | kInvalidBlockId, |
| 59 | 0, |
| 60 | 1 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 63 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 64 | } |
| 65 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 66 | TEST_F(OptimizerTest, CFG1) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 67 | const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 68 | Instruction::GOTO | 0x100, // Block number 1 |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 69 | Instruction::RETURN_VOID); // Block number 2 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 70 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 71 | const uint32_t dominators[] = { |
| 72 | kInvalidBlockId, |
| 73 | 0, |
| 74 | 1, |
| 75 | 2 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 78 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 79 | } |
| 80 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 81 | TEST_F(OptimizerTest, CFG2) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 82 | const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 83 | Instruction::GOTO | 0x100, // Block number 1 |
| 84 | Instruction::GOTO | 0x100, // Block number 2 |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 85 | Instruction::RETURN_VOID); // Block number 3 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 86 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 87 | const uint32_t dominators[] = { |
| 88 | kInvalidBlockId, |
| 89 | 0, |
| 90 | 1, |
| 91 | 2, |
| 92 | 3 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 95 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 96 | } |
| 97 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 98 | TEST_F(OptimizerTest, CFG3) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 99 | const std::vector<uint16_t> data1 = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 100 | Instruction::GOTO | 0x200, // Block number 1 |
| 101 | Instruction::RETURN_VOID, // Block number 2 |
| 102 | Instruction::GOTO | 0xFF00); // Block number 3 |
| 103 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 104 | const uint32_t dominators[] = { |
| 105 | kInvalidBlockId, |
| 106 | 0, |
| 107 | 3, |
| 108 | 1, |
| 109 | 2 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 112 | TestCode(data1, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 113 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 114 | const std::vector<uint16_t> data2 = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 115 | Instruction::GOTO_16, 3, |
| 116 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 117 | Instruction::GOTO_16, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 118 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 119 | TestCode(data2, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 120 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 121 | const std::vector<uint16_t> data3 = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 122 | Instruction::GOTO_32, 4, 0, |
| 123 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 124 | Instruction::GOTO_32, 0xFFFF, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 125 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 126 | TestCode(data3, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 127 | } |
| 128 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 129 | TEST_F(OptimizerTest, CFG4) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 130 | const std::vector<uint16_t> data1 = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 131 | Instruction::NOP, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 132 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 133 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 134 | const uint32_t dominators[] = { |
| 135 | kInvalidBlockId, |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 136 | 3, |
| 137 | kInvalidBlockId, |
| 138 | 0 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 141 | TestCode(data1, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 142 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 143 | const std::vector<uint16_t> data2 = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 144 | Instruction::GOTO_32, 0, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 145 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 146 | TestCode(data2, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 147 | } |
| 148 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 149 | TEST_F(OptimizerTest, CFG5) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 150 | const std::vector<uint16_t> data = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 151 | Instruction::RETURN_VOID, // Block number 1 |
| 152 | Instruction::GOTO | 0x100, // Dead block |
| 153 | Instruction::GOTO | 0xFE00); // Block number 2 |
| 154 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 155 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 156 | const uint32_t dominators[] = { |
| 157 | kInvalidBlockId, |
| 158 | 0, |
| 159 | kInvalidBlockId, |
| 160 | 1 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 163 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 164 | } |
| 165 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 166 | TEST_F(OptimizerTest, CFG6) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 167 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 788aaad | 2014-03-10 12:00:43 +0000 | [diff] [blame] | 168 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 169 | Instruction::IF_EQ, 3, |
| 170 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 171 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 172 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 173 | const uint32_t dominators[] = { |
| 174 | kInvalidBlockId, |
| 175 | 0, |
| 176 | 1, |
| 177 | 1, |
| 178 | 3, |
| 179 | 1, // Synthesized block to avoid critical edge. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 182 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 183 | } |
| 184 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 185 | TEST_F(OptimizerTest, CFG7) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 186 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 788aaad | 2014-03-10 12:00:43 +0000 | [diff] [blame] | 187 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 188 | Instruction::IF_EQ, 3, // Block number 1 |
| 189 | Instruction::GOTO | 0x100, // Block number 2 |
| 190 | Instruction::GOTO | 0xFF00); // Block number 3 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 191 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 192 | const uint32_t dominators[] = { |
| 193 | kInvalidBlockId, |
| 194 | 0, |
| 195 | 1, |
| 196 | 1, |
| 197 | kInvalidBlockId, // exit block is not dominated by any block due to the spin loop. |
| 198 | 1, // block to avoid critical edge. |
| 199 | 1 // block to avoid critical edge. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 202 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 203 | } |
| 204 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 205 | TEST_F(OptimizerTest, CFG8) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 206 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 788aaad | 2014-03-10 12:00:43 +0000 | [diff] [blame] | 207 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 208 | Instruction::IF_EQ, 3, // Block number 1 |
| 209 | Instruction::GOTO | 0x200, // Block number 2 |
| 210 | Instruction::GOTO | 0x100, // Block number 3 |
| 211 | Instruction::GOTO | 0xFF00); // Block number 4 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 212 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 213 | const uint32_t dominators[] = { |
| 214 | kInvalidBlockId, |
| 215 | 0, |
| 216 | 1, |
| 217 | 1, |
| 218 | 1, |
| 219 | kInvalidBlockId, // exit block is not dominated by any block due to the spin loop. |
| 220 | 1 // block to avoid critical edge. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 223 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 224 | } |
| 225 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 226 | TEST_F(OptimizerTest, CFG9) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 227 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 788aaad | 2014-03-10 12:00:43 +0000 | [diff] [blame] | 228 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 229 | Instruction::IF_EQ, 3, // Block number 1 |
| 230 | Instruction::GOTO | 0x200, // Block number 2 |
| 231 | Instruction::GOTO | 0x100, // Block number 3 |
| 232 | Instruction::GOTO | 0xFE00); // Block number 4 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 233 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 234 | const uint32_t dominators[] = { |
| 235 | kInvalidBlockId, |
| 236 | 0, |
| 237 | 1, |
| 238 | 1, |
| 239 | 1, |
| 240 | kInvalidBlockId, // exit block is not dominated by any block due to the spin loop. |
| 241 | 1 // block to avoid critical edge. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 242 | }; |
| 243 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 244 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 245 | } |
| 246 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 247 | TEST_F(OptimizerTest, CFG10) { |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 248 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 788aaad | 2014-03-10 12:00:43 +0000 | [diff] [blame] | 249 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 250 | Instruction::IF_EQ, 6, // Block number 1 |
| 251 | Instruction::IF_EQ, 3, // Block number 2 |
| 252 | Instruction::GOTO | 0x100, // Block number 3 |
| 253 | Instruction::GOTO | 0x100, // Block number 4 |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 254 | Instruction::RETURN_VOID); // Block number 5 |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 255 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 256 | const uint32_t dominators[] = { |
| 257 | kInvalidBlockId, |
| 258 | 0, |
| 259 | 1, |
| 260 | 2, |
| 261 | 2, |
| 262 | 1, |
| 263 | 5, // Block number 5 dominates exit block |
| 264 | 1, // block to avoid critical edge. |
| 265 | 2 // block to avoid critical edge. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 268 | TestCode(data, dominators, sizeof(dominators) / sizeof(int)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | } // namespace art |