Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm] Set the name of the LLVM function of the real function to its name #6495

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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