Skip to content

[LoadableByAddress] Fix debug info holes when expanding alloc_stack. #15575

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
Mar 28, 2018

Conversation

dcci
Copy link
Member

@dcci dcci commented Mar 28, 2018

We should also skip debug info as they don't really are lowered
to anything real. Add an helper so that we can use it in passes
as well.

@adrian-prantl I'm dealing with a bot failure, but I wanted to put this online so you can take a look and let me know if this is fine. I'm going to add a test & run the tests.

This is the last failure we have before enabling the verifier for debug info, so my plan is to flip the switch today (crossing fingers).

@dcci dcci requested a review from adrian-prantl March 28, 2018 15:13
@dcci dcci force-pushed the loadable-debuginfo branch from 862a9c6 to 64e8189 Compare March 28, 2018 15:17
@dcci dcci changed the title [WIP/SILVerifier] Loosen verification for debug info scopes holes. [WIP/LoadableByAddress] Fix debug info holes when expanding alloc_stack. Mar 28, 2018
@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

@adrian-prantl now with the correct patch, after coffee.

// that aren't lowered to anything real (e.g. debug_value).
static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
auto It = BB.begin();
while (It != BB.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it could be a range-based-for.

// Find the correct debug scope for alloc stack. We want to give to the
// expanded sequence the correct debug scope so we skip over instructions
// that aren't lowered to anything real (e.g. debug_value).
static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this utility would make sense in SILBasicBlock.h or even as a member function of SILBasicBlock. It's going to be useful for other passes that have similar issues, too. Perhaps call it getScopeOfFirstNonMetaInstruction.

void LoadableStorageAllocation::replaceLoadWithCopyAddr(
LoadInst *optimizableLoad) {
SILValue value = optimizableLoad->getOperand();

SILBuilderWithScope allocBuilder(pass.F->begin()->begin());
SILBuilder allocBuilder(pass.F->begin()->begin());
allocBuilder.setCurrentDebugScope(findAllocStackDebugScope(*pass.F->begin()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to add a new constructor to SILBuilderWithScope that has this behavior?

/// Creates a new SILBuilder with an insertion point at the beginning of BB and the debug scope from the first non-metainstruction in the BB.
explicit SILBuilderWithScope(SILBasicBlock *BB) {}

static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
auto It = BB.begin();
while (It != BB.end()) {
if (!isMaintenanceInst(&*It))
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename isMaintenanceInst to isMetaInstruction. This is the same name we are using in MIR.

@dcci dcci force-pushed the loadable-debuginfo branch from 64e8189 to 0c43de8 Compare March 28, 2018 18:27
@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

@swift-ci please test

@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

@adrian-prantl addressed all your comments. Please take another look.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 64e8189182faa94c22d5ff1b5593370956f1546e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 64e8189182faa94c22d5ff1b5593370956f1546e

/// Returns true if the instruction \p Inst is a meta instruction which
/// is relevant for debug information and does not get lowered to a real
/// instruction.
inline bool isMetaInstruction(SILInstruction *Inst) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this a method of SILInstruction?
I also believe that every SILInstruction that implements getVarInfo() should be included in this list (DebugValueAddr, AllocBox, ...) .

@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

Sure!

@dcci dcci changed the title [WIP/LoadableByAddress] Fix debug info holes when expanding alloc_stack. [LoadableByAddress] Fix debug info holes when expanding alloc_stack. Mar 28, 2018
@dcci dcci force-pushed the loadable-debuginfo branch from 0c43de8 to dfaf133 Compare March 28, 2018 18:54
@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

Done. I think as a follow up I'm going to move isDebugInst() from DebugUtils.h to be a member function of class SILInstruction (and probably rename that to isDebugInstruction() for consistency.
But that seemed too much of a change for this PR :)

@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

@swift-ci please test and merge

1 similar comment
@dcci
Copy link
Member Author

dcci commented Mar 28, 2018

@swift-ci please test and merge

@swift-ci swift-ci merged commit 27c88a9 into swiftlang:master Mar 28, 2018
felipepiovezan added a commit to felipepiovezan/swift that referenced this pull request Jan 12, 2024
This function is clearly returning the opposite of what its name says:

```
const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() {
  for (auto &Inst : *this)
    if (Inst.isMetaInstruction())
      return Inst.getDebugScope();
  return begin()->getDebugScope();
}
```

Looking at the PR history (sadly GH doesn't preserve old versions of the patch...)
swiftlang#15575

There was this snippet of code:

```
// Find the correct debug scope for alloc stack. We want to give to the
// expanded sequence the correct debug scope so we skip over instructions
// that aren't lowered to anything real (e.g. debug_value).
static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
  auto It = BB.begin();
  while (It != BB.end()) {
    if (!isMaintenanceInst(&*It))
```

We don't know what used to be after that line but, based on the comments, it
must have been a `return It->getDebugScope()`.

Adrian then asked the author to make this a different helper function
`getScopeOfFirstNonMetaInstruction`, and the subsequence force-push had the code
we see today. So maybe it was in this conversion that the author made the
mistake?

Fixing the implementation doesn't cause any tests to fail (sadly the original PR
did not add any SIL->SIL tests, which would have been ideal).
Catfish-Man pushed a commit to Catfish-Man/swift that referenced this pull request Jan 19, 2024
This function is clearly returning the opposite of what its name says:

```
const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() {
  for (auto &Inst : *this)
    if (Inst.isMetaInstruction())
      return Inst.getDebugScope();
  return begin()->getDebugScope();
}
```

Looking at the PR history (sadly GH doesn't preserve old versions of the patch...)
swiftlang#15575

There was this snippet of code:

```
// Find the correct debug scope for alloc stack. We want to give to the
// expanded sequence the correct debug scope so we skip over instructions
// that aren't lowered to anything real (e.g. debug_value).
static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
  auto It = BB.begin();
  while (It != BB.end()) {
    if (!isMaintenanceInst(&*It))
```

We don't know what used to be after that line but, based on the comments, it
must have been a `return It->getDebugScope()`.

Adrian then asked the author to make this a different helper function
`getScopeOfFirstNonMetaInstruction`, and the subsequence force-push had the code
we see today. So maybe it was in this conversion that the author made the
mistake?

Fixing the implementation doesn't cause any tests to fail (sadly the original PR
did not add any SIL->SIL tests, which would have been ideal).
carlos4242 pushed a commit to carlos4242/swift that referenced this pull request May 31, 2024
This function is clearly returning the opposite of what its name says:

```
const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() {
  for (auto &Inst : *this)
    if (Inst.isMetaInstruction())
      return Inst.getDebugScope();
  return begin()->getDebugScope();
}
```

Looking at the PR history (sadly GH doesn't preserve old versions of the patch...)
swiftlang#15575

There was this snippet of code:

```
// Find the correct debug scope for alloc stack. We want to give to the
// expanded sequence the correct debug scope so we skip over instructions
// that aren't lowered to anything real (e.g. debug_value).
static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) {
  auto It = BB.begin();
  while (It != BB.end()) {
    if (!isMaintenanceInst(&*It))
```

We don't know what used to be after that line but, based on the comments, it
must have been a `return It->getDebugScope()`.

Adrian then asked the author to make this a different helper function
`getScopeOfFirstNonMetaInstruction`, and the subsequence force-push had the code
we see today. So maybe it was in this conversion that the author made the
mistake?

Fixing the implementation doesn't cause any tests to fail (sadly the original PR
did not add any SIL->SIL tests, which would have been ideal).
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.

3 participants