Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [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" |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 18 | #include "base/macros.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 19 | #include "builder.h" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 20 | #include "code_generator.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 21 | #include "dex/dex_file.h" |
| 22 | #include "dex/dex_instruction.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 23 | #include "driver/compiler_options.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 24 | #include "nodes.h" |
| 25 | #include "optimizing_unit_test.h" |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 26 | #include "prepare_for_register_allocation.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 27 | #include "ssa_liveness_analysis.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 28 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 29 | namespace art HIDDEN { |
David Brazdil | d9510df | 2015-11-04 23:30:22 +0000 | [diff] [blame] | 30 | |
Santiago Aboy Solanes | 2c50b3a | 2023-02-10 10:25:31 +0000 | [diff] [blame] | 31 | class LivenessTest : public CommonCompilerTest, public OptimizingUnitTestHelper { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 32 | protected: |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 33 | void TestCode(const std::vector<uint16_t>& data, const char* expected); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 34 | }; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 36 | static void DumpBitVector(BitVector* vector, |
| 37 | std::ostream& buffer, |
| 38 | size_t count, |
| 39 | const char* prefix) { |
| 40 | buffer << prefix; |
| 41 | buffer << '('; |
| 42 | for (size_t i = 0; i < count; ++i) { |
| 43 | buffer << vector->IsBitSet(i); |
| 44 | } |
| 45 | buffer << ")\n"; |
| 46 | } |
| 47 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 48 | void LivenessTest::TestCode(const std::vector<uint16_t>& data, const char* expected) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 49 | HGraph* graph = CreateCFG(data); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 50 | // `Inline` conditions into ifs. |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 51 | std::unique_ptr<CompilerOptions> compiler_options = |
| 52 | CommonCompilerTest::CreateCompilerOptions(kRuntimeISA, "default"); |
| 53 | PrepareForRegisterAllocation(graph, *compiler_options).Run(); |
| 54 | std::unique_ptr<CodeGenerator> codegen = CodeGenerator::Create(graph, *compiler_options); |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 55 | SsaLivenessAnalysis liveness(graph, codegen.get(), GetScopedAllocator()); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 56 | liveness.Analyze(); |
| 57 | |
| 58 | std::ostringstream buffer; |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 59 | for (HBasicBlock* block : graph->GetBlocks()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 60 | buffer << "Block " << block->GetBlockId() << std::endl; |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 61 | size_t ssa_values = liveness.GetNumberOfSsaValues(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 62 | BitVector* live_in = liveness.GetLiveInSet(*block); |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 63 | DumpBitVector(live_in, buffer, ssa_values, " live in: "); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 64 | BitVector* live_out = liveness.GetLiveOutSet(*block); |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 65 | DumpBitVector(live_out, buffer, ssa_values, " live out: "); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 66 | BitVector* kill = liveness.GetKillSet(*block); |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 67 | DumpBitVector(kill, buffer, ssa_values, " kill: "); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 68 | } |
| 69 | ASSERT_STREQ(expected, buffer.str().c_str()); |
| 70 | } |
| 71 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 72 | TEST_F(LivenessTest, CFG1) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 73 | const char* expected = |
| 74 | "Block 0\n" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 75 | " live in: (0)\n" |
| 76 | " live out: (0)\n" |
| 77 | " kill: (1)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 78 | "Block 1\n" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 79 | " live in: (0)\n" |
| 80 | " live out: (0)\n" |
| 81 | " kill: (0)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 82 | "Block 2\n" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 83 | " live in: (0)\n" |
| 84 | " live out: (0)\n" |
| 85 | " kill: (0)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 86 | |
| 87 | // Constant is not used. |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 88 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 89 | Instruction::CONST_4 | 0 | 0, |
| 90 | Instruction::RETURN_VOID); |
| 91 | |
| 92 | TestCode(data, expected); |
| 93 | } |
| 94 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 95 | TEST_F(LivenessTest, CFG2) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 96 | const char* expected = |
| 97 | "Block 0\n" |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 98 | " live in: (0)\n" |
| 99 | " live out: (1)\n" |
| 100 | " kill: (1)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 101 | "Block 1\n" |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 102 | " live in: (1)\n" |
| 103 | " live out: (0)\n" |
| 104 | " kill: (0)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 105 | "Block 2\n" |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 106 | " live in: (0)\n" |
| 107 | " live out: (0)\n" |
| 108 | " kill: (0)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 109 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 110 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 111 | Instruction::CONST_4 | 0 | 0, |
| 112 | Instruction::RETURN); |
| 113 | |
| 114 | TestCode(data, expected); |
| 115 | } |
| 116 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 117 | TEST_F(LivenessTest, CFG3) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 118 | const char* expected = |
| 119 | "Block 0\n" // entry block |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 120 | " live in: (000)\n" |
| 121 | " live out: (110)\n" |
| 122 | " kill: (110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 123 | "Block 1\n" // block with add |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 124 | " live in: (110)\n" |
| 125 | " live out: (001)\n" |
| 126 | " kill: (001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 127 | "Block 2\n" // block with return |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 128 | " live in: (001)\n" |
| 129 | " live out: (000)\n" |
| 130 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 131 | "Block 3\n" // exit block |
Nicolas Geoffray | 26066f2 | 2014-06-03 10:36:16 +0000 | [diff] [blame] | 132 | " live in: (000)\n" |
| 133 | " live out: (000)\n" |
| 134 | " kill: (000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 135 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 136 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 137 | Instruction::CONST_4 | 3 << 12 | 0, |
| 138 | Instruction::CONST_4 | 4 << 12 | 1 << 8, |
| 139 | Instruction::ADD_INT_2ADDR | 1 << 12, |
| 140 | Instruction::GOTO | 0x100, |
| 141 | Instruction::RETURN); |
| 142 | |
| 143 | TestCode(data, expected); |
| 144 | } |
| 145 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 146 | TEST_F(LivenessTest, CFG4) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 147 | // var a; |
| 148 | // if (0 == 0) { |
| 149 | // a = 5; |
| 150 | // } else { |
| 151 | // a = 4; |
| 152 | // } |
| 153 | // return a; |
| 154 | // |
| 155 | // Bitsets are made of: |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 156 | // (constant0, constant5, constant4, phi) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 157 | const char* expected = |
| 158 | "Block 0\n" // entry block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 159 | " live in: (0000)\n" |
| 160 | " live out: (1110)\n" |
| 161 | " kill: (1110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 162 | "Block 1\n" // block with if |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 163 | " live in: (1110)\n" |
| 164 | " live out: (0110)\n" |
| 165 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 166 | "Block 2\n" // else block |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 167 | " live in: (0010)\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 168 | " live out: (0000)\n" |
| 169 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 170 | "Block 3\n" // then block |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 171 | " live in: (0100)\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 172 | " live out: (0000)\n" |
| 173 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 174 | "Block 4\n" // return block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 175 | " live in: (0000)\n" |
| 176 | " live out: (0000)\n" |
| 177 | " kill: (0001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 178 | "Block 5\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 179 | " live in: (0000)\n" |
| 180 | " live out: (0000)\n" |
| 181 | " kill: (0000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 182 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 183 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 184 | Instruction::CONST_4 | 0 | 0, |
| 185 | Instruction::IF_EQ, 4, |
| 186 | Instruction::CONST_4 | 4 << 12 | 0, |
| 187 | Instruction::GOTO | 0x200, |
| 188 | Instruction::CONST_4 | 5 << 12 | 0, |
| 189 | Instruction::RETURN | 0 << 8); |
| 190 | |
| 191 | TestCode(data, expected); |
| 192 | } |
| 193 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 194 | TEST_F(LivenessTest, CFG5) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 195 | // var a = 0; |
| 196 | // if (0 == 0) { |
| 197 | // } else { |
| 198 | // a = 4; |
| 199 | // } |
| 200 | // return a; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 201 | // |
| 202 | // Bitsets are made of: |
| 203 | // (constant0, constant4, phi) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 204 | const char* expected = |
| 205 | "Block 0\n" // entry block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 206 | " live in: (000)\n" |
| 207 | " live out: (110)\n" |
| 208 | " kill: (110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 209 | "Block 1\n" // block with if |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 210 | " live in: (110)\n" |
| 211 | " live out: (110)\n" |
| 212 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 213 | "Block 2\n" // else block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 214 | " live in: (010)\n" |
| 215 | " live out: (000)\n" |
| 216 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 217 | "Block 3\n" // return block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 218 | " live in: (000)\n" |
| 219 | " live out: (000)\n" |
| 220 | " kill: (001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 221 | "Block 4\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 222 | " live in: (000)\n" |
| 223 | " live out: (000)\n" |
| 224 | " kill: (000)\n" |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 225 | "Block 5\n" // block to avoid critical edge. Predecessor is 1, successor is 3. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 226 | " live in: (100)\n" |
| 227 | " live out: (000)\n" |
| 228 | " kill: (000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 229 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 230 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 231 | Instruction::CONST_4 | 0 | 0, |
| 232 | Instruction::IF_EQ, 3, |
| 233 | Instruction::CONST_4 | 4 << 12 | 0, |
| 234 | Instruction::RETURN | 0 << 8); |
| 235 | |
| 236 | TestCode(data, expected); |
| 237 | } |
| 238 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 239 | TEST_F(LivenessTest, Loop1) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 240 | // Simple loop with one preheader and one back edge. |
| 241 | // var a = 0; |
| 242 | // while (a == a) { |
| 243 | // a = 4; |
| 244 | // } |
| 245 | // return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | // Bitsets are made of: |
| 247 | // (constant0, constant4, phi) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 248 | const char* expected = |
| 249 | "Block 0\n" // entry block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 250 | " live in: (000)\n" |
| 251 | " live out: (110)\n" |
| 252 | " kill: (110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 253 | "Block 1\n" // pre header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 254 | " live in: (110)\n" |
| 255 | " live out: (010)\n" |
| 256 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 257 | "Block 2\n" // loop header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 258 | " live in: (010)\n" |
| 259 | " live out: (010)\n" |
| 260 | " kill: (001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 261 | "Block 3\n" // back edge |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 262 | " live in: (010)\n" |
| 263 | " live out: (010)\n" |
| 264 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 265 | "Block 4\n" // return block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 266 | " live in: (000)\n" |
| 267 | " live out: (000)\n" |
| 268 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 269 | "Block 5\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 270 | " live in: (000)\n" |
| 271 | " live out: (000)\n" |
| 272 | " kill: (000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 273 | |
| 274 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 275 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 276 | Instruction::CONST_4 | 0 | 0, |
| 277 | Instruction::IF_EQ, 4, |
| 278 | Instruction::CONST_4 | 4 << 12 | 0, |
| 279 | Instruction::GOTO | 0xFD00, |
| 280 | Instruction::RETURN_VOID); |
| 281 | |
| 282 | TestCode(data, expected); |
| 283 | } |
| 284 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 285 | TEST_F(LivenessTest, Loop3) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 286 | // Test that the returned value stays live in a preceding loop. |
| 287 | // var a = 0; |
| 288 | // while (a == a) { |
| 289 | // a = 4; |
| 290 | // } |
| 291 | // return 5; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 292 | // Bitsets are made of: |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 293 | // (constant0, constant5, constant4, phi) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 294 | const char* expected = |
| 295 | "Block 0\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 296 | " live in: (0000)\n" |
| 297 | " live out: (1110)\n" |
| 298 | " kill: (1110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 299 | "Block 1\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 300 | " live in: (1110)\n" |
| 301 | " live out: (0110)\n" |
| 302 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 303 | "Block 2\n" // loop header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 304 | " live in: (0110)\n" |
| 305 | " live out: (0110)\n" |
| 306 | " kill: (0001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 307 | "Block 3\n" // back edge |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 308 | " live in: (0110)\n" |
| 309 | " live out: (0110)\n" |
| 310 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 311 | "Block 4\n" // return block |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 312 | " live in: (0100)\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 313 | " live out: (0000)\n" |
| 314 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 315 | "Block 5\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 316 | " live in: (0000)\n" |
| 317 | " live out: (0000)\n" |
| 318 | " kill: (0000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 319 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 320 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 321 | Instruction::CONST_4 | 0 | 0, |
| 322 | Instruction::IF_EQ, 4, |
| 323 | Instruction::CONST_4 | 4 << 12 | 0, |
| 324 | Instruction::GOTO | 0xFD00, |
| 325 | Instruction::CONST_4 | 5 << 12 | 1 << 8, |
| 326 | Instruction::RETURN | 1 << 8); |
| 327 | |
| 328 | TestCode(data, expected); |
| 329 | } |
| 330 | |
| 331 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 332 | TEST_F(LivenessTest, Loop4) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 333 | // Make sure we support a preheader of a loop not being the first predecessor |
| 334 | // in the predecessor list of the header. |
| 335 | // var a = 0; |
| 336 | // while (a == a) { |
| 337 | // a = 4; |
| 338 | // } |
| 339 | // return a; |
| 340 | // Bitsets are made of: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 341 | // (constant0, constant4, phi) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 342 | const char* expected = |
| 343 | "Block 0\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 344 | " live in: (000)\n" |
| 345 | " live out: (110)\n" |
| 346 | " kill: (110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 347 | "Block 1\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 348 | " live in: (110)\n" |
| 349 | " live out: (110)\n" |
| 350 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 351 | "Block 2\n" // loop header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 352 | " live in: (010)\n" |
| 353 | " live out: (011)\n" |
| 354 | " kill: (001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 355 | "Block 3\n" // back edge |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 356 | " live in: (010)\n" |
| 357 | " live out: (010)\n" |
| 358 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 359 | "Block 4\n" // pre loop header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 360 | " live in: (110)\n" |
| 361 | " live out: (010)\n" |
| 362 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 363 | "Block 5\n" // return block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 364 | " live in: (001)\n" |
| 365 | " live out: (000)\n" |
| 366 | " kill: (000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 367 | "Block 6\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 368 | " live in: (000)\n" |
| 369 | " live out: (000)\n" |
| 370 | " kill: (000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 371 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 372 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 373 | Instruction::CONST_4 | 0 | 0, |
| 374 | Instruction::GOTO | 0x500, |
| 375 | Instruction::IF_EQ, 5, |
| 376 | Instruction::CONST_4 | 4 << 12 | 0, |
| 377 | Instruction::GOTO | 0xFD00, |
| 378 | Instruction::GOTO | 0xFC00, |
| 379 | Instruction::RETURN | 0 << 8); |
| 380 | |
| 381 | TestCode(data, expected); |
| 382 | } |
| 383 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 384 | TEST_F(LivenessTest, Loop5) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 385 | // Make sure we create a preheader of a loop when a header originally has two |
| 386 | // incoming blocks and one back edge. |
| 387 | // Bitsets are made of: |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 388 | // (constant0, constant5, constant4, phi in block 8) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 389 | const char* expected = |
| 390 | "Block 0\n" |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 391 | " live in: (0000)\n" |
| 392 | " live out: (1110)\n" |
| 393 | " kill: (1110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 394 | "Block 1\n" |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 395 | " live in: (1110)\n" |
| 396 | " live out: (0110)\n" |
| 397 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 398 | "Block 2\n" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 399 | " live in: (0010)\n" |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 400 | " live out: (0000)\n" |
| 401 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 402 | "Block 3\n" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 403 | " live in: (0100)\n" |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 404 | " live out: (0000)\n" |
| 405 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 406 | "Block 4\n" // loop header |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 407 | " live in: (0001)\n" |
| 408 | " live out: (0001)\n" |
| 409 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 410 | "Block 5\n" // back edge |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 411 | " live in: (0001)\n" |
| 412 | " live out: (0001)\n" |
| 413 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 414 | "Block 6\n" // return block |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 415 | " live in: (0001)\n" |
| 416 | " live out: (0000)\n" |
| 417 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 418 | "Block 7\n" // exit block |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 419 | " live in: (0000)\n" |
| 420 | " live out: (0000)\n" |
| 421 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 422 | "Block 8\n" // synthesized pre header |
Nicolas Geoffray | 3afca78 | 2015-03-10 18:59:31 +0000 | [diff] [blame] | 423 | " live in: (0000)\n" |
| 424 | " live out: (0001)\n" |
| 425 | " kill: (0001)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 426 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 427 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 428 | Instruction::CONST_4 | 0 | 0, |
| 429 | Instruction::IF_EQ, 4, |
| 430 | Instruction::CONST_4 | 4 << 12 | 0, |
| 431 | Instruction::GOTO | 0x200, |
| 432 | Instruction::CONST_4 | 5 << 12 | 0, |
| 433 | Instruction::IF_EQ, 3, |
| 434 | Instruction::GOTO | 0xFE00, |
| 435 | Instruction::RETURN | 0 << 8); |
| 436 | |
| 437 | TestCode(data, expected); |
| 438 | } |
| 439 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 440 | TEST_F(LivenessTest, Loop6) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 441 | // Bitsets are made of: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 442 | // (constant0, constant4, constant5, phi in block 2) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 443 | const char* expected = |
| 444 | "Block 0\n" |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 445 | " live in: (0000)\n" |
| 446 | " live out: (1110)\n" |
| 447 | " kill: (1110)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 448 | "Block 1\n" |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 449 | " live in: (1110)\n" |
| 450 | " live out: (0110)\n" |
| 451 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 452 | "Block 2\n" // loop header |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 453 | " live in: (0110)\n" |
| 454 | " live out: (0111)\n" |
| 455 | " kill: (0001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 456 | "Block 3\n" |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 457 | " live in: (0110)\n" |
| 458 | " live out: (0110)\n" |
| 459 | " kill: (0000)\n" |
| 460 | "Block 4\n" // back edge |
| 461 | " live in: (0110)\n" |
| 462 | " live out: (0110)\n" |
| 463 | " kill: (0000)\n" |
| 464 | "Block 5\n" // back edge |
| 465 | " live in: (0110)\n" |
| 466 | " live out: (0110)\n" |
| 467 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 468 | "Block 6\n" // return block |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 469 | " live in: (0001)\n" |
| 470 | " live out: (0000)\n" |
| 471 | " kill: (0000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 472 | "Block 7\n" // exit block |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 473 | " live in: (0000)\n" |
| 474 | " live out: (0000)\n" |
| 475 | " kill: (0000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 476 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 477 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 478 | Instruction::CONST_4 | 0 | 0, |
| 479 | Instruction::IF_EQ, 8, |
| 480 | Instruction::CONST_4 | 4 << 12 | 0, |
| 481 | Instruction::IF_EQ, 4, |
| 482 | Instruction::CONST_4 | 5 << 12 | 0, |
| 483 | Instruction::GOTO | 0xFA00, |
| 484 | Instruction::GOTO | 0xF900, |
| 485 | Instruction::RETURN | 0 << 8); |
| 486 | |
| 487 | TestCode(data, expected); |
| 488 | } |
| 489 | |
| 490 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 491 | TEST_F(LivenessTest, Loop7) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 492 | // Bitsets are made of: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 493 | // (constant0, constant4, constant5, phi in block 2, phi in block 6) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 494 | const char* expected = |
| 495 | "Block 0\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 496 | " live in: (00000)\n" |
| 497 | " live out: (11100)\n" |
| 498 | " kill: (11100)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 499 | "Block 1\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 500 | " live in: (11100)\n" |
| 501 | " live out: (01100)\n" |
| 502 | " kill: (00000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 503 | "Block 2\n" // loop header |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 504 | " live in: (01100)\n" |
| 505 | " live out: (01110)\n" |
| 506 | " kill: (00010)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 507 | "Block 3\n" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 508 | " live in: (01100)\n" |
| 509 | " live out: (01100)\n" |
| 510 | " kill: (00000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 511 | "Block 4\n" // loop exit |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 512 | " live in: (00100)\n" |
| 513 | " live out: (00000)\n" |
| 514 | " kill: (00000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 515 | "Block 5\n" // back edge |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 516 | " live in: (01100)\n" |
| 517 | " live out: (01100)\n" |
| 518 | " kill: (00000)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 519 | "Block 6\n" // return block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 520 | " live in: (00000)\n" |
| 521 | " live out: (00000)\n" |
| 522 | " kill: (00001)\n" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 523 | "Block 7\n" // exit block |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 524 | " live in: (00000)\n" |
| 525 | " live out: (00000)\n" |
| 526 | " kill: (00000)\n" |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 527 | "Block 8\n" // synthesized block to avoid critical edge. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 528 | " live in: (00010)\n" |
| 529 | " live out: (00000)\n" |
| 530 | " kill: (00000)\n"; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 531 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 532 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 533 | Instruction::CONST_4 | 0 | 0, |
| 534 | Instruction::IF_EQ, 8, |
| 535 | Instruction::CONST_4 | 4 << 12 | 0, |
| 536 | Instruction::IF_EQ, 4, |
| 537 | Instruction::CONST_4 | 5 << 12 | 0, |
| 538 | Instruction::GOTO | 0x0200, |
| 539 | Instruction::GOTO | 0xF900, |
| 540 | Instruction::RETURN | 0 << 8); |
| 541 | |
| 542 | TestCode(data, expected); |
| 543 | } |
| 544 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 545 | TEST_F(LivenessTest, Loop8) { |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 546 | // var a = 0; |
| 547 | // while (a == a) { |
| 548 | // a = a + a; |
| 549 | // } |
| 550 | // return a; |
| 551 | // |
| 552 | // We want to test that the ins of the loop exit |
| 553 | // does contain the phi. |
| 554 | // Bitsets are made of: |
| 555 | // (constant0, phi, add) |
| 556 | const char* expected = |
| 557 | "Block 0\n" |
| 558 | " live in: (000)\n" |
| 559 | " live out: (100)\n" |
| 560 | " kill: (100)\n" |
| 561 | "Block 1\n" // pre loop header |
| 562 | " live in: (100)\n" |
| 563 | " live out: (000)\n" |
| 564 | " kill: (000)\n" |
| 565 | "Block 2\n" // loop header |
| 566 | " live in: (000)\n" |
| 567 | " live out: (010)\n" |
| 568 | " kill: (010)\n" |
| 569 | "Block 3\n" // back edge |
| 570 | " live in: (010)\n" |
| 571 | " live out: (000)\n" |
| 572 | " kill: (001)\n" |
| 573 | "Block 4\n" // return block |
| 574 | " live in: (010)\n" |
| 575 | " live out: (000)\n" |
| 576 | " kill: (000)\n" |
| 577 | "Block 5\n" // exit block |
| 578 | " live in: (000)\n" |
| 579 | " live out: (000)\n" |
| 580 | " kill: (000)\n"; |
| 581 | |
Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 582 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 583 | Instruction::CONST_4 | 0 | 0, |
| 584 | Instruction::IF_EQ, 6, |
| 585 | Instruction::ADD_INT, 0, 0, |
| 586 | Instruction::GOTO | 0xFB00, |
| 587 | Instruction::RETURN | 0 << 8); |
| 588 | |
| 589 | TestCode(data, expected); |
| 590 | } |
| 591 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 592 | } // namespace art |