[code generation] fixed bug in on-the-fly AST to IR lowering
This commit is contained in:
@@ -21,32 +21,75 @@ namespace tdl{
|
||||
namespace codegen{
|
||||
|
||||
class allocation;
|
||||
class tune;
|
||||
|
||||
struct distributed_axis {
|
||||
std::vector<llvm::Value*> values;
|
||||
};
|
||||
|
||||
class tile {
|
||||
protected:
|
||||
typedef std::vector<unsigned> shapes_t;
|
||||
|
||||
public:
|
||||
tile(const shapes_t &shapes): shapes_(shapes){ }
|
||||
|
||||
private:
|
||||
shapes_t shapes_;
|
||||
};
|
||||
|
||||
class shared_tile: public tile {
|
||||
public:
|
||||
using tile::tile;
|
||||
|
||||
};
|
||||
|
||||
class distributed_tile: public tile{
|
||||
typedef std::vector<distributed_axis> axes_t;
|
||||
|
||||
public:
|
||||
distributed_tile(const shapes_t& shapes, const axes_t &axes)
|
||||
: tile(shapes), axes_(axes) {}
|
||||
|
||||
private:
|
||||
axes_t axes_;
|
||||
};
|
||||
|
||||
|
||||
class selection{
|
||||
typedef std::map<ir::value *, llvm::Value *> vmap_t;
|
||||
typedef std::map<ir::basic_block *, llvm::BasicBlock *> bmap_t;
|
||||
typedef std::map<ir::value *, tile *> tmap_t;
|
||||
|
||||
private:
|
||||
// LLVM conversions
|
||||
llvm::Type* llvm_type(ir::type *ty, llvm::LLVMContext &ctx);
|
||||
llvm::Value* llvm_value(ir::value *v,llvm:: LLVMContext &ctx);
|
||||
llvm::Instruction* llvm_inst(ir::instruction *inst, llvm::LLVMContext &ctx);
|
||||
llvm::Constant* llvm_constant(ir::constant *cst, llvm::LLVMContext &ctx);
|
||||
|
||||
// grid construction
|
||||
void create_grids(std::vector<ir::instruction*> &grids,
|
||||
std::map<unsigned*, ir::instruction*> &references,
|
||||
ir::function *fn);
|
||||
void init_axes(ir::instruction *i, llvm::IRBuilder<> &builder, llvm::Value *u_thread_id, llvm::Value *u_warp_id);
|
||||
void init_grids(ir::function *fn, llvm::IRBuilder<> &builder);
|
||||
|
||||
// lowering
|
||||
void lower_instruction(ir::instruction *src, llvm::IRBuilder<> &builder);
|
||||
void lower_tile_instruction(ir::instruction *src, llvm::IRBuilder<> &builder);
|
||||
|
||||
public:
|
||||
selection(allocation *alloc): alloc_(alloc){ }
|
||||
selection(allocation *alloc, tune *params): alloc_(alloc), params_(params){ }
|
||||
void run(ir::module &src, llvm::Module &dst);
|
||||
|
||||
private:
|
||||
vmap_t vmap_;
|
||||
bmap_t bmap_;
|
||||
tmap_t tmap_;
|
||||
allocation *alloc_;
|
||||
|
||||
tune *params_;
|
||||
std::map<ir::instruction*, std::vector<distributed_axis>> axes_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ namespace ir{
|
||||
class value;
|
||||
class module;
|
||||
class instruction;
|
||||
class function;
|
||||
}
|
||||
|
||||
namespace codegen{
|
||||
@@ -24,11 +25,13 @@ private:
|
||||
void init_c_phi(ir::instruction *i);
|
||||
void init_c_graph(ir::instruction *v);
|
||||
void connected_components(node_t x, const std::vector<unsigned*> vals, std::set<node_t> &nodes, graph_t &graph);
|
||||
void create_grids(std::vector<ir::instruction*> &grids, std::map<unsigned*, ir::instruction*> &references, ir::function *fn);
|
||||
|
||||
|
||||
public:
|
||||
void get_params(ir::module& mod, std::vector<unsigned*> &result);
|
||||
unsigned *get_param(ir::value *value);
|
||||
std::vector<unsigned *> get_params(ir::module& mod);
|
||||
std::map<std::string, unsigned *> get_params(ir::instruction* i);
|
||||
unsigned *get_param(ir::value *value, const std::string &key) { return params_[value][key]; }
|
||||
bool check_constraints(ir::module &fn, std::map<ir::value *, std::vector<std::string>> &errors);
|
||||
void run(ir::module &mod);
|
||||
|
||||
|
Reference in New Issue
Block a user