1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include "compiler/optimizer/ir/basicblock.h" 19 #include "graph.h" 20 #include "graph_test.h" 21 #include "mem/pool_manager.h" 22 #include "optimizer/analysis/liveness_analyzer.h" 23 #include "optimizer/analysis/rpo.h" 24 25 using namespace testing::ext; 26 27 namespace panda::compiler { 28 class LivenessAnalyzerTest : public testing::Test { 29 public: SetUpTestCase(void)30 static void SetUpTestCase(void) {} TearDownTestCase(void)31 static void TearDownTestCase(void) {} SetUp()32 void SetUp() {} TearDown()33 void TearDown() {} 34 35 GraphTest graph_test_; 36 }; 37 38 /** 39 * @tc.name: liveness_analyzer_test_001 40 * @tc.desc: Verify the DumpLifeIntervals function. 41 * @tc.type: FUNC 42 * @tc.require: issueNumber 43 */ 44 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_001, TestSize.Level1) 45 { 46 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 47 const char *test_method_name = "func_main_0"; 48 bool status = false; 49 __anona4efd4bf0102(Graph* graph, std::string &method_name) 50 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 51 if (test_method_name != method_name) { 52 return; 53 } 54 status = true; 55 EXPECT_NE(graph, nullptr); 56 LivenessAnalyzer liveness_analyzer(graph); 57 std::stringstream out; 58 liveness_analyzer.DumpLifeIntervals(out); 59 std::string str = "\nRegisters intervals\n-\n\n" 60 "Vector registers intervals\n-\n\n" 61 "Stack slots intervals\n-\n"; 62 EXPECT_EQ(out.str(), str); 63 EXPECT_EQ(0, liveness_analyzer.GetBlocksCount()); 64 }); 65 EXPECT_TRUE(status); 66 } 67 68 /** 69 * @tc.name: liveness_analyzer_test_002 70 * @tc.desc: Verify the DumpLifeIntervals function. 71 * @tc.type: FUNC 72 * @tc.require: issueNumber 73 */ 74 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_002, TestSize.Level1) 75 { 76 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 77 const char *test_method_name = "func_main_0"; 78 bool status = false; 79 __anona4efd4bf0202(Graph* graph, std::string &method_name) 80 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 81 if (test_method_name != method_name) { 82 return; 83 } 84 status = true; 85 EXPECT_NE(graph, nullptr); 86 87 graph->RunPass<LivenessAnalyzer>(); 88 auto liveness_analyzer = &graph->GetAnalysis<LivenessAnalyzer>(); 89 90 Location location(Location::Kind::FP_REGISTER, 0); 91 for (auto a : liveness_analyzer->GetLifeIntervals()) { 92 a->SetLocation(location); 93 EXPECT_EQ(a->GetLocation().GetValue(), 0); 94 a->SetType(DataType::FLOAT32); 95 EXPECT_EQ(a->GetType(), DataType::FLOAT32); 96 } 97 98 std::stringstream out; 99 liveness_analyzer->DumpLifeIntervals(out); 100 std::string str = "BB 7\t[0:10)\n" 101 "v5\t[2:4)@ ; \n" 102 "v6\t[4:6)@ ; \n" 103 "v7\t[6:8)@ ; \n" 104 "v8\t[8:20)@ ; \n" 105 "BB 0\t[10:12)\n" 106 "BB 2\t[12:16)\n" 107 "v0\t[14:16)@ ; \n" 108 "BB 4\t[16:22)\n" 109 "v10\t[18:20)@ ; \n" 110 "v9\t[20:22)@ ; \n" 111 "BB 3\t[22:24)\n" 112 "BB 9\t[26:28)\n" 113 "BB 6\t[28:34)\n" 114 "v12\t[30:32)@ ; \n" 115 "v11\t[32:34)@ ; \n" 116 "BB 5\t[24:26)\n" 117 "BB 1\t[34:40)\n" 118 "v18\t[36:38)@ ; \n" 119 "v17\t[38:40)@ ; \n" 120 "BB 8\t[40:42)\n\n" 121 "Registers intervals\n-\n\n" 122 "Vector registers intervals\n" 123 "vr0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); " 124 "[38:40)\n\n" 125 "Stack slots intervals\n-\n"; 126 EXPECT_EQ(out.str(), str); 127 EXPECT_TRUE(location.IsFpRegister()); 128 129 Location location1(Location::Kind::REGISTER, 0); 130 for (auto a : liveness_analyzer->GetLifeIntervals()) { 131 a->SetLocation(location1); 132 } 133 out.clear(); 134 out.str(""); 135 liveness_analyzer->DumpLifeIntervals(out); 136 str = "BB 7\t[0:10)\n" 137 "v5\t[2:4)@ ; \n" 138 "v6\t[4:6)@ ; \n" 139 "v7\t[6:8)@ ; \n" 140 "v8\t[8:20)@ ; \n" 141 "BB 0\t[10:12)\n" 142 "BB 2\t[12:16)\n" 143 "v0\t[14:16)@ ; \n" 144 "BB 4\t[16:22)\n" 145 "v10\t[18:20)@ ; \n" 146 "v9\t[20:22)@ ; \n" 147 "BB 3\t[22:24)\n" 148 "BB 9\t[26:28)\n" 149 "BB 6\t[28:34)\n" 150 "v12\t[30:32)@ ; \n" 151 "v11\t[32:34)@ ; \n" 152 "BB 5\t[24:26)\n" 153 "BB 1\t[34:40)\n" 154 "v18\t[36:38)@ ; \n" 155 "v17\t[38:40)@ ; \n" 156 "BB 8\t[40:42)\n\n" 157 "Registers intervals\n" 158 "r0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); " 159 "[38:40)\n\n" 160 "Vector registers intervals\n-\n\n" 161 "Stack slots intervals\n-\n"; 162 EXPECT_EQ(out.str(), str); 163 EXPECT_TRUE(location1.IsRegister()); 164 165 Location location2(Location::Kind::STACK, 0); 166 for (auto a : liveness_analyzer->GetLifeIntervals()) { 167 a->SetLocation(location2); 168 } 169 out.clear(); 170 out.str(""); 171 liveness_analyzer->DumpLifeIntervals(out); 172 str = "BB 7\t[0:10)\n" 173 "v5\t[2:4)@ ; \n" 174 "v6\t[4:6)@ ; \n" 175 "v7\t[6:8)@ ; \n" 176 "v8\t[8:20)@ ; \n" 177 "BB 0\t[10:12)\n" 178 "BB 2\t[12:16)\n" 179 "v0\t[14:16)@ ; \n" 180 "BB 4\t[16:22)\n" 181 "v10\t[18:20)@ ; \n" 182 "v9\t[20:22)@ ; \n" 183 "BB 3\t[22:24)\n" 184 "BB 9\t[26:28)\n" 185 "BB 6\t[28:34)\n" 186 "v12\t[30:32)@ ; \n" 187 "v11\t[32:34)@ ; \n" 188 "BB 5\t[24:26)\n" 189 "BB 1\t[34:40)\n" 190 "v18\t[36:38)@ ; \n" 191 "v17\t[38:40)@ ; \n" 192 "BB 8\t[40:42)\n\n" 193 "Registers intervals\n-\n\n" 194 "Vector registers intervals\n-\n\n" 195 "Stack slots intervals\n" 196 "s0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); " 197 "[38:40)\n"; 198 EXPECT_EQ(out.str(), str); 199 EXPECT_TRUE(location2.IsStack()); 200 }); 201 EXPECT_TRUE(status); 202 } 203 204 /** 205 * @tc.name: liveness_analyzer_test_003 206 * @tc.desc: Verify the IsCallBlockingRegisters function. 207 * @tc.type: FUNC 208 * @tc.require: issueNumber 209 */ 210 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_003, TestSize.Level1) 211 { 212 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 213 const char *test_method_name = "func_main_0"; 214 bool status = false; 215 __anona4efd4bf0302(Graph* graph, std::string &method_name) 216 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 217 if (test_method_name != method_name) { 218 return; 219 } 220 status = true; 221 EXPECT_NE(graph, nullptr); 222 LivenessAnalyzer liveness_analyzer(graph); 223 for (auto bb : graph->GetBlocksRPO()) { 224 EXPECT_NE(bb, nullptr); 225 if (!bb->IsTry()) { 226 continue; 227 } 228 EXPECT_FALSE(liveness_analyzer.IsCallBlockingRegisters(bb->GetFirstInst())); 229 230 bb->GetFirstInst()->SetFlag(compiler::inst_flags::CALL); 231 EXPECT_TRUE(liveness_analyzer.IsCallBlockingRegisters(bb->GetFirstInst())); 232 } 233 }); 234 EXPECT_TRUE(status); 235 } 236 237 /** 238 * @tc.name: liveness_analyzer_test_004 239 * @tc.desc: Verify the AppendRange function. 240 * @tc.type: FUNC 241 * @tc.require: issueNumber 242 */ 243 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_004, TestSize.Level1) 244 { 245 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 246 const char *test_method_name = "func_main_0"; 247 bool status = false; 248 __anona4efd4bf0402(Graph* graph, std::string &method_name) 249 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 250 if (test_method_name != method_name) { 251 return; 252 } 253 status = true; 254 EXPECT_NE(graph, nullptr); 255 auto bb = graph->GetStartBlock(); 256 LifeNumber end = 2; // 2: It's a random number 257 LiveRange live_range(0, end); 258 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 259 260 life_intervals.SplitAt(1, graph->GetAllocator()); 261 EXPECT_NE(life_intervals.SplitAt(1, graph->GetAllocator()), nullptr); 262 life_intervals.AppendRange(live_range); 263 auto intervals = life_intervals.GetRanges(); 264 auto it = find(intervals.begin(), intervals.end(), live_range); 265 EXPECT_NE(it, intervals.end()); 266 LifeNumber begin = 3; // 3: It's a random number 267 LiveRange live_range1(begin, end + begin); 268 LifeIntervals life_intervals1(graph->GetAllocator(), bb->GetFirstInst(), live_range1); 269 EXPECT_NE(life_intervals1.SplitAt(4, graph->GetAllocator()), nullptr); 270 }); 271 EXPECT_TRUE(status); 272 } 273 274 /** 275 * @tc.name: liveness_analyzer_test_005 276 * @tc.desc: Verify the SplitAt function. 277 * @tc.type: FUNC 278 * @tc.require: issueNumber 279 */ 280 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_005, TestSize.Level1) 281 { 282 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 283 const char *test_method_name = "func_main_0"; 284 bool status = false; 285 __anona4efd4bf0502(Graph* graph, std::string &method_name) 286 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 287 if (test_method_name != method_name) { 288 return; 289 } 290 status = true; 291 EXPECT_NE(graph, nullptr); 292 auto bb = graph->GetStartBlock(); 293 LifeNumber end = 2; // 2: It's a random number 294 LiveRange live_range(0, end); 295 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 296 297 EXPECT_NE(life_intervals.SplitAt(1, graph->GetAllocator()), nullptr); 298 life_intervals.AppendRange(live_range); 299 auto intervals = life_intervals.GetRanges(); 300 auto it = find(intervals.begin(), intervals.end(), live_range); 301 EXPECT_NE(it, intervals.end()); 302 }); 303 EXPECT_TRUE(status); 304 } 305 306 /** 307 * @tc.name: liveness_analyzer_test_006 308 * @tc.desc: Verify the MergeSibling function. 309 * @tc.type: FUNC 310 * @tc.require: issueNumber 311 */ 312 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_006, TestSize.Level1) 313 { 314 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 315 const char *test_method_name = "func_main_0"; 316 bool status = false; 317 __anona4efd4bf0602(Graph* graph, std::string &method_name) 318 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 319 if (test_method_name != method_name) { 320 return; 321 } 322 status = true; 323 EXPECT_NE(graph, nullptr); 324 auto bb = graph->GetStartBlock(); 325 LifeNumber begin = 2; // 2: It's a random number 326 LiveRange live_range(begin, begin + 1); 327 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 328 329 LifeNumber ln = 3; // 3: It's a random number 330 life_intervals.AddUsePosition(ln); 331 EXPECT_NE(life_intervals.SplitAt(ln, graph->GetAllocator()), nullptr); 332 life_intervals.MergeSibling(); 333 EXPECT_EQ(life_intervals.GetSibling(), nullptr); 334 }); 335 EXPECT_TRUE(status); 336 } 337 338 /** 339 * @tc.name: liveness_analyzer_test_007 340 * @tc.desc: Verify the FindSiblingAt function. 341 * @tc.type: FUNC 342 * @tc.require: issueNumber 343 */ 344 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_007, TestSize.Level1) 345 { 346 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 347 const char *test_method_name = "func_main_0"; 348 bool status = false; 349 __anona4efd4bf0702(Graph* graph, std::string &method_name) 350 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 351 if (test_method_name != method_name) { 352 return; 353 } 354 status = true; 355 EXPECT_NE(graph, nullptr); 356 auto bb = graph->GetStartBlock(); 357 LifeNumber end = 2; // 2: It's a random number 358 LiveRange live_range(1, end); 359 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 360 361 EXPECT_NE(life_intervals.FindSiblingAt(1), nullptr); 362 }); 363 EXPECT_TRUE(status); 364 } 365 366 /** 367 * @tc.name: liveness_analyzer_test_008 368 * @tc.desc: Verify the FindSiblingAt function. 369 * @tc.type: FUNC 370 * @tc.require: issueNumber 371 */ 372 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_008, TestSize.Level1) 373 { 374 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 375 const char *test_method_name = "func_main_0"; 376 bool status = false; 377 __anona4efd4bf0802(Graph* graph, std::string &method_name) 378 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 379 if (test_method_name != method_name) { 380 return; 381 } 382 status = true; 383 EXPECT_NE(graph, nullptr); 384 auto bb = graph->GetStartBlock(); 385 LifeNumber begin = 2; // 2: It's a random number 386 LiveRange live_range(begin, 1); 387 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 388 389 EXPECT_EQ(life_intervals.FindSiblingAt(1), nullptr); 390 LiveRange live_range1(begin, 1); 391 EXPECT_TRUE(life_intervals.Intersects(live_range1)); 392 }); 393 EXPECT_TRUE(status); 394 } 395 396 /** 397 * @tc.name: liveness_analyzer_test_009 398 * @tc.desc: Verify the GetFirstIntersectionWith function. 399 * @tc.type: FUNC 400 * @tc.require: issueNumber 401 */ 402 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_009, TestSize.Level1) 403 { 404 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 405 const char *test_method_name = "func_main_0"; 406 bool status = false; 407 __anona4efd4bf0902(Graph* graph, std::string &method_name) 408 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 409 if (test_method_name != method_name) { 410 return; 411 } 412 status = true; 413 EXPECT_NE(graph, nullptr); 414 auto bb = graph->GetStartBlock(); 415 LifeNumber begin = 2; // 2: It's a random number 416 LiveRange live_range(begin, 1); 417 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 418 419 LifeIntervals other(graph->GetAllocator()); 420 EXPECT_EQ(life_intervals.GetFirstIntersectionWith(&other, 1), INVALID_VN); 421 }); 422 EXPECT_TRUE(status); 423 } 424 425 /** 426 * @tc.name: liveness_analyzer_test_010 427 * @tc.desc: Verify the GetFirstIntersectionWith function. 428 * @tc.type: FUNC 429 * @tc.require: issueNumber 430 */ 431 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_010, TestSize.Level1) 432 { 433 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 434 const char *test_method_name = "func_main_0"; 435 bool status = false; 436 __anona4efd4bf0a02(Graph* graph, std::string &method_name) 437 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 438 if (test_method_name != method_name) { 439 return; 440 } 441 status = true; 442 EXPECT_NE(graph, nullptr); 443 auto bb = graph->GetStartBlock(); 444 LifeNumber begin = 7; // 7: It's a random number 445 LifeNumber end = 5; // 5: It's a random number 446 LiveRange live_range(begin, end + 2); 447 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 448 449 LifeIntervals other(graph->GetAllocator()); 450 451 LifeNumber begin1 = 31; // 31: It's a random number 452 LiveRange live_range1(begin1, begin1 + 1); 453 454 other.AppendRange(live_range1); 455 auto intervals = life_intervals.GetRanges(); 456 auto it = find(intervals.begin(), intervals.end(), live_range); 457 EXPECT_NE(it, intervals.end()); 458 EXPECT_EQ(life_intervals.GetFirstIntersectionWith(&other, 0), INVALID_LIFE_NUMBER); 459 }); 460 EXPECT_TRUE(status); 461 } 462 463 /** 464 * @tc.name: liveness_analyzer_test_011 465 * @tc.desc: Verify the SplitCover function. 466 * @tc.type: FUNC 467 * @tc.require: issueNumber 468 */ 469 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_011, TestSize.Level1) 470 { 471 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 472 const char *test_method_name = "func_main_0"; 473 bool status = false; 474 __anona4efd4bf0b02(Graph* graph, std::string &method_name) 475 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 476 if (test_method_name != method_name) { 477 return; 478 } 479 status = true; 480 EXPECT_NE(graph, nullptr); 481 auto bb = graph->GetStartBlock(); 482 LifeNumber first_end = 3; // 3: It's a random number 483 LiveRange firstlive_range(0, first_end); 484 LifeIntervals firstlife_intervals(graph->GetAllocator(), bb->GetFirstInst(), firstlive_range); 485 486 LifeNumber first_position = 2; // 2: It's a random number 487 EXPECT_TRUE(firstlife_intervals.SplitCover(first_position)); 488 489 LifeNumber secondBegin = 2; // 2: It's a random number 490 LiveRange secondlive_range(secondBegin, 1); 491 LifeIntervals second_life_intervals(graph->GetAllocator(), bb->GetFirstInst(), secondlive_range); 492 493 EXPECT_FALSE(second_life_intervals.SplitCover(1)); 494 }); 495 EXPECT_TRUE(status); 496 } 497 498 /** 499 * @tc.name: liveness_analyzer_test_012 500 * @tc.desc: Verify the SetPhysicalReg function. 501 * @tc.type: FUNC 502 * @tc.require: issueNumber 503 */ 504 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_012, TestSize.Level1) 505 { 506 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 507 const char *test_method_name = "func_main_0"; 508 bool status = false; 509 __anona4efd4bf0c02(Graph* graph, std::string &method_name) 510 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 511 if (test_method_name != method_name) { 512 return; 513 } 514 status = true; 515 EXPECT_NE(graph, nullptr); 516 auto bb = graph->GetStartBlock(); 517 LifeNumber begin = 2; // 2: It's a random number 518 LiveRange live_range(begin, 1); 519 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 520 521 life_intervals.SetPhysicalReg(1, DataType::Type::INT64); 522 EXPECT_TRUE(life_intervals.HasReg()); 523 }); 524 EXPECT_TRUE(status); 525 } 526 527 /** 528 * @tc.name: liveness_analyzer_test_013 529 * @tc.desc: Verify the ClearLocation function. 530 * @tc.type: FUNC 531 * @tc.require: issueNumber 532 */ 533 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_013, TestSize.Level1) 534 { 535 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 536 const char *test_method_name = "func_main_0"; 537 bool status = false; 538 __anona4efd4bf0d02(Graph* graph, std::string &method_name) 539 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 540 if (test_method_name != method_name) { 541 return; 542 } 543 status = true; 544 EXPECT_NE(graph, nullptr); 545 auto bb = graph->GetStartBlock(); 546 LifeNumber begin = 2; // 2: It's a random number 547 LiveRange live_range(begin, 1); 548 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range); 549 life_intervals.ClearLocation(); 550 EXPECT_EQ(life_intervals.GetLocation().GetKind(), Location::Kind::INVALID); 551 }); 552 EXPECT_TRUE(status); 553 } 554 555 /** 556 * @tc.name: liveness_analyzer_test_014 557 * @tc.desc: Verify the Contains function. 558 * @tc.type: FUNC 559 * @tc.require: issueNumber 560 */ 561 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_014, TestSize.Level1) 562 { 563 LifeNumber begin = 2; // 2: It's a random number 564 LiveRange live_range(begin, 1); 565 EXPECT_TRUE(live_range.Contains(live_range)); 566 LifeNumber number = 3; // 3: It's a random number 567 EXPECT_FALSE(live_range.Contains(number)); 568 } 569 570 /** 571 * @tc.name: liveness_analyzer_test_015 572 * @tc.desc: Verify the Cleanup function. 573 * @tc.type: FUNC 574 * @tc.require: issueNumber 575 */ 576 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_015, TestSize.Level1) 577 { 578 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 579 const char *test_method_name = "func_main_0"; 580 bool status = false; 581 __anona4efd4bf0e02(Graph* graph, std::string &method_name) 582 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 583 if (test_method_name != method_name) { 584 return; 585 } 586 status = true; 587 EXPECT_NE(graph, nullptr); 588 589 EXPECT_TRUE(graph->RunPass<LivenessAnalyzer>()); 590 auto liveness_analyzer = &graph->GetAnalysis<LivenessAnalyzer>(); 591 liveness_analyzer->Cleanup(); 592 }); 593 EXPECT_TRUE(status); 594 } 595 } // namespace panda::compiler 596