CGRAOmp  0.1
DecoupledAnalysis.hpp
Go to the documentation of this file.
1 /*
2 * MIT License
3 *
4 * Copyright (c) 2021 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/DecoupledAnalysis.hpp
25 * Project: CGRAOmp
26 * Author: Takuya Kojima in The University of Tokyo (tkojima@hal.ipc.i.u-tokyo.ac.jp)
27 * Created Date: 14-12-2021 11:36:50
28 * Last Modified: 18-02-2022 03:08:00
29 */
30 #ifndef DecoupledAnalysis_H
31 #define DecoupledAnalysis_H
32 
33 #include "llvm/IR/PassManager.h"
34 #include "llvm/Analysis/LoopInfo.h"
35 #include "llvm/Analysis/LoopAnalysisManager.h"
36 #include "llvm/ADT/iterator_range.h"
37 #include "llvm/ADT/SmallVector.h"
38 #include "llvm/ADT/DenseMap.h"
39 
40 using namespace llvm;
41 
42 
43 namespace CGRAOmp {
44 
50  public:
53 
54 
55  using MemLoadList = SmallVector<LoadInst*>;
56  using MemStoreList = SmallVector<StoreInst*>;
57  using CompList = SmallVector<User*>;
58  using InvarList = SmallVector<Value*>;
59 
60  using load_iterator = MemLoadList::iterator;
61  using store_iterator = MemStoreList::iterator;
62  using comp_iterator = CompList::iterator;
63  using invar_iterator = InvarList::iterator;
64 
65 
66  void setMemLoad(MemLoadList &&l) {
67  mem_load = l;
68  }
69 
71  mem_store = l;
72  }
73  void setComp(CompList &&l) {
74  comp = l;
75  }
76  void setInvars(InvarList &&l) {
77  loop_invariant = l;
78  }
79 
80  void setError(StringRef cause) {
81  err_cause = cause;
82  err = true;
83  }
84 
85  void print(raw_ostream &OS) const {
86  if (!err) {
87  OS << "Success";
88  } else {
89  OS << "Error " << err_cause;
90  }
91  }
92 
99  explicit operator bool() {
100  return !err;
101  }
102 
103  // load instrcution
105  return mem_load.begin();
106  }
108  return mem_load.end();
109  }
110  inline iterator_range<load_iterator> loads() {
111  return make_range(load_begin(), load_end());
112  }
113  // store instruction
115  return mem_store.begin();
116  }
118  return mem_store.end();
119  }
120  inline iterator_range<store_iterator> stores() {
121  return make_range(store_begin(), store_end());
122  }
123  // computation
125  return comp.begin();
126  }
128  return comp.end();
129  }
130  inline iterator_range<comp_iterator> comps() {
131  return make_range(comp_begin(), comp_end());
132  }
133  // loop invariant
135  return loop_invariant.begin();
136  }
138  return loop_invariant.end();
139  }
140  inline iterator_range<invar_iterator> invars() {
141  return make_range(invars_begin(), invars_end());
142  }
143 
145  return mem_load;
146  }
147 
149  return mem_store;
150  }
151 
153  return comp;
154  }
155 
157  return loop_invariant;
158  }
159 
166  void setInvarSkipSequence(Value* node, SmallVector<Value*> seq) {
167  invar_skip_seq[node] = seq;
168  }
169 
177  SmallVector<Value*>* getSkipSequence(Value* node) {
178  if (invar_skip_seq.find(node) != invar_skip_seq.end()) {
179  return &(invar_skip_seq[node]);
180  } else {
181  return nullptr;
182  }
183  }
184 
185 
186  private:
191  StringRef err_cause;
192  // key = , value =
193  DenseMap<Value*, SmallVector<Value*>> invar_skip_seq;
194 
195  bool err = false;
196 
197  };
198 
204  public AnalysisInfoMixin<DecoupledAnalysisPass> {
205  public:
207  Result run(Loop &L, LoopAnalysisManager &AM,
208  LoopStandardAnalysisResults &AR);
209  private:
210  friend AnalysisInfoMixin<DecoupledAnalysisPass>;
211  static AnalysisKey Key;
212 
213  void traversal(SmallVector<LoadInst*> &LL, SmallVector<StoreInst*> &SL);
214 
222  bool isPointerValue(LoadInst *I);
223 
224  // /**
225  // * @brief check if the instruction is memory access or not
226  // *
227  // * @param I Instruction to be checked
228  // * @return true if it is a memory access
229  // * @return otherwise: false
230  // */
231  // inline bool isMemAccess(Instruction &I) {
232  // return isa<LoadInst>(I) || isa<StoreInst>(I);
233  // }
234  };
235 }
236 
237 
238 #endif //DecoupledAnalysis_H
CGRAOmp::DecoupledAnalysis::~DecoupledAnalysis
~DecoupledAnalysis()
Definition: DecoupledAnalysis.hpp:52
llvm
Definition: OptionPlugin.cpp:128
CGRAOmp::DecoupledAnalysis::store_iterator
MemStoreList::iterator store_iterator
Definition: DecoupledAnalysis.hpp:61
CGRAOmp::DecoupledAnalysis::setError
void setError(StringRef cause)
Definition: DecoupledAnalysis.hpp:80
CGRAOmp::DecoupledAnalysis::loads
iterator_range< load_iterator > loads()
Definition: DecoupledAnalysis.hpp:110
CGRAOmp::DecoupledAnalysis::mem_store
MemStoreList mem_store
Definition: DecoupledAnalysis.hpp:188
CGRAOmp::DecoupledAnalysis::get_invars
InvarList & get_invars()
Definition: DecoupledAnalysis.hpp:156
CGRAOmp::DecoupledAnalysis::load_iterator
MemLoadList::iterator load_iterator
Definition: DecoupledAnalysis.hpp:60
CGRAOmp::DecoupledAnalysis::comp
CompList comp
Definition: DecoupledAnalysis.hpp:189
CGRAOmp::DecoupledAnalysis::get_stores
MemStoreList & get_stores()
Definition: DecoupledAnalysis.hpp:148
CGRAOmp::DecoupledAnalysis::DecoupledAnalysis
DecoupledAnalysis()
Definition: DecoupledAnalysis.hpp:51
CGRAOmp::DecoupledAnalysis::invars_end
invar_iterator invars_end()
Definition: DecoupledAnalysis.hpp:137
CGRAOmp::DecoupledAnalysis::InvarList
SmallVector< Value * > InvarList
Definition: DecoupledAnalysis.hpp:58
CGRAOmp::DecoupledAnalysis::setInvarSkipSequence
void setInvarSkipSequence(Value *node, SmallVector< Value * > seq)
Set the node traversal skip sequence for loop invariant nodes.
Definition: DecoupledAnalysis.hpp:166
CGRAOmp::DecoupledAnalysis::err_cause
StringRef err_cause
Definition: DecoupledAnalysis.hpp:191
CGRAOmp::DecoupledAnalysis::get_loads
MemLoadList & get_loads()
Definition: DecoupledAnalysis.hpp:144
CGRAOmp
Definition: AGVerifyPass.hpp:50
CGRAOmp::DecoupledAnalysisPass::Key
static AnalysisKey Key
Definition: DecoupledAnalysis.hpp:211
CGRAOmp::DecoupledAnalysis::invar_skip_seq
DenseMap< Value *, SmallVector< Value * > > invar_skip_seq
Definition: DecoupledAnalysis.hpp:193
CGRAOmp::DecoupledAnalysis::mem_load
MemLoadList mem_load
Definition: DecoupledAnalysis.hpp:187
CGRAOmp::DecoupledAnalysis::MemLoadList
SmallVector< LoadInst * > MemLoadList
Definition: DecoupledAnalysis.hpp:55
CGRAOmp::DecoupledAnalysis::CompList
SmallVector< User * > CompList
Definition: DecoupledAnalysis.hpp:57
CGRAOmp::DecoupledAnalysis::comp_end
comp_iterator comp_end()
Definition: DecoupledAnalysis.hpp:127
CGRAOmp::DecoupledAnalysisPass
A loop pass to analyze memory access for decoupling.
Definition: DecoupledAnalysis.hpp:203
CGRAOmp::DecoupledAnalysis
An analysis result of memory access decoupling for loop kernel.
Definition: DecoupledAnalysis.hpp:49
CGRAOmp::DecoupledAnalysis::comp_begin
comp_iterator comp_begin()
Definition: DecoupledAnalysis.hpp:124
CGRAOmp::DecoupledAnalysis::MemStoreList
SmallVector< StoreInst * > MemStoreList
Definition: DecoupledAnalysis.hpp:56
CGRAOmp::DecoupledAnalysis::setComp
void setComp(CompList &&l)
Definition: DecoupledAnalysis.hpp:73
CGRAOmp::DecoupledAnalysis::load_end
load_iterator load_end()
Definition: DecoupledAnalysis.hpp:107
CGRAOmp::DecoupledAnalysis::comps
iterator_range< comp_iterator > comps()
Definition: DecoupledAnalysis.hpp:130
CGRAOmp::DecoupledAnalysis::invars_begin
invar_iterator invars_begin()
Definition: DecoupledAnalysis.hpp:134
CGRAOmp::DecoupledAnalysis::invar_iterator
InvarList::iterator invar_iterator
Definition: DecoupledAnalysis.hpp:63
CGRAOmp::DecoupledAnalysis::get_comps
CompList & get_comps()
Definition: DecoupledAnalysis.hpp:152
CGRAOmp::DecoupledAnalysis::load_begin
load_iterator load_begin()
Definition: DecoupledAnalysis.hpp:104
CGRAOmp::DecoupledAnalysis::comp_iterator
CompList::iterator comp_iterator
Definition: DecoupledAnalysis.hpp:62
CGRAOmp::DecoupledAnalysis::store_begin
store_iterator store_begin()
Definition: DecoupledAnalysis.hpp:114
CGRAOmp::DecoupledAnalysis::invars
iterator_range< invar_iterator > invars()
Definition: DecoupledAnalysis.hpp:140
CGRAOmp::DecoupledAnalysis::store_end
store_iterator store_end()
Definition: DecoupledAnalysis.hpp:117
CGRAOmp::DecoupledAnalysis::setInvars
void setInvars(InvarList &&l)
Definition: DecoupledAnalysis.hpp:76
CGRAOmp::DecoupledAnalysis::setMemLoad
void setMemLoad(MemLoadList &&l)
Definition: DecoupledAnalysis.hpp:66
CGRAOmp::DecoupledAnalysis::setMemStore
void setMemStore(MemStoreList &&l)
Definition: DecoupledAnalysis.hpp:70
CGRAOmp::DecoupledAnalysis::print
void print(raw_ostream &OS) const
Definition: DecoupledAnalysis.hpp:85
CGRAOmp::DecoupledAnalysis::stores
iterator_range< store_iterator > stores()
Definition: DecoupledAnalysis.hpp:120
CGRAOmp::DecoupledAnalysis::loop_invariant
InvarList loop_invariant
Definition: DecoupledAnalysis.hpp:190
CGRAOmp::DecoupledAnalysis::getSkipSequence
SmallVector< Value * > * getSkipSequence(Value *node)
get the node traversal skip sequence
Definition: DecoupledAnalysis.hpp:177