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_X64_REACHING_H 17 #define MAPLEBE_INCLUDE_CG_X64_REACHING_H 18 19 #include "reaching.h" 20 21 namespace maplebe { 22 class X64ReachingDefinition : public ReachingDefinition { 23 public: X64ReachingDefinition(CGFunc & func,MemPool & memPool)24 X64ReachingDefinition(CGFunc &func, MemPool &memPool) : ReachingDefinition(func, memPool) {} 25 ~X64ReachingDefinition() override = default; 26 bool FindRegUseBetweenInsn(uint32 regNO, Insn *startInsn, Insn *endInsn, InsnSet &useInsnSet) const final; 27 std::vector<Insn *> FindRegDefBetweenInsnGlobal(uint32 regNO, Insn *startInsn, Insn *endInsn) const final; 28 std::vector<Insn *> FindMemDefBetweenInsn(uint32 offset, const Insn *startInsn, Insn *endInsn) const final; 29 bool FindRegUseBetweenInsnGlobal(uint32 regNO, Insn *startInsn, Insn *endInsn, BB *movBB) const final; 30 bool FindMemUseBetweenInsn(uint32 offset, Insn *startInsn, const Insn *endInsn, InsnSet &useInsnSet) const final; 31 bool HasRegDefBetweenInsnGlobal(uint32 regNO, Insn &startInsn, Insn &endInsn); 32 bool DFSFindRegDefBetweenBB(const BB &startBB, const BB &endBB, uint32 regNO, 33 std::vector<VisitStatus> &visitedBB) const; 34 InsnSet FindDefForRegOpnd(Insn &insn, uint32 indexOrRegNO, bool isRegNO = false) const final; 35 InsnSet FindDefForMemOpnd(Insn &insn, uint32 indexOrOffset, bool isOffset = false) const final; 36 InsnSet FindUseForMemOpnd(Insn &insn, uint8 index, bool secondMem = false) const final; 37 bool FindRegUsingBetweenInsn(uint32 regNO, Insn *startInsn, const Insn *endInsn) const; 38 39 protected: 40 void InitStartGen() final; 41 void InitGenUse(BB &bb, bool firstTime = true) final; 42 void GenAllAsmDefRegs(BB &bb, Insn &insn, uint32 index) final; 43 void GenAllAsmUseRegs(BB &bb, Insn &insn, uint32 index) final; 44 void GenAllCallerSavedRegs(BB &bb, Insn &insn) final; 45 bool IsRegKilledByCallInsn(const Insn &insn, regno_t regNO) const final; 46 bool KilledByCallBetweenInsnInSameBB(const Insn &startInsn, const Insn &endInsn, regno_t regNO) const final; 47 void AddRetPseudoInsn(BB &bb) final; 48 49 void AddRetPseudoInsns() final; 50 bool IsCallerSavedReg(uint32 regNO) const final; 51 void FindRegDefInBB(uint32 regNO, BB &bb, InsnSet &defInsnSet) const final; 52 void FindMemDefInBB(uint32 offset, BB &bb, InsnSet &defInsnSet) const final; 53 void DFSFindDefForRegOpnd(const BB &startBB, uint32 regNO, std::vector<VisitStatus> &visitedBB, 54 InsnSet &defInsnSet) const final; 55 void DFSFindDefForMemOpnd(const BB &startBB, uint32 offset, std::vector<VisitStatus> &visitedBB, 56 InsnSet &defInsnSet) const final; 57 int32 GetStackSize() const final; 58 59 private: 60 bool IsDiv(const Insn &insn) const; 61 }; 62 } /* namespace maplebe */ 63 64 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_REACHING_H */ 65