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_AARCH64_SSA_H 17 #define MAPLEBE_CG_INCLUDE_AARCH64_SSA_H 18 19 #include "cg_ssa.h" 20 #include "aarch64_insn.h" 21 22 namespace maplebe { 23 class AArch64CGSSAInfo : public CGSSAInfo { 24 public: AArch64CGSSAInfo(CGFunc & f,DomAnalysis & da,MemPool & mp,MemPool & tmp)25 AArch64CGSSAInfo(CGFunc &f, DomAnalysis &da, MemPool &mp, MemPool &tmp) : CGSSAInfo(f, da, mp, tmp) {} 26 ~AArch64CGSSAInfo() override = default; 27 void DumpInsnInSSAForm(const Insn &insn) const override; 28 RegOperand *GetRenamedOperand(RegOperand &vRegOpnd, bool isDef, Insn &curInsn, uint32 idx) override; 29 MemOperand *CreateMemOperand(MemOperand &memOpnd, bool isOnSSA /* false = on cgfunc */); 30 void ReplaceInsn(Insn &oriInsn, Insn &newInsn) override; 31 void ReplaceAllUse(VRegVersion *toBeReplaced, VRegVersion *newVersion) override; 32 void CreateNewInsnSSAInfo(Insn &newInsn) override; 33 34 private: 35 void RenameInsn(Insn &insn) override; 36 VRegVersion *RenamedOperandSpecialCase(RegOperand &vRegOpnd, Insn &curInsn, uint32 idx); 37 RegOperand *CreateSSAOperand(RegOperand &virtualOpnd) override; 38 void CheckAsmDUbinding(Insn &insn, const VRegVersion *toBeReplaced, VRegVersion *newVersion); 39 }; 40 41 class A64SSAOperandRenameVisitor : public SSAOperandVisitor { 42 public: A64SSAOperandRenameVisitor(AArch64CGSSAInfo & cssaInfo,Insn & cInsn,const OpndDesc & cProp,uint32 idx)43 A64SSAOperandRenameVisitor(AArch64CGSSAInfo &cssaInfo, Insn &cInsn, const OpndDesc &cProp, uint32 idx) 44 : SSAOperandVisitor(cInsn, cProp, idx), ssaInfo(&cssaInfo) 45 { 46 } 47 ~A64SSAOperandRenameVisitor() override = default; 48 void Visit(RegOperand *v) final; 49 void Visit(ListOperand *v) final; 50 void Visit(MemOperand *a64MemOpnd) final; 51 52 private: 53 AArch64CGSSAInfo *ssaInfo; 54 }; 55 56 class A64OpndSSAUpdateVsitor : public SSAOperandVisitor, public OperandVisitor<PhiOperand> { 57 public: A64OpndSSAUpdateVsitor(AArch64CGSSAInfo & cssaInfo)58 explicit A64OpndSSAUpdateVsitor(AArch64CGSSAInfo &cssaInfo) : ssaInfo(&cssaInfo) {} 59 ~A64OpndSSAUpdateVsitor() override = default; MarkIncrease()60 void MarkIncrease() 61 { 62 isDecrease = false; 63 }; MarkDecrease()64 void MarkDecrease() 65 { 66 isDecrease = true; 67 }; HasDeleteDef()68 bool HasDeleteDef() const 69 { 70 return !deletedDef.empty(); 71 } 72 void Visit(RegOperand *regOpnd) final; 73 void Visit(ListOperand *v) final; 74 void Visit(MemOperand *a64MemOpnd) final; 75 void Visit(PhiOperand *phiOpnd) final; 76 IsPhi()77 bool IsPhi() const 78 { 79 return isPhi; 80 } 81 SetPhi(bool flag)82 void SetPhi(bool flag) 83 { 84 isPhi = flag; 85 } 86 87 private: 88 void UpdateRegUse(uint32 ssaIdx); 89 void UpdateRegDef(uint32 ssaIdx); 90 AArch64CGSSAInfo *ssaInfo; 91 bool isDecrease = false; 92 std::set<regno_t> deletedDef; 93 bool isPhi = false; 94 }; 95 96 class A64SSAOperandDumpVisitor : public SSAOperandDumpVisitor { 97 public: A64SSAOperandDumpVisitor(const MapleUnorderedMap<regno_t,VRegVersion * > & allssa)98 explicit A64SSAOperandDumpVisitor(const MapleUnorderedMap<regno_t, VRegVersion *> &allssa) 99 : SSAOperandDumpVisitor(allssa) {}; 100 ~A64SSAOperandDumpVisitor() override = default; 101 void Visit(RegOperand *a64RegOpnd) final; 102 void Visit(ListOperand *v) final; 103 void Visit(MemOperand *a64MemOpnd) final; 104 void Visit(PhiOperand *phi) final; 105 }; 106 } // namespace maplebe 107 108 #endif // MAPLEBE_CG_INCLUDE_AARCH64_SSA_H 109