From d83165d2981b67991f8d8985db5807a36785b74b Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Wed, 2 Nov 2022 10:13:38 +0800 Subject: [PATCH] [llvm] Set the name of the LLVM function of the real function to its name (#6495) Issue: #602 ### Brief Summary Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- taichi/codegen/llvm/codegen_llvm.cpp | 15 +++++++++------ taichi/codegen/llvm/codegen_llvm.h | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/taichi/codegen/llvm/codegen_llvm.cpp b/taichi/codegen/llvm/codegen_llvm.cpp index ff1988458bf94..711f2d562ccb6 100644 --- a/taichi/codegen/llvm/codegen_llvm.cpp +++ b/taichi/codegen/llvm/codegen_llvm.cpp @@ -22,15 +22,16 @@ namespace taichi::lang { // TODO(k-ye): Hide FunctionCreationGuard inside cpp file FunctionCreationGuard::FunctionCreationGuard( TaskCodeGenLLVM *mb, - std::vector arguments) + std::vector arguments, + const std::string &func_name) : mb(mb) { // Create the loop body function auto body_function_type = llvm::FunctionType::get( llvm::Type::getVoidTy(*mb->llvm_context), arguments, false); body = llvm::Function::Create(body_function_type, - llvm::Function::InternalLinkage, - "function_body", mb->module.get()); + llvm::Function::InternalLinkage, func_name, + mb->module.get()); old_func = mb->func; // emit into loop body function mb->func = body; @@ -2668,8 +2669,9 @@ void TaskCodeGenLLVM::eliminate_unused_functions() { } FunctionCreationGuard TaskCodeGenLLVM::get_function_creation_guard( - std::vector argument_types) { - return FunctionCreationGuard(this, argument_types); + std::vector argument_types, + const std::string &func_name) { + return FunctionCreationGuard(this, argument_types, func_name); } void TaskCodeGenLLVM::initialize_context() { @@ -2804,7 +2806,8 @@ void TaskCodeGenLLVM::visit(ReferenceStmt *stmt) { void TaskCodeGenLLVM::visit(FuncCallStmt *stmt) { if (!func_map.count(stmt->func)) { auto guard = get_function_creation_guard( - {llvm::PointerType::get(get_runtime_type("RuntimeContext"), 0)}); + {llvm::PointerType::get(get_runtime_type("RuntimeContext"), 0)}, + stmt->func->get_name()); func_map.insert({stmt->func, guard.body}); stmt->func->ir->accept(this); } diff --git a/taichi/codegen/llvm/codegen_llvm.h b/taichi/codegen/llvm/codegen_llvm.h index c26a858f32553..78db83f35c8ff 100644 --- a/taichi/codegen/llvm/codegen_llvm.h +++ b/taichi/codegen/llvm/codegen_llvm.h @@ -25,7 +25,8 @@ class FunctionCreationGuard { llvm::IRBuilder<>::InsertPoint ip; FunctionCreationGuard(TaskCodeGenLLVM *mb, - std::vector arguments); + std::vector arguments, + const std::string &func_name); ~FunctionCreationGuard(); }; @@ -316,7 +317,8 @@ class TaskCodeGenLLVM : public IRVisitor, public LLVMModuleBuilder { void finalize_offloaded_task_function(); FunctionCreationGuard get_function_creation_guard( - std::vector argument_types); + std::vector argument_types, + const std::string &func_name = "function_body"); std::tuple get_range_for_bounds( OffloadedStmt *stmt);