• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REACHING_H
17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_REACHING_H
18 
19 #include "reaching.h"
20 #include "aarch64_operand.h"
21 
22 namespace maplebe {
23 class AArch64ReachingDefinition : public ReachingDefinition {
24 public:
AArch64ReachingDefinition(CGFunc & func,MemPool & memPool)25     AArch64ReachingDefinition(CGFunc &func, MemPool &memPool) : ReachingDefinition(func, memPool) {}
26     ~AArch64ReachingDefinition() override = default;
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 FindRegUseBetweenInsn(uint32 regNO, Insn *startInsn, Insn *endInsn, InsnSet &useInsnSet) const final;
30     bool FindRegUseBetweenInsnGlobal(uint32 regNO, Insn *startInsn, Insn *endInsn, BB *movBB) const final;
31     bool FindMemUseBetweenInsn(uint32 offset, Insn *startInsn, const Insn *endInsn, InsnSet &useInsnSet) const final;
32     bool HasRegDefBetweenInsnGlobal(uint32 regNO, Insn &startInsn, Insn &endInsn) const;
33     bool DFSFindRegDefBetweenBB(const BB &startBB, const BB &endBB, uint32 regNO,
34                                 std::vector<VisitStatus> &visitedBB) const;
35     InsnSet FindDefForRegOpnd(Insn &insn, uint32 indexOrRegNO, bool isRegNO = false) const final;
36     InsnSet FindDefForMemOpnd(Insn &insn, uint32 indexOrOffset, bool isOffset = false) const final;
37     InsnSet FindUseForMemOpnd(Insn &insn, uint8 index, bool secondMem = false) const final;
38     bool FindRegUsingBetweenInsn(uint32 regNO, Insn *startInsn, const Insn *endInsn) const;
39 
40 protected:
41     void InitStartGen() final;
42     void InitGenUse(BB &bb, bool firstTime = true) final;
43     void GenAllAsmDefRegs(BB &bb, Insn &insn, uint32 index) final;
44     void GenAllAsmUseRegs(BB &bb, Insn &insn, uint32 index) final;
45     void GenAllCallerSavedRegs(BB &bb, Insn &insn) final;
46     bool IsRegKilledByCallInsn(const Insn &insn, regno_t regNO) const final;
47     bool KilledByCallBetweenInsnInSameBB(const Insn &startInsn, const Insn &endInsn, regno_t regNO) const final;
48     void AddRetPseudoInsn(BB &bb) final;
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     void InitInfoForMemOperand(Insn &insn, Operand &opnd, bool isDef);
61     void InitInfoForListOpnd(const BB &bb, Operand &opnd);
62     void InitInfoForConditionCode(const BB &bb);
63     void InitInfoForRegOpnd(const BB &bb, Operand &opnd, bool isDef);
64     void InitMemInfoForClearStackCall(Insn &callInsn);
65     inline bool CallInsnClearDesignateStackRef(const Insn &callInsn, int64 offset) const;
66     int64 GetEachMemSizeOfPair(MOperator opCode) const;
67     bool DFSFindRegInfoBetweenBB(const BB startBB, const BB &endBB, uint32 regNO, std::vector<VisitStatus> &visitedBB,
68                                  std::list<bool> &pathStatus, DumpType infoType) const;
69     bool DFSFindRegDomianBetweenBB(const BB startBB, uint32 regNO, std::vector<VisitStatus> &visitedBB) const;
70 };
71 } /* namespace maplebe */
72 
73 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_REACHING_H */
74