• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstring>
17 #include <gtest/gtest.h>
18 #include <memory>
19 #include <iomanip>
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 
24 #include "bytecode_optimizer/reg_encoder.h"
25 #include "bytecode_optimizer/reg_acc_alloc.h"
26 #include "compiler_options.h"
27 #include "constants.h"
28 #include "compiler/optimizer/analysis/rpo.h"
29 #include "compiler/optimizer/ir_builder/phi_resolver.h"
30 #include "compiler/optimizer/optimizations/vn.h"
31 #include "compiler/optimizer/optimizations/lowering.h"
32 #include "compiler/optimizer/optimizations/move_constants.h"
33 #include "compiler/optimizer/pass_manager.h"
34 #include "graph.h"
35 #include "graph.cpp"
36 #include "graph_checker.h"
37 #include "graph_test.h"
38 #include "graph_visitor.h"
39 #include "inst.h"
40 #include "locations.h"
41 #include "mem/pool_manager.h"
42 
43 using namespace testing::ext;
44 
45 namespace panda::compiler {
46 
47 class CompilerGraphTest : public testing::Test {
48 public:
SetUpTestCase(void)49     static void SetUpTestCase(void) {}
TearDownTestCase(void)50     static void TearDownTestCase(void) {}
SetUp()51     void SetUp() {}
TearDown()52     void TearDown() {}
53 
54     GraphTest graph_test_;
55 };
56 
57 /**
58  * @tc.name: graph_test_001
59  * @tc.desc: Verify the MarkBlocksRec function.
60  * @tc.type: FUNC
61  * @tc.require: issueNumber
62  */
63 HWTEST_F(CompilerGraphTest, graph_test_001, TestSize.Level1)
64 {
65     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
66     const char *test_method_name = "func_main_0";
67     bool status = false;
__anon65fffef30102(Graph* graph, std::string &method_name) 68     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
69         if (test_method_name != method_name) {
70             return;
71         }
72         status = true;
73         EXPECT_NE(graph, nullptr);
74         auto start_block = graph->GetStartBlock();
75         Marker mrk = 16;  // 16: random number
76         MarkBlocksRec(mrk, start_block);
77         EXPECT_TRUE(start_block->IsMarked(mrk));
78     });
79     EXPECT_TRUE(status);
80 }
81 
82 /**
83  * @tc.name: graph_test_002
84  * @tc.desc: Verify the DisconnectBlockRec function.
85  * @tc.type: FUNC
86  * @tc.require: issueNumber
87  */
88 HWTEST_F(CompilerGraphTest, graph_test_002, TestSize.Level1)
89 {
90     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
91     const char *test_method_name = "func_main_0";
92     bool status = false;
__anon65fffef30202(Graph* graph, std::string &method_name) 93     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
94         if (test_method_name != method_name) {
95             return;
96         }
97         status = true;
98         EXPECT_NE(graph, nullptr);
99 
100         BasicBlock *bb = nullptr;
101         for (const auto &block : graph->GetVectorBlocks()) {
102             if (block == nullptr) {
103                 continue;
104             }
105             bb = block;
106         }
107         graph->DisconnectBlockRec(bb, true, true);
108         EXPECT_NE(bb->GetGraph(), nullptr);
109     });
110     EXPECT_TRUE(status);
111 }
112 
113 /**
114  * @tc.name: graph_test_003
115  * @tc.desc: Verify the GetParametersSlotsCount function.
116  * @tc.type: FUNC
117  * @tc.require: issueNumber
118  */
119 HWTEST_F(CompilerGraphTest, graph_test_003, TestSize.Level1)
120 {
121     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
122     const char *test_method_name = "func_main_0";
123     bool status = false;
__anon65fffef30302(Graph* graph, std::string &method_name) 124     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
125         if (test_method_name != method_name) {
126             return;
127         }
128         status = true;
129         EXPECT_NE(graph, nullptr);
130         EXPECT_EQ(graph->GetParametersSlotsCount(), 0);
131     });
132     EXPECT_TRUE(status);
133 }
134 
135 /**
136  * @tc.name: graph_test_004
137  * @tc.desc: Verify the GetBranchCounter function.
138  * @tc.type: FUNC
139  * @tc.require: issueNumber
140  */
141 HWTEST_F(CompilerGraphTest, graph_test_004, TestSize.Level1)
142 {
143     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
144     const char *test_method_name = "func5";
145     bool status = false;
__anon65fffef30402(Graph* graph, std::string &method_name) 146     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
147         if (test_method_name != method_name) {
148             return;
149         }
150 
151         EXPECT_NE(graph, nullptr);
152         for (const auto &block : graph->GetVectorBlocks()) {
153             if (block == nullptr) {
154                 continue;
155             }
156             for (auto inst : block->AllInsts()) {
157                 if (inst->GetOpcode() != Opcode::IfImm) {
158                     continue;
159                 }
160                 status = true;
161                 EXPECT_EQ(graph->GetBranchCounter(block, true), 1);
162                 block->GetLastInst()->SetOpcode(Opcode::If);
163                 EXPECT_EQ(block->GetLastInst()->GetOpcode(), Opcode::If);
164             }
165         }
166     });
167     EXPECT_TRUE(status);
168 }
169 
170 /**
171  * @tc.name: graph_test_005
172  * @tc.desc: Verify the RemoveUnreachableBlocks function.
173  * @tc.type: FUNC
174  * @tc.require: issueNumber
175  */
176 HWTEST_F(CompilerGraphTest,  graph_test_005, TestSize.Level1)
177 {
178     std::string pfile = GRAPH_TEST_ABC_DIR "testTryCatch.abc";
179     const char *test_method_name = "func_main_0";
180     bool status = false;
__anon65fffef30502(Graph* graph, std::string &method_name) 181     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
182         if (test_method_name != method_name) {
183             return;
184         }
185 
186         EXPECT_NE(graph, nullptr);
187         status = true;
188         auto size = graph->GetBlocksRPO().size();
189         graph->RemoveUnreachableBlocks();
190         EXPECT_EQ(graph->GetBlocksRPO().size(), size);
191     });
192     EXPECT_TRUE(status);
193 }
194 
195 /**
196  * @tc.name: graph_test_006
197  * @tc.desc: Verify the FindOrAddConstant function.
198  * @tc.type: FUNC
199  * @tc.require: issueNumber
200  */
201 HWTEST_F(CompilerGraphTest,  graph_test_006, TestSize.Level1)
202 {
203     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
204     const char *test_method_name = "func5";
205     bool status = false;
__anon65fffef30602(Graph* graph, std::string &method_name) 206     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
207         if (test_method_name != method_name) {
208             return;
209         }
210 
211         EXPECT_NE(graph, nullptr);
212         ConstantInst first_constant(Opcode::Constant, 0, false);
213         first_constant.SetType(DataType::Type::ANY);
214         for (auto bb : graph->GetBlocksRPO()) {
215             for (auto inst : bb->AllInsts()) {
216                 if (inst->GetOpcode() != Opcode::Constant) {
217                     continue;
218                 }
219 
220                 status = true;
221                 auto constant = inst->CastToConstant();
222                 EXPECT_TRUE(graph->FindOrAddConstant(constant)->HasType());
223             }
224         }
225         EXPECT_NE(graph->FindOrAddConstant(&first_constant), nullptr);
226     });
227     EXPECT_TRUE(status);
228 }
229 
230 /**
231  * @tc.name: graph_test_007
232  * @tc.desc: Verify the DumpThrowableInsts function.
233  * @tc.type: FUNC
234  * @tc.require: issueNumber
235  */
236 HWTEST_F(CompilerGraphTest,  graph_test_007, TestSize.Level1)
237 {
238     std::stringstream out;
239     std::string pfile = GRAPH_TEST_ABC_DIR "moduleTryCatch.abc";
240     const char *test_method_name = "func_main_0";
241     bool status = false;
242     graph_test_.TestBuildGraphFromFile(pfile,
__anon65fffef30702(Graph* graph, std::string &method_name) 243         [&test_method_name, &out, &status](Graph* graph, std::string &method_name) {
244             if (test_method_name != method_name) {
245                 return;
246             }
247             status = true;
248             EXPECT_NE(graph, nullptr);
249             graph->DumpThrowableInsts(&out);
250             std::string str = "Throwable Inst   "
251                             "22.void Intrinsic.trystglobalbyname v21, v23"
252                             "                                                         bc: 0x0000001f\n"
253                             "Catch handlers: BB 9\n";
254             EXPECT_EQ(out.str(), str);
255         });
256     EXPECT_TRUE(status);
257 }
258 
259 /**
260  * @tc.name: graph_test_008
261  * @tc.desc: Verify the GetMethodFullName function.
262  * @tc.type: FUNC
263  * @tc.require: issueNumber
264  */
265 HWTEST_F(CompilerGraphTest,  graph_test_011, TestSize.Level1)
266 {
267     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
268     const char *test_method_name = "func_main_0";
269     bool status = false;
__anon65fffef30802(Graph* graph, std::string &method_name) 270     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
271         if (test_method_name != method_name) {
272             return;
273         }
274         status = true;
275         EXPECT_NE(graph, nullptr);
276         std::string str = GetMethodFullName(graph, graph->GetMethod());
277         EXPECT_EQ(str, "L_GLOBAL;::func_main_0");
278     });
279     EXPECT_TRUE(status);
280 }
281 
282 /**
283  * @tc.name: graph_test_012
284  * @tc.desc: Verify the InitDefaultLocations function.
285  * @tc.type: FUNC
286  * @tc.require: issueNumber
287  */
288 HWTEST_F(CompilerGraphTest,  graph_test_012, TestSize.Level1)
289 {
290     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
291     const char* test_method_name = "func_main_0";
292     bool status = false;
__anon65fffef30902(Graph* graph, std::string &method_name) 293     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
294         if (test_method_name != method_name) {
295             return;
296         }
297         status = true;
298         EXPECT_NE(graph, nullptr);
299         graph->InitDefaultLocations();
300         EXPECT_TRUE(graph->IsDefaultLocationsInit());
301     });
302     EXPECT_TRUE(status);
303 }
304 
305 /**
306  * @tc.name: graph_test_013
307  * @tc.desc: Verify the MakeStackParameter function.
308  * @tc.type: FUNC
309  * @tc.require: issueNumber
310  */
311 HWTEST_F(CompilerGraphTest,  graph_test_013, TestSize.Level1)
312 {
313     Location locations(Location::Kind::STACK_PARAMETER, 2);  // 2: random number
314     Location location1(Location::Kind::REGISTER, 1);
315     Location location;
316     locations.MakeRegister(2, DataType::Type::FLOAT32);  // 2: random number
317     EXPECT_TRUE(location.MakeStackSlot(3).IsStack());  // 3: random number
318     EXPECT_EQ(location1.MakeStackParameter(4).GetValue(), 4);  // 4: random number
319 }
320 
321 /**
322  * @tc.name: graph_test_014
323  * @tc.desc: Verify the AddNewParameter function.
324  * @tc.type: FUNC
325  * @tc.require: issueNumber
326  */
327 HWTEST_F(CompilerGraphTest,  graph_test_014, TestSize.Level1)
328 {
329     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
330     const char* test_method_name = "func_main_0";
331     bool status = false;
__anon65fffef30a02(Graph* graph, std::string &method_name) 332     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
333         if (test_method_name != method_name) {
334             return;
335         }
336         status = true;
337         EXPECT_NE(graph, nullptr);
338         uint16_t arg_number = 16;  // 16: random number
339         auto inst = graph->AddNewParameter(arg_number);
340         EXPECT_NE(inst, nullptr);
341         EXPECT_TRUE(inst->IsParameter());
342     });
343     EXPECT_TRUE(status);
344 }
345 
346 /**
347  * @tc.name: graph_test_015
348  * @tc.desc: Verify the RemoveConstFromList function.
349  * @tc.type: FUNC
350  * @tc.require: issueNumber
351  */
352 HWTEST_F(CompilerGraphTest,  graph_test_015, TestSize.Level1)
353 {
354     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
355     const char* test_method_name = "func_main_0";
356     bool status = false;
__anon65fffef30b02(Graph* graph, std::string &method_name) 357     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
358         if (test_method_name != method_name) {
359             return;
360         }
361         status = true;
362         EXPECT_NE(graph, nullptr);
363         graph->RemoveConstFromList(graph->GetFirstConstInst());
364         EXPECT_NE(graph->GetFirstConstInst()->GetNextConst(), nullptr);
365     });
366     EXPECT_TRUE(status);
367 }
368 
369 /**
370  * @tc.name: graph_test_016
371  * @tc.desc: Verify the RemoveThrowableInst function.
372  * @tc.type: FUNC
373  * @tc.require: issueNumber
374  */
375 HWTEST_F(CompilerGraphTest,  graph_test_016, TestSize.Level1)
376 {
377     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
378     const char *test_method_name = "func_main_0";
379     bool status = false;
__anon65fffef30c02(Graph* graph, std::string &method_name) 380     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
381         if (test_method_name != method_name) {
382             return;
383         }
384 
385         EXPECT_NE(graph, nullptr);
386         for (auto bb : graph->GetBlocksRPO()) {
387             for (auto inst : bb->AllInsts()) {
388                 if (inst->GetOpcode() != Opcode::CatchPhi) {
389                     continue;
390                 }
391                 status = true;
392                 auto catch_phi = inst->CastToCatchPhi();
393                 catch_phi->SetIsAcc();
394                 graph->AppendThrowableInst(catch_phi, bb);
395                 EXPECT_TRUE(graph->IsInstThrowable(catch_phi));
396                 graph->RemoveThrowableInst(catch_phi);
397                 EXPECT_FALSE(graph->IsInstThrowable(catch_phi));
398             }
399         }
400     });
401     EXPECT_TRUE(status);
402 }
403 
404 /**
405  * @tc.name: graph_test_017
406  * @tc.desc: Verify the RestoreBlock function.
407  * @tc.type: FUNC
408  * @tc.require: issueNumber
409  */
410 HWTEST_F(CompilerGraphTest,  graph_test_017, TestSize.Level1)
411 {
412     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
413     const char *test_method_name = "func_main_0";
414     bool status = false;
__anon65fffef30d02(Graph* graph, std::string &method_name) 415     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
416         if (test_method_name != method_name) {
417             return;
418         }
419         status = true;
420         EXPECT_NE(graph, nullptr);
421         BasicBlock *bb = nullptr;
422         for (const auto &block : graph->GetVectorBlocks()) {
423             if (block == nullptr) {
424                 continue;
425             }
426             bb = block;
427         }
428         graph->EraseBlock(bb);
429         EXPECT_EQ(bb->GetGraph(), nullptr);
430         graph->RestoreBlock(bb);
431         EXPECT_NE(bb->GetGraph(), nullptr);
432     });
433     EXPECT_TRUE(status);
434 }
435 
436 /**
437  * @tc.name: graph_test_018
438  * @tc.desc: Verify the DynamicMethod function.
439  * @tc.type: FUNC
440  * @tc.require: issueNumber
441  */
442 HWTEST_F(CompilerGraphTest,  graph_test_018, TestSize.Level1)
443 {
444     std::stringstream out;
445     // Numbers are random numbers
446     int32_t arg = 20;
447     int32_t arg1 = 88;
448     GraphMode mode(arg1);
449     mode.Native(true);
450     mode.Dump(out);
451     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
452     GraphMode mode1(arg);
453     mode1.FastPath(true);
454     out.clear();
455     out.str("");
456     mode1.Dump(out);
457     EXPECT_EQ(out.str(), "DynamicMethod, FastPath");
458     GraphMode graph_mode(arg1);
459     graph_mode.Boundary(true);
460     out.clear();
461     out.str("");
462     graph_mode.Dump(out);
463     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
464     GraphMode graph_mode1(arg1);
465     graph_mode1.Interpreter(true);
466     out.clear();
467     out.str("");
468     graph_mode1.Dump(out);
469     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
470     GraphMode graph(arg1);
471     graph.InterpreterEntry(true);
472     out.clear();
473     out.str("");
474     graph.Dump(out);
475     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
476     GraphMode graph1(arg1);
477     graph1.Osr(true);
478     out.clear();
479     out.str("");
480     graph1.Dump(out);
481     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
482     GraphMode graph2(arg1);
483     graph2.DynamicMethod(true);
484     out.clear();
485     out.str("");
486     graph2.Dump(out);
487     EXPECT_EQ(out.str(), "Native, FastPath, Interpreter");
488     EXPECT_FALSE(graph1.SupportManagedCode());
489 }
490 
491 /**
492  * @tc.name: graph_test_019
493  * @tc.desc: Verify the SupportManagedCode function.
494  * @tc.type: FUNC
495  * @tc.require: issueNumber
496  */
497 HWTEST_F(CompilerGraphTest,  graph_test_019, TestSize.Level1)
498 {
499     // Numbers are random numbers
500     int32_t arg = 20;
501     int32_t arg1 = 88;
502     GraphMode mode(88);
503     mode.Native(true);
504     EXPECT_TRUE(!mode.SupportManagedCode());
505     GraphMode mode1(arg);
506     mode1.FastPath(true);
507     EXPECT_TRUE(!mode1.SupportManagedCode());
508 
509     GraphMode graph_mode(arg1);
510     graph_mode.Boundary(true);
511     EXPECT_TRUE(!graph_mode.SupportManagedCode());
512     GraphMode graph_mode1(arg1);
513     graph_mode1.Interpreter(true);
514     EXPECT_TRUE(!graph_mode1.SupportManagedCode());
515     GraphMode graph(arg1);
516     graph.InterpreterEntry(true);
517     EXPECT_FALSE(graph.SupportManagedCode());
518     GraphMode graph1(arg1);
519     graph1.SetNative(false);
520     graph1.SetFastPath(false);
521     graph1.SetBoundary(false);
522     graph1.SetInterpreter(false);
523     graph1.SetInterpreterEntry(false);
524     graph1.SetOsr(true);
525     EXPECT_TRUE(graph1.SupportManagedCode());
526 }
527 
528 /**
529  * @tc.name: graph_test_020
530  * @tc.desc: Verify the MarkLoopExits function.
531  * @tc.type: FUNC
532  * @tc.require: issueNumber
533  */
534 HWTEST_F(CompilerGraphTest,  graph_test_020, TestSize.Level1)
535 {
536     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
537     const char *test_method_name = "func_main_0";
538     bool status = false;
__anon65fffef30e02(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         Marker mark = 4;
545         EXPECT_NE(graph, nullptr);
546         MarkLoopExits(graph, mark);
547         EXPECT_FALSE(graph->GetEndBlock()->IsMarked(mark));
548     });
549     EXPECT_TRUE(status);
550 }
551 
552 /**
553  * @tc.name: graph_test_021
554  * @tc.desc: Verify the RemovePredecessors function.
555  * @tc.type: FUNC
556  * @tc.require: issueNumber
557  */
558 HWTEST_F(CompilerGraphTest,  graph_test_021, TestSize.Level1)
559 {
560     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
561     const char *test_method_name = "func_main_0";
562     bool status = false;
__anon65fffef30f02(Graph* graph, std::string &method_name) 563     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
564         if (test_method_name != method_name) {
565             return;
566         }
567         status = true;
568         EXPECT_NE(graph, nullptr);
569         for (auto bb : graph->GetBlocksRPO()) {
570             graph->RemovePredecessors(bb, true);
571             EXPECT_EQ(bb->GetPredsBlocks().size(), 0);
572             graph->RemovePredecessors(bb, false);
573             EXPECT_EQ(bb->GetPredsBlocks().size(), 0);
574         }
575     });
576     EXPECT_TRUE(status);
577 }
578 
579 /**
580  * @tc.name: graph_test_022
581  * @tc.desc: Verify the GetParametersSlotsCount function.
582  * @tc.type: FUNC
583  * @tc.require: issueNumber
584  */
585 HWTEST_F(CompilerGraphTest,  graph_test_022, TestSize.Level1)
586 {
587     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
588     const char* test_method_name = "func5";
589     bool status = false;
__anon65fffef31002(Graph* graph, std::string &method_name) 590     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
591         if (test_method_name != method_name) {
592             return;
593         }
594 
595         EXPECT_NE(graph, nullptr);
596         status = true;
597         ArenaVector<bool> regs =
598             ArenaVector<bool>(std::max(MAX_NUM_REGS, MAX_NUM_VREGS), false, graph->GetAllocator()->Adapter());
599         graph->InitUsedRegs<DataType::FLOAT64>(&regs);
600         graph->SetRegUsage(0, DataType::FLOAT64);
601         EXPECT_NE(graph->GetUsedRegs<DataType::FLOAT64>(), nullptr);
602         graph->SetExtSlotsStart(0);
603         EXPECT_EQ(graph->GetExtSlotsStart(), 0);
604         EXPECT_NE(graph->GetRootLoop(), nullptr);
605         EXPECT_TRUE(graph->HasLoop());
606         EXPECT_FALSE(graph->HasInfiniteLoop());
607         EXPECT_EQ(graph->GetParametersSlotsCount(), 0);
608     });
609     EXPECT_TRUE(status);
610 }
611 
612 /**
613  * @tc.name: graph_test_023
614  * @tc.desc: Verify the Run function.
615  * @tc.type: FUNC
616  * @tc.require: issueNumber
617  */
618 HWTEST_F(CompilerGraphTest, graph_test_023, TestSize.Level1)
619 {
620     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
621     const char* test_method_name = "func5";
622     bool status = false;
__anon65fffef31102(Graph* graph, std::string &method_name) 623     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) {
624         if (test_method_name != method_name) {
625             return;
626         }
627         status = true;
628         EXPECT_NE(graph, nullptr);
629         PhiResolver phi_resolver(graph);
630         phi_resolver.Run();
631     });
632     EXPECT_TRUE(status);
633 }
634 
635 /**
636  * @tc.name: graph_test_024
637  * @tc.desc: Verify the CreateRootsStackMask function.
638  * @tc.type: FUNC
639  * @tc.require: issueNumber
640  */
641 HWTEST_F(CompilerGraphTest, graph_test_024, TestSize.Level1)
642 {
643     std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc";
644     const char* test_method_name = "func5";
645     bool status = false;
646     bool status1 = false;
647     graph_test_.TestBuildGraphFromFile(pfile, [&test_method_name, &status, &status1](Graph* graph,
__anon65fffef31202(Graph* graph, std::string &method_name) 648         std::string &method_name) {
649         if (test_method_name != method_name) {
650             return;
651         }
652 
653         EXPECT_NE(graph, nullptr);
654 
655         for (auto block : graph->GetBlocksRPO()) {
656             if (block == nullptr) {
657                 continue;
658             }
659             for (auto inst : block->AllInstsSafe()) {
660                 if (inst->IsPhi()) {
661                     status = true;
662                     auto phiInst = inst->CastToPhi();
663                     phiInst->SetPhiInputBbNum(0, 0);
664                     EXPECT_FALSE(inst->IsBoolConst());
665                     EXPECT_EQ(phiInst->GetPhiInputBbNum(0), 0);
666                 }
667                 if (inst->IsSaveState()) {
668                     status1 = true;
669                     auto save_inst = inst->CastToSaveState();
670                     VirtualRegister reg(0, true);
671                     save_inst->CreateRootsStackMask(graph->GetAllocator());
672                     EXPECT_NE(save_inst->GetRootsStackMask(), nullptr);
673                 }
674             }
675         }
676     });
677     EXPECT_TRUE(status);
678     EXPECT_TRUE(status1);
679 }
680 }  // namespace panda::compiler
681