[intermediate representation] added some builder function definitions
This commit is contained in:
@@ -41,9 +41,10 @@ public:
|
|||||||
block_->get_inst_list().insert(insert_point_, inst);
|
block_->get_inst_list().insert(insert_point_, inst);
|
||||||
inst->set_name(name);
|
inst->set_name(name);
|
||||||
}
|
}
|
||||||
// Branch instructions
|
// terminator instructions
|
||||||
value* create_br(basic_block *dest);
|
value* create_br(basic_block *dest);
|
||||||
value* create_cond_br(value *cond, basic_block* if_dest, basic_block* else_dest);
|
value* create_cond_br(value *cond, basic_block* if_dest, basic_block* else_dest);
|
||||||
|
value* create_ret_void();
|
||||||
// Cast instructions
|
// Cast instructions
|
||||||
value *create_cast(cast_inst::op_t op, value *v, type *dst_ty, const std::string &name = "");
|
value *create_cast(cast_inst::op_t op, value *v, type *dst_ty, const std::string &name = "");
|
||||||
value* create_si_to_fp(value *src, type *dst_ty, const std::string &name = "");
|
value* create_si_to_fp(value *src, type *dst_ty, const std::string &name = "");
|
||||||
@@ -106,8 +107,6 @@ public:
|
|||||||
value *create_splat(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
value *create_splat(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
||||||
value *create_reshape(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
value *create_reshape(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
||||||
value *create_broadcast(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
value *create_broadcast(value *arg, const std::vector<unsigned> &shapes, const std::string &name = "");
|
||||||
// Terminators
|
|
||||||
value *create_ret_void();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
context &ctx_;
|
context &ctx_;
|
||||||
|
@@ -227,7 +227,7 @@ private:
|
|||||||
static type *get_indexed_type(type *ty, const std::vector<value*> &idx);
|
static type *get_indexed_type(type *ty, const std::vector<value*> &idx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static getelementptr_inst* create(value *ptr, const std::vector<value*> &idx,
|
static getelementptr_inst* create(type *pointee_ty, value *ptr, const std::vector<value*> &idx,
|
||||||
const std::string &name = "", instruction *next = nullptr);
|
const std::string &name = "", instruction *next = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -239,20 +239,41 @@ private:
|
|||||||
// retile_inst classes
|
// retile_inst classes
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
class retile_inst: public instruction{
|
// retile
|
||||||
|
|
||||||
|
class retile_inst: public instruction {
|
||||||
|
protected:
|
||||||
|
retile_inst(value *arg, const std::vector<unsigned> &shapes, const std::string &name, instruction *next);
|
||||||
};
|
};
|
||||||
|
|
||||||
class reshape_inst: public instruction{
|
// reshape
|
||||||
|
|
||||||
|
class reshape_inst: public retile_inst {
|
||||||
|
using retile_inst::retile_inst;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static instruction* create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name = "", instruction *next = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
class splat_inst: public instruction{
|
// splat
|
||||||
|
|
||||||
|
class splat_inst: public retile_inst {
|
||||||
|
using retile_inst::retile_inst;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static instruction* create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name = "", instruction *next = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
class broadcast_inst: public instruction{
|
// broadcast
|
||||||
|
|
||||||
|
class broadcast_inst: public retile_inst {
|
||||||
|
using retile_inst::retile_inst;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static instruction* create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name = "", instruction *next = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -155,12 +155,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class function_type: public type {
|
class function_type: public type {
|
||||||
|
private:
|
||||||
|
function_type(type *ret_ty, const std::vector<type *> ¶m_tys);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static function_type* get(type *ret_ty, const std::vector<type*>& param_tys);
|
static function_type* get(type *ret_ty, const std::vector<type*>& param_tys);
|
||||||
|
|
||||||
private:
|
|
||||||
type *return_type_;
|
|
||||||
std::vector<type *> param_types_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ void builder::set_insert_point(basic_block *block){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// branch instructions
|
// terminator instructions
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
value* builder::create_br(basic_block *dest){
|
value* builder::create_br(basic_block *dest){
|
||||||
@@ -36,6 +36,10 @@ value* builder::create_cond_br(value *cond, basic_block *if_dest, basic_block *e
|
|||||||
return insert(branch_inst::create(cond, if_dest, else_dest));
|
return insert(branch_inst::create(cond, if_dest, else_dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value *builder::create_ret_void() {
|
||||||
|
return insert(return_inst::create(ctx_));
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// cast instructions
|
// cast instructions
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -133,7 +137,7 @@ DEFINE_UNARY_INT(not)
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
value* builder::create_gep(value *ptr, const std::vector<value*>& idx_list, const std::string &name){
|
value* builder::create_gep(value *ptr, const std::vector<value*>& idx_list, const std::string &name){
|
||||||
return insert(getelementptr_inst::create(ptr, idx_list), name);
|
return insert(getelementptr_inst::create(nullptr, ptr, idx_list), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -199,24 +203,17 @@ DEFINE_FCMP_INSTR(ONE, llvm::FCmpInst::FCMP_ONE)
|
|||||||
// tile instructions
|
// tile instructions
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
//value *create_splat(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
value *builder::create_reshape(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
||||||
//}
|
return insert(reshape_inst::create(arg, shapes, name));
|
||||||
|
}
|
||||||
|
|
||||||
//value *create_reshape(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
value *builder::create_splat(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
||||||
|
return insert(splat_inst::create(arg, shapes, name));
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
value *builder::create_broadcast(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
||||||
|
return insert(broadcast_inst::create(arg, shapes, name));
|
||||||
//value *create_broadcast(value *arg, const std::vector<unsigned> &shapes, const std::string &name) {
|
}
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// terminator instructions
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
//value *create_red_void() {
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -280,6 +280,43 @@ type *getelementptr_inst::get_indexed_type(type *ty, const std::vector<value *>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getelementptr_inst *getelementptr_inst::create(type *pointee_ty, value *ptr, const std::vector<value *> &idx, const std::string &name, instruction *next) {
|
||||||
|
return new getelementptr_inst(pointee_ty, ptr, idx, name, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// retile_inst classes
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
retile_inst::retile_inst(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name, instruction *next)
|
||||||
|
: instruction(tile_type::get(arg->get_type()->get_scalar_ty(), shapes), 1, name, next) {
|
||||||
|
set_operand(0, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reshape
|
||||||
|
|
||||||
|
instruction* reshape_inst::create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name, instruction *next) {
|
||||||
|
return new reshape_inst(arg, shapes, name, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// splat
|
||||||
|
|
||||||
|
instruction* splat_inst::create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name, instruction *next) {
|
||||||
|
return new splat_inst(arg, shapes, name, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
// broadcast
|
||||||
|
|
||||||
|
instruction* broadcast_inst::create(value *arg, const std::vector<unsigned> &shapes,
|
||||||
|
const std::string &name, instruction *next) {
|
||||||
|
return new broadcast_inst(arg, shapes, name, next);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,5 +152,20 @@ tile_type* tile_type::get_same_shapes(type *ty, type *ref){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// function_type class
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
function_type::function_type(type *ret_ty, const std::vector<type*> ¶m_tys):
|
||||||
|
type(ret_ty->get_context(), FunctionTyID) {
|
||||||
|
contained_tys_.push_back(ret_ty);
|
||||||
|
for(type *ty: param_tys)
|
||||||
|
contained_tys_.push_back(ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
function_type* function_type::get(type *ret_ty, const std::vector<type *> ¶m_tys) {
|
||||||
|
return new function_type(ret_ty, param_tys);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user