Созонов Илья. Лабораторная работа 4. MLIR. Вариант 1. #162
+195
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andtrace_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
, andaffine.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.