diff --git a/taichi/codegen/codegen.h b/taichi/codegen/codegen.h index 9b72b1c99c5db..d29d45713cfa0 100644 --- a/taichi/codegen/codegen.h +++ b/taichi/codegen/codegen.h @@ -12,6 +12,29 @@ #endif namespace taichi::lang { +/* + [Note] Codegen of LLVM-based backends + * KernelCodeGen is the base class of the codegen of all backends using LLVM. + * Function `compile_to_function` first compiles the IR of a kernel + * into a LLVM module using `compile_kernel_to_module`, and then constructs a + * function for runtime execution using `ModuleToFunctionConverter`. + * + * Function `compile_kernel_to_module` compiles the IR of a kernel into a LLVM + * module. A kernel is composed of several offloaded tasks. To compile a kernel, + * we first compile each task independently into an LLVM module using function + * `compile_task`. Then, we link the LLVM modules of the offloaded tasks, + * the runtime module and the struct modules of the SNode trees which are used + * in the kernel all together into a single LLVM module using + * `tlctx->link_compiled_tasks`. The LLVM module and the names of the entry + * functions of the offloaded tasks in the module are stored in the returned + * LLVMCompiledKernel. + * + * Function `compile_task` uses `TaskCodeGen` of the respective backend to + * compile the IR of a offloaded task to an LLVM module. It also generates some + * extra information for linking such as which SNode tree is used in the task. + * The LLVM module, the name of the entry function of the offloaded task in the + * module and the extra information are stored in the returned LLVMCompiledTask. + */ class KernelCodeGen { protected: Program *prog;