• 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 // Build intra/inter block data dependence graph.
17 // 1: Build data dependence nodes
18 // 2: Build edges between dependence nodes. Edges are:
19 //   2.1) True dependence
20 //   2.2) Anti dependence
21 //   2.3) Output dependence
22 //   2.4) Barrier dependence
23 #ifndef MAPLEBE_INCLUDE_CG_DATA_DEP_ANALYSIS_H
24 #define MAPLEBE_INCLUDE_CG_DATA_DEP_ANALYSIS_H
25 
26 #include "data_dep_base.h"
27 #include "mempool.h"
28 #include "cg_cdg.h"
29 
30 namespace maplebe {
31 constexpr uint32 kMaxDumpRegionNodeNum = 6;
32 
33 // Create data dependence of region, include:
34 // inter-data-dependence-analysis (cross-bb) and
35 // intra-data-dependence-analysis (in-bb)
36 class DataDepAnalysis {
37 public:
DataDepAnalysis(CGFunc & f,MemPool & memPool,DataDepBase & dataDepBase)38     DataDepAnalysis(CGFunc &f, MemPool &memPool, DataDepBase &dataDepBase)
39         : cgFunc(f), interMp(memPool), interAlloc(&memPool), ddb(dataDepBase)
40     {
41     }
42     virtual ~DataDepAnalysis() = default;
43 
44     void Run(CDGRegion &region);
45     void GenerateDataDepGraphDotOfRegion(CDGRegion &region);
46 
47 protected:
48     void InitInfoInRegion(MemPool &regionMp, MapleAllocator &regionAlloc, CDGRegion &region);
49     void InitInfoInCDGNode(MemPool &regionMp, MapleAllocator &regionAlloc, BB &bb, CDGNode &cdgNode);
50     void ClearInfoInRegion(MemPool *regionMp, MapleAllocator *regionAlloc, CDGRegion &region) const;
51     void BuildDepsForPrevSeparator(CDGNode &cdgNode, DepNode &depNode, CDGRegion &curRegion);
52     void BuildSpecialInsnDependency(Insn &insn, CDGNode &cdgNode, CDGRegion &region, MapleAllocator &alloc);
53     void UpdateRegUseAndDef(Insn &insn, const DepNode &depNode, CDGNode &cdgNode);
54     void UpdateReadyNodesInfo(CDGNode &cdgNode, const CDGNode &root) const;
55 
56 private:
57     CGFunc &cgFunc;
58     MemPool &interMp;
59     MapleAllocator interAlloc;
60     DataDepBase &ddb;
61 };
62 }  // namespace maplebe
63 
64 #endif  // MAPLEBE_INCLUDE_CG_DATA_DEP_ANALYSIS_H
65