Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Jan 22, 2020

Pretty straightforward given all we have so far.

Note that fannkuch3_manyopts has an example of
a sequence of ranges of which some must be skipped
while others must not, showing we handle that by
skipping the bad ones and updating the remaining.

@kripken kripken requested a review from dschuff January 22, 2020 20:57
@kripken
Copy link
Member Author

kripken commented Jan 22, 2020

Imagine that we have a sequence of two (begin, end) spans

[(10, 20),
 (30, 40)]

It's possible (10, 20) maps in the new binary to (110, 120)
while (30, 40) was eliminated by the optimizer and we have
nothing valid to map it to. In that case we emit

[(110, 120)]

@dschuff
Copy link
Member

dschuff commented Jan 22, 2020

Ah, got it. I guess if just an internal subrange were eliminated it would just work. what about if the beginning or end subrange is gone? I guess a downside of using real compiler output as test input is that we can't handpick edge cases.

@kripken
Copy link
Member Author

kripken commented Jan 22, 2020

Not sure what you mean by "beginning subrange" - is that (10, 20) in that example? It currently handles all subranges in the same way.

newEnd = 0;
// If this was not an end marker, try to find what it should be updated to.
if (oldStart != 0 && oldEnd != 0) {
if (locationUpdater.hasOldExprAddr(oldStart)) {
Copy link
Member

Choose a reason for hiding this comment

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

should we have some kind of combined lookup like hasOldExprOrFuncStartAddr() ? I guess when updating ranges we have no way to tell the context of the use...

Copy link
Member Author

Choose a reason for hiding this comment

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

I could refactor a function for this, but I don't think that would be reusable anywhere else. This is the one place where we update both sides of a span (start, end) at once.

Copy link
Member Author

Choose a reason for hiding this comment

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

For the second part, yeah, we can't tell the context atm. If the context would help I could work on getting it. However, I think it should be safe as it is, as we do have the context of whether we are at the start or end of a span, and the risky thing is just the ambiguity of the end of one thing which is equal to the start of the next, which we avoid here.

} else if (locationUpdater.hasOldFuncEndAddr(oldEnd)) {
newEnd = locationUpdater.getNewFuncEndAddr(oldEnd);
}
if (newStart == 0 || newEnd == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess in answer to my earlier question, If we have a range that represents a run of several instructions and we eliminate the last, I guess we don't have a good way to do "nearby" lookups in our current data structure.

@dschuff
Copy link
Member

dschuff commented Jan 22, 2020

by "beginning subrange" I meant e.g. [10, 15)

@kripken
Copy link
Member Author

kripken commented Jan 22, 2020

I see now, thanks. Yeah, we could try to split subranges like (10, 20) if we know part of the instructions there. One issue is if we split into more than one piece then we need to rewrite all range section indexes. But what worries me more is that I'm not sure it would be correct or not - does part of a subrange make sense in all contexts? I have no idea...

@dschuff
Copy link
Member

dschuff commented Jan 22, 2020

Yeah, that might be the point where it makes more sense to just take the LLVM-style metadata approach (i.e. the debug info symbolically refers to IR constructs like functions and expressions) and regenerate it from scratch.

@kripken kripken merged commit 60cfc85 into master Jan 22, 2020
@kripken kripken deleted the ranges branch January 22, 2020 22:00
awtcode pushed a commit to awtcode/binaryen that referenced this pull request Jan 23, 2020
Pretty straightforward given all we have so far.

Note that fannkuch3_manyopts has an example of
a sequence of ranges of which some must be skipped
while others must not, showing we handle that by
skipping the bad ones and updating the remaining. That
is, if that we have a sequence of two (begin, end) spans

[(10, 20),
 (30, 40)]

It's possible (10, 20) maps in the new binary to (110, 120)
while (30, 40) was eliminated by the optimizer and we have
nothing valid to map it to. In that case we emit

[(110, 120)]
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