2018-12-31 22:47:31 -05:00
|
|
|
#ifndef TDL_INCLUDE_IR_INSTRUCTIONS_H
|
|
|
|
#define TDL_INCLUDE_IR_INSTRUCTIONS_H
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
#include <vector>
|
2018-12-31 22:47:31 -05:00
|
|
|
#include "value.h"
|
2019-02-23 11:37:01 -05:00
|
|
|
#include "ir/type.h"
|
2019-01-02 01:06:43 -05:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2018-12-31 22:47:31 -05:00
|
|
|
|
|
|
|
namespace tdl{
|
|
|
|
namespace ir{
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
class basic_block;
|
2019-01-02 19:29:59 -05:00
|
|
|
class context;
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// instruction classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class instruction: public user{
|
2019-02-15 22:03:09 -05:00
|
|
|
public:
|
|
|
|
struct mask_info_t {
|
|
|
|
value *pred;
|
|
|
|
value *else_value;
|
|
|
|
};
|
|
|
|
|
2019-02-17 21:35:03 -05:00
|
|
|
virtual std::string repr_impl() const = 0;
|
|
|
|
|
2019-01-02 14:37:14 -05:00
|
|
|
protected:
|
2019-01-02 01:06:43 -05:00
|
|
|
// constructors
|
2019-01-02 19:29:59 -05:00
|
|
|
instruction(type *ty, unsigned num_ops, const std::string &name = "", instruction *next = nullptr);
|
2019-01-02 14:37:14 -05:00
|
|
|
|
|
|
|
public:
|
2019-01-02 01:06:43 -05:00
|
|
|
// parent
|
2019-02-15 22:03:09 -05:00
|
|
|
void set_parent(basic_block *block) { parent_ = block; }
|
|
|
|
const basic_block *get_parent() const { return parent_; }
|
|
|
|
basic_block *get_parent() { return parent_; }
|
2019-01-06 22:43:18 -05:00
|
|
|
void erase_from_parent();
|
2019-02-15 11:14:50 -05:00
|
|
|
// mask
|
2019-02-21 18:00:27 -05:00
|
|
|
void set_mask_pred(value *pred) { resize_hidden(1); set_operand(get_num_operands(), pred); }
|
|
|
|
value* get_mask_pred() const { if(get_num_hidden() == 0) return nullptr; return get_operand(get_num_operands()); }
|
2019-01-26 02:05:56 -05:00
|
|
|
// helpers
|
|
|
|
bool has_tile_result_or_op();
|
2019-02-17 21:35:03 -05:00
|
|
|
// repr
|
|
|
|
std::string repr() const { return repr_impl(); }
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
basic_block *parent_;
|
2019-02-13 15:41:03 -05:00
|
|
|
value *pred_;
|
2019-02-21 18:00:27 -05:00
|
|
|
value *mask_pred_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// phi_node classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
class phi_node: public instruction{
|
2019-01-02 01:06:43 -05:00
|
|
|
private:
|
2019-01-03 00:42:37 -05:00
|
|
|
phi_node(type *ty, unsigned num_reserved, const std::string &name, instruction *next);
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "phi"; }
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
public:
|
2019-01-02 19:29:59 -05:00
|
|
|
void set_incoming_value(unsigned i, value *v);
|
|
|
|
void set_incoming_block(unsigned i, basic_block *block);
|
2019-01-05 19:23:00 -05:00
|
|
|
value *get_incoming_value(unsigned i) { return get_operand(i); }
|
|
|
|
basic_block *get_incoming_block(unsigned i) { return blocks_[i]; }
|
|
|
|
unsigned get_num_incoming() { return get_num_operands(); }
|
2019-01-02 19:29:59 -05:00
|
|
|
void add_incoming(value *v, basic_block *block);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-02-17 21:35:03 -05:00
|
|
|
// Type
|
|
|
|
void set_type(type *ty) { ty_ = ty; }
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
// Factory methods
|
2019-01-03 00:42:37 -05:00
|
|
|
static phi_node* create(type *ty, unsigned num_reserved, const std::string &name = "", instruction *next = nullptr);
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned num_reserved_;
|
2019-01-02 19:29:59 -05:00
|
|
|
std::vector<basic_block*> blocks_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// binary_operator classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
class binary_operator: public instruction{
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
typedef llvm::BinaryOperator::BinaryOps op_t;
|
2019-02-17 21:35:03 -05:00
|
|
|
using llop = llvm::BinaryOperator::BinaryOps;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string repr_impl() const;
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Constructors
|
|
|
|
binary_operator(op_t op, value *lhs, value *rhs, type *ty, const std::string &name, instruction *next);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Get operand
|
|
|
|
op_t get_op() const { return op_; }
|
|
|
|
|
2019-01-05 14:50:31 -05:00
|
|
|
// Bool
|
|
|
|
bool is_terminator() const;
|
|
|
|
bool is_binary_op() const;
|
|
|
|
bool is_int_div_rem() const;
|
|
|
|
bool is_shift() const;
|
|
|
|
bool is_cast() const;
|
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
// Wraps
|
|
|
|
void set_has_no_unsigned_wrap(bool b = true) { has_no_unsigned_wrap_ = b; }
|
|
|
|
void set_has_no_signed_wrap(bool b = true) { has_no_signed_wrap_ = b; }
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
// Factory methods
|
|
|
|
static binary_operator *create(op_t op, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_fneg(value *arg, const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_neg(value *arg, const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_not(value *arg, const std::string &name = "", instruction *next = nullptr);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
op_t op_;
|
2019-01-03 15:32:22 -05:00
|
|
|
bool has_no_unsigned_wrap_;
|
|
|
|
bool has_no_signed_wrap_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// cmp_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class cmp_inst: public instruction{
|
|
|
|
public:
|
|
|
|
typedef llvm::CmpInst::Predicate pred_t;
|
2019-02-17 21:35:03 -05:00
|
|
|
using llop = llvm::CmpInst;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string repr_impl() const;
|
2019-01-02 14:37:14 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
protected:
|
2019-01-02 19:29:59 -05:00
|
|
|
cmp_inst(type *ty, pred_t pred, value *lhs, value *rhs, const std::string &name, instruction *next);
|
2019-01-02 14:37:14 -05:00
|
|
|
static bool is_fp_predicate(pred_t pred);
|
|
|
|
static bool is_int_predicate(pred_t pred);
|
2019-01-05 14:50:31 -05:00
|
|
|
static type* make_cmp_result_type(type *ty);
|
2019-01-02 14:37:14 -05:00
|
|
|
|
|
|
|
public:
|
2019-01-05 14:50:31 -05:00
|
|
|
pred_t get_pred() const { return pred_; }
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
pred_t pred_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class icmp_inst: public cmp_inst{
|
2019-01-02 14:37:14 -05:00
|
|
|
using cmp_inst::cmp_inst;
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
static icmp_inst* create(pred_t pred, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
class fcmp_inst: public cmp_inst{
|
2019-01-02 14:37:14 -05:00
|
|
|
using cmp_inst::cmp_inst;
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
static fcmp_inst* create(pred_t pred, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
2019-01-02 19:29:59 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// unary_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class unary_inst: public instruction {
|
|
|
|
protected:
|
|
|
|
unary_inst(type *Ty, value *v, const std::string &name, instruction *next);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// cast_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-02 19:29:59 -05:00
|
|
|
class cast_inst: public unary_inst{
|
|
|
|
using ic = llvm::Instruction::CastOps;
|
|
|
|
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
|
|
|
std::string repr_impl() const;
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
typedef llvm::CastInst::CastOps op_t;
|
|
|
|
|
2019-01-23 00:11:42 -05:00
|
|
|
protected:
|
|
|
|
cast_inst(type *ty, value *v, const std::string &name, instruction *next, op_t op)
|
|
|
|
: unary_inst(ty, v, name, next), op_(op) { }
|
|
|
|
|
2019-01-02 19:29:59 -05:00
|
|
|
private:
|
2019-01-04 01:43:02 -05:00
|
|
|
static bool is_valid(op_t op, value *arg, type *ty);
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
public:
|
2019-01-05 14:50:31 -05:00
|
|
|
// accessors
|
|
|
|
op_t get_op() const { return op_; }
|
|
|
|
|
|
|
|
// factory methods
|
2019-01-02 01:06:43 -05:00
|
|
|
static cast_inst *create(op_t op, value *arg, type *ty,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static cast_inst *create_integer_cast(value *arg, type *ty, bool is_signed,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
op_t op_;
|
|
|
|
};
|
|
|
|
|
2019-01-23 00:11:42 -05:00
|
|
|
#define TDL_IR_DECLARE_CAST_INST_SIMPLE(name, op) \
|
|
|
|
class name : public cast_inst{ \
|
|
|
|
friend class cast_inst; \
|
|
|
|
name(type *ty, value *v, const std::string &name, instruction *next) \
|
|
|
|
: cast_inst(ty, v, name, next, op){ } \
|
|
|
|
};
|
|
|
|
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(trunc_inst, llvm::Instruction::CastOps::Trunc)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(z_ext_inst, llvm::Instruction::CastOps::ZExt)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(s_ext_inst, llvm::Instruction::CastOps::SExt)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(fp_trunc_inst, llvm::Instruction::CastOps::FPTrunc)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(fp_ext_inst, llvm::Instruction::CastOps::FPExt)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(ui_to_fp_inst, llvm::Instruction::CastOps::UIToFP)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(si_to_fp_inst, llvm::Instruction::CastOps::SIToFP)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(fp_to_ui_inst, llvm::Instruction::CastOps::FPToUI)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(fp_to_si_inst, llvm::Instruction::CastOps::FPToSI)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(ptr_to_int_inst, llvm::Instruction::CastOps::PtrToInt)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(int_to_ptr_inst, llvm::Instruction::CastOps::IntToPtr)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(bit_cast_inst, llvm::Instruction::CastOps::BitCast)
|
|
|
|
TDL_IR_DECLARE_CAST_INST_SIMPLE(addr_space_cast_inst, llvm::Instruction::CastOps::AddrSpaceCast)
|
2019-01-02 19:29:59 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// terminator_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class terminator_inst: public instruction{
|
2019-01-02 19:29:59 -05:00
|
|
|
using instruction::instruction;
|
2019-01-02 01:06:43 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 19:29:59 -05:00
|
|
|
// return instruction
|
|
|
|
class return_inst: public terminator_inst{
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
|
|
|
std::string repr_impl() const { return "ret"; }
|
2019-01-02 19:29:59 -05:00
|
|
|
return_inst(context &ctx, value *ret_val, instruction *next);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// accessors
|
|
|
|
value *get_return_value()
|
|
|
|
{ return get_num_operands() ? get_operand(0) : nullptr; }
|
|
|
|
|
|
|
|
unsigned get_num_successors() const { return 0; }
|
2019-01-02 01:06:43 -05:00
|
|
|
|
2019-01-02 19:29:59 -05:00
|
|
|
// factory methods
|
|
|
|
static return_inst* create(context &ctx, value *ret_val = nullptr, instruction *next = nullptr);
|
2019-01-02 01:06:43 -05:00
|
|
|
};
|
|
|
|
|
2019-01-05 14:50:31 -05:00
|
|
|
// base branch instruction
|
2019-01-02 19:29:59 -05:00
|
|
|
class branch_inst: public terminator_inst{
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
|
|
|
std::string repr_impl() const { return "br"; }
|
|
|
|
|
2019-01-05 14:50:31 -05:00
|
|
|
protected:
|
|
|
|
using terminator_inst::terminator_inst;
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static branch_inst* create(basic_block *dest,
|
2019-01-02 19:29:59 -05:00
|
|
|
instruction *next = nullptr);
|
2019-01-02 01:06:43 -05:00
|
|
|
static branch_inst* create(value *cond, basic_block *if_dest, basic_block *else_dest,
|
2019-01-02 19:29:59 -05:00
|
|
|
instruction *next = nullptr);
|
2019-01-02 01:06:43 -05:00
|
|
|
};
|
|
|
|
|
2019-01-05 14:50:31 -05:00
|
|
|
// conditional branch
|
|
|
|
class cond_branch_inst: public branch_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-05 14:50:31 -05:00
|
|
|
friend class branch_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
cond_branch_inst(basic_block *if_dst, basic_block *else_dst, value *cond, instruction *next);
|
2019-01-05 14:50:31 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
basic_block *get_true_dest() { return (basic_block*)get_operand(0); }
|
|
|
|
basic_block *get_false_dest() { return (basic_block*)get_operand(1); }
|
|
|
|
value *get_cond() { return get_operand(2); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// unconditional branch
|
|
|
|
class uncond_branch_inst: public branch_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-05 14:50:31 -05:00
|
|
|
friend class branch_inst;
|
|
|
|
uncond_branch_inst(basic_block *dst, instruction *next);
|
|
|
|
|
|
|
|
public:
|
|
|
|
basic_block *get_dest() { return (basic_block*)get_operand(0); }
|
|
|
|
};
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// getelementptr_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class getelementptr_inst: public instruction{
|
2019-01-05 14:50:31 -05:00
|
|
|
private:
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "getelementptr"; }
|
2019-01-02 19:29:59 -05:00
|
|
|
getelementptr_inst(type *pointee_ty, value *ptr, const std::vector<value*> &idx, const std::string &name, instruction *next);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static type *get_return_type(type *ty, value *ptr, const std::vector<value*> &idx);
|
|
|
|
static type *get_indexed_type_impl(type *ty, const std::vector<value *> &idx);
|
|
|
|
static type *get_indexed_type(type *ty, const std::vector<value*> &idx);
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
2019-01-05 14:50:31 -05:00
|
|
|
// accessors
|
|
|
|
type *get_source_elt_ty() { return source_elt_ty; }
|
|
|
|
op_iterator idx_begin() { return op_begin() + 1; }
|
|
|
|
op_iterator idx_end() { return op_end(); }
|
|
|
|
|
|
|
|
// factory methods
|
2019-01-07 04:08:55 -05:00
|
|
|
static getelementptr_inst* create(value *ptr, const std::vector<value*> &idx,
|
2019-01-02 01:06:43 -05:00
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2019-01-02 19:29:59 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
type *source_elt_ty;
|
|
|
|
type *res_elt_ty;
|
2019-01-02 01:06:43 -05:00
|
|
|
};
|
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// load_inst/store_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class load_inst: public unary_inst{
|
2019-01-10 16:50:47 -05:00
|
|
|
private:
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "load"; }
|
2019-01-03 15:32:22 -05:00
|
|
|
load_inst(value *ptr, const std::string &name, instruction *next);
|
|
|
|
|
2019-01-10 16:50:47 -05:00
|
|
|
private:
|
|
|
|
static type *get_pointee_type(type *ty);
|
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
public:
|
2019-01-05 14:50:31 -05:00
|
|
|
// accessors
|
|
|
|
value *get_pointer_operand() { return get_operand(0); }
|
|
|
|
// factory method
|
2019-01-03 15:32:22 -05:00
|
|
|
static load_inst* create(value *ptr, const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
2019-01-10 23:53:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class store_inst: public instruction{
|
|
|
|
private:
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "store"; }
|
2019-01-10 23:53:27 -05:00
|
|
|
store_inst(value *ptr, value *v, const std::string &name, instruction *next);
|
2019-01-03 15:32:22 -05:00
|
|
|
|
2019-01-10 23:53:27 -05:00
|
|
|
public:
|
|
|
|
value *get_pointer_operand() { return get_operand(0); }
|
|
|
|
value *get_value_operand() { return get_operand(1); }
|
|
|
|
// factory method
|
|
|
|
static store_inst* create(value* ptr, value *v, const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
2019-01-03 15:32:22 -05:00
|
|
|
};
|
|
|
|
|
2019-01-03 00:42:37 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// retile_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
// retile
|
2019-01-03 00:42:37 -05:00
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
class retile_inst: public unary_inst {
|
2019-01-03 12:44:33 -05:00
|
|
|
protected:
|
2019-02-23 11:37:01 -05:00
|
|
|
retile_inst(value *arg, const type::tile_shapes_t &shapes, const std::string &name, instruction *next);
|
2019-02-17 21:35:03 -05:00
|
|
|
static std::string shape_suffix(ir::type* ty);
|
2019-01-03 00:42:37 -05:00
|
|
|
};
|
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
// reshape
|
|
|
|
|
|
|
|
class reshape_inst: public retile_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-03 12:44:33 -05:00
|
|
|
using retile_inst::retile_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "reshape" + shape_suffix(get_type()); }
|
2019-01-03 00:42:37 -05:00
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
public:
|
2019-02-23 11:37:01 -05:00
|
|
|
static instruction* create(value *arg, const type::tile_shapes_t &shape_suffix,
|
2019-01-03 12:44:33 -05:00
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2019-01-03 00:42:37 -05:00
|
|
|
};
|
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
// splat
|
|
|
|
|
|
|
|
class splat_inst: public retile_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-03 12:44:33 -05:00
|
|
|
using retile_inst::retile_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "splat" + shape_suffix(get_type()); }
|
2019-01-03 00:42:37 -05:00
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
public:
|
2019-02-23 11:37:01 -05:00
|
|
|
static instruction* create(value *arg, const type::tile_shapes_t &shape_suffix,
|
2019-01-03 12:44:33 -05:00
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2019-01-03 00:42:37 -05:00
|
|
|
};
|
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
// broadcast
|
|
|
|
|
|
|
|
class broadcast_inst: public retile_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-03 12:44:33 -05:00
|
|
|
using retile_inst::retile_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "broadcast" + shape_suffix(get_type()); }
|
2019-01-03 00:42:37 -05:00
|
|
|
|
2019-01-03 12:44:33 -05:00
|
|
|
public:
|
2019-02-23 11:37:01 -05:00
|
|
|
static instruction* create(value *arg, const type::tile_shapes_t &shape_suffix,
|
2019-01-03 12:44:33 -05:00
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2019-01-03 00:42:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-12 23:24:25 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// builtin_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-09 02:07:34 -05:00
|
|
|
class builtin_inst: public instruction{
|
|
|
|
protected:
|
|
|
|
using instruction::instruction;
|
|
|
|
};
|
|
|
|
|
|
|
|
class get_global_range_inst: public builtin_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-09 02:07:34 -05:00
|
|
|
get_global_range_inst(type *ty, unsigned axis, const std::string &name, instruction *next);
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "get_global_range(" + std::to_string(axis_) + ")"; }
|
2019-01-09 02:07:34 -05:00
|
|
|
|
|
|
|
public:
|
2019-02-23 11:37:01 -05:00
|
|
|
static instruction* create(context &ctx, unsigned axis, type::tile_shapes_t::value_type size,
|
2019-01-09 02:07:34 -05:00
|
|
|
const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
2019-02-06 15:02:01 -05:00
|
|
|
unsigned get_axis() const { return axis_; }
|
2019-01-09 02:07:34 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned axis_;
|
|
|
|
};
|
|
|
|
|
2019-01-10 23:53:27 -05:00
|
|
|
class matmul_inst: public builtin_inst {
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-10 23:53:27 -05:00
|
|
|
matmul_inst(value *A, value *B, value *C, const std::string &name, instruction *next);
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "dot"; }
|
2019-01-10 23:53:27 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static instruction* create(value *A, value *B, value *C,
|
|
|
|
const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
2019-01-12 23:24:25 -05:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// intrinsics classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class copy_to_shared_inst: public unary_inst{
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-01-12 23:24:25 -05:00
|
|
|
using unary_inst::unary_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "copy_to_shared"; }
|
2019-01-12 23:24:25 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static copy_to_shared_inst* create(value *arg, const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
2019-02-12 19:36:16 -05:00
|
|
|
class barrier_inst: public instruction{
|
|
|
|
private:
|
|
|
|
barrier_inst(context &ctx, const std::string &name, instruction *next);
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "barrier"; }
|
2019-02-12 19:36:16 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static barrier_inst* create(context &ctx, const std::string &name = "",
|
|
|
|
instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
2019-02-10 21:59:41 -05:00
|
|
|
class vectorize_inst: public unary_inst{
|
2019-02-17 21:35:03 -05:00
|
|
|
private:
|
2019-02-10 21:59:41 -05:00
|
|
|
using unary_inst::unary_inst;
|
2019-02-17 21:35:03 -05:00
|
|
|
std::string repr_impl() const { return "vectorize"; }
|
2019-02-10 21:59:41 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static vectorize_inst* create(value *arg, const std::string &name = "", instruction *next = nullptr);
|
|
|
|
};
|
2019-01-12 23:24:25 -05:00
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|