-
Notifications
You must be signed in to change notification settings - Fork 54
Соловьев Алексей. Лабораторная работа 4. MLIR. Вариант 2 #149
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?
Соловьев Алексей. Лабораторная работа 4. MLIR. Вариант 2 #149
Conversation
// CHECK-NEXT: %c3 = arith.constant 3 : index | ||
// CHECK-NEXT: %[[NEG2:.*]] = arith.constant -2 : index | ||
// CHECK-NEXT: scf.for %{{.*}} = %c0 to %c3 step %[[NEG2]] { | ||
// CHECK-NEXT: } {trip_count = 0 : index} |
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.
It is not a safe assumption. Yes, loop is malformed, but it can perform thousands of iterations before it crashes a program. Another weak moment is that there is no formal difference between cases when lb
== ub
in a loop and when iteration space is malformed. In both cases trip_count
== 0.
I'd suggest to set it to -1 or not to set it at all if a loop's iteration space is malformed.
// CHECK-NEXT: %c3 = arith.constant 3 : index | ||
// CHECK-NEXT: %[[NEG2:.*]] = arith.constant -2 : index | ||
// CHECK-NEXT: scf.for %{{.*}} = %c0 to %c3 step %[[NEG2]] { | ||
// CHECK-NEXT: } |
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.
Actually, if the pass suddenly prints trip_count, this check won't detect that. Because it doesn't check that there is no more text in current line after closing brace.
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.
Added CHECK-NOT for trip_count validation
Этот MLIR-пасс аннотирует циклы scf.for, у которых статически известны границы и шаг, атрибутом trip_count, содержащим количество итераций цикла. Пасс обходит все операции внутри модуля и для каждого цикла scf.for проверяет, задаются ли нижняя граница, верхняя граница и шаг как константы. Если все три значения заданы явно и шаг не равен нулю, вычисляется количество итераций по формуле (upperBound - lowerBound + step - 1) / step, после чего цикл аннотируется соответствующим атрибутом. Такой подход позволяет упростить последующий анализ и оптимизацию кода, например, при проведении loop unrolling или vectorization.