-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Split constructing and compilation of lang::Function (#7209)
Issue: #7002 ### Brief Summary Removed dependencies on `Program::this_thread_config()` in `lang::Function` compilation (AST->IR part) * Push off the compilation of `lang::Function`: Introduce the `irpass::compile_called_function(IRNode *root, const CompileConfig &config)`, which compiles the AST/IR of `Function`s called in `root` to the final IR.
- Loading branch information
Showing
5 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "taichi/ir/transforms.h" | ||
#include "taichi/ir/visitors.h" | ||
#include "taichi/ir/statements.h" | ||
#include "taichi/program/function.h" | ||
#include "taichi/program/compile_config.h" | ||
|
||
namespace taichi::lang { | ||
|
||
class CompileTaichiFunctions : public BasicStmtVisitor { | ||
public: | ||
using BasicStmtVisitor::visit; | ||
|
||
explicit CompileTaichiFunctions(const CompileConfig &compile_config) | ||
: compile_config_(compile_config) { | ||
} | ||
|
||
void visit(FuncCallStmt *stmt) override { | ||
using IRType = Function::IRType; | ||
auto *func = stmt->func; | ||
const auto ir_type = func->ir_type(); | ||
if (ir_type != IRType::OptimizedIR) { | ||
TI_ASSERT(ir_type == IRType::AST || ir_type == IRType::InitialIR); | ||
func->set_ir_type(IRType::OptimizedIR); | ||
irpass::compile_function(func->ir.get(), compile_config_, func, | ||
/*autodiff_mode=*/AutodiffMode::kNone, | ||
/*verbose=*/compile_config_.print_ir, | ||
/*start_from_ast=*/ir_type == IRType::AST); | ||
func->ir->accept(this); | ||
} | ||
} | ||
|
||
static void run(IRNode *ir, const CompileConfig &compile_config) { | ||
CompileTaichiFunctions ctf{compile_config}; | ||
ir->accept(&ctf); | ||
} | ||
|
||
private: | ||
const CompileConfig &compile_config_; | ||
}; | ||
|
||
namespace irpass { | ||
|
||
void compile_taichi_functions(IRNode *ir, const CompileConfig &compile_config) { | ||
TI_AUTO_PROF; | ||
CompileTaichiFunctions::run(ir, compile_config); | ||
} | ||
|
||
} // namespace irpass | ||
|
||
} // namespace taichi::lang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters