Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +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 | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 19 | #include "builder.h" |
| 20 | #include "nodes.h" |
| 21 | #include "optimizing_unit_test.h" |
| 22 | #include "pretty_printer.h" |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 23 | |
| 24 | #include "gtest/gtest.h" |
| 25 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 26 | namespace art HIDDEN { |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 27 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 28 | class GraphTest : public OptimizingUnitTest { |
| 29 | protected: |
| 30 | HBasicBlock* CreateIfBlock(HGraph* graph); |
| 31 | HBasicBlock* CreateGotoBlock(HGraph* graph); |
| 32 | HBasicBlock* CreateEntryBlock(HGraph* graph); |
| 33 | HBasicBlock* CreateReturnBlock(HGraph* graph); |
| 34 | HBasicBlock* CreateExitBlock(HGraph* graph); |
| 35 | }; |
| 36 | |
| 37 | HBasicBlock* GraphTest::CreateIfBlock(HGraph* graph) { |
| 38 | HBasicBlock* if_block = new (GetAllocator()) HBasicBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 39 | graph->AddBlock(if_block); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 40 | HInstruction* instr = graph->GetIntConstant(4); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 41 | HInstruction* equal = new (GetAllocator()) HEqual(instr, instr); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 42 | if_block->AddInstruction(equal); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 43 | instr = new (GetAllocator()) HIf(equal); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 44 | if_block->AddInstruction(instr); |
| 45 | return if_block; |
| 46 | } |
| 47 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 48 | HBasicBlock* GraphTest::CreateGotoBlock(HGraph* graph) { |
| 49 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 50 | graph->AddBlock(block); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 51 | HInstruction* got = new (GetAllocator()) HGoto(); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 52 | block->AddInstruction(got); |
| 53 | return block; |
| 54 | } |
| 55 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 56 | HBasicBlock* GraphTest::CreateEntryBlock(HGraph* graph) { |
| 57 | HBasicBlock* block = CreateGotoBlock(graph); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | graph->SetEntryBlock(block); |
| 59 | return block; |
| 60 | } |
| 61 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 62 | HBasicBlock* GraphTest::CreateReturnBlock(HGraph* graph) { |
| 63 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 64 | graph->AddBlock(block); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 65 | HInstruction* return_instr = new (GetAllocator()) HReturnVoid(); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 66 | block->AddInstruction(return_instr); |
| 67 | return block; |
| 68 | } |
| 69 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 70 | HBasicBlock* GraphTest::CreateExitBlock(HGraph* graph) { |
| 71 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 72 | graph->AddBlock(block); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 73 | HInstruction* exit_instr = new (GetAllocator()) HExit(); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 74 | block->AddInstruction(exit_instr); |
| 75 | return block; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 80 | // This test sets the false block to be the return block. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 81 | TEST_F(GraphTest, IfSuccessorSimpleJoinBlock1) { |
| 82 | HGraph* graph = CreateGraph(); |
| 83 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 84 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 85 | HBasicBlock* if_true = CreateGotoBlock(graph); |
| 86 | HBasicBlock* return_block = CreateReturnBlock(graph); |
| 87 | HBasicBlock* exit_block = CreateExitBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 88 | |
| 89 | entry_block->AddSuccessor(if_block); |
| 90 | if_block->AddSuccessor(if_true); |
| 91 | if_true->AddSuccessor(return_block); |
| 92 | if_block->AddSuccessor(return_block); |
| 93 | return_block->AddSuccessor(exit_block); |
| 94 | |
| 95 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), if_true); |
| 96 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), return_block); |
| 97 | |
| 98 | graph->SimplifyCFG(); |
| 99 | |
| 100 | // Ensure we still have the same if true block. |
| 101 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), if_true); |
| 102 | |
| 103 | // Ensure the critical edge has been removed. |
| 104 | HBasicBlock* false_block = if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(); |
| 105 | ASSERT_NE(false_block, return_block); |
| 106 | |
| 107 | // Ensure the new block branches to the join block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 108 | ASSERT_EQ(false_block->GetSuccessors()[0], return_block); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 112 | // This test sets the true block to be the return block. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 113 | TEST_F(GraphTest, IfSuccessorSimpleJoinBlock2) { |
| 114 | HGraph* graph = CreateGraph(); |
| 115 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 116 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 117 | HBasicBlock* if_false = CreateGotoBlock(graph); |
| 118 | HBasicBlock* return_block = CreateReturnBlock(graph); |
| 119 | HBasicBlock* exit_block = CreateExitBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 120 | |
| 121 | entry_block->AddSuccessor(if_block); |
| 122 | if_block->AddSuccessor(return_block); |
| 123 | if_false->AddSuccessor(return_block); |
| 124 | if_block->AddSuccessor(if_false); |
| 125 | return_block->AddSuccessor(exit_block); |
| 126 | |
| 127 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), return_block); |
| 128 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), if_false); |
| 129 | |
| 130 | graph->SimplifyCFG(); |
| 131 | |
| 132 | // Ensure we still have the same if true block. |
| 133 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), if_false); |
| 134 | |
| 135 | // Ensure the critical edge has been removed. |
| 136 | HBasicBlock* true_block = if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(); |
| 137 | ASSERT_NE(true_block, return_block); |
| 138 | |
| 139 | // Ensure the new block branches to the join block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 140 | ASSERT_EQ(true_block->GetSuccessors()[0], return_block); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 144 | // This test sets the true block to be the loop header. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 145 | TEST_F(GraphTest, IfSuccessorMultipleBackEdges1) { |
| 146 | HGraph* graph = CreateGraph(); |
| 147 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 148 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 149 | HBasicBlock* return_block = CreateReturnBlock(graph); |
| 150 | HBasicBlock* exit_block = CreateExitBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 151 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 152 | entry_block->AddSuccessor(if_block); |
| 153 | if_block->AddSuccessor(if_block); |
| 154 | if_block->AddSuccessor(return_block); |
| 155 | return_block->AddSuccessor(exit_block); |
| 156 | |
| 157 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), if_block); |
| 158 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), return_block); |
| 159 | |
| 160 | graph->BuildDominatorTree(); |
| 161 | |
| 162 | // Ensure we still have the same if false block. |
| 163 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), return_block); |
| 164 | |
| 165 | // Ensure there is only one back edge. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 166 | ASSERT_EQ(if_block->GetPredecessors().size(), 2u); |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 167 | ASSERT_EQ(if_block->GetPredecessors()[0], entry_block->GetSingleSuccessor()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 168 | ASSERT_NE(if_block->GetPredecessors()[1], if_block); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 169 | |
| 170 | // Ensure the new block is the back edge. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 171 | ASSERT_EQ(if_block->GetPredecessors()[1], |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 172 | if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor()); |
| 173 | } |
| 174 | |
| 175 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 176 | // This test sets the false block to be the loop header. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 177 | TEST_F(GraphTest, IfSuccessorMultipleBackEdges2) { |
| 178 | HGraph* graph = CreateGraph(); |
| 179 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 180 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 181 | HBasicBlock* return_block = CreateReturnBlock(graph); |
| 182 | HBasicBlock* exit_block = CreateExitBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 183 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 184 | entry_block->AddSuccessor(if_block); |
| 185 | if_block->AddSuccessor(return_block); |
| 186 | if_block->AddSuccessor(if_block); |
| 187 | return_block->AddSuccessor(exit_block); |
| 188 | |
| 189 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), return_block); |
| 190 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), if_block); |
| 191 | |
| 192 | graph->BuildDominatorTree(); |
| 193 | |
| 194 | // Ensure we still have the same if true block. |
| 195 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), return_block); |
| 196 | |
| 197 | // Ensure there is only one back edge. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 198 | ASSERT_EQ(if_block->GetPredecessors().size(), 2u); |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 199 | ASSERT_EQ(if_block->GetPredecessors()[0], entry_block->GetSingleSuccessor()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 200 | ASSERT_NE(if_block->GetPredecessors()[1], if_block); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 201 | |
| 202 | // Ensure the new block is the back edge. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 203 | ASSERT_EQ(if_block->GetPredecessors()[1], |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 204 | if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor()); |
| 205 | } |
| 206 | |
| 207 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 208 | // This test sets the true block to be a loop header with multiple pre headers. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 209 | TEST_F(GraphTest, IfSuccessorMultiplePreHeaders1) { |
| 210 | HGraph* graph = CreateGraph(); |
| 211 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 212 | HBasicBlock* first_if_block = CreateIfBlock(graph); |
| 213 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 214 | HBasicBlock* loop_block = CreateGotoBlock(graph); |
| 215 | HBasicBlock* return_block = CreateReturnBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 216 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 217 | entry_block->AddSuccessor(first_if_block); |
| 218 | first_if_block->AddSuccessor(if_block); |
| 219 | first_if_block->AddSuccessor(loop_block); |
| 220 | loop_block->AddSuccessor(loop_block); |
| 221 | if_block->AddSuccessor(loop_block); |
| 222 | if_block->AddSuccessor(return_block); |
| 223 | |
| 224 | |
| 225 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), loop_block); |
| 226 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), return_block); |
| 227 | |
| 228 | graph->BuildDominatorTree(); |
| 229 | |
| 230 | HIf* if_instr = if_block->GetLastInstruction()->AsIf(); |
| 231 | // Ensure we still have the same if false block. |
| 232 | ASSERT_EQ(if_instr->IfFalseSuccessor(), return_block); |
| 233 | |
| 234 | // Ensure there is only one pre header.. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 235 | ASSERT_EQ(loop_block->GetPredecessors().size(), 2u); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 236 | |
| 237 | // Ensure the new block is the successor of the true block. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 238 | ASSERT_EQ(if_instr->IfTrueSuccessor()->GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 239 | ASSERT_EQ(if_instr->IfTrueSuccessor()->GetSuccessors()[0], |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 240 | loop_block->GetLoopInformation()->GetPreHeader()); |
| 241 | } |
| 242 | |
| 243 | // Test that the successors of an if block stay consistent after a SimplifyCFG. |
| 244 | // This test sets the false block to be a loop header with multiple pre headers. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 245 | TEST_F(GraphTest, IfSuccessorMultiplePreHeaders2) { |
| 246 | HGraph* graph = CreateGraph(); |
| 247 | HBasicBlock* entry_block = CreateEntryBlock(graph); |
| 248 | HBasicBlock* first_if_block = CreateIfBlock(graph); |
| 249 | HBasicBlock* if_block = CreateIfBlock(graph); |
| 250 | HBasicBlock* loop_block = CreateGotoBlock(graph); |
| 251 | HBasicBlock* return_block = CreateReturnBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 252 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 253 | entry_block->AddSuccessor(first_if_block); |
| 254 | first_if_block->AddSuccessor(if_block); |
| 255 | first_if_block->AddSuccessor(loop_block); |
| 256 | loop_block->AddSuccessor(loop_block); |
| 257 | if_block->AddSuccessor(return_block); |
| 258 | if_block->AddSuccessor(loop_block); |
| 259 | |
| 260 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), return_block); |
| 261 | ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), loop_block); |
| 262 | |
| 263 | graph->BuildDominatorTree(); |
| 264 | |
| 265 | HIf* if_instr = if_block->GetLastInstruction()->AsIf(); |
| 266 | // Ensure we still have the same if true block. |
| 267 | ASSERT_EQ(if_instr->IfTrueSuccessor(), return_block); |
| 268 | |
| 269 | // Ensure there is only one pre header.. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 270 | ASSERT_EQ(loop_block->GetPredecessors().size(), 2u); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 271 | |
| 272 | // Ensure the new block is the successor of the false block. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 273 | ASSERT_EQ(if_instr->IfFalseSuccessor()->GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 274 | ASSERT_EQ(if_instr->IfFalseSuccessor()->GetSuccessors()[0], |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 275 | loop_block->GetLoopInformation()->GetPreHeader()); |
| 276 | } |
| 277 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 278 | TEST_F(GraphTest, InsertInstructionBefore) { |
| 279 | HGraph* graph = CreateGraph(); |
| 280 | HBasicBlock* block = CreateGotoBlock(graph); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 281 | HInstruction* got = block->GetLastInstruction(); |
| 282 | ASSERT_TRUE(got->IsControlFlow()); |
| 283 | |
| 284 | // Test at the beginning of the block. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 285 | HInstruction* first_instruction = new (GetAllocator()) HIntConstant(4); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 286 | block->InsertInstructionBefore(first_instruction, got); |
| 287 | |
| 288 | ASSERT_NE(first_instruction->GetId(), -1); |
| 289 | ASSERT_EQ(first_instruction->GetBlock(), block); |
| 290 | ASSERT_EQ(block->GetFirstInstruction(), first_instruction); |
| 291 | ASSERT_EQ(block->GetLastInstruction(), got); |
| 292 | ASSERT_EQ(first_instruction->GetNext(), got); |
| 293 | ASSERT_EQ(first_instruction->GetPrevious(), nullptr); |
| 294 | ASSERT_EQ(got->GetNext(), nullptr); |
| 295 | ASSERT_EQ(got->GetPrevious(), first_instruction); |
| 296 | |
| 297 | // Test in the middle of the block. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 298 | HInstruction* second_instruction = new (GetAllocator()) HIntConstant(4); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 299 | block->InsertInstructionBefore(second_instruction, got); |
| 300 | |
| 301 | ASSERT_NE(second_instruction->GetId(), -1); |
| 302 | ASSERT_EQ(second_instruction->GetBlock(), block); |
| 303 | ASSERT_EQ(block->GetFirstInstruction(), first_instruction); |
| 304 | ASSERT_EQ(block->GetLastInstruction(), got); |
| 305 | ASSERT_EQ(first_instruction->GetNext(), second_instruction); |
| 306 | ASSERT_EQ(first_instruction->GetPrevious(), nullptr); |
| 307 | ASSERT_EQ(second_instruction->GetNext(), got); |
| 308 | ASSERT_EQ(second_instruction->GetPrevious(), first_instruction); |
| 309 | ASSERT_EQ(got->GetNext(), nullptr); |
| 310 | ASSERT_EQ(got->GetPrevious(), second_instruction); |
| 311 | } |
| 312 | |
| 313 | } // namespace art |