From cf1a583dbff2a615c9df0f1ef7f668973f2d9d0c Mon Sep 17 00:00:00 2001 From: Philippe Tillet Date: Fri, 15 Feb 2019 22:03:09 -0500 Subject: [PATCH] bla --- examples/matrix.cpp | 6 +++--- include/ast/ast.h | 9 ++++++--- include/ir/instructions.h | 18 ++++++++++++------ lib/ast/lowering.cpp | 8 ++++---- lib/codegen/selection.cpp | 14 +++++++++----- lib/codegen/tune.cpp | 6 ++---- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/examples/matrix.cpp b/examples/matrix.cpp index 8145ddb90..b96d32bdb 100644 --- a/examples/matrix.cpp +++ b/examples/matrix.cpp @@ -54,8 +54,8 @@ void test(fp32 *a, fp32 *b, fp32 *c, int32 M, int32 N, int32 K, int32 bound){\ int1 checkc1[16] = ryc < N;\ int1 checkc[16, 16] = checkc0[:, newaxis] && checkc1[newaxis, :];\ for(k = K; k > 0; k = k - 8){\ - int1 sanitya[16, 8] = (k >= bound);\ - int1 sanityb[16, 8] = (k >= bound);\ + int1 sanitya[16, 8] = (k > 16);\ + int1 sanityb[16, 8] = (k > 16);\ C = dot(a, b, C);\ pa = pa + 8*M;\ pb = pb + 8*K;\ @@ -236,7 +236,7 @@ int main() { // execute machine code // Allocate buffers typedef float numeric_t; - size_t M = 128, N = 128, K = 128; + size_t M = 32, N = 32, K = 32; size_t bound = 8; std::vector c(M*N); std::vector rc(M*N); diff --git a/include/ast/ast.h b/include/ast/ast.h index 4a9889093..51e3f97f2 100644 --- a/include/ast/ast.h +++ b/include/ast/ast.h @@ -287,14 +287,17 @@ public: class assignment_expression: public expression{ public: assignment_expression(node *lvalue, ASSIGN_OP_T op, node *rvalue) - : lvalue_((named_expression*)lvalue), op_(op), rvalue_((expression*)rvalue) { } + : lhs_((named_expression*)lvalue), op_(op), rhs_((expression*)rvalue) { } + + const expression *lhs() const { return lhs_; } + const expression *rhs() const { return rhs_; } ir::value* codegen(ir::module *mod) const; public: ASSIGN_OP_T op_; - const expression *lvalue_; - const expression *rvalue_; + const expression *lhs_; + const expression *rhs_; }; diff --git a/include/ir/instructions.h b/include/ir/instructions.h index 6c835ec2e..74d5040f3 100644 --- a/include/ir/instructions.h +++ b/include/ir/instructions.h @@ -16,26 +16,32 @@ class context; //===----------------------------------------------------------------------===// class instruction: public user{ +public: + struct mask_info_t { + value *pred; + value *else_value; + }; + protected: // constructors instruction(type *ty, unsigned num_ops, const std::string &name = "", instruction *next = nullptr); public: // parent - void set_parent(basic_block *block) { parent_ = block; } - const basic_block *get_parent() const { return parent_; } - basic_block *get_parent() { return parent_; } + void set_parent(basic_block *block) { parent_ = block; } + const basic_block *get_parent() const { return parent_; } + basic_block *get_parent() { return parent_; } void erase_from_parent(); // mask - value* set_mask(value *mask) { mask_ = mask; } - value* get_mask() { return mask_; } + value* set_mask(value *pred, value *else_value = nullptr) { mask_ = {pred, else_value}; } + const mask_info_t get_mask() const { return mask_; } // helpers bool has_tile_result_or_op(); private: basic_block *parent_; value *pred_; - value *mask_; + mask_info_t mask_; }; //===----------------------------------------------------------------------===// diff --git a/lib/ast/lowering.cpp b/lib/ast/lowering.cpp index 4a9d7ff3e..6f44f24c5 100644 --- a/lib/ast/lowering.cpp +++ b/lib/ast/lowering.cpp @@ -527,16 +527,16 @@ ir::value *conditional_expression::codegen(ir::module *mod) const{ /* Assignment expression */ ir::value *assignment_expression::codegen(ir::module *mod) const{ - ir::value *rvalue = rvalue_->codegen(mod); + ir::value *rhs = rhs_->codegen(mod); if(auto *x = dynamic_cast(lvalue_)) - mod->set_value(x->id()->name(), rvalue); + mod->set_value(x->id()->name(), rhs); else if(auto* x = dynamic_cast(lvalue_)){ assert(x->get_op()==DEREF); assert(x->lvalue()); ir::value *ptr = x->lvalue()->codegen(mod); - rvalue = mod->get_builder().create_store(ptr, rvalue); + rhs = mod->get_builder().create_store(ptr, rhs); } - return rvalue; + return rhs; } /* Type name */ diff --git a/lib/codegen/selection.cpp b/lib/codegen/selection.cpp index 85fdb2189..1b9116e51 100644 --- a/lib/codegen/selection.cpp +++ b/lib/codegen/selection.cpp @@ -481,14 +481,16 @@ void selection::lower_tile_instruction(ir::instruction *ins, llvm::IRBuilder<> & BasicBlock *block = builder.GetInsertBlock(); Module *module = block->getModule(); Function *function = block->getParent(); - ir::value *mask = ins->get_mask(); + ir::instruction::mask_info_t mask = ins->get_mask(); LLVMContext &ctx = builder.getContext(); // helper to handle masks auto insert_masked = [&](indices_t idx, std::function insert_value) { BasicBlock *block = builder.GetInsertBlock(); Value *result; - if(mask){ - Value *llvm_mask = tmap_.at(mask)->get_value(idx); + if(mask.pred){ +// if(mask.else_value) +// std::cout << mask.else_value << std::endl; + Value *llvm_mask = tmap_.at(mask.pred)->get_value(idx); BasicBlock *then_bb = BasicBlock::Create(ctx, "", function); BasicBlock *done_bb = BasicBlock::Create(ctx, "", function); builder.CreateCondBr(llvm_mask, then_bb, done_bb); @@ -499,7 +501,10 @@ void selection::lower_tile_instruction(ir::instruction *ins, llvm::IRBuilder<> & if(!ins->get_type()->is_void_ty()){ Type *ty = result->getType(); PHINode *phi = builder.CreatePHI(ty, 2); - phi->addIncoming(llvm::UndefValue::get(ty), block); +// if(mask.else_value) +// phi->addIncoming(tmap_.at(mask.else_value)->get_value(idx), block); +// else + phi->addIncoming(llvm::UndefValue::get(ty), block); phi->addIncoming(result, then_bb); return (Value*)phi; } @@ -728,7 +733,6 @@ void selection::run(ir::module &src, Module &dst){ for(unsigned n = 0; n < phi->get_num_incoming(); n++){ ir::value *inc_val = phi->get_incoming_value(n); ir::basic_block *inc_block = phi->get_incoming_block(n); - std::cout << typeid(*inc_val).name() << " " << inc_val << " " << inc_block << std::endl; BasicBlock *llvm_inc_block = last_block.at(inc_block); if(phi->get_type()->is_tile_ty()) { distributed_tile *phi_tile = (distributed_tile*)tmap_.at(phi); diff --git a/lib/codegen/tune.cpp b/lib/codegen/tune.cpp index 924392cab..8919f171b 100644 --- a/lib/codegen/tune.cpp +++ b/lib/codegen/tune.cpp @@ -67,17 +67,15 @@ void tune::init_c_graph(ir::instruction *v) { } // Element-wise else if(dynamic_cast(v)){ - std::cout << typeid(*v).name() << std::endl; for(unsigned i = 0; i < shapes.size(); i ++) for(ir::value* op: v->ops()) add_constraint({v, i}, {op, i}); } /* Add mask constraints */ - if(ir::value *mask = v->get_mask()){ - std::cout << typeid(*mask).name() << " " << typeid(*v->ops()[0]).name() << std::endl; + if(ir::value *pred = v->get_mask().pred){ for(unsigned i = 0; i < shapes.size(); i++) - add_constraint({v->ops()[0], i}, {mask, i}); + add_constraint({v->ops()[0], i}, {pred, i}); } }