-
Notifications
You must be signed in to change notification settings - Fork 54
Резанцева Анастасия. 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
base: course-spring-2025
Are you sure you want to change the base?
Резанцева Анастасия. 3822Б1ФИ1. Лабораторная 4: MLIR. Вариант 4. #151
Conversation
unsigned maxDepth = currentDepth; | ||
|
||
if (isNestingOp(op)) { | ||
maxDepth = std::max(maxDepth, currentDepth + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsigned maxDepth = currentDepth; | |
if (isNestingOp(op)) { | |
maxDepth = std::max(maxDepth, currentDepth + 1); | |
if (isNestingOp(op)) | |
currentDepth++; | |
unsigned maxDepth = currentDepth; |
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
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(); | |
} |
maxDepth = std::max( | ||
maxDepth, computeDepth(&nestedOp, | ||
currentDepth + (isNestingOp(op) ? 1 : 0))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxDepth = std::max( | |
maxDepth, computeDepth(&nestedOp, | |
currentDepth + (isNestingOp(op) ? 1 : 0))); | |
maxDepth = std::max(maxDepth, computeDepth(&nestedOp, currentDepth)); |
return "It's a pass, that counts the max depth of region nests in each " | ||
"loop."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."; |
MaxDepthPass - это пасс, который вычисляет максимальную глубину вложенности для каждого цикла в MLIR-функциях. Пасс поддерживает различные виды циклов и учитывает вложенные условные конструкции.
Рекурсивный анализ вложенности:
Метод computeDepth() рекурсивно обходит регионы операций
Учитывает как вложенные циклы, так и условные конструкции
Сохраняет результаты как атрибут функции my_loop_depths (отсортированный по убыванию)
Поддерживаемые операции:
Циклы: affine.for, scf.for, scf.while, scf.forall, spirv.LoopOp
Условия: affine.if, scf.if, spirv.SelectionOp