Skip to content

Commit

Permalink
[llvm] Add comment about the structure of the CodeGen (#6150)
Browse files Browse the repository at this point in the history
Issue: #5511 

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ailing  <ailzhang@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 26, 2022
1 parent e90276c commit f892b13
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions taichi/codegen/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f892b13

Please sign in to comment.