Go to the documentation of this file.
34 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/ADT/StringRef.h"
36 #include "llvm/IR/Constant.h"
37 #include "llvm/IR/Function.h"
38 #include "llvm/IR/InstrTypes.h"
39 #include "llvm/IR/Instruction.h"
40 #include "llvm/IR/Operator.h"
41 #include "llvm/Support/JSON.h"
42 #include "llvm/IR/PassManager.h"
51 #define CGRAOMP_CUSTOM_INST_ATTR "cgra_custom_inst"
54 #define FLAG_GETTER(FLAG, ISA, GETTER) make_pair(FLAG, [](Instruction *I) { \
62 #define CMP_PRED_PAIR(STR, ENUM) make_pair(STR, CmpInst::Predicate::ENUM)
65 #define BINOP_ENTRY(OPCODE, OPENUM) make_pair(OPCODE, [](MapCondition *c){ \
67 return make_shared<BinaryOpMapEntry>(OPCODE, BinaryOperator::OPENUM, c); \
69 return make_shared<BinaryOpMapEntry>(OPCODE, BinaryOperator::OPENUM); \
72 #define COMPOP_ENTRY(OPCODE, IS_INTEGER) make_pair(OPCODE, [](MapCondition *c){ \
74 return make_shared<CompOpMapEntry>(OPCODE, IS_INTEGER, c); \
76 return make_shared<CompOpMapEntry>(OPCODE, IS_INTEGER); \
79 #define MEMOP_ENTRY(OPCODE, OPENUM) make_pair(OPCODE, [](MapCondition *c){ \
81 return make_shared<MemoryOpMapEntry>(OPCODE, Instruction::MemoryOps::OPENUM, c); \
83 return make_shared<MemoryOpMapEntry>(OPCODE, Instruction::MemoryOps::OPENUM); \
87 #define OTHEROP_ENTRY(OPCODE, OPENUM) make_pair(OPCODE, [](MapCondition *c){ \
89 return make_shared<OtherOpMapEntry>(OPCODE, OPENUM, c); \
91 return make_shared<OtherOpMapEntry>(OPCODE, OPENUM); \
96 #define INST_KEY "inst"
98 #define CONST_RHS_KEY "rhs"
99 #define CONST_LHS_KEY "lhs"
100 #define FLAGS_KEY "flags"
101 #define PRED_KEY "pred"
102 #define CONST_INT_KEY "ConstantInt"
103 #define CONST_DBL_KEY "ConstantDouble"
105 #define VEC_MAKE_RANGE(VEC) (make_range(VEC.begin(), VEC.end()))
107 using namespace llvm;
124 map_name(map.str()), anyLHS(true),
125 anyRHS(true), anyPred(true) {};
140 void setConst(
int use,
bool isLeft);
149 void setConst(
double use,
bool isLeft);
157 Error setFlags(ArrayRef<std::string> flags);
165 Error setPred(StringRef pred);
174 bool match(Instruction *I);
185 void print(raw_ostream &OS);
200 bool isUseInt =
false;
217 return (fabs(a - b) <= DBL_EPSILON
218 * fmax(1, fmax(fabs(a), fabs(b))));
223 static StringMap<std::function<bool(Instruction*)>>
FlagGetter;
239 json::Object *json_obj,
251 Expected<SmallVector<std::string>>
getStringArray(json::Object *json_obj,
252 StringRef key, StringRef filename);
275 opcode_str(opcode.str()), Kind(Kind) {
287 opcode_str(opcode.str()), Kind(Kind), map_cond(cond) {};
309 virtual bool match(Instruction *I) = 0;
317 virtual bool match(StringRef opcode) {
318 return opcode_str == opcode;
325 return map_cond->getMapName();
328 void print(raw_ostream &OS);
353 InstMapEntry::InstMapKind::BinaryOp;
377 bool match(Instruction *I);
380 return imap->
getKind() == BinaryOp;
383 Instruction::BinaryOps
ops;
393 InstMapEntry::InstMapKind::CompOp;
404 isInteger(isInteger) {};
418 isInteger(isInteger) {};
421 return imap->
getKind() == CompOp;
427 bool match(Instruction *I);
439 InstMapEntry::InstMapKind::MemOp;
462 return imap->
getKind() == MemOp;
468 bool match(Instruction *I);
480 InstMapEntry::InstMapKind::CustomOp;
488 ModuleAnalysisManager &MAM) :
498 ModuleAnalysisManager &MAM,
500 InstMapEntry(func_name, CustomOp, map_cond), MAM(MAM) {};
503 return imap->
getKind() == CustomOp;
509 bool match(Instruction *I);
512 bool isCustomOpFunc(Function *F);
513 ModuleAnalysisManager &
MAM;
523 InstMapEntry::InstMapKind::OtherOp;
561 template <
typename OpEnumTy>
571 bool match(Instruction *I);
574 return imap->
getKind() == OtherOp;
621 Error add_generic_inst(StringRef opcode);
629 void add_custom_inst(StringRef opcode, ModuleAnalysisManager &MAM);
638 Error add_map_entry(StringRef opcode,
MapCondition* map_cond);
656 #endif //CGRAInstMap_H
SmallVector< entry_ptr > entries
Definition: CGRAInstMap.hpp:649
Expected< std::pair< StringRef, MapCondition * > > createMapCondition(json::Object *json_obj, StringRef filename)
create a MapCondition instance from json object
Definition: CGRAInstMap.cpp:503
~MapCondition()
Destructor.
Definition: CGRAInstMap.hpp:132
virtual bool match(StringRef opcode)
check this entry is for the specified instruction This will not check the mapping condition.
Definition: CGRAInstMap.hpp:317
Definition: OptionPlugin.cpp:128
CompOpMapEntry(StringRef opcode, bool isInteger)
Construct a new CompOpMapEntry object.
Definition: CGRAInstMap.hpp:402
OtherOpMapEntry(StringRef opcode, OpEnumTy ops, MapCondition *cond)
Construct a new OtherOpMapEntry object with an initial MapCondition instance.
Definition: CGRAInstMap.hpp:562
MapCondition(StringRef map)
Construct a new MapCondition object.
Definition: CGRAInstMap.hpp:123
Instruction::MemoryOps mem_kind
Definition: CGRAInstMap.hpp:470
bool anyLHS
Definition: CGRAInstMap.hpp:201
OtherOpMapEntry(StringRef opcode, Instruction::OtherOps ops)
Construct a new OtherOpMapEntry object for other instructions.
Definition: CGRAInstMap.hpp:549
static StringMap< std::function< bool(Instruction *)> > FlagGetter
Definition: CGRAInstMap.hpp:223
OptCategory
Definition: CGRAInstMap.hpp:577
bool isInteger
Definition: CGRAInstMap.hpp:429
MemoryOpMapEntry(StringRef opcode, Instruction::MemoryOps kind, MapCondition *cond)
Construct a new MemoryOpMapEntry object.
Definition: CGRAInstMap.hpp:456
A derived class from InstMapEntry for BinaryOperation.
Definition: CGRAInstMap.hpp:350
A derived class from InstMapEntry for memory operation.
Definition: CGRAInstMap.hpp:436
void dump()
Definition: CGRAInstMap.hpp:187
static bool classof(const InstMapEntry *imap)
Definition: CGRAInstMap.hpp:573
bool anyPred
Definition: CGRAInstMap.hpp:203
std::function< entry_ptr(MapCondition *)> entry_generator
Definition: CGRAInstMap.hpp:643
BinaryOpMapEntry(StringRef opcode, Instruction::BinaryOps ops)
Construct a new BinaryOpMapEntry object.
Definition: CGRAInstMap.hpp:360
static bool equal_double(double a, double b)
equality comparetor for double values
Definition: CGRAInstMap.hpp:216
std::shared_ptr< InstMapEntry > entry_ptr
Definition: CGRAInstMap.hpp:641
InstMapKind Kind
Definition: CGRAInstMap.hpp:338
InstMapKind
Definition: CGRAInstMap.hpp:260
std::string opcode_str
Definition: CGRAInstMap.hpp:341
void dump()
Definition: CGRAInstMap.hpp:329
A derived class from InstMapEntry for comparison instructions.
Definition: CGRAInstMap.hpp:390
Instruction::CastOps cast_ops
Definition: CGRAInstMap.hpp:585
static bool classof(const InstMapEntry *imap)
Definition: CGRAInstMap.hpp:461
Definition: AGVerifyPass.hpp:50
A derived class from InstMapEntry for custom instruction.
Definition: CGRAInstMap.hpp:477
CmpInst::Predicate cmp_pred
Definition: CGRAInstMap.hpp:199
A derived class from InstMapEntry for other type of operations.
Definition: CGRAInstMap.hpp:520
OtherOpMapEntry(StringRef opcode, Instruction::CastOps ops)
Construct a new OtherOpMapEntry object for cast instructions.
Definition: CGRAInstMap.hpp:540
Expected< SmallVector< std::string > > getStringArray(json::Object *json_obj, StringRef key, StringRef filename)
Get the String Array from json object.
Definition: CGRAInstMap.cpp:456
OtherOpMapEntry(StringRef opcode, Instruction::TermOps ops)
Construct a new OtherOpMapEntry object for terminator instructions.
Definition: CGRAInstMap.hpp:530
std::function< bool(Instruction *I)> match_use
wrapper for const operand comparison
Definition: CGRAInstMap.hpp:193
static bool classof(const InstMapEntry *imap)
Definition: CGRAInstMap.hpp:502
a representation of instruction mapping condition
Definition: CGRAInstMap.hpp:116
CustomInstMapEntry(StringRef func_name, ModuleAnalysisManager &MAM)
Construct a new CustomIns MapEntry object.
Definition: CGRAInstMap.hpp:487
static bool classof(const InstMapEntry *imap)
Definition: CGRAInstMap.hpp:379
int use_int
Definition: CGRAInstMap.hpp:196
SmallVector< StringRef > flag_list
Definition: CGRAInstMap.hpp:198
OptCategory cat
Definition: CGRAInstMap.hpp:582
InstMapEntry(StringRef opcode, InstMapKind Kind)
Construct a new InstMapEntry object.
Definition: CGRAInstMap.hpp:274
~InstMapEntry()
Definition: CGRAInstMap.hpp:289
Instruction::BinaryOps ops
Definition: CGRAInstMap.hpp:383
InstMap()
Constructor.
Definition: CGRAInstMap.hpp:595
InstMapEntry(StringRef opcode, InstMapKind Kind, MapCondition *cond)
Construct a new InstMapEntry object with an initial MapCondition instance.
Definition: CGRAInstMap.hpp:286
Instruction::OtherOps other_ops
Definition: CGRAInstMap.hpp:583
virtual std::string getMapName()
get the map name of this entry
Definition: CGRAInstMap.hpp:324
BinaryOpMapEntry(StringRef opcode, Instruction::BinaryOps ops, MapCondition *cond)
Construct a new BinaryOpMapEntry object with an initial MapCondition instance.
Definition: CGRAInstMap.hpp:370
static bool classof(const InstMapEntry *imap)
Definition: CGRAInstMap.hpp:420
StringRef pred_str
Definition: CGRAInstMap.hpp:206
CompOpMapEntry(StringRef opcode, bool isInteger, MapCondition *cond)
Construct a new CompOpMapEntry object with an initial MapCondition instance.
Definition: CGRAInstMap.hpp:415
static StringMap< CmpInst::Predicate > PredMap
Definition: CGRAInstMap.hpp:226
collective of all the instruction mapping
Definition: CGRAInstMap.hpp:592
ModuleAnalysisManager & MAM
Definition: CGRAInstMap.hpp:513
bool anyRHS
Definition: CGRAInstMap.hpp:202
int const_operand
Definition: CGRAInstMap.hpp:204
static StringMap< entry_generator > entry_gen
Definition: CGRAInstMap.hpp:647
std::string map_name
Definition: CGRAInstMap.hpp:195
std::string getMapName()
get map name associated with this condition
Definition: CGRAInstMap.hpp:181
Instruction::TermOps term_ops
Definition: CGRAInstMap.hpp:584
SmallVector< entry_ptr >::iterator entry_iterator
Definition: CGRAInstMap.hpp:642
CustomInstMapEntry(StringRef func_name, ModuleAnalysisManager &MAM, MapCondition *map_cond)
Construct a new CustomInstMapEntry object with an initial MapCondition instance.
Definition: CGRAInstMap.hpp:497
MemoryOpMapEntry(StringRef opcode, Instruction::MemoryOps kind)
Construct a new MemoryOpMapEntry object.
Definition: CGRAInstMap.hpp:446
StringMap< entry_ptr > defaultEntries
Definition: CGRAInstMap.hpp:650
InstMapKind getKind() const
Definition: CGRAInstMap.hpp:334
double use_double
Definition: CGRAInstMap.hpp:197
MapCondition * map_cond
Definition: CGRAInstMap.hpp:340
void addMapping(MapCondition *cond)
set a mapping condition
Definition: CGRAInstMap.hpp:298
An abstract class for an entry to replace IR instruction to targeting CGRA instruction.
Definition: CGRAInstMap.hpp:258