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