Skip to content

[DebugInfo] Stop relying on asm gadgets to extend variable ranges #29029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2020

Conversation

vedantk
Copy link
Contributor

@vedantk vedantk commented Jan 6, 2020

The 'fake use' asm gadget does not always keep variables alive. E.g., in
rdar://57754659, llvm was unable to preserve two local variables despite
the use of these gadgets. These variables were backed by a LoadInst and
an ExtractValueInst respectively. Instead of emitting shadow copies for
just those kinds of instructions, use shadow copies exclusively. This
may cause more variables to appear in the debugger window before they
are initialized, but should result in fewer variables being dropped.

rdar://57754659

@vedantk vedantk requested a review from adrian-prantl January 6, 2020 22:58
@vedantk
Copy link
Contributor Author

vedantk commented Jan 6, 2020

@swift-ci smoke test

@vedantk
Copy link
Contributor Author

vedantk commented Jan 6, 2020

I'll add that for the specific case of rdar://57754659, I tested a change in LiveDebugValues that would preserve the two dropped variables without requiring any changes to Swift IRGen. However, the change has a significant compile-time impact for very little pay-off. E.g. variable scope coverage in an optimized kernel build is unaffected by the change.

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is trading one class of bugs against another, but this is also how Clang works at -O0, so I'm on board with this change. We might even be able to describe the values with dbg.addr/dbg.value instead of dbg.declare and thus reclaim the precise start point in some cases.

return (IGM.DataLayout.getTypeSizeInBits(Storage->getType()) >
IGM.getClangASTContext().getTargetInfo().getRegisterWidth()) ||
isa<llvm::PHINode>(Storage);
return !isa<llvm::Constant>(Storage) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes sense

isa<llvm::PHINode>(Storage);
return !isa<llvm::Constant>(Storage) ||
(IGM.DataLayout.getTypeSizeInBits(Storage->getType()) >
IGM.getClangASTContext().getTargetInfo().getRegisterWidth());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this condition, I'm not sure of

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect all non-constants to require a shadow copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All non-constants do get a shadow copy, I left the register-width condition in place to handle constants that don't fit in a register. However it looks like swift IRgen doesn't produce this kind of constant, so I'll just delete the condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misread that. We cannot express constants > 64bits in LLVM IR. A 80-bit float or a 128-bit vector would violate that requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For swift, I think it's safe to remove the register-width check, based on a quick skim of GenConstant/IRGenSIL.

In the past though, clang has emitted e.g. i65 integers to implement overflow checks. In some cases it might still use i129 etc.

The 'fake use' asm gadget does not always keep variables alive. E.g., in
rdar://57754659, llvm was unable to preserve two local variables despite
the use of these gadgets. These variables were backed by a LoadInst and
an ExtractValueInst respectively. Instead of emitting shadow copies for
just those kinds of instructions, use shadow copies exclusively. This
may cause more variables to appear in the debugger window before they
are initialized, but should result in fewer variables being dropped.

rdar://57754659
@vedantk
Copy link
Contributor Author

vedantk commented Jan 7, 2020

@swift-ci smoke test

@varungandhi-apple
Copy link
Contributor

Borked change was reverted recently, so I'm re-running the test.

@swift-ci please smoke test

@vedantk
Copy link
Contributor Author

vedantk commented Jan 7, 2020

@varungandhi-apple Thanks!

@vedantk
Copy link
Contributor Author

vedantk commented Jan 9, 2020

@adrian-prantl did you have any other concerns on this one?

@vedantk vedantk requested a review from dcci January 10, 2020 22:41
@vedantk vedantk merged commit a83bfab into swiftlang:master Jan 11, 2020
@vedantk vedantk deleted the no-gadgets branch January 11, 2020 00:31
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.

4 participants