CGRAOmp  0.1
AGVerifyPass.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/AGVerifyPass.hpp
25 * Project: CGRAOmp
26 * Author: Takuya Kojima in The University of Tokyo (tkojima@hal.ipc.i.u-tokyo.ac.jp)
27 * Created Date: 15-02-2022 13:23:43
28 * Last Modified: 22-02-2022 06:18:30
29 */
30 #ifndef AGVerifyPass_H
31 #define AGVerifyPass_H
32 
33 #include "llvm/IR/PassManager.h"
34 #include "llvm/Passes/PassBuilder.h"
35 #include "llvm/Passes/PassPlugin.h"
36 #include "llvm/Support/raw_ostream.h"
37 #include "llvm/Analysis/LoopAnalysisManager.h"
38 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
39 #include "llvm/Support/Debug.h"
40 #include "llvm/Support/JSON.h"
41 
42 #include "VerifyPass.hpp"
43 
44 
45 #include <map>
46 
47 using namespace llvm;
48 
49 
50 namespace CGRAOmp {
51 
58  public:
62  AGCompatibility(AddressGenerator::Kind AGKind) : ag_kind(AGKind),
64 
65 
66  static bool classof(const VerifyResultBase* R) {
67  return R->getKind() == VerificationKind::MemoryAccess;
68  }
69 
70  void print(raw_ostream &OS) const override {}
71 
77  return ag_kind;
78  }
79 
80  StringRef getName() const {
81  return "Address generator compatibility";
82  }
83 
84  virtual llvm::json::Value getConfigAsJson(Instruction* I) const {
85  return json::Object({});
86  };
87 
88  int getDynamicTripCount();
89 
90  private:
92 
93  };
94 
100  public:
101  AffineAGCompatibility() : AGCompatibility(AddressGenerator::Kind::Affine), nested_level(0)
102  {};
103 
107  typedef struct {
108  int64_t start;
109  int64_t step;
110  int64_t count;
111  } DimEntry_t;
112 
113  typedef struct {
114  bool valid;
115  SmallVector<DimEntry_t> config;
116  Value *base = nullptr;
117  } ConfigTy;
118 
119 
120  // for dyn_cast from VerifyResultBase pointer
121  static bool classof(const VerifyResultBase* R) {
122  if (auto ag_compat = dyn_cast<AGCompatibility>(R)) {
123  return ag_compat->geAGtKind() == AddressGenerator::Kind::Affine;
124  }
125  return false;
126  }
127 
128  void print(raw_ostream &OS) const override;
129 
130  void add(Instruction* I, ConfigTy C) {
131  if (!C.valid) {
132  invalid_list.emplace_back(I);
133  setVio();
134  }
135  config[I] = C;
136  };
137 
138  virtual llvm::json::Value getConfigAsJson(Instruction *I) const;
139 
140  private:
141  DenseMap<Instruction*, ConfigTy> config;
142  SmallVector<Instruction*> invalid_list;
144 
145  };
146 
155  template <typename AGCompatibilityTy>
157  public AnalysisInfoMixin<VerifyAGCompatiblePass<AGCompatibilityTy>> {
158  public:
159  using Result = AGCompatibilityTy;
160 
169  Result run(Loop &L, LoopAnalysisManager &AM,
170  LoopStandardAnalysisResults &AR);
171  private:
172  friend AnalysisInfoMixin<VerifyAGCompatiblePass<AGCompatibilityTy>>;
173  static AnalysisKey Key;
174 
175  };
176 
177  template <typename AGCompatibilityTy>
179 
180 
181  // /**
182  // * @brief parse the expression of addition between SCEVs
183  // *
184  // * @param SAR parted expression
185  // * @param SE a result of ScalarEvolution for the function
186  // */
187  // void parseSCEVAddRecExpr(const SCEVAddRecExpr *SAR,
188  // ScalarEvolution &SE);
189  // void parseSCEV(const SCEV *scev, ScalarEvolution &SE, int depth = 0);
190 
191  void verifySCEVAsAffineAG(const SCEV* S, LoopStandardAnalysisResults &AR, AffineAGCompatibility::ConfigTy& C);
192 
193  bool parseStartSCEV(const SCEV* S, int *offset, Value **base);
194 
195  unsigned computeLoopTripCount(const Loop *L, LoopStandardAnalysisResults &AR);
196 }
197 
198 #endif //AGVerifyPass_H
llvm
Definition: OptionPlugin.cpp:128
CGRAOmp::AffineAGCompatibility::DimEntry_t::step
int64_t step
Definition: AGVerifyPass.hpp:109
CGRAOmp::AffineAGCompatibility::config
DenseMap< Instruction *, ConfigTy > config
Definition: AGVerifyPass.hpp:141
CGRAOmp::VerifyResultBase
An abstract class for the verification information.
Definition: VerifyPass.hpp:96
CGRAOmp::AGCompatibility
A derived class from VerifyResultBase describing whether the memory access pattern is compatible with...
Definition: AGVerifyPass.hpp:57
CGRAOmp::AffineAGCompatibility::invalid_list
SmallVector< Instruction * > invalid_list
Definition: AGVerifyPass.hpp:142
CGRAOmp::VerifyResultBase::getKind
virtual VerificationKind getKind() const
get the kind of derived class
Definition: VerifyPass.hpp:149
CGRAOmp::VerifyAGCompatiblePass
A function pass to verify the memory access pattern.
Definition: AGVerifyPass.hpp:156
CGRAOmp::AGCompatibility::ag_kind
AddressGenerator::Kind ag_kind
Definition: AGVerifyPass.hpp:91
CGRAOmp::verifySCEVAsAffineAG
void verifySCEVAsAffineAG(const SCEV *S, LoopStandardAnalysisResults &AR, AffineAGCompatibility::ConfigTy &C)
Definition: AGVerifyPass.cpp:158
CGRAOmp::VerificationKind::MemoryAccess
@ MemoryAccess
Checking each memory access meets the allowed access pattern.
CGRAOmp::AGCompatibility::geAGtKind
AddressGenerator::Kind geAGtKind() const
Get the Kind object.
Definition: AGVerifyPass.hpp:76
CGRAOmp::AGCompatibility::print
void print(raw_ostream &OS) const override
An abstract method to print the verification result.
Definition: AGVerifyPass.hpp:70
CGRAOmp::AffineAGCompatibility
A derived class from AGCompatibility for affine AGs.
Definition: AGVerifyPass.hpp:99
CGRAOmp::AffineAGCompatibility::ConfigTy
Definition: AGVerifyPass.hpp:113
CGRAOmp
Definition: AGVerifyPass.hpp:50
CGRAOmp::AffineAGCompatibility::classof
static bool classof(const VerifyResultBase *R)
Definition: AGVerifyPass.hpp:121
CGRAOmp::computeLoopTripCount
unsigned computeLoopTripCount(const Loop *L, LoopStandardAnalysisResults &AR)
Definition: AGVerifyPass.cpp:281
CGRAOmp::AGCompatibility::classof
static bool classof(const VerifyResultBase *R)
Definition: AGVerifyPass.hpp:66
CGRAOmp::AffineAGCompatibility::ConfigTy::config
SmallVector< DimEntry_t > config
Definition: AGVerifyPass.hpp:115
CGRAOmp::parseStartSCEV
bool parseStartSCEV(const SCEV *S, int *offset, Value **base)
Definition: AGVerifyPass.cpp:256
CGRAOmp::AffineAGCompatibility::DimEntry_t
a configration of loop control for a dimention
Definition: AGVerifyPass.hpp:107
CGRAOmp::AddressGenerator
An abstract class representing a type of address generator.
Definition: CGRAModel.hpp:215
CGRAOmp::AGCompatibility::AGCompatibility
AGCompatibility(AddressGenerator::Kind AGKind)
Construct a new AGCompatibility object.
Definition: AGVerifyPass.hpp:62
CGRAOmp::VerifyAGCompatiblePass::Key
static AnalysisKey Key
Definition: AGVerifyPass.hpp:173
CGRAOmp::AffineAGCompatibility::ConfigTy::valid
bool valid
Definition: AGVerifyPass.hpp:114
CGRAOmp::AffineAGCompatibility::AffineAGCompatibility
AffineAGCompatibility()
Definition: AGVerifyPass.hpp:101
CGRAOmp::AGCompatibility::getConfigAsJson
virtual llvm::json::Value getConfigAsJson(Instruction *I) const
Definition: AGVerifyPass.hpp:84
CGRAOmp::AffineAGCompatibility::DimEntry_t::start
int64_t start
Definition: AGVerifyPass.hpp:108
CGRAOmp::AffineAGCompatibility::DimEntry_t::count
int64_t count
Definition: AGVerifyPass.hpp:110
VerifyPass.hpp
CGRAOmp::VerificationKind
VerificationKind
Kind of verification.
Definition: VerifyPass.hpp:64
CGRAOmp::AddressGenerator::Kind
Kind
Definition: CGRAModel.hpp:217
CGRAOmp::AffineAGCompatibility::nested_level
int nested_level
Definition: AGVerifyPass.hpp:143
CGRAOmp::AGCompatibility::getName
StringRef getName() const
Definition: AGVerifyPass.hpp:80
CGRAOmp::AffineAGCompatibility::add
void add(Instruction *I, ConfigTy C)
Definition: AGVerifyPass.hpp:130