Skip to content

Commit

Permalink
[llvm] Set the name of the LLVM function of the real function to its …
Browse files Browse the repository at this point in the history
…name (#6495)

Issue: #602

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lin-hitonami and pre-commit-ci[bot] authored Nov 2, 2022
1 parent bb6f907 commit d83165d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 9 additions & 6 deletions taichi/codegen/llvm/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ namespace taichi::lang {
// TODO(k-ye): Hide FunctionCreationGuard inside cpp file
FunctionCreationGuard::FunctionCreationGuard(
TaskCodeGenLLVM *mb,
std::vector<llvm::Type *> arguments)
std::vector<llvm::Type *> 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;
Expand Down Expand Up @@ -2668,8 +2669,9 @@ void TaskCodeGenLLVM::eliminate_unused_functions() {
}

FunctionCreationGuard TaskCodeGenLLVM::get_function_creation_guard(
std::vector<llvm::Type *> argument_types) {
return FunctionCreationGuard(this, argument_types);
std::vector<llvm::Type *> argument_types,
const std::string &func_name) {
return FunctionCreationGuard(this, argument_types, func_name);
}

void TaskCodeGenLLVM::initialize_context() {
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions taichi/codegen/llvm/codegen_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class FunctionCreationGuard {
llvm::IRBuilder<>::InsertPoint ip;

FunctionCreationGuard(TaskCodeGenLLVM *mb,
std::vector<llvm::Type *> arguments);
std::vector<llvm::Type *> arguments,
const std::string &func_name);

~FunctionCreationGuard();
};
Expand Down Expand Up @@ -316,7 +317,8 @@ class TaskCodeGenLLVM : public IRVisitor, public LLVMModuleBuilder {
void finalize_offloaded_task_function();

FunctionCreationGuard get_function_creation_guard(
std::vector<llvm::Type *> argument_types);
std::vector<llvm::Type *> argument_types,
const std::string &func_name = "function_body");

std::tuple<llvm::Value *, llvm::Value *> get_range_for_bounds(
OffloadedStmt *stmt);
Expand Down

0 comments on commit d83165d

Please sign in to comment.