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_AARCH64_AARCH64_EBO_H 17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_EBO_H 18 19 #include "ebo.h" 20 #include "aarch64_operand.h" 21 #include "aarch64_cgfunc.h" 22 23 namespace maplebe { 24 25 class AArch64Ebo : public Ebo { 26 public: AArch64Ebo(CGFunc & func,MemPool & memPool,LiveAnalysis * live,bool before,const std::string & phase)27 AArch64Ebo(CGFunc &func, MemPool &memPool, LiveAnalysis *live, bool before, const std::string &phase) 28 : Ebo(func, memPool, live, before, phase), callerSaveRegTable(eboAllocator.Adapter()) 29 { 30 a64CGFunc = static_cast<AArch64CGFunc *>(cgFunc); 31 } 32 33 enum ExtOpTable : uint8; 34 35 ~AArch64Ebo() override = default; 36 37 protected: 38 MapleVector<RegOperand *> callerSaveRegTable; 39 AArch64CGFunc *a64CGFunc; 40 int32 GetOffsetVal(const MemOperand &mem) const override; 41 OpndInfo *OperandInfoDef(BB ¤tBB, Insn ¤tInsn, Operand &localOpnd) override; 42 const RegOperand &GetRegOperand(const Operand &opnd) const override; 43 bool IsGlobalNeeded(Insn &insn) const override; 44 bool IsDecoupleStaticOp(Insn &insn) const override; 45 bool OperandEqSpecial(const Operand &op1, const Operand &op2) const override; 46 void BuildCallerSaveRegisters() override; 47 void DefineAsmRegisters(InsnInfo &insnInfo) override; 48 void DefineCallerSaveRegisters(InsnInfo &insnInfo) override; 49 void DefineReturnUseRegister(Insn &insn) override; 50 void DefineCallUseSpecialRegister(Insn &insn) override; 51 void DefineClinitSpecialRegisters(InsnInfo &insnInfo) override; 52 bool CombineExtensionAndLoad(Insn *insn, const MapleVector<OpndInfo *> &origInfos, ExtOpTable idx, bool is64Bits); 53 bool IsMovToSIMDVmov(Insn &insn, const Insn &replaceInsn) const override; 54 bool IsPseudoRet(Insn &insn) const override; 55 bool IsAdd(const Insn &insn) const override; 56 bool IsFmov(const Insn &insn) const override; 57 bool IsClinitCheck(const Insn &insn) const override; 58 bool IsLastAndBranch(BB &bb, Insn &insn) const override; 59 bool IsSameRedefine(BB &bb, Insn &insn, OpndInfo &opndInfo) const override; 60 bool ResIsNotDefAndUse(Insn &insn) const override; 61 bool LiveOutOfBB(const Operand &opnd, const BB &bb) const override; 62 bool IsInvalidReg(const RegOperand &opnd) const override; 63 bool IsZeroRegister(const Operand &opnd) const override; 64 bool IsConstantImmOrReg(const Operand &opnd) const override; 65 bool OperandLiveAfterInsn(const RegOperand ®Opnd, Insn &insn) const; 66 bool ValidPatternForCombineExtAndLoad(OpndInfo *prevOpndInfo, Insn *insn, MOperator newMop, MOperator oldMop, 67 const RegOperand &opnd); 68 69 private: 70 /* The number of elements in callerSaveRegTable must less then 45. */ 71 static constexpr int32 kMaxCallerSaveReg = 45; 72 MOperator ExtLoadSwitchBitSize(MOperator lowMop) const; 73 bool CheckCondCode(const CondOperand &cond) const; 74 bool CombineMultiplyAdd(Insn *insn, const Insn *prevInsn, InsnInfo *insnInfo, Operand *addOpnd, bool is64bits, 75 bool isFp) const; 76 bool CheckCanDoMadd(Insn *insn, OpndInfo *opndInfo, int32 pos, bool is64bits, bool isFp); 77 bool CombineMultiplySub(Insn *insn, OpndInfo *opndInfo, bool is64bits, bool isFp) const; 78 bool CombineMultiplyNeg(Insn *insn, OpndInfo *opndInfo, bool is64bits, bool isFp) const; 79 bool SimplifyBothConst(BB &bb, Insn &insn, const ImmOperand &immOperand0, const ImmOperand &immOperand1, 80 uint32 opndSize) const; 81 ConditionCode GetReverseCond(const CondOperand &cond) const; 82 bool CombineLsrAnd(Insn &insn, const OpndInfo &opndInfo, bool is64bits, bool isFp) const; 83 }; 84 } /* namespace maplebe */ 85 86 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_EBO_H */ 87