• 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_DEPENDENCE_H
17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_DEPENDENCE_H
18 
19 #include "dependence.h"
20 #include "cgfunc.h"
21 #include "aarch64_operand.h"
22 
23 namespace maplebe {
24 class AArch64DepAnalysis : public DepAnalysis {
25 public:
26     AArch64DepAnalysis(CGFunc &func, MemPool &mp, MAD &mad, bool beforeRA);
27 
28     ~AArch64DepAnalysis() override = default;
29 
30     void Run(BB &bb, MapleVector<DepNode *> &nodes) override;
31     const std::string &GetDepTypeName(DepType depType) const override;
32     void DumpDepNode(DepNode &node) const override;
33     void DumpDepLink(DepLink &link, const DepNode *node) const override;
34 
35 protected:
36     void Init(BB &bb, MapleVector<DepNode *> &nodes) override;
37     void ClearAllDepData() override;
38     void AppendRegUseList(Insn &insn, regno_t regNO) override;
39     void AddDependence(DepNode &fromNode, DepNode &toNode, DepType depType) override;
40     void RemoveSelfDeps(Insn &insn) override;
41     void CombineClinit(DepNode &firstNode, DepNode &secondNode, bool isAcrossSeparator) override;
42     void CombineDependence(DepNode &firstNode, DepNode &secondNode, bool isAcrossSeparator,
43                            bool isMemCombine = false) override;
44     void CombineMemoryAccessPair(DepNode &firstNode, DepNode &secondNode, bool useFirstOffset) override;
45     void BuildDepsUseReg(Insn &insn, regno_t regNO) override;
46     void BuildDepsDefReg(Insn &insn, regno_t regNO) override;
47     void BuildDepsAmbiInsn(Insn &insn) override;
48     void BuildDepsMayThrowInsn(Insn &insn) override;
49     bool NeedBuildDepsMem(const MemOperand &memOpnd, const MemOperand *nextMemOpnd, const Insn &memInsn) const;
50     void BuildDepsUseMem(Insn &insn, MemOperand &memOpnd) override;
51     void BuildAntiDepsDefStackMem(Insn &insn, MemOperand &memOpnd, const MemOperand *nextMemOpnd);
52     void BuildOutputDepsDefStackMem(Insn &insn, MemOperand &memOpnd, const MemOperand *nextMemOpnd);
53     void BuildDepsMemBar(Insn &insn) override;
54     void BuildDepsSeparator(DepNode &newSepNode, MapleVector<DepNode *> &nodes) override;
55     void BuildDepsControlAll(DepNode &depNode, const MapleVector<DepNode *> &nodes) override;
56     void BuildDepsAccessStImmMem(Insn &insn, bool isDest) override;
57     void BuildCallerSavedDeps(Insn &insn) override;
58     void BuildDepsBetweenControlRegAndCall(Insn &insn, bool isDest) override;
59     void BuildStackPassArgsDeps(Insn &insn) override;
60     void BuildDepsDirtyStack(Insn &insn) override;
61     void BuildDepsUseStack(Insn &insn) override;
62     void BuildDepsDirtyHeap(Insn &insn) override;
63     DepNode *BuildSeparatorNode() override;
64     bool IfInAmbiRegs(regno_t regNO) const override;
65     bool IsFrameReg(const RegOperand &) const override;
66 
67 private:
68     MemOperand *GetNextMemOperand(const Insn &insn, const MemOperand &aarchMemOpnd) const;
69     void BuildMemOpndDependency(Insn &insn, Operand &opnd, const OpndDesc &regProp);
70     void BuildOpndDependency(Insn &insn);
71     void BuildSpecialInsnDependency(Insn &insn, DepNode &depNode, const MapleVector<DepNode *> &nodes);
72     void SeperateDependenceGraph(MapleVector<DepNode *> &nodes, uint32 &nodeSum);
73     DepNode *GenerateDepNode(Insn &insn, MapleVector<DepNode *> &nodes, int32 nodeSum,
74                              const MapleVector<Insn *> &comments);
75     void BuildAmbiInsnDependency(Insn &insn);
76     void BuildMayThrowInsnDependency(Insn &insn);
77     void UpdateRegUseAndDef(Insn &insn, const DepNode &depNode, MapleVector<DepNode *> &nodes);
78     void UpdateStackAndHeapDependency(DepNode &depNode, Insn &insn, const Insn &locInsn);
79     MemOperand *BuildNextMemOperandByByteSize(const MemOperand &aarchMemOpnd, uint32 byteSize) const;
80     void AddDependence4InsnInVectorByType(MapleVector<Insn *> &insns, Insn &insn, const DepType &type);
81     void AddDependence4InsnInVectorByTypeAndCmp(MapleVector<Insn *> &insns, Insn &insn, const DepType &type);
82     void ReplaceDepNodeWithNewInsn(DepNode &firstNode, DepNode &secondNode, Insn &newInsn, bool isFromClinit) const;
83     void ClearDepNodeInfo(DepNode &depNode) const;
84     void AddEndSeparatorNode(MapleVector<DepNode *> &nodes);
85 
86     Insn **regDefs = nullptr;
87     RegList **regUses = nullptr;
88     Insn *memBarInsn = nullptr;
89     bool hasAmbiRegs = false;
90     Insn *lastCallInsn = nullptr;
91     uint32 separatorIndex = 0;
92     Insn *lastFrameDef = nullptr;
93     MapleVector<Insn *> stackUses;
94     MapleVector<Insn *> stackDefs;
95     MapleVector<Insn *> heapUses;
96     MapleVector<Insn *> heapDefs;
97     MapleVector<Insn *> mayThrows;
98     /* instructions that can not across may throw instructions. */
99     MapleVector<Insn *> ambiInsns;
100     /* register number that catch bb and cleanup bb uses. */
101     MapleSet<regno_t> ehInRegs;
102     /* the bb to be scheduling currently */
103     BB *curBB = nullptr;
104 };
105 }  // namespace maplebe
106 
107 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_DEPENDENCE_H */
108