fix generator.cc: generator::visit_function: segfault

This commit is contained in:
Michael Melesse
2022-10-24 17:41:20 +00:00
parent 56a06f7a06
commit eb89e9bdd9
2 changed files with 16 additions and 1 deletions

View File

@@ -79,11 +79,13 @@ std::unique_ptr<llvm::Module> add_passes_to_emit_bin(
ir::module& ir, llvm::LLVMContext& ctx, codegen::target* target, ir::module& ir, llvm::LLVMContext& ctx, codegen::target* target,
int num_warps, int num_stages, int& shared_static, int num_warps, int num_stages, int& shared_static,
const ExternLibMap& extern_lib_map) { const ExternLibMap& extern_lib_map) {
std::cout << "pass.cc: add_passes_to_emit_bin" << std::endl;
// generate llvm code // generate llvm code
std::string name = ir.get_function_list()[0]->get_name(); std::string name = ir.get_function_list()[0]->get_name();
std::unique_ptr<llvm::Module> llvm(new llvm::Module(name, ctx)); std::unique_ptr<llvm::Module> llvm(new llvm::Module(name, ctx));
// optimizations // optimizations
bool has_sm80 = target->as_nvidia() && target->as_nvidia()->sm() >= 80; // bool has_sm80 = target->as_nvidia() && target->as_nvidia()->sm() >= 80;
bool has_sm80 = false;
// create passes // create passes
codegen::analysis::align align; codegen::analysis::align align;
codegen::transform::inliner inliner; codegen::transform::inliner inliner;

View File

@@ -3798,6 +3798,7 @@ Value *generator::cast_shared_layout_ptr(analysis::data_layout *layout,
} }
void generator::visit_function(ir::function* fn) { void generator::visit_function(ir::function* fn) {
std::cout << "generator.cc: generator::visit_function:" << std::endl;
idxs_.clear(); idxs_.clear();
vals_.clear(); vals_.clear();
seen_.clear(); seen_.clear();
@@ -3807,6 +3808,7 @@ void generator::visit_function(ir::function* fn) {
// set attributes // set attributes
std::cout << "\t// set attributes" << std::endl;
for(auto attr_pair: fn->attrs()){ for(auto attr_pair: fn->attrs()){
unsigned id = attr_pair.first; unsigned id = attr_pair.first;
for(ir::attribute attr: attr_pair.second) for(ir::attribute attr: attr_pair.second)
@@ -3817,6 +3819,7 @@ void generator::visit_function(ir::function* fn) {
} }
} }
// set metadata // set metadata
std::cout << "\t// set metadata" << std::endl;
if(tgt_->is_gpu()){ if(tgt_->is_gpu()){
tgt_->set_kernel(*builder_, ctx, mod_, ret); tgt_->set_kernel(*builder_, ctx, mod_, ret);
#ifndef USE_ROCM #ifndef USE_ROCM
@@ -3829,9 +3832,11 @@ void generator::visit_function(ir::function* fn) {
#endif #endif
} }
// set arguments // set arguments
std::cout << "\t// set arguments" << std::endl;
for(unsigned i = 0; i < fn->args().size(); i++) for(unsigned i = 0; i < fn->args().size(); i++)
vals_[fn->args()[i]][{}] = &*(ret->arg_begin() + i); vals_[fn->args()[i]][{}] = &*(ret->arg_begin() + i);
// create blocks // create blocks
std::cout << "\t// create blocks" << std::endl;
auto blocks = ir::cfg::reverse_post_order(fn); auto blocks = ir::cfg::reverse_post_order(fn);
for(ir::basic_block *block: blocks) { for(ir::basic_block *block: blocks) {
BasicBlock *dst_block = BasicBlock::Create(ctx, block->get_name(), ret); BasicBlock *dst_block = BasicBlock::Create(ctx, block->get_name(), ret);
@@ -3839,6 +3844,8 @@ void generator::visit_function(ir::function* fn) {
} }
builder_->SetInsertPoint(bbs_[fn->blocks()[0]]); builder_->SetInsertPoint(bbs_[fn->blocks()[0]]);
// create policies // create policies
#ifndef USE_ROCM
std::cout << "\t// create policies" << std::endl;
if(tgt_->as_nvidia()->sm() >= 80) if(tgt_->as_nvidia()->sm() >= 80)
for(ir::load_inst::EVICTION_POLICY evict: {ir::load_inst::EVICT_FIRST, ir::load_inst::EVICT_LAST}){ for(ir::load_inst::EVICTION_POLICY evict: {ir::load_inst::EVICT_FIRST, ir::load_inst::EVICT_LAST}){
std::string policy = (evict == ir::load_inst::EVICT_FIRST) ? "evict_first" : "evict_last"; std::string policy = (evict == ir::load_inst::EVICT_FIRST) ? "evict_first" : "evict_last";
@@ -3846,17 +3853,22 @@ void generator::visit_function(ir::function* fn) {
InlineAsm* iasm = InlineAsm::get(FunctionType::get(i64_ty, {}), asm_str, "=l", false); InlineAsm* iasm = InlineAsm::get(FunctionType::get(i64_ty, {}), asm_str, "=l", false);
policies_[evict] = call(iasm); policies_[evict] = call(iasm);
} }
#endif
// initialize layouts // initialize layouts
std::cout << "\t// initialize layouts" << std::endl;
for(auto x: layouts_->get_all()){ for(auto x: layouts_->get_all()){
visit_layout(x.second); visit_layout(x.second);
} }
// generate LLVM-IR code // generate LLVM-IR code
std::cout << "\t// generate LLVM-IR code" << std::endl;
for(ir::basic_block *block: blocks) for(ir::basic_block *block: blocks)
visit_basic_block(block); visit_basic_block(block);
// finalize // finalize
std::cout << "\t// verifyFunction" << std::endl;
finalize_function(fn); finalize_function(fn);
// verifyFunction // verifyFunction
std::cout << "\t// verifyFunction" << std::endl;
llvm::verifyFunction(*ret); llvm::verifyFunction(*ret);
} }
@@ -4276,6 +4288,7 @@ void generator::packed_type(ir::value* i){
} }
void generator::visit(ir::module &src, llvm::Module &dst) { void generator::visit(ir::module &src, llvm::Module &dst) {
std::cout << "generator.cc: generator::visit" << std::endl;
mod_ = &dst; mod_ = &dst;
ctx_ = &dst.getContext(); ctx_ = &dst.getContext();
builder_ = new Builder(*ctx_); builder_ = new Builder(*ctx_);