Skip to content

[VM] Index bytecode debug database source maps by function ordinal - #25278

Open
hamidelmaazouz wants to merge 1 commit into
iree-org:mainfrom
hamidelmaazouz:users/hamidelmaazouz/vm-debug-database-ordinals
Open

hamidelmaazouz wants to merge 1 commit into
iree-org:mainfrom
hamidelmaazouz:users/hamidelmaazouz/vm-debug-database-ordinals

Conversation

@hamidelmaazouz

Copy link
Copy Markdown

DebugDatabaseBuilder::addFunctionSourceMap placed each function source map at the ordinal attribute of the function and fell back to 0 when the attribute was absent. Since ordinals moved to OrdinalAnalysis the bytecode target no longer sets that attribute, so every function wrote slot 0 and the debug database kept only the map of the last function encoded. The runtime looks function names and locations up in that table by internal ordinal, which made --trace_execution and backtraces report the wrong function for ordinal 0 and a bare ordinal for the others.

The fallback dates from the introduction of the debug database in 2e711d4. At the time the bytecode pipeline ran OrdinalAllocationPass and every function carried the attribute by serialisation, so the default never applied. The move to OrdinalAnalysis in aa776b3 (#23115) dropped that pass from the bytecode pipeline and replaced the other ordinal reads of the target, which dereference the attribute and would have asserted. This one substituted 0 and went unnoticed, since no test covered the contents of the debug database.

The encoder already holds the OrdinalAnalysis, so it now passes the ordinal to the builder, and the builder no longer reads the attribute. A new lit test, debug_database.mlir, checks that each function of a module gets its own entry in debug_database.functions.

The ordinal attributes remain on the VM ops, and only the C target still sets them through OrdinalAllocationPass. Moving the C target to OrdinalAnalysis and dropping the attributes would rule out this kind of stale read altogether. That touches EmitC, so it seems better kept to a separate change, and I am happy to open an issue for it if that sounds useful.

Thanks for taking a look!

Fixes #25277

`DebugDatabaseBuilder::addFunctionSourceMap` placed each function source map at the `ordinal` attribute of the function and fell back to 0 when the attribute was absent. Since ordinals moved to `OrdinalAnalysis` the bytecode target no longer sets that attribute, so every function wrote slot 0 and the debug database kept only the map of the last function encoded. The runtime looks function names and locations up in that table by internal ordinal, which made `--trace_execution` and backtraces report the wrong function for ordinal 0 and a bare ordinal for the others.

The fallback dates from the introduction of the debug database in 2e711d4. At the time the bytecode pipeline ran `OrdinalAllocationPass` and every function carried the attribute by serialisation, so the default never applied. The move to `OrdinalAnalysis` in aa776b3 (iree-org#23115) dropped that pass from the bytecode pipeline and replaced the other ordinal reads of the target, which dereference the attribute and would have asserted. This one substituted 0 and went unnoticed, since no test covered the contents of the debug database.

The encoder already holds the `OrdinalAnalysis`, so it now passes the ordinal to the builder, and the builder no longer reads the attribute. A new lit test, `debug_database.mlir`, checks that each function of a module gets its own entry in `debug_database.functions`.

Fixes iree-org#25277

Signed-off-by: Hamid El Maazouz <[email protected]>
@github-actions

Copy link
Copy Markdown

Hello @hamidelmaazouz 👋

Thank you for submitting a Pull Request to IREE! It looks like this is your first one. We have one ask, and you can also find some general tips below.


Action required: acknowledge IREE project policies

IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.

All contributions to IREE must follow our IREE AI Tool Use Policy. In particular:

  • Contributors must fully understand, and vouch for, all submitted changes and the intent behind them.
  • Substantial use of LLM/generative AI tools must be noted in the PR description, e.g. via Assisted-by: tool-name or Co-authored-by: tool-name tool@email trailers.
  • Contributors must write PR descriptions themselves. There must always be a human in the loop: contributors must respond to reviews and questions by themselves.
    If a response includes LLM-assisted segments (e.g. reproducers, LLM agent analysis excerpts), the segment should be clearly marked as "assisted", same as for PR contents.
  • GitHub issues labeled as "Good first issue" are explicitly designated as learning opportunities for newcomers to the project. With exceptions for boilerplate edits, AI tool usage for resolutions to such issues is forbidden.

We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy.


General guidance

Our general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system.

A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin.
In these cases, it should suffice to amend your commit signature(s) per the guide and force-push the PR branch.

If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.

Thank you,
The IREE Community

@hamidelmaazouz

Copy link
Copy Markdown
Author

Hello @hamidelmaazouz 👋

Thank you for submitting a Pull Request to IREE! It looks like this is your first one. We have one ask, and you can also find some general tips below.

Action required: acknowledge IREE project policies

IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.

All contributions to IREE must follow our IREE AI Tool Use Policy. In particular:

  • Contributors must fully understand, and vouch for, all submitted changes and the intent behind them.
  • Substantial use of LLM/generative AI tools must be noted in the PR description, e.g. via Assisted-by: tool-name or Co-authored-by: tool-name tool@email trailers.
  • Contributors must write PR descriptions themselves. There must always be a human in the loop: contributors must respond to reviews and questions by themselves.
    If a response includes LLM-assisted segments (e.g. reproducers, LLM agent analysis excerpts), the segment should be clearly marked as "assisted", same as for PR contents.
  • GitHub issues labeled as "Good first issue" are explicitly designated as learning opportunities for newcomers to the project. With exceptions for boilerplate edits, AI tool usage for resolutions to such issues is forbidden.

We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy.

General guidance

Our general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system.

A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin. In these cases, it should suffice to amend your commit signature(s) per the guide and force-push the PR branch.

If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.

Thank you, The IREE Community

I understand and accept the cited policies, particularly the AI Tool Use Policy.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VM] Bytecode debug database keeps a single function source map, so traces label functions with the wrong name

1 participant