Skip to content

Резанцева Анастасия. 3822Б1ФИ1. Лабораторная 4: MLIR. Вариант 4. #151

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

Open
wants to merge 4 commits into
base: course-spring-2025
Choose a base branch
from

Conversation

AnastasiaRezantseva
Copy link

MaxDepthPass - это пасс, который вычисляет максимальную глубину вложенности для каждого цикла в MLIR-функциях. Пасс поддерживает различные виды циклов и учитывает вложенные условные конструкции.

Рекурсивный анализ вложенности:

  • Метод computeDepth() рекурсивно обходит регионы операций

  • Учитывает как вложенные циклы, так и условные конструкции

  • Сохраняет результаты как атрибут функции my_loop_depths (отсортированный по убыванию)

Поддерживаемые операции:

Циклы: affine.for, scf.for, scf.while, scf.forall, spirv.LoopOp

Условия: affine.if, scf.if, spirv.SelectionOp

Comment on lines +31 to +34
unsigned maxDepth = currentDepth;

if (isNestingOp(op)) {
maxDepth = std::max(maxDepth, currentDepth + 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned maxDepth = currentDepth;
if (isNestingOp(op)) {
maxDepth = std::max(maxDepth, currentDepth + 1);
if (isNestingOp(op))
currentDepth++;
unsigned maxDepth = currentDepth;

Comment on lines +65 to +81
if (isLoopOp(op)) {
Operation *parent = op->getParentOp();
bool isNestedInLoop = false;
while (parent && !isa<func::FuncOp>(parent)) {
if (isLoopOp(parent)) {
isNestedInLoop = true;
break;
}
parent = parent->getParentOp();
}
if (!isNestedInLoop) {
unsigned depth = computeDepth(op);
if (depth > 0) {
loopDepths.push_back(depth);
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WalkResult::skip() result will break recursive visiting nested operations of current op and goes to the next op at current or upper level.

Suggested change
if (isLoopOp(op)) {
Operation *parent = op->getParentOp();
bool isNestedInLoop = false;
while (parent && !isa<func::FuncOp>(parent)) {
if (isLoopOp(parent)) {
isNestedInLoop = true;
break;
}
parent = parent->getParentOp();
}
if (!isNestedInLoop) {
unsigned depth = computeDepth(op);
if (depth > 0) {
loopDepths.push_back(depth);
}
}
}
if (isLoopOp(op)) {
unsigned depth = computeDepth(op);
if (depth > 0) {
loopDepths.push_back(depth);
}
return WalkResult::skip();
}

Comment on lines +40 to +42
maxDepth = std::max(
maxDepth, computeDepth(&nestedOp,
currentDepth + (isNestingOp(op) ? 1 : 0)));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxDepth = std::max(
maxDepth, computeDepth(&nestedOp,
currentDepth + (isNestingOp(op) ? 1 : 0)));
maxDepth = std::max(maxDepth, computeDepth(&nestedOp, currentDepth));

Comment on lines +56 to +57
return "It's a pass, that counts the max depth of region nests in each "
"loop.";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "It's a pass, that counts the max depth of region nests in each "
"loop.";
return "The pass counts the max depth of control flow operations nests in each "
"loop.";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants