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/dominators_tree.h" 23 24 using namespace testing::ext; 25 26 namespace panda::compiler { 27 class DominatorsTreeTest : public testing::Test { 28 public: SetUpTestCase(void)29 static void SetUpTestCase(void) {} TearDownTestCase(void)30 static void TearDownTestCase(void) {} SetUp()31 void SetUp() {} TearDown()32 void TearDown() {} 33 34 GraphTest graph_test_; 35 }; 36 37 /** 38 * @tc.name: dominators_tree_test_001 39 * @tc.desc: Verify the UpdateAfterResolverInsertion function. 40 * @tc.type: FUNC 41 * @tc.require: issueNumber 42 */ 43 HWTEST_F(DominatorsTreeTest, dominators_tree_test_001, TestSize.Level1) 44 { 45 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 46 const char *test_method_name = "func_main_0"; 47 bool status = false; 48 __anon57c65a000102(Graph* graph, std::string &method_name) 49 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 50 if (test_method_name != method_name) { 51 return; 52 } 53 status = true; 54 EXPECT_NE(graph, nullptr); 55 for (auto bb : graph->GetBlocksRPO()) { 56 EXPECT_NE(bb, nullptr); 57 if (!bb->IsCatchBegin()) { 58 continue; 59 } 60 DominatorsTree dominators_tree(graph); 61 bb->GetPredecessor(1)->SetDominator(bb->GetPredecessor(0)); 62 EXPECT_NE(bb->GetPredecessor(1)->GetDominator(), nullptr); 63 bb->GetPredecessor(0)->AddDominatedBlock(bb->GetPredecessor(1)); 64 dominators_tree.UpdateAfterResolverInsertion(bb->GetPredecessor(0), bb->GetPredecessor(1), 65 bb->GetPredecessor(0)->GetSuccsBlocks()[0]); 66 EXPECT_TRUE(dominators_tree.IsValid()); 67 } 68 }); 69 EXPECT_TRUE(status); 70 } 71 72 /** 73 * @tc.name: dominators_tree_test_002 74 * @tc.desc: Verify the UpdateAfterResolverInsertion function. 75 * @tc.type: FUNC 76 * @tc.require: issueNumber 77 */ 78 HWTEST_F(DominatorsTreeTest, dominators_tree_test_002, TestSize.Level1) 79 { 80 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 81 const char *test_method_name = "func_main_0"; 82 bool status = false; 83 __anon57c65a000202(Graph* graph, std::string &method_name) 84 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 85 if (test_method_name != method_name) { 86 return; 87 } 88 status = true; 89 EXPECT_NE(graph, nullptr); 90 for (auto bb : graph->GetBlocksRPO()) { 91 EXPECT_NE(bb, nullptr); 92 if (!bb->IsCatchBegin()) { 93 continue; 94 } 95 DominatorsTree dominators_tree(graph); 96 bb->GetPredecessor(1)->SetDominator(bb->GetPredecessor(0)); 97 EXPECT_NE(bb->GetPredecessor(1)->GetDominator(), nullptr); 98 dominators_tree.UpdateAfterResolverInsertion(bb->GetPredecessor(0), bb->GetPredecessor(1), 99 bb->GetSuccessor(0)); 100 EXPECT_TRUE(dominators_tree.IsValid()); 101 } 102 }); 103 EXPECT_TRUE(status); 104 } 105 106 /** 107 * @tc.name: dominators_tree_test_003 108 * @tc.desc: Verify the RunImpl function. 109 * @tc.type: FUNC 110 * @tc.require: issueNumber 111 */ 112 HWTEST_F(DominatorsTreeTest, dominators_tree_test_003, TestSize.Level1) 113 { 114 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 115 const char *test_method_name = "func_main_0"; 116 bool status = false; 117 __anon57c65a000302(Graph* graph, std::string &method_name) 118 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 119 if (test_method_name != method_name) { 120 return; 121 } 122 status = true; 123 EXPECT_NE(graph, nullptr); 124 EXPECT_TRUE(graph->RunPass<DominatorsTree>()); 125 }); 126 EXPECT_TRUE(status); 127 } 128 } // namespace panda::compiler