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_STANDARDIZE_H 17 #define MAPLEBE_INCLUDE_STANDARDIZE_H 18 19 #include "cgfunc.h" 20 namespace maplebe { 21 class Standardize { 22 public: Standardize(CGFunc & f)23 explicit Standardize(CGFunc &f) : cgFunc(&f) {} 24 ~Standardize()25 virtual ~Standardize() 26 { 27 cgFunc = nullptr; 28 } 29 30 /* 31 * for cpu instruction contains different operands 32 * maple provide a default implement from three address to two address 33 * convertion rule is: 34 * mop(dest, src1, src2) -> mov(dest, src1) 35 * mop(dest, src2) 36 * maple provide a default implement from two address to one address for unary op 37 * convertion rule is: 38 * mop(dest, src) -> mov(dest, src1) 39 * mop(dest) 40 */ 41 void AddressMapping(Insn &insn); 42 43 void DoStandardize(); 44 45 protected: SetAddressMapping(bool needMapping)46 void SetAddressMapping(bool needMapping) 47 { 48 needAddrMapping = needMapping; 49 } NeedAddressMapping(const Insn & insn)50 bool NeedAddressMapping(const Insn &insn) 51 { 52 /* Operand number for two addressing mode is 2 */ 53 /* and 3 for three addressing mode */ 54 constexpr uint32 operandSizeNeedAddrMapping = 3; 55 needAddrMapping = (insn.GetOperandSize() >= operandSizeNeedAddrMapping) || (insn.IsUnaryOp()); 56 return needAddrMapping; 57 } 58 59 private: 60 virtual void StdzMov(Insn &insn) = 0; 61 virtual void StdzStrLdr(Insn &insn) = 0; 62 virtual void StdzBasicOp(Insn &insn) = 0; 63 virtual void StdzUnaryOp(Insn &insn, CGFunc &cgFunc) = 0; 64 virtual void StdzCvtOp(Insn &insn, CGFunc &cgFunc) = 0; 65 virtual void StdzShiftOp(Insn &insn, CGFunc &cgFunc) = 0; 66 CGFunc *cgFunc; 67 bool needAddrMapping = false; 68 }; 69 MAPLE_FUNC_PHASE_DECLARE_BEGIN(InstructionStandardize, maplebe::CGFunc) 70 MAPLE_FUNC_PHASE_DECLARE_END 71 } // namespace maplebe 72 #endif /* MAPLEBE_INCLUDE_STANDARDIZE_H */ 73