Skip to content

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

Open

Description

@hamidelmaazouz

What happened?

Hi all, I came across this while reading through the execution trace of a small module, and it looks like a leftover from the move to on-demand ordinals.

The bytecode debug database holds one function source map whatever the number of functions, stored at slot 0 and belonging to the last function encoded. The runtime looks function names and locations up in that table by internal ordinal, so ordinal 0 is reported under the name and locations of another function and every other ordinal has none.

--trace_execution shows it directly. Running @first of the module below labels every frame module.second, and running @second labels its frames module@1.

EXEC @first
[module.second+00000000]    <block>
[module.second+00000001]    %i1 = vm.const.i32 1  // 0x00000001
[module.second+00000008]    %i1 = vm.add.i32 %i0(3), %i1(1)
[module.second+0000000F]    vm.return %i1(4)
result[0]: i32=4
EXEC @second
[module@1+00000000]    <block>
[module@1+00000001]    %i1 = vm.const.i32 2  // 0x00000002
[module@1+00000008]    %i1 = vm.mul.i32 %i0(3), %i1(2)
[module@1+0000000F]    vm.return %i1(6)
result[0]: i32=6

The flatbuffer-text output agrees. debug_database.functions has one entry, second, while function_descriptors has two.

The cause is in DebugDatabaseBuilder::addFunctionSourceMap (compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/DebugDatabaseBuilder.cpp), which places each map at funcOp.getOrdinal().value_or(0). Since the change that made OrdinalAnalysis compute ordinals on demand (aa776b3, first released in 3.10.0), the bytecode target no longer stores the ordinal attribute on vm.func. OrdinalAllocationPass now runs only in CModuleTarget.cpp. Every call therefore writes slot 0 and the last write wins.

The same table backs source locations, so backtraces and any tool that resolves bytecode offsets to locations through the debug database get the locations of the wrong function, or none.

A possible fix is to pass the ordinal in. BytecodeEncoder::encodeFunction in BytecodeEncoder.cpp already holds the OrdinalAnalysis and calls debugDatabase.addFunctionSourceMap(funcOp, sourceMap), so it can pass ordinalAnalysis.getOrdinal(funcOp) and the builder can drop its read of the attribute. A lit or runtime test that checks the size of debug_database.functions against the function count, or the trace label of a second function, would keep it from regressing. I am happy to send a PR along these lines.

Steps to reproduce your issue

two.mlir:

func.func @first(%a: i32) -> i32 {
  %c = arith.constant 1 : i32
  %r = arith.addi %a, %c : i32
  return %r : i32
}
func.func @second(%a: i32) -> i32 {
  %c = arith.constant 2 : i32
  %r = arith.muli %a, %c : i32
  return %r : i32
}
iree-compile two.mlir -o two.vmfb
iree-run-module --module=two.vmfb --function=first --input=3 --trace_execution=true
iree-run-module --module=two.vmfb --function=second --input=3 --trace_execution=true
iree-compile two.mlir --iree-vm-bytecode-module-output-format=flatbuffer-text -o two.json

Expected: frames labelled module.first and module.second, and two entries in debug_database.functions.

What component(s) does this issue relate to?

Compiler, Runtime

Version information

Reproduced with a build of v3.13.0 (89ece87) on macOS arm64. DebugDatabaseBuilder.cpp and its call site are unchanged on main at 5332c68.

Additional context

The bytecode module of any real program shows the same thing. A matmul module with __init, an outlined memoize function and the entry point has one source map, named __init, so the trace prints module.__init for ordinal 0 and module@1, module@2 for the others.

Thanks for taking a look!

Activity

  1. github-actions commented on Nov 14, 2026

    @github-actions

    Hello @hamidelmaazouz 👋

    Thank you for submitting an issue to IREE! It looks like it's your first one.

    The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
    Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them 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.

    Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:

    • Issue reporters must fully understand the primary issue and the impact of the problem.
      For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
      For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
    • Contributors must write the summary of the issue themselves, so that the exact impact and scenario is clear to other participants.
    • Issue authors are expected to review and understand all LLM/AI-assisted segments of the report, if any. E.g.: CLI commands and IR reproducers, model/framework details, lowering pipeline details, assumptions about problematic behaviors of IREE components.
    • Substantial use of LLM/generative AI tools must be disclaimed in the header or footer of the issue description.

    Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.


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

    Thank you,
    The IREE Community

  2. hamidelmaazouz commented on Nov 14, 2026

    @hamidelmaazouz
    Author

    Hello @hamidelmaazouz 👋

    Thank you for submitting an issue to IREE! It looks like it's your first one.

    The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there. Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them 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.

    Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:

    • Issue reporters must fully understand the primary issue and the impact of the problem.
      For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
      For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
    • Contributors must write the summary of the issue themselves, so that the exact impact and scenario is clear to other participants.
    • Issue authors are expected to review and understand all LLM/AI-assisted segments of the report, if any. E.g.: CLI commands and IR reproducers, model/framework details, lowering pipeline details, assumptions about problematic behaviors of IREE components.
    • Substantial use of LLM/generative AI tools must be disclaimed in the header or footer of the issue description.

    Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.

    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 proposed policy.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions