This is an archive of the discontinued LLVM Phabricator instance.

[StructurizeCFG][DebugInfo] Maintain DILocations in the branches created by StructurizeCFG
ClosedPublic

Authored by jmmartinez on Oct 14 2022, 9:14 AM.

Details

Summary

Make StructurizeCFG preserve the debug locations of the branch instructions it introduces.

Diff Detail

Event Timeline

jmmartinez created this revision.Oct 14 2022, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2022, 9:14 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Updated todo comments before the weekend

Small update to submit for review.

Check the following recordings to see the differences while debugging

Notice how the behaviour after the patch is applied matches what happens for the cpu case.

jmmartinez published this revision for review.Oct 18 2022, 8:45 AM
jmmartinez edited the summary of this revision. (Show Details)
jmmartinez added a reviewer: arsenm.
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2022, 8:45 AM
jmmartinez added inline comments.Oct 18 2022, 8:46 AM
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
956

Fix this: remove empty line

jmmartinez marked an inline comment as not done.Oct 18 2022, 8:46 AM
arsenm added inline comments.Oct 18 2022, 8:48 AM
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
859

Why can't you just directly set the debug info when the terminator is created?

jmmartinez added inline comments.Oct 18 2022, 9:02 AM
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
859

That was my original approach, however I struggled to make it always work.

For example, in the function changeExit when the branch is created and appended to the basic-block, sometimes there is the old terminator that's going to be replaced, but sometims the basic-block is empty (when it's a new flow block created by getNextFlow).

In the end, I picked the current strategy since it was the simpler one.

jmmartinez added inline comments.Oct 19 2022, 12:29 AM
llvm/test/Transforms/StructurizeCFG/structurizecfg-debug-loc.ll
41

Remove this comment. This is the good behaviour.

71

Remove this one too. Again, this gives the good behaviour.

Removed useless TODO and empty line

jmmartinez added a project: Restricted Project.Oct 19 2022, 12:39 AM
jmmartinez marked an inline comment as done.Oct 25 2022, 2:51 AM
arsenm added inline comments.Oct 25 2022, 2:03 PM
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
553

I think the current guidance is DebugLocs should be handled by const reference

  • Handle DebugLoc by const-ref instead of by copy
jmmartinez marked an inline comment as done.Oct 26 2022, 5:03 AM
jmmartinez added inline comments.
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
553

I changed to use a const-ref in here and in the loop in setTerminatorDebugLoc . Indeed, internally it uses a TrackingMDRef so it'd better to avoid constructing a new one. Thanks !

jmmartinez marked an inline comment as done.Oct 26 2022, 6:57 AM
arsenm accepted this revision.Oct 27 2022, 8:07 AM

LGTM (although I would be a bit happier if this was setting something at the creation point)

This revision is now accepted and ready to land.Oct 27 2022, 8:07 AM

Set DebugLoc at BranchInst creation

LGTM (although I would be a bit happier if this was setting something at the creation point)

I found a way to do it (although I wasn't able to get rid of the map).

This revision was landed with ongoing or failed builds.Oct 28 2022, 12:51 AM
This revision was automatically updated to reflect the committed changes.