• 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 "loop.h"
17 #include "cg_prop.h"
18 
19 namespace maplebe {
DoCopyProp()20 void CGProp::DoCopyProp()
21 {
22     CopyProp();
23     cgDce->DoDce();
24 }
25 
DoTargetProp()26 void CGProp::DoTargetProp()
27 {
28     DoCopyProp();
29     /* instruction level opt */
30     FOR_ALL_BB(bb, cgFunc) {
31         FOR_BB_INSNS(insn, bb) {
32             if (!insn->IsMachineInstruction()) {
33                 continue;
34             }
35             TargetProp(*insn);
36         }
37     }
38     /* pattern  level opt */
39     if (CGOptions::GetInstance().GetOptimizeLevel() == CGOptions::kLevel2) {
40         PropPatternOpt();
41     }
42 }
43 
FindDefInsn(const VRegVersion * useVersion)44 Insn *PropOptimizePattern::FindDefInsn(const VRegVersion *useVersion)
45 {
46     if (!useVersion) {
47         return nullptr;
48     }
49     DUInsnInfo *defInfo = useVersion->GetDefInsnInfo();
50     if (!defInfo) {
51         return nullptr;
52     }
53     return defInfo->GetInsn();
54 }
55 
PhaseRun(maplebe::CGFunc & f)56 bool CgCopyProp::PhaseRun(maplebe::CGFunc &f)
57 {
58     CGSSAInfo *ssaInfo = GET_ANALYSIS(CgSSAConstruct, f);
59     LiveIntervalAnalysis *ll = GET_ANALYSIS(CGliveIntervalAnalysis, f);
60     CGProp *cgProp = f.GetCG()->CreateCGProp(*GetPhaseMemPool(), f, *ssaInfo, *ll);
61     cgProp->DoCopyProp();
62     ll->ClearBFS();
63     return false;
64 }
GetAnalysisDependence(maple::AnalysisDep & aDep) const65 void CgCopyProp::GetAnalysisDependence(maple::AnalysisDep &aDep) const
66 {
67     aDep.AddRequired<CgSSAConstruct>();
68     aDep.AddRequired<CGliveIntervalAnalysis>();
69     aDep.AddPreserved<CgSSAConstruct>();
70 }
MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgCopyProp,cgcopyprop)71 MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgCopyProp, cgcopyprop)
72 
73 bool CgTargetProp::PhaseRun(maplebe::CGFunc &f)
74 {
75     CGSSAInfo *ssaInfo = GET_ANALYSIS(CgSSAConstruct, f);
76     LiveIntervalAnalysis *ll = GET_ANALYSIS(CGliveIntervalAnalysis, f);
77     CGProp *cgProp = f.GetCG()->CreateCGProp(*GetPhaseMemPool(), f, *ssaInfo, *ll);
78     DEBUG_ASSERT(cgProp != nullptr, "nullptr check");
79     cgProp->DoTargetProp();
80     ll->ClearBFS();
81     return false;
82 }
GetAnalysisDependence(maple::AnalysisDep & aDep) const83 void CgTargetProp::GetAnalysisDependence(maple::AnalysisDep &aDep) const
84 {
85     aDep.AddRequired<CgSSAConstruct>();
86     aDep.AddRequired<CGliveIntervalAnalysis>();
87     aDep.AddPreserved<CgSSAConstruct>();
88 }
89 MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgTargetProp, cgtargetprop)
90 }  // namespace maplebe
91