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