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 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_001, TestSize.Level1)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
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 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_002, TestSize.Level1)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
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:44)\n"
118 "v18\t[36:38)@ ; \n"
119 "v17\t[38:40)@ ; \n"
120 "v20\t[40:42)@ ; \n"
121 "v19\t[42:44)@ ; \n"
122 "BB 8\t[44:46)\n\n"
123 "Registers intervals\n-\n\n"
124 "Vector registers intervals\n"
125 "vr0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); "
126 "[38:40); [40:42); [42:44)\n\n"
127 "Stack slots intervals\n-\n";
128 EXPECT_EQ(out.str(), str);
129 EXPECT_TRUE(location.IsFpRegister());
130
131 Location location1(Location::Kind::REGISTER, 0);
132 for (auto a : liveness_analyzer->GetLifeIntervals()) {
133 a->SetLocation(location1);
134 }
135 out.clear();
136 out.str("");
137 liveness_analyzer->DumpLifeIntervals(out);
138 str = "BB 7\t[0:10)\n"
139 "v5\t[2:4)@ ; \n"
140 "v6\t[4:6)@ ; \n"
141 "v7\t[6:8)@ ; \n"
142 "v8\t[8:20)@ ; \n"
143 "BB 0\t[10:12)\n"
144 "BB 2\t[12:16)\n"
145 "v0\t[14:16)@ ; \n"
146 "BB 4\t[16:22)\n"
147 "v10\t[18:20)@ ; \n"
148 "v9\t[20:22)@ ; \n"
149 "BB 3\t[22:24)\n"
150 "BB 9\t[26:28)\n"
151 "BB 6\t[28:34)\n"
152 "v12\t[30:32)@ ; \n"
153 "v11\t[32:34)@ ; \n"
154 "BB 5\t[24:26)\n"
155 "BB 1\t[34:44)\n"
156 "v18\t[36:38)@ ; \n"
157 "v17\t[38:40)@ ; \n"
158 "v20\t[40:42)@ ; \n"
159 "v19\t[42:44)@ ; \n"
160 "BB 8\t[44:46)\n\n"
161 "Registers intervals\n"
162 "r0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); "
163 "[38:40); [40:42); [42:44)\n\n"
164 "Vector registers intervals\n-\n\n"
165 "Stack slots intervals\n-\n";
166 EXPECT_EQ(out.str(), str);
167 EXPECT_TRUE(location1.IsRegister());
168
169 Location location2(Location::Kind::STACK, 0);
170 for (auto a : liveness_analyzer->GetLifeIntervals()) {
171 a->SetLocation(location2);
172 }
173 out.clear();
174 out.str("");
175 liveness_analyzer->DumpLifeIntervals(out);
176 str = "BB 7\t[0:10)\n"
177 "v5\t[2:4)@ ; \n"
178 "v6\t[4:6)@ ; \n"
179 "v7\t[6:8)@ ; \n"
180 "v8\t[8:20)@ ; \n"
181 "BB 0\t[10:12)\n"
182 "BB 2\t[12:16)\n"
183 "v0\t[14:16)@ ; \n"
184 "BB 4\t[16:22)\n"
185 "v10\t[18:20)@ ; \n"
186 "v9\t[20:22)@ ; \n"
187 "BB 3\t[22:24)\n"
188 "BB 9\t[26:28)\n"
189 "BB 6\t[28:34)\n"
190 "v12\t[30:32)@ ; \n"
191 "v11\t[32:34)@ ; \n"
192 "BB 5\t[24:26)\n"
193 "BB 1\t[34:44)\n"
194 "v18\t[36:38)@ ; \n"
195 "v17\t[38:40)@ ; \n"
196 "v20\t[40:42)@ ; \n"
197 "v19\t[42:44)@ ; \n"
198 "BB 8\t[44:46)\n\n"
199 "Registers intervals\n-\n\n"
200 "Vector registers intervals\n-\n\n"
201 "Stack slots intervals\n"
202 "s0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); "
203 "[38:40); [40:42); [42:44)\n";
204 EXPECT_EQ(out.str(), str);
205 EXPECT_TRUE(location2.IsStack());
206 });
207 EXPECT_TRUE(status);
208 }
209
210 /**
211 * @tc.name: liveness_analyzer_test_003
212 * @tc.desc: Verify the IsCallBlockingRegisters function.
213 * @tc.type: FUNC
214 * @tc.require: issueNumber
215 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_003, TestSize.Level1)216 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_003, TestSize.Level1)
217 {
218 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
219 const char *test_method_name = "func_main_0";
220 bool status = false;
221
222 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
223 if (test_method_name != method_name) {
224 return;
225 }
226 status = true;
227 EXPECT_NE(graph, nullptr);
228 LivenessAnalyzer liveness_analyzer(graph);
229 for (auto bb : graph->GetBlocksRPO()) {
230 EXPECT_NE(bb, nullptr);
231 if (!bb->IsTry()) {
232 continue;
233 }
234 EXPECT_FALSE(liveness_analyzer.IsCallBlockingRegisters(bb->GetFirstInst()));
235
236 bb->GetFirstInst()->SetFlag(compiler::inst_flags::CALL);
237 EXPECT_TRUE(liveness_analyzer.IsCallBlockingRegisters(bb->GetFirstInst()));
238 }
239 });
240 EXPECT_TRUE(status);
241 }
242
243 /**
244 * @tc.name: liveness_analyzer_test_004
245 * @tc.desc: Verify the AppendRange function.
246 * @tc.type: FUNC
247 * @tc.require: issueNumber
248 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_004, TestSize.Level1)249 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_004, TestSize.Level1)
250 {
251 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
252 const char *test_method_name = "func_main_0";
253 bool status = false;
254
255 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
256 if (test_method_name != method_name) {
257 return;
258 }
259 status = true;
260 EXPECT_NE(graph, nullptr);
261 auto bb = graph->GetStartBlock();
262 LifeNumber end = 2; // 2: It's a random number
263 LiveRange live_range(0, end);
264 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
265
266 life_intervals.SplitAt(1, graph->GetAllocator());
267 EXPECT_NE(life_intervals.SplitAt(1, graph->GetAllocator()), nullptr);
268 life_intervals.AppendRange(live_range);
269 auto intervals = life_intervals.GetRanges();
270 auto it = find(intervals.begin(), intervals.end(), live_range);
271 EXPECT_NE(it, intervals.end());
272 LifeNumber begin = 3; // 3: It's a random number
273 LiveRange live_range1(begin, end + begin);
274 LifeIntervals life_intervals1(graph->GetAllocator(), bb->GetFirstInst(), live_range1);
275 EXPECT_NE(life_intervals1.SplitAt(4, graph->GetAllocator()), nullptr);
276 });
277 EXPECT_TRUE(status);
278 }
279
280 /**
281 * @tc.name: liveness_analyzer_test_005
282 * @tc.desc: Verify the SplitAt function.
283 * @tc.type: FUNC
284 * @tc.require: issueNumber
285 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_005, TestSize.Level1)286 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_005, TestSize.Level1)
287 {
288 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
289 const char *test_method_name = "func_main_0";
290 bool status = false;
291
292 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
293 if (test_method_name != method_name) {
294 return;
295 }
296 status = true;
297 EXPECT_NE(graph, nullptr);
298 auto bb = graph->GetStartBlock();
299 LifeNumber end = 2; // 2: It's a random number
300 LiveRange live_range(0, end);
301 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
302
303 EXPECT_NE(life_intervals.SplitAt(1, graph->GetAllocator()), nullptr);
304 life_intervals.AppendRange(live_range);
305 auto intervals = life_intervals.GetRanges();
306 auto it = find(intervals.begin(), intervals.end(), live_range);
307 EXPECT_NE(it, intervals.end());
308 });
309 EXPECT_TRUE(status);
310 }
311
312 /**
313 * @tc.name: liveness_analyzer_test_006
314 * @tc.desc: Verify the MergeSibling function.
315 * @tc.type: FUNC
316 * @tc.require: issueNumber
317 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_006, TestSize.Level1)318 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_006, TestSize.Level1)
319 {
320 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
321 const char *test_method_name = "func_main_0";
322 bool status = false;
323
324 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
325 if (test_method_name != method_name) {
326 return;
327 }
328 status = true;
329 EXPECT_NE(graph, nullptr);
330 auto bb = graph->GetStartBlock();
331 LifeNumber begin = 2; // 2: It's a random number
332 LiveRange live_range(begin, begin + 1);
333 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
334
335 LifeNumber ln = 3; // 3: It's a random number
336 life_intervals.AddUsePosition(ln);
337 EXPECT_NE(life_intervals.SplitAt(ln, graph->GetAllocator()), nullptr);
338 life_intervals.MergeSibling();
339 EXPECT_EQ(life_intervals.GetSibling(), nullptr);
340 });
341 EXPECT_TRUE(status);
342 }
343
344 /**
345 * @tc.name: liveness_analyzer_test_007
346 * @tc.desc: Verify the FindSiblingAt function.
347 * @tc.type: FUNC
348 * @tc.require: issueNumber
349 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_007, TestSize.Level1)350 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_007, TestSize.Level1)
351 {
352 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
353 const char *test_method_name = "func_main_0";
354 bool status = false;
355
356 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
357 if (test_method_name != method_name) {
358 return;
359 }
360 status = true;
361 EXPECT_NE(graph, nullptr);
362 auto bb = graph->GetStartBlock();
363 LifeNumber end = 2; // 2: It's a random number
364 LiveRange live_range(1, end);
365 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
366
367 EXPECT_NE(life_intervals.FindSiblingAt(1), nullptr);
368 });
369 EXPECT_TRUE(status);
370 }
371
372 /**
373 * @tc.name: liveness_analyzer_test_008
374 * @tc.desc: Verify the FindSiblingAt function.
375 * @tc.type: FUNC
376 * @tc.require: issueNumber
377 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_008, TestSize.Level1)378 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_008, TestSize.Level1)
379 {
380 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
381 const char *test_method_name = "func_main_0";
382 bool status = false;
383
384 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
385 if (test_method_name != method_name) {
386 return;
387 }
388 status = true;
389 EXPECT_NE(graph, nullptr);
390 auto bb = graph->GetStartBlock();
391 LifeNumber begin = 2; // 2: It's a random number
392 LiveRange live_range(begin, 1);
393 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
394
395 EXPECT_EQ(life_intervals.FindSiblingAt(1), nullptr);
396 LiveRange live_range1(begin, 1);
397 EXPECT_TRUE(life_intervals.Intersects(live_range1));
398 });
399 EXPECT_TRUE(status);
400 }
401
402 /**
403 * @tc.name: liveness_analyzer_test_009
404 * @tc.desc: Verify the GetFirstIntersectionWith function.
405 * @tc.type: FUNC
406 * @tc.require: issueNumber
407 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_009, TestSize.Level1)408 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_009, TestSize.Level1)
409 {
410 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
411 const char *test_method_name = "func_main_0";
412 bool status = false;
413
414 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
415 if (test_method_name != method_name) {
416 return;
417 }
418 status = true;
419 EXPECT_NE(graph, nullptr);
420 auto bb = graph->GetStartBlock();
421 LifeNumber begin = 2; // 2: It's a random number
422 LiveRange live_range(begin, 1);
423 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
424
425 LifeIntervals other(graph->GetAllocator());
426 EXPECT_EQ(life_intervals.GetFirstIntersectionWith(&other, 1), INVALID_VN);
427 });
428 EXPECT_TRUE(status);
429 }
430
431 /**
432 * @tc.name: liveness_analyzer_test_010
433 * @tc.desc: Verify the GetFirstIntersectionWith function.
434 * @tc.type: FUNC
435 * @tc.require: issueNumber
436 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_010, TestSize.Level1)437 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_010, TestSize.Level1)
438 {
439 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
440 const char *test_method_name = "func_main_0";
441 bool status = false;
442
443 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
444 if (test_method_name != method_name) {
445 return;
446 }
447 status = true;
448 EXPECT_NE(graph, nullptr);
449 auto bb = graph->GetStartBlock();
450 LifeNumber begin = 7; // 7: It's a random number
451 LifeNumber end = 5; // 5: It's a random number
452 LiveRange live_range(begin, end + 2);
453 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
454
455 LifeIntervals other(graph->GetAllocator());
456
457 LifeNumber begin1 = 31; // 31: It's a random number
458 LiveRange live_range1(begin1, begin1 + 1);
459
460 other.AppendRange(live_range1);
461 auto intervals = life_intervals.GetRanges();
462 auto it = find(intervals.begin(), intervals.end(), live_range);
463 EXPECT_NE(it, intervals.end());
464 EXPECT_EQ(life_intervals.GetFirstIntersectionWith(&other, 0), INVALID_LIFE_NUMBER);
465 });
466 EXPECT_TRUE(status);
467 }
468
469 /**
470 * @tc.name: liveness_analyzer_test_011
471 * @tc.desc: Verify the SplitCover function.
472 * @tc.type: FUNC
473 * @tc.require: issueNumber
474 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_011, TestSize.Level1)475 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_011, TestSize.Level1)
476 {
477 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
478 const char *test_method_name = "func_main_0";
479 bool status = false;
480
481 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
482 if (test_method_name != method_name) {
483 return;
484 }
485 status = true;
486 EXPECT_NE(graph, nullptr);
487 auto bb = graph->GetStartBlock();
488 LifeNumber first_end = 3; // 3: It's a random number
489 LiveRange firstlive_range(0, first_end);
490 LifeIntervals firstlife_intervals(graph->GetAllocator(), bb->GetFirstInst(), firstlive_range);
491
492 LifeNumber first_position = 2; // 2: It's a random number
493 EXPECT_TRUE(firstlife_intervals.SplitCover(first_position));
494
495 LifeNumber secondBegin = 2; // 2: It's a random number
496 LiveRange secondlive_range(secondBegin, 1);
497 LifeIntervals second_life_intervals(graph->GetAllocator(), bb->GetFirstInst(), secondlive_range);
498
499 EXPECT_FALSE(second_life_intervals.SplitCover(1));
500 });
501 EXPECT_TRUE(status);
502 }
503
504 /**
505 * @tc.name: liveness_analyzer_test_012
506 * @tc.desc: Verify the SetPhysicalReg function.
507 * @tc.type: FUNC
508 * @tc.require: issueNumber
509 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_012, TestSize.Level1)510 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_012, TestSize.Level1)
511 {
512 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
513 const char *test_method_name = "func_main_0";
514 bool status = false;
515
516 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
517 if (test_method_name != method_name) {
518 return;
519 }
520 status = true;
521 EXPECT_NE(graph, nullptr);
522 auto bb = graph->GetStartBlock();
523 LifeNumber begin = 2; // 2: It's a random number
524 LiveRange live_range(begin, 1);
525 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
526
527 life_intervals.SetPhysicalReg(1, DataType::Type::INT64);
528 EXPECT_TRUE(life_intervals.HasReg());
529 });
530 EXPECT_TRUE(status);
531 }
532
533 /**
534 * @tc.name: liveness_analyzer_test_013
535 * @tc.desc: Verify the ClearLocation function.
536 * @tc.type: FUNC
537 * @tc.require: issueNumber
538 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_013, TestSize.Level1)539 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_013, TestSize.Level1)
540 {
541 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
542 const char *test_method_name = "func_main_0";
543 bool status = false;
544
545 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
546 if (test_method_name != method_name) {
547 return;
548 }
549 status = true;
550 EXPECT_NE(graph, nullptr);
551 auto bb = graph->GetStartBlock();
552 LifeNumber begin = 2; // 2: It's a random number
553 LiveRange live_range(begin, 1);
554 LifeIntervals life_intervals(graph->GetAllocator(), bb->GetFirstInst(), live_range);
555 life_intervals.ClearLocation();
556 EXPECT_EQ(life_intervals.GetLocation().GetKind(), Location::Kind::INVALID);
557 });
558 EXPECT_TRUE(status);
559 }
560
561 /**
562 * @tc.name: liveness_analyzer_test_014
563 * @tc.desc: Verify the Contains function.
564 * @tc.type: FUNC
565 * @tc.require: issueNumber
566 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_014, TestSize.Level1)567 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_014, TestSize.Level1)
568 {
569 LifeNumber begin = 2; // 2: It's a random number
570 LiveRange live_range(begin, 1);
571 EXPECT_TRUE(live_range.Contains(live_range));
572 LifeNumber number = 3; // 3: It's a random number
573 EXPECT_FALSE(live_range.Contains(number));
574 }
575
576 /**
577 * @tc.name: liveness_analyzer_test_015
578 * @tc.desc: Verify the Cleanup function.
579 * @tc.type: FUNC
580 * @tc.require: issueNumber
581 */
HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_015, TestSize.Level1)582 HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_015, TestSize.Level1)
583 {
584 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc";
585 const char *test_method_name = "func_main_0";
586 bool status = false;
587
588 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) {
589 if (test_method_name != method_name) {
590 return;
591 }
592 status = true;
593 EXPECT_NE(graph, nullptr);
594
595 EXPECT_TRUE(graph->RunPass<LivenessAnalyzer>());
596 auto liveness_analyzer = &graph->GetAnalysis<LivenessAnalyzer>();
597 liveness_analyzer->Cleanup();
598 });
599 EXPECT_TRUE(status);
600 }
601 } // namespace panda::compiler
602