CGRAOmp  0.1
OptionPlugin.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/OptionPlugin.hpp
25 * Project: CGRAOmp
26 * Author: Takuya Kojima in The University of Tokyo (tkojima@hal.ipc.i.u-tokyo.ac.jp)
27 * Created Date: 27-08-2021 14:20:02
28 * Last Modified: 17-07-2022 19:59:36
29 */
30 #ifndef OptionPlugin_H
31 #define OptionPlugin_H
32 
33 #include "llvm/Support/CommandLine.h"
34 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/Support/FormatVariadic.h"
36 #include "llvm/Support/raw_ostream.h"
37 
38 #include <regex>
39 #include <string>
40 
41 using namespace llvm;
42 using namespace std;
43 
44 namespace CGRAOmp
45 {
50  class OptKeyValue {
51  public:
56  OptKeyValue() : key(""), value(""), valid(false) {}
63  OptKeyValue(string key, string value) :
64  key(key), value(value), valid(true) {};
72  OptKeyValue(const char* s) : OptKeyValue(string(s)) {}
80  OptKeyValue(string keyvalue);
81 
83  OptKeyValue(const OptKeyValue &) = default;
85  OptKeyValue(OptKeyValue &&) = default;
86 
92  pair<string, string> get() {
93  return make_pair(key, value);
94  }
95 
101  string get_key() const {
102  return key;
103  }
104 
110  string get_value() const {
111  return value;
112  }
113 
132  explicit operator bool() const noexcept {
133  return valid;
134  }
135 
139  bool operator!=(const OptKeyValue &rhs) {
140  return !(*this == rhs);
141  }
142 
146  bool operator==(const OptKeyValue &rhs) {
147  return (key == rhs.key) && (value == rhs.value);
148  }
149 
151  OptKeyValue& operator=(OptKeyValue &&r) = default;
153  OptKeyValue& operator=(const OptKeyValue &r) = default;
154 
155  private:
156  bool valid;
157  string key;
158  string value;
159  };
160 
162  extern cl::opt<string> PathToCGRAConfig;
164  extern cl::alias PathToCGRAConfigAlias;
165 
167  extern cl::opt<bool> OptVerbose;
169  extern cl::opt<string> OptDFGOpKey;
171  extern cl::opt<bool> OptDFGPlainNodeName;
172 
174  extern cl::list<OptKeyValue> OptDFGGraphProp;
176  extern cl::list<OptKeyValue> OptDFGNodeProp;
178  extern cl::list<OptKeyValue> OptDFGEdgeProp;
179 
181  extern cl::opt<int> OptDFGFloatPrecWidth;
182 
184  extern cl::list<string> OptDFGPassPipeline;
185 
187  extern cl::list<string> OptDFGPassPlugin;
188 
190  extern cl::opt<string> OptDFGFilePrefix;
191 
193  extern cl::opt<bool> OptLoopInvariantAsConstant;
194 
196  extern cl::opt<bool> OptUseSimpleDFGName;
197 
199  extern cl::opt<int> OptMemoryDependencyDistanceThreshold;
200 
202  extern cl::opt<bool> OptEnableLoopFlatten;
203 
204 
205 
206 }
207 
208 namespace llvm {
209 
211 raw_ostream& operator<<(raw_ostream &OS, const CGRAOmp::OptKeyValue &D);
212 
213 namespace cl {
214 
215 using namespace CGRAOmp;
216 
218 bool operator==(const OptKeyValue &lhs, const OptKeyValue &rhs);
220 bool operator!=(const OptKeyValue &lhs, const OptKeyValue &rhs);
221 
223 template <>
224 struct OptionValue<OptKeyValue> final : OptionValueCopy<OptKeyValue> {
226 
227  OptionValue() = default;
228 
229  OptionValue(const OptKeyValue &V) { this->setValue(V); }
230 
232  setValue(V);
233  return *this;
234  }
235 
236 private:
237  void anchor() override;
238 };
239 
241 template <> class parser<OptKeyValue> : public basic_parser<OptKeyValue> {
242  public:
243  parser(Option &O) : basic_parser(O) {}
244 
245  // parse - Return true on error.
246  bool parse(Option &O, StringRef, StringRef Arg, OptKeyValue &Value) {
247  Value = OptKeyValue(Arg.str());
248  if (!Value) {
249  return O.error("'" + Arg +
250  "' value invalid for key-value argument!");
251  }
252  return false;
253  }
254 
255  // getValueName - Overload in subclass to provide a better default value.
256  StringRef getValueName() const override { return "key=value"; }
257 
258  void printOptionDiff(const Option &O, const OptVal &V, const OptVal &Default, size_t GlobalWidth) const;
259 
260  // An out-of-line virtual method to provide a 'home' for this class.
261  void anchor() override;
262 };
263 
264 extern template class basic_parser<OptKeyValue>;
265 
266 } // end namespace cl
267 
268 } // end namespace llvm
269 
270 #endif //OptionPlugin_H
CGRAOmp::OptKeyValue::operator!=
bool operator!=(const OptKeyValue &rhs)
equality comparetor
Definition: OptionPlugin.hpp:139
llvm
Definition: OptionPlugin.cpp:128
llvm::cl::OptionValue< OptKeyValue >
template specialization of OptionValue for OptKeyValue
Definition: OptionPlugin.hpp:224
CGRAOmp::PathToCGRAConfig
cl::opt< string > PathToCGRAConfig
path to model config
CGRAOmp::OptVerbose
cl::opt< bool > OptVerbose
a verbose option
CGRAOmp::OptUseSimpleDFGName
cl::opt< bool > OptUseSimpleDFGName
simplify the file name of DFG
llvm::cl::OptionValue< OptKeyValue >::OptionValue
OptionValue(const OptKeyValue &V)
Definition: OptionPlugin.hpp:229
llvm::cl::OptionValue< OptKeyValue >::operator=
OptionValue< OptKeyValue > & operator=(const OptKeyValue &V)
Definition: OptionPlugin.hpp:231
CGRAOmp::OptKeyValue::OptKeyValue
OptKeyValue()
Default constructor Instances made by this constructor are always invalidated.
Definition: OptionPlugin.hpp:56
llvm::cl::parser< OptKeyValue >::parser
parser(Option &O)
Definition: OptionPlugin.hpp:243
CGRAOmp::OptKeyValue::get
pair< string, string > get()
Get both key and value.
Definition: OptionPlugin.hpp:92
CGRAOmp::OptDFGPlainNodeName
cl::opt< bool > OptDFGPlainNodeName
to save human readable DOT
operator==
bool operator==(const OptKeyValue &lhs, const OptKeyValue &rhs)
Definition: OptionPlugin.cpp:140
CGRAOmp
Definition: AGVerifyPass.hpp:50
operator!=
bool operator!=(const OptKeyValue &lhs, const OptKeyValue &rhs)
Definition: OptionPlugin.cpp:134
CGRAOmp::OptMemoryDependencyDistanceThreshold
cl::opt< int > OptMemoryDependencyDistanceThreshold
threshold count for how close memory dependency is regarded as a data dependency in data flow graph
llvm::cl::parser< OptKeyValue >::getValueName
StringRef getValueName() const override
Definition: OptionPlugin.hpp:256
CGRAOmp::OptDFGEdgeProp
cl::list< OptKeyValue > OptDFGEdgeProp
to set common preference for edge
CGRAOmp::OptEnableLoopFlatten
cl::opt< bool > OptEnableLoopFlatten
to enable loop-flatten pass for CGRA kernel
CGRAOmp::OptDFGOpKey
cl::opt< string > OptDFGOpKey
key string for opcode in DOT graph
CGRAOmp::OptKeyValue::value
string value
Definition: OptionPlugin.hpp:158
CGRAOmp::OptKeyValue::key
string key
Definition: OptionPlugin.hpp:157
CGRAOmp::OptLoopInvariantAsConstant
cl::opt< bool > OptLoopInvariantAsConstant
consider loop invariant memory load as constant values for decoupled CGRAs
CGRAOmp::OptDFGFloatPrecWidth
cl::opt< int > OptDFGFloatPrecWidth
to specify precision width for floating-point number in DOT file
CGRAOmp::OptKeyValue::operator==
bool operator==(const OptKeyValue &rhs)
inequality comparator
Definition: OptionPlugin.hpp:146
CGRAOmp::OptKeyValue::get_value
string get_value() const
Get the value.
Definition: OptionPlugin.hpp:110
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const CGRAOmp::OptKeyValue &D)
stream insertion operator for llvm::raw_ostream
CGRAOmp::OptDFGNodeProp
cl::list< OptKeyValue > OptDFGNodeProp
to set common preference for node
CGRAOmp::OptKeyValue::OptKeyValue
OptKeyValue(string key, string value)
Construct a new Key-Value object.
Definition: OptionPlugin.hpp:63
CGRAOmp::OptDFGPassPlugin
cl::list< string > OptDFGPassPlugin
path list to load user DFG pass libraries
CGRAOmp::OptDFGPassPipeline
cl::list< string > OptDFGPassPipeline
to specify which DFG Pass is applied
llvm::cl::parser< OptKeyValue >::parse
bool parse(Option &O, StringRef, StringRef Arg, OptKeyValue &Value)
Definition: OptionPlugin.hpp:246
CGRAOmp::OptDFGGraphProp
cl::list< OptKeyValue > OptDFGGraphProp
to set common preference for graph
CGRAOmp::OptDFGFilePrefix
cl::opt< string > OptDFGFilePrefix
prefix for dot file name
CGRAOmp::OptKeyValue
A pair of key and value for command line option.
Definition: OptionPlugin.hpp:50
CGRAOmp::PathToCGRAConfigAlias
cl::alias PathToCGRAConfigAlias
alias of config file path
CGRAOmp::OptKeyValue::valid
bool valid
Definition: OptionPlugin.hpp:156
CGRAOmp::OptKeyValue::OptKeyValue
OptKeyValue(const char *s)
 converting constructor from char*
Definition: OptionPlugin.hpp:72
CGRAOmp::OptKeyValue::get_key
string get_key() const
Get the key.
Definition: OptionPlugin.hpp:101