Skip to content

Созонов Илья. Лабораторная работа 4. MLIR. Вариант 1. #162

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

Merged
merged 5 commits into from
May 21, 2025

Conversation

sozozzya
Copy link

@sozozzya sozozzya commented May 18, 2025

This MLIR transformation pass instruments loops by inserting tracing calls at the beginning and end of each loop iteration. The goal is to support runtime profiling or debugging by capturing entry and exit events for every iteration of supported loop types.

1. Declaration of Tracing Functions
The pass ensures that two function declarations - trace_loop_iter_begin and trace_loop_iter_end - exist in the module. If either is missing, it adds a private, zero-argument, zero-result function definition to the module. These functions serve as hooks for external instrumentation logic.

2. Traversal of Loop Operations
The pass walks through all operations in the module, identifying loops of types scf.for, scf.while, and affine.for. These loop types are part of MLIR's structured control flow and affine dialects.

3. Instrumentation of Loop Body Entry
For each identified loop, the pass inserts a call to trace_loop_iter_begin at the very start of the first block in the loop body. This marks the entry point of every loop iteration.

4. Instrumentation of Loop Body Exit
The pass then inserts a call to trace_loop_iter_end immediately before the terminator of every block in the loop body. This ensures that the end of each iteration is recorded, regardless of how control exits the body.

5. Preservation of Program Semantics
The inserted calls do not interfere with data flow, as they take no arguments and produce no results. This makes them side-effect-only operations that can be safely used for logging or profiling.

@m-ly4 m-ly4 removed the delayed label May 21, 2025
@m-ly4 m-ly4 added this pull request to the merge queue May 21, 2025
Merged via the queue into NN-complr-tech:course-spring-2025 with commit 301edeb May 21, 2025
11 checks passed
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