[code generation] testing analysis passes
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
#include "ir/module.h"
|
||||
#include "codegen/selection.h"
|
||||
#include "codegen/tune.h"
|
||||
#include "codegen/shared_copy.h"
|
||||
#include "codegen/allocation.h"
|
||||
#include "codegen/liveness.h"
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
@@ -53,9 +56,14 @@ int main() {
|
||||
llvm::LLVMContext llvm_context;
|
||||
llvm::Module llvm_module("test", llvm_context);
|
||||
// lowering passes
|
||||
tdl::codegen::selection selection;
|
||||
tdl::codegen::place_shared_copy shared;
|
||||
tdl::codegen::tune tune;
|
||||
tdl::codegen::liveness liveness;
|
||||
tdl::codegen::allocation allocation(&liveness);
|
||||
tune.run(module);
|
||||
shared.run(module);
|
||||
liveness.run(module);
|
||||
allocation.run();
|
||||
std::vector<unsigned*> params;
|
||||
tune.get_params(module, params);
|
||||
std::cout << params.size() << std::endl;
|
||||
|
@@ -20,6 +20,9 @@ class loop_info;
|
||||
|
||||
class allocation {
|
||||
public:
|
||||
allocation(liveness *live)
|
||||
: liveness_(live){ }
|
||||
|
||||
// accessors
|
||||
unsigned get_offset(ir::value *x) const { return offsets_.at(x); }
|
||||
unsigned get_allocated_size() const { return allocated_size_; }
|
||||
@@ -33,8 +36,6 @@ private:
|
||||
size_t allocated_size_;
|
||||
// dependences
|
||||
liveness *liveness_;
|
||||
layout *layout_;
|
||||
loop_info *loop_info_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -13,8 +13,6 @@ namespace ir{
|
||||
|
||||
namespace codegen{
|
||||
|
||||
class layout;
|
||||
|
||||
typedef unsigned slot_index;
|
||||
|
||||
struct segment {
|
||||
@@ -54,7 +52,6 @@ private:
|
||||
has_storage_map_t has_dedicated_storage_;
|
||||
indices_map_t indices_;
|
||||
intervals_map_t intervals_;
|
||||
layout* layouts_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -20,6 +20,14 @@ namespace llvm{
|
||||
namespace tdl{
|
||||
namespace codegen{
|
||||
|
||||
class allocation;
|
||||
|
||||
struct distributed_axis {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class selection{
|
||||
typedef std::map<ir::value *, llvm::Value *> vmap_t;
|
||||
typedef std::map<ir::basic_block *, llvm::BasicBlock *> bmap_t;
|
||||
@@ -31,11 +39,13 @@ private:
|
||||
llvm::Constant* llvm_constant(ir::constant *cst, llvm::LLVMContext &ctx);
|
||||
|
||||
public:
|
||||
selection(allocation *alloc): alloc_(alloc){ }
|
||||
void run(ir::module &src, llvm::Module &dst);
|
||||
|
||||
private:
|
||||
vmap_t vmap_;
|
||||
bmap_t bmap_;
|
||||
allocation *alloc_;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -27,6 +27,7 @@ public:
|
||||
builder(context &ctx);
|
||||
// Setters
|
||||
void set_insert_point(iterator instr);
|
||||
void set_insert_point(instruction* i);
|
||||
void set_insert_point(basic_block* block);
|
||||
basic_block* get_insert_block() { return block_; }
|
||||
iterator get_insert_point() { return insert_point_;}
|
||||
@@ -42,7 +43,6 @@ public:
|
||||
block_->get_inst_list().insert(insert_point_, inst);
|
||||
inst->set_parent(block_);
|
||||
inst->set_name(name);
|
||||
insert_point_ = block_->end();
|
||||
return inst;
|
||||
}
|
||||
// terminator instructions
|
||||
@@ -116,7 +116,8 @@ public:
|
||||
// Built-in instruction
|
||||
value *create_get_global_range(unsigned axis, unsigned size, const std::string &name = "");
|
||||
value *create_matmul(value *A, value *B, value *C, const std::string &name = "");
|
||||
|
||||
// Intrinsics
|
||||
value *create_copy_to_shared(value *arg, const std::string &name = "");
|
||||
private:
|
||||
context &ctx_;
|
||||
basic_block *block_;
|
||||
|
@@ -347,7 +347,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// built-in
|
||||
//===----------------------------------------------------------------------===//
|
||||
// builtin_inst classes
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class builtin_inst: public instruction{
|
||||
protected:
|
||||
using instruction::instruction;
|
||||
@@ -374,6 +377,21 @@ public:
|
||||
instruction *next = nullptr);
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// intrinsics classes
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
class copy_to_shared_inst: public unary_inst{
|
||||
using unary_inst::unary_inst;
|
||||
|
||||
public:
|
||||
static copy_to_shared_inst* create(value *arg, const std::string &name = "",
|
||||
instruction *next = nullptr);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
namespace tdl{
|
||||
namespace codegen{
|
||||
|
||||
|
||||
void allocation::run(){
|
||||
using std::max;
|
||||
using std::min;
|
||||
@@ -108,8 +107,9 @@ void allocation::run(){
|
||||
|
||||
// Save maximum size of induced memory space
|
||||
allocated_size_ = 0;
|
||||
for(auto &x: offsets_)
|
||||
for(auto &x: offsets_){
|
||||
allocated_size_ = std::max<size_t>(allocated_size_, x.second + get_num_bytes(x.first));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "codegen/liveness.h"
|
||||
#include "codegen/layout.h"
|
||||
#include "ir/basic_block.h"
|
||||
#include "ir/function.h"
|
||||
#include "ir/module.h"
|
||||
@@ -24,9 +23,7 @@ for(ir::function *fn: mod.get_function_list()){
|
||||
// Creates live intervals
|
||||
for(auto i: indices_){
|
||||
ir::value *v = i.first;
|
||||
if(!layouts_->get_num_shared_views(v))
|
||||
continue;
|
||||
if(!layouts_->get_shared_view(v, 0).has_dedicated_storage)
|
||||
if(!dynamic_cast<ir::copy_to_shared_inst*>(v))
|
||||
continue;
|
||||
unsigned start = i.second;
|
||||
unsigned end = start;
|
||||
|
@@ -63,7 +63,7 @@ Constant *selection::llvm_constant(ir::constant *cst, LLVMContext &ctx) {
|
||||
}
|
||||
|
||||
|
||||
/* convert ir::instruction to Instruction */
|
||||
/* convert ir::instruction to llvm::Instruction */
|
||||
Instruction *selection::llvm_inst(ir::instruction *inst, LLVMContext & ctx) {
|
||||
auto value = [&](ir::value *x) { return llvm_value(x, ctx); };
|
||||
auto block = [&](ir::basic_block *x) { return bmap_.at(x); };
|
||||
@@ -125,7 +125,9 @@ Instruction *selection::llvm_inst(ir::instruction *inst, LLVMContext & ctx) {
|
||||
throw std::runtime_error("unknown conversion from ir::type to Type");
|
||||
}
|
||||
|
||||
/* convert ir::value to llvm::Value */
|
||||
Value* selection::llvm_value(ir::value *v, LLVMContext &ctx) {
|
||||
assert(!v->get_type()->is_tile_ty());
|
||||
if(vmap_.find(v) != vmap_.end())
|
||||
return vmap_.at(v);
|
||||
// create operands
|
||||
@@ -141,6 +143,11 @@ Value* selection::llvm_value(ir::value *v, LLVMContext &ctx) {
|
||||
throw std::runtime_error("unknown conversion from ir::value to Value");
|
||||
}
|
||||
|
||||
/* lower tile to a set of llvm::Value's */
|
||||
//void selection::lower_tile(ir::value *v) {
|
||||
|
||||
//}
|
||||
|
||||
void selection::run(ir::module &src, Module &dst){
|
||||
vmap_.clear();
|
||||
bmap_.clear();
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "ir/builder.h"
|
||||
#include "ir/constant.h"
|
||||
#include "ir/instructions.h"
|
||||
#include "ir/intrinsics.h"
|
||||
#include "ir/type.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
|
||||
@@ -16,11 +17,18 @@ builder::builder(context &ctx):
|
||||
// utilities
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void builder::set_insert_point(basic_block::iterator instr){
|
||||
block_ = (*instr)->get_parent();
|
||||
insert_point_ = instr;
|
||||
void builder::set_insert_point(basic_block::iterator it){
|
||||
block_ = (*it)->get_parent();
|
||||
insert_point_ = it;
|
||||
}
|
||||
|
||||
void builder::set_insert_point(instruction* i){
|
||||
block_ = i->get_parent();
|
||||
auto it = std::find(block_->begin(), block_->end(), i);
|
||||
set_insert_point(it);
|
||||
}
|
||||
|
||||
|
||||
void builder::set_insert_point(basic_block *block){
|
||||
block_ = block;
|
||||
insert_point_ = block->end();
|
||||
@@ -262,5 +270,14 @@ value *builder::create_matmul(value *A, value *B, value *C, const std::string &n
|
||||
return insert(matmul_inst::create(A, B, C, name));
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// intrinsic instructions
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
value *builder::create_copy_to_shared(value *arg, const std::string &name) {
|
||||
return insert(copy_to_shared_inst::create(arg, name));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -360,8 +360,8 @@ matmul_inst::matmul_inst(value *A, value *B, value *C,
|
||||
const std::string &name, instruction *next)
|
||||
: builtin_inst(C->get_type(), 3, name, next) {
|
||||
set_operand(0, A);
|
||||
set_operand(0, B);
|
||||
set_operand(0, C);
|
||||
set_operand(1, B);
|
||||
set_operand(2, C);
|
||||
}
|
||||
|
||||
instruction *matmul_inst::create(value *A, value *B, value *C,
|
||||
@@ -385,5 +385,13 @@ instruction* get_global_range_inst::create(context &ctx, unsigned axis, unsigned
|
||||
return new get_global_range_inst(tile_ty, axis, name, next);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// intrinsic instructions
|
||||
//===----------------------------------------------------------------------===//
|
||||
copy_to_shared_inst* copy_to_shared_inst::create(value *arg, const std::string &name,
|
||||
instruction *next) {
|
||||
return new copy_to_shared_inst(arg->get_type(), arg, name, next);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -160,7 +160,7 @@ bool tile_type::is_valid_elt_ty(type *ty) {
|
||||
unsigned tile_type::get_num_elements() const {
|
||||
unsigned res = 1;
|
||||
for(unsigned shape: shapes_)
|
||||
shape *= res;
|
||||
res *= shape;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user