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_INCLUDE_CG_DCE_H 17 #define MAPLEBE_INCLUDE_CG_DCE_H 18 #include "cgfunc.h" 19 #include "cg_ssa.h" 20 21 namespace maplebe { 22 /* dead code elimination*/ 23 class CGDce { 24 public: CGDce(MemPool & mp,CGFunc & f,CGSSAInfo & sInfo)25 CGDce(MemPool &mp, CGFunc &f, CGSSAInfo &sInfo) : memPool(&mp), cgFunc(&f), ssaInfo(&sInfo) {} 26 virtual ~CGDce() = default; 27 28 void DoDce(); 29 /* provide public use in ssa opt */ 30 virtual bool RemoveUnuseDef(VRegVersion &defVersion) = 0; GetSSAInfo()31 CGSSAInfo *GetSSAInfo() 32 { 33 return ssaInfo; 34 } 35 36 protected: 37 MemPool *memPool; 38 CGFunc *cgFunc; 39 CGSSAInfo *ssaInfo; 40 }; 41 42 class DeleteRegUseVisitor : public OperandVisitorBase, 43 public OperandVisitors<RegOperand, ListOperand, MemOperand>, 44 public OperandVisitor<PhiOperand> { 45 public: DeleteRegUseVisitor(CGSSAInfo & cgSSAInfo,uint32 dInsnID)46 DeleteRegUseVisitor(CGSSAInfo &cgSSAInfo, uint32 dInsnID) : deleteInsnId(dInsnID), ssaInfo(&cgSSAInfo) {} 47 virtual ~DeleteRegUseVisitor() = default; 48 49 protected: GetSSAInfo()50 CGSSAInfo *GetSSAInfo() 51 { 52 return ssaInfo; 53 } 54 uint32 deleteInsnId; 55 56 private: 57 CGSSAInfo *ssaInfo; 58 }; 59 60 MAPLE_FUNC_PHASE_DECLARE(CgDce, maplebe::CGFunc) 61 } // namespace maplebe 62 #endif /* MAPLEBE_INCLUDE_CG_DCE_H */ 63