Skip to content

Commit

Permalink
[TIR] ConvertSSA process entry func first (apache#16236)
Browse files Browse the repository at this point in the history
* convert ssa process entry func first

* add doc
  • Loading branch information
jinhongyii authored Dec 14, 2023
1 parent a59db03 commit b0e146f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/tir/transforms/ir_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,13 @@ Pass ConvertSSA() {
tir::IRConvertSSA converter;
Map<GlobalVar, BaseFunc> functions;
bool made_change = false;
// FIXME: This is just a temporal workaround to ensure free vars
// in device function have the same pointer as the host function
for (auto [gvar, base_func] : mod->functions) {
if (auto* ptr = base_func.as<tir::PrimFuncNode>()) {
if (!ptr->HasNonzeroAttr(tir::attr::kIsEntryFunc)) {
continue;
}
auto updated = converter.VisitPrimFunc(GetRef<tir::PrimFunc>(ptr));
if (!updated.same_as(base_func)) {
made_change = true;
Expand All @@ -725,6 +730,19 @@ Pass ConvertSSA() {
}
functions.Set(gvar, base_func);
}
for (auto [gvar, base_func] : mod->functions) {
if (auto* ptr = base_func.as<tir::PrimFuncNode>()) {
if (ptr->HasNonzeroAttr(tir::attr::kIsEntryFunc)) {
continue;
}
auto updated = converter.VisitPrimFunc(GetRef<tir::PrimFunc>(ptr));
if (!updated.same_as(base_func)) {
made_change = true;
base_func = updated;
}
functions.Set(gvar, base_func);
}
}
if (made_change) {
mod.CopyOnWrite()->functions = std::move(functions);
}
Expand Down

0 comments on commit b0e146f

Please sign in to comment.