• 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 "cg_dce.h"
17 #include "cg.h"
18 namespace maplebe {
DoDce()19 void CGDce::DoDce()
20 {
21     bool tryDceAgain = false;
22     do {
23         tryDceAgain = false;
24         for (auto &ssaIt : GetSSAInfo()->GetAllSSAOperands()) {
25             if (ssaIt.second != nullptr && !ssaIt.second->IsDeleted()) {
26                 if (RemoveUnuseDef(*ssaIt.second)) {
27                     tryDceAgain = true;
28                 }
29             }
30         }
31     } while (tryDceAgain);
32 }
33 
PhaseRun(maplebe::CGFunc & f)34 bool CgDce::PhaseRun(maplebe::CGFunc &f)
35 {
36     CGSSAInfo *ssaInfo = GET_ANALYSIS(CgSSAConstruct, f);
37     CGDce *cgDce = f.GetCG()->CreateCGDce(*GetPhaseMemPool(), f, *ssaInfo);
38     cgDce->DoDce();
39     return false;
40 }
41 
GetAnalysisDependence(maple::AnalysisDep & aDep) const42 void CgDce::GetAnalysisDependence(maple::AnalysisDep &aDep) const
43 {
44     aDep.AddRequired<CgSSAConstruct>();
45     aDep.AddPreserved<CgSSAConstruct>();
46 }
47 MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgDce, cgdeadcodeelimination)
48 }  // namespace maplebe
49