This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add support for generating debug locations from intermediate levels of the IR.
ClosedPublic

Authored by rriddle on Feb 4 2020, 6:52 PM.

Details

Summary

This revision adds a utility to generate debug locations from the IR during compilation, by snapshotting to a output stream and using the locations that operations were dumped in that stream. The new locations may either;

  • Replace the original location of the operation.

old:

loc("original_source.cpp":1:1)

new:

loc("snapshot_source.mlir":10:10)
  • Fuse with the original locations as NamedLocs with a specific tag.

old:

loc("original_source.cpp":1:1)

new:

loc(fused["original_source.cpp":1:1, "snapshot"("snapshot_source.mlir":10:10)])

This feature may be used by a debugger to display the code at various different levels of the IR. It would also be able to show the different levels of IR attached to a specific source line in the original source file.

This feature may also be used to generate locations for operations generated during compilation, that don't necessarily have a user source location to attach to.

This requires changes in the printer to track the locations of operations emitted in the stream. Moving forward we need to properly(and efficiently) track the number of newlines emitted to the stream during printing.

Diff Detail

Event Timeline

rriddle created this revision.Feb 4 2020, 6:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2020, 6:52 PM

Unit tests: unknown.

clang-tidy: unknown.

clang-format: unknown.

Build artifacts: diff.json, CMakeCache.txt, console-log.txt

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

mehdi_amini accepted this revision.Feb 7 2020, 9:20 PM

Nice!

mlir/lib/Transforms/LocationSnapshot.cpp
31

Can this all move after the printing?

43

Is this expected / possible? Otherwise assert()? (if this is a valid case, can you add a comment?)

This revision is now accepted and ready to land.Feb 7 2020, 9:20 PM
rriddle updated this revision to Diff 243394.Feb 8 2020, 11:39 AM
rriddle marked 3 inline comments as done.

Resolve comments

mlir/lib/Transforms/LocationSnapshot.cpp
43

Yep, some region terminators are elided so they won't have a valid custom assembly form. Added a comment.

This revision was automatically updated to reflect the committed changes.