• 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_DEPENDENCE_H
17 #define MAPLEBE_INCLUDE_CG_DEPENDENCE_H
18 
19 #include "deps.h"
20 #include "cgbb.h"
21 
22 namespace maplebe {
23 using namespace maple;
24 
25 class DepAnalysis {
26 public:
DepAnalysis(CGFunc & func,MemPool & memPool,MAD & mad,bool beforeRA)27     DepAnalysis(CGFunc &func, MemPool &memPool, MAD &mad, bool beforeRA)
28         : cgFunc(func), memPool(memPool), alloc(&memPool), beforeRA(beforeRA), mad(mad), lastComments(alloc.Adapter())
29     {
30     }
31 
32     virtual ~DepAnalysis() = default;
33 
34     virtual void Run(BB &bb, MapleVector<DepNode *> &nodes) = 0;
35 
GetLastComments()36     const MapleVector<Insn *> &GetLastComments() const
37     {
38         return lastComments;
39     }
40     virtual void CombineClinit(DepNode &firstNode, DepNode &secondNode, bool isAcrossSeparator) = 0;
41     virtual void CombineDependence(DepNode &firstNode, DepNode &secondNode, bool isAcrossSeparator,
42                                    bool isMemCombine = false) = 0;
43     virtual void CombineMemoryAccessPair(DepNode &firstNode, DepNode &secondNode, bool useFirstOffset) = 0;
44 
45     virtual const std::string &GetDepTypeName(DepType depType) const = 0;
46     virtual void DumpDepNode(DepNode &node) const = 0;
47     virtual void DumpDepLink(DepLink &link, const DepNode *node) const = 0;
48 
49 protected:
50     CGFunc &cgFunc;
51     MemPool &memPool;
52     MapleAllocator alloc;
53     bool beforeRA;
54     MAD &mad;
55     MapleVector<Insn *> lastComments;
56 
57     virtual void Init(BB &bb, MapleVector<DepNode *> &nodes) = 0;
58     virtual void ClearAllDepData() = 0;
59     virtual void AppendRegUseList(Insn &insn, regno_t regNO) = 0;
60     virtual void AddDependence(DepNode &fromNode, DepNode &toNode, DepType depType) = 0;
61     virtual void RemoveSelfDeps(Insn &insn) = 0;
62     virtual void BuildDepsUseReg(Insn &insn, regno_t regNO) = 0;
63     virtual void BuildDepsDefReg(Insn &insn, regno_t regNO) = 0;
64     virtual void BuildDepsAmbiInsn(Insn &insn) = 0;
65     virtual void BuildDepsMayThrowInsn(Insn &insn) = 0;
66     virtual void BuildDepsUseMem(Insn &insn, MemOperand &memOpnd) = 0;
67     virtual void BuildDepsMemBar(Insn &insn) = 0;
68     virtual void BuildDepsSeparator(DepNode &newSepNode, MapleVector<DepNode *> &nodes) = 0;
69     virtual void BuildDepsControlAll(DepNode &depNode, const MapleVector<DepNode *> &nodes) = 0;
70     virtual void BuildDepsAccessStImmMem(Insn &insn, bool isDest) = 0;
71     virtual void BuildCallerSavedDeps(Insn &insn) = 0;
72     virtual void BuildDepsBetweenControlRegAndCall(Insn &insn, bool isDest) = 0;
73     virtual void BuildStackPassArgsDeps(Insn &insn) = 0;
74     virtual void BuildDepsDirtyStack(Insn &insn) = 0;
75     virtual void BuildDepsUseStack(Insn &insn) = 0;
76     virtual void BuildDepsDirtyHeap(Insn &insn) = 0;
77     virtual DepNode *BuildSeparatorNode() = 0;
78     virtual bool IfInAmbiRegs(regno_t regNO) const = 0;
79     virtual bool IsFrameReg(const RegOperand &) const = 0;
80 };
81 }  // namespace maplebe
82 
83 #endif /* MAPLEBE_INCLUDE_CG_DEPENDENCE_H */
84