• 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 #ifndef MAPLEBE_CG_INCLUDE_CG_PHI_ELIMINATE_H
17 #define MAPLEBE_CG_INCLUDE_CG_PHI_ELIMINATE_H
18 
19 #include "cgfunc.h"
20 #include "cg_ssa.h"
21 
22 namespace maplebe {
23 class PhiEliminate {
24 public:
PhiEliminate(CGFunc & f,CGSSAInfo & ssaAnalysisResult,MemPool & mp)25     PhiEliminate(CGFunc &f, CGSSAInfo &ssaAnalysisResult, MemPool &mp)
26         : cgFunc(&f),
27           ssaInfo(&ssaAnalysisResult),
28           phiEliAlloc(&mp),
29           eliminatedBB(phiEliAlloc.Adapter()),
30           replaceVreg(phiEliAlloc.Adapter()),
31           remateInfoAfterSSA(phiEliAlloc.Adapter())
32     {
33         tempRegNO = static_cast<uint32_t>(GetSSAInfo()->GetAllSSAOperands().size()) + CGSSAInfo::SSARegNObase;
34     }
35     virtual ~PhiEliminate() = default;
GetSSAInfo()36     CGSSAInfo *GetSSAInfo()
37     {
38         return ssaInfo;
39     }
40     void TranslateTSSAToCSSA();
41     /* move ssaRegOperand from ssaInfo to cgfunc */
42     virtual void ReCreateRegOperand(Insn &insn) = 0;
43 
44 protected:
45     virtual Insn &CreateMov(RegOperand &destOpnd, RegOperand &fromOpnd) = 0;
46     virtual void MaintainRematInfo(RegOperand &destOpnd, RegOperand &fromOpnd, bool isCopy) = 0;
47     virtual void AppendMovAfterLastVregDef(BB &bb, Insn &movInsn) const = 0;
48     void UpdateRematInfo();
49     regno_t GetAndIncreaseTempRegNO();
50     RegOperand *MakeRoomForNoDefVreg(RegOperand &conflictReg);
51     void RecordRematInfo(regno_t vRegNO, PregIdx pIdx);
FindRematInfo(regno_t vRegNO)52     PregIdx FindRematInfo(regno_t vRegNO)
53     {
54         return remateInfoAfterSSA.count(vRegNO) ? remateInfoAfterSSA[vRegNO] : -1;
55     }
56     CGFunc *cgFunc;
57     CGSSAInfo *ssaInfo;
58     MapleAllocator phiEliAlloc;
59 
60 private:
61     void PlaceMovInPredBB(uint32 predBBId, Insn &movInsn);
62     virtual RegOperand &CreateTempRegForCSSA(RegOperand &oriOpnd) = 0;
63     MapleSet<uint32> eliminatedBB;
64     /*
65      * noDef Vregs occupy the vregno_t which is used for ssa re_creating
66      * first : conflicting VReg with noDef VReg  second : new_Vreg opnd to replace occupied Vreg
67      */
68     MapleUnorderedMap<regno_t, RegOperand *> replaceVreg;
69     regno_t tempRegNO = 0; /* use for create mov insn for phi */
70     MapleMap<regno_t, PregIdx> remateInfoAfterSSA;
71 };
72 
73 class OperandPhiElmVisitor : public OperandVisitorBase, public OperandVisitors<RegOperand, ListOperand, MemOperand> {
74 };
75 
76 MAPLE_FUNC_PHASE_DECLARE(CgPhiElimination, maplebe::CGFunc)
77 }  // namespace maplebe
78 
79 #endif  // MAPLEBE_CG_INCLUDE_CG_PHI_ELIMINATE_H
80