Go to the documentation of this file.
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/ADT/StringMap.h"
35 #include "llvm/ADT/StringRef.h"
36 #include "llvm/ADT/StringSet.h"
37 #include "llvm/ADT/SmallSet.h"
38 #include "llvm/Support/Error.h"
39 #include "llvm/Support/FormatVariadic.h"
40 #include "llvm/Support/JSON.h"
48 #define CATEGORY_KEY "category"
49 #define AG_CONF_KEY "address_generator"
50 #define AG_STYLE_KEY "control"
51 #define AG_MAX_NEST_KEY "max_nested_level"
52 #define COND_STYLE_KEY "conditional"
53 #define IDP_STYLE_KEY "inter-loop-dependency"
54 #define OPT_ENABLE_KEY "allowed"
55 #define OPT_TYPE_KEY "type"
56 #define CUSTOM_INST_KEY "custom_instructions"
57 #define GEN_INST_KEY "generic_instructions"
58 #define INST_MAP_KEY "instruction_map"
128 filename(filename), category(category),
129 cond(cond), inter_loop_dep(inter_loop_dep) {};
143 Error addSupportedInst(StringRef opcode);
153 void addCustomInst(StringRef opcode, ModuleAnalysisManager &MAM);
162 Error add_map_entry(StringRef opcode,
MapCondition *map_cond);
179 template <
typename DerivedT>
181 return dyn_cast<DerivedT>(
this);
199 return inter_loop_dep;
232 template <
typename DerivedT>
234 return dyn_cast<DerivedT>(
this);
257 cond, inter_loop_dep), AG(AG) {};
278 return M->
getKind() == CGRACategory::Decoupled;
309 max_nests(max_nests) {};
323 return ag->
getKind() == Kind::Affine;
341 return ag->
getKind() == Kind::FullState;
364 return M->
getKind() == CGRAModel::CGRACategory::TimeMultiplexed;
386 error_key(missed_key) {}
397 StringRef exptected_type,
398 json::Value *v =
nullptr) :
402 exptected_type(exptected_type) {
404 raw_string_ostream OS(json_val);
415 ModelError(StringRef filename, std::pair<StringRef,StringRef> config) :
416 filename(filename), errtype(
ErrorType::NoImplemented),
417 error_key(config.first), error_val(config.second.str()) {};
428 StringRef val, ArrayRef<StringRef> list);
442 return std::error_code(41, std::generic_category());
444 void log(raw_ostream &OS)
const override;
454 return errtype == ErrorType::MissingKey;
474 std::string json_val =
"";
479 StringRef region =
"";
494 ModuleAnalysisManager &MAM);
503 template <
typename SettingT>
515 template <
typename SettingT>
525 Expected<CGRAModel::CGRACategory>
getCategory(json::Object *json_obj,
538 template <
char const *key_str,
typename SettingT>
539 Expected<SettingT>
getOption(json::Object *json_obj,
541 StringMap<SettingT> settingMap);
550 Expected<AddressGenerator*>
parseAGConfig(json::Object *json_obj,
560 Expected<AddressGenerator*>
createAffineAG(json::Object *json_obj,
563 using AGGen_t = std::function<Expected<AddressGenerator*>(json::Object*,StringRef)>;
ConditionalStyle
Ability to handle conditional execution (i.e., if-else part)
Definition: CGRAModel.hpp:88
Definition: OptionPlugin.cpp:128
CGRA model for category "decoupled".
Definition: CGRAModel.hpp:245
ModelError(StringRef filename, StringRef key, StringRef exptected_type, json::Value *v=nullptr)
Construct a new ModelError when unexpected value type is specified.
Definition: CGRAModel.hpp:396
int max_nests
Definition: CGRAModel.hpp:327
int getMaxNests() const
Get the maximum nested level supported by this AddressGenerator.
Definition: CGRAModel.hpp:317
AddressGenerator(Kind kind)
Definition: CGRAModel.hpp:223
SmallVector< StringRef > valid_values
Definition: CGRAModel.hpp:480
static bool classof(const CGRAModel *M)
for downcasting from CGRAModel by llvm::dyn_cast
Definition: CGRAModel.hpp:363
Kind getKind() const
Definition: CGRAModel.hpp:228
Expected< SettingT > getOption(json::Object *json_obj, StringRef filename, StringMap< SettingT > settingMap)
Get common option from JSON config.
Definition: CGRAModel.cpp:164
AffineAG()
Default constructor without any limitation about the nested level.
Definition: CGRAModel.hpp:300
ErrorType
Type of error cause.
Definition: CGRAModel.hpp:462
DerivedT * asDerived()
Definition: CGRAModel.hpp:233
DerivedT * asDerived()
an interface to down cast to derived classes
Definition: CGRAModel.hpp:180
a model of address generator without any constraints
Definition: CGRAModel.hpp:334
AddressGenerator * AG
Definition: CGRAModel.hpp:281
static StringMap< CGRACategory > CategoryMap
Map category string to CGRACategory.
Definition: CGRAModel.hpp:110
bool isMissingKey()
check if the error cause if due to missing key
Definition: CGRAModel.hpp:453
CGRACategory category
Definition: CGRAModel.hpp:206
CGRA model for category "time-multiplexed".
Definition: CGRAModel.hpp:349
A model of address generator compatible to memory access with affine expression the accessed memory a...
Definition: CGRAModel.hpp:294
std::string error_val
Definition: CGRAModel.hpp:477
Definition: AGVerifyPass.hpp:50
InterLoopDep inter_loop_dep
Definition: CGRAModel.hpp:205
ErrorType errtype
Definition: CGRAModel.hpp:473
a representation of instruction mapping condition
Definition: CGRAInstMap.hpp:116
DecoupledCGRA(StringRef filename, AddressGenerator *AG, ConditionalStyle cond, InterLoopDep inter_loop_dep)
Construct a new DecoupledCGRA.
Definition: CGRAModel.hpp:254
InstMap inst_map
Definition: CGRAModel.hpp:207
CGRACategory
a category of the CGRA model
Definition: CGRAModel.hpp:77
Expected< CGRAModel * > parseCGRASetting(StringRef filepath, ModuleAnalysisManager &MAM)
a helper function to instantiate CGRAModel based on JSON configfile
Definition: CGRAModel.cpp:299
InterLoopDep getInterLoopDepType() const
Get the Inter Loop Dependency avility.
Definition: CGRAModel.hpp:198
An abstract class representing a type of address generator.
Definition: CGRAModel.hpp:215
CGRACategory getKind() const
Get the category of the CGRA.
Definition: CGRAModel.hpp:189
static StringMap< InterLoopDep > InterLoopDepMap
Map category string to InterLoopDep.
Definition: CGRAModel.hpp:114
A base class of CGRA model for DFG extraction.
Definition: CGRAModel.hpp:71
CGRAModel(StringRef filename, CGRACategory category, ConditionalStyle cond, InterLoopDep inter_loop_dep)
Construct a new CGRAModel object.
Definition: CGRAModel.hpp:125
ConditionalStyle cond
Definition: CGRAModel.hpp:204
AffineAG(int max_nests)
Construct a new AffineAG object.
Definition: CGRAModel.hpp:308
AddressGenerator * getAG() const
get the address generator
Definition: CGRAModel.hpp:272
static StringMap< ConditionalStyle > CondStyleMap
Map category string to ConditionalStyle.
Definition: CGRAModel.hpp:112
Expected< CGRAModel::CGRACategory > getCategory(json::Object *json_obj, StringRef filename)
Get CGRACategory from JSON config.
Definition: CGRAModel.cpp:116
void setRegion(StringRef region_str)
set a region where parse error ocurrs
Definition: CGRAModel.hpp:435
ModelError(StringRef filename, std::pair< StringRef, StringRef > config)
Construct a new ModelError when not implemented configuration is specified.
Definition: CGRAModel.hpp:415
A custom error used to notice the specified configuration file is invalid.
Definition: CGRAModel.hpp:375
ModelError(StringRef filename, StringRef missed_key)
Construct a new ModelError when missing a required item.
Definition: CGRAModel.hpp:383
bool containsValidData(StringMap< SettingT > settingMap, StringRef val)
Check if val is a valid setting for SettingT.
Definition: CGRAModel.cpp:100
SmallVector< StringRef > get_setting_values(StringMap< SettingT > settingMap)
a template to extract only values from SettingMap
Definition: CGRAModel.cpp:107
TMCGRA(StringRef filename)
Construct a new time-multiplexed CGRA object.
Definition: CGRAModel.hpp:356
StringRef exptected_type
Definition: CGRAModel.hpp:478
static bool classof(const AG *ag)
for downcasting from AddressGenerator by llvm::dyn_cast
Definition: CGRAModel.hpp:322
collective of all the instruction mapping
Definition: CGRAInstMap.hpp:592
static char ID
Definition: CGRAModel.hpp:439
Kind kind
Definition: CGRAModel.hpp:238
std::error_code convertToErrorCode() const override
Definition: CGRAModel.hpp:440
Kind
Definition: CGRAModel.hpp:217
static bool classof(const CGRAModel *M)
for downcasting from CGRAModel by llvm::dyn_cast
Definition: CGRAModel.hpp:277
StringRef filename
Definition: CGRAModel.hpp:475
StringRef error_key
Definition: CGRAModel.hpp:476
StringRef filename
Definition: CGRAModel.hpp:203
static bool classof(const AG *ag)
for downcasting from AddressGenerator by llvm::dyn_cast
Definition: CGRAModel.hpp:340
Expected< AddressGenerator * > parseAGConfig(json::Object *json_obj, StringRef filename)
parse a JSON config and instantiate AddressGenerator
Definition: CGRAModel.cpp:224
~DecoupledCGRA()
destructor
Definition: CGRAModel.hpp:263
Expected< AddressGenerator * > createAffineAG(json::Object *json_obj, StringRef filename)
Create a AffineAG object according to JSON config.
Definition: CGRAModel.cpp:267
An abstract class for an entry to replace IR instruction to targeting CGRA instruction.
Definition: CGRAInstMap.hpp:258
InterLoopDep
How to describe the inter-loop dependecy.
Definition: CGRAModel.hpp:101
std::function< Expected< AddressGenerator * >(json::Object *, StringRef)> AGGen_t
Definition: CGRAModel.hpp:563