This is an archive of the discontinued LLVM Phabricator instance.

[NFC][SelectionDAG][DebugInfo] Remove duplicate parameter from handleDebugValue
ClosedPublic

Authored by Orlando on Oct 19 2022, 4:53 AM.

Details

Summary

[NFC][SelectionDAG][DebugInfo] Remove duplicate parameter from handleDebugValue

handleDebugValue has two DebugLoc parameters that appear to always take the
same value. Remove one of the duplicate parameters.

Now an attempt to disentangle the code and explain why I think they are always
the same value:

The call to handleDebugValue in visitIntrinsicCall uses dl and
DI.getDebugLoc() as the two DebugLoc arguments, where DI is the
current instruction being visited casted to a DbgValueInst.

At the start of visitIntrinsicCall we can see

DebugLoc dl = getCurDebugLoc();

Here's the definition for getCurDebugLoc:

DebugLoc getCurDebugLoc() const {
  return CurInst ? CurInst->getDebugLoc() : DebugLoc();
}

Noting that CurInst is set to the instruction-being-visited in
SelectionDAGBuilder::visit(const Instruction &I) before calling visit
which results in the call to visitIntrinsicCall. This shows that dl
and DI.getDebugLoc() are the same.

The other two calls to handleDebugValue occur inside
SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI). The
two DebugLocs passed to handleDebugValue from here are:

DebugLoc DL = DDI.getdl();
DebugLoc InstDL = DDI.getDI()->getDebugLoc();

The DanglingDebugInfo parameter DDI is created by the call from
visitIntrinsicCall to addDanglingDebugInfo:

addDanglingDebugInfo(&DI, dl, SDNodeOrder);

So following the logic for the arguments to the call to handleDebugValue in
visitIntrinsicCall, DDI.getdl() and DDI.getDI()->getDebugLoc() used in
salvageUnresolvedDbgValue are also the same value.

To help test this I added an assert to check the arguments were equal and built
the CTMark test suite - the assert wasn't tripped. That's not conclusive, but
adds confidence.


I'll put up another NFC patch that removes unneeded DebugLoc field from
DanglingDebugInfo shortly.

As well as being a nice tidy-up, these changes is used by an upcoming assignment tracking patch.

Diff Detail

Event Timeline

Orlando created this revision.Oct 19 2022, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 4:53 AM
Orlando requested review of this revision.Oct 19 2022, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 4:53 AM
StephenTozer accepted this revision.Oct 19 2022, 8:27 AM

LGTM, doing a bit of archaeology doesn't reveal any reason why we would expect dl != DI.getDebugLoc(), it seems as though the same thing was just written in two different ways and then embedded as parameters when the code was extracted to a new function. That being said, just pinging @jmorse to double check that there is no intentional difference between the two recorded locations.

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