CGRAOmp  0.1
BalanceTree.hpp
Go to the documentation of this file.
1 /*
2 * MIT License
3 *
4 * Copyright (c) 2022 Amano laboratory, Keio University & Processor Research Team, RIKEN Center for Computational Science
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 * this software and associated documentation files (the "Software"), to deal in
8 * the Software without restriction, including without limitation the rights to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is furnished to do
11 * so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * File: /include/BalanceTree.hpp
25 * Project: CGRAOmp
26 * Author: Takuya Kojima in The University of Tokyo (tkojima@hal.ipc.i.u-tokyo.ac.jp)
27 * Created Date: 01-02-2022 11:45:50
28 * Last Modified: 07-02-2022 16:11:05
29 */
30 
31 #ifndef BALANCETREE_H
32 #define BALANCETREE_H
33 
34 #include "DFGPass.hpp"
35 #include "CGRADataFlowGraph.hpp"
36 
37 #include "llvm/IR/PassManager.h"
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/SmallVector.h"
40 #include "llvm/ADT/SmallPtrSet.h"
41 #include "llvm/IR/Instruction.h"
42 
43 #define PREC_PAIR(OP, LEVEL) std::make_pair(Instruction::OP, LEVEL)
44 
45 using namespace llvm;
46 
47 namespace CGRAOmp
48 {
49 
57  class BalanceTree : public PassInfoMixin<BalanceTree> {
58  public:
70  bool run(CGRADFG &G, Loop &L, FunctionAnalysisManager &FAM,
71  LoopAnalysisManager &LAM,
72  LoopStandardAnalysisResults &AR);
73  private:
74  using EdgeListTy = SmallVector<DFGEdge *, 10U>;
80  void initWeight(CGRADFG &G);
81 
88  SmallVector<ComputeNode*> findRootCandidates(CGRADFG &G);
89 
96  void toBalanced(CGRADFG &G, ComputeNode* Root);
97 
98  // status storage
99  DenseMap<DFGNode*,int> weight;
100  DenseMap<DFGNode*,bool> visited;
101  SmallPtrSet<DFGNode*, 10> candidate_set;
102  bool changed;
103 
109  static std::map<int,int> OperatorPrecedence;
110 
117  return OperatorPrecedence[N->getInst()->getOpcode()];
118  }
119  };
120 }
121 
122 #endif //BALANCETREE_H
CGRAOmp::BalanceTree::getOperatorPrecedence
static int getOperatorPrecedence(ComputeNode *N)
Function to obtain the precedence for a given ComputeNode.
Definition: BalanceTree.hpp:116
llvm
Definition: OptionPlugin.cpp:128
CGRAOmp::BalanceTree::OperatorPrecedence
static std::map< int, int > OperatorPrecedence
map to decode operator precedence
Definition: BalanceTree.hpp:109
CGRAOmp::BalanceTree
A DFGPass to balance the tree structure.
Definition: BalanceTree.hpp:57
CGRAOmp::BalanceTree::EdgeListTy
SmallVector< DFGEdge *, 10U > EdgeListTy
Definition: BalanceTree.hpp:74
CGRAOmp::BalanceTree::weight
DenseMap< DFGNode *, int > weight
Definition: BalanceTree.hpp:99
CGRAOmp
Definition: AGVerifyPass.hpp:50
CGRADataFlowGraph.hpp
CGRAOmp::BalanceTree::visited
DenseMap< DFGNode *, bool > visited
Definition: BalanceTree.hpp:100
llvm::CGRADFG
A graph class for CGRA kernel DFG derived from llvm::DirectedGraph.
Definition: CGRADataFlowGraph.hpp:505
CGRAOmp::BalanceTree::candidate_set
SmallPtrSet< DFGNode *, 10 > candidate_set
Definition: BalanceTree.hpp:101
llvm::ComputeNode
A concrete class for computational nodes.
Definition: CGRADataFlowGraph.hpp:171
llvm::ComputeNode::getInst
Instruction * getInst() const
Definition: CGRADataFlowGraph.hpp:185
CGRAOmp::BalanceTree::changed
bool changed
Definition: BalanceTree.hpp:102
DFGPass.hpp