On 2013/12/03 20:58:27, adonovan wrote: > Hello mailto:gri@golang.org, mailto:axwalk@gmail.com (cc: mailto:golang-dev@googlegroups.com), > > I'd like ...
10 years, 4 months ago
(2013-12-04 00:36:22 UTC)
#2
On 2013/12/03 20:58:27, adonovan wrote:
> Hello mailto:gri@golang.org, mailto:axwalk@gmail.com (cc:
mailto:golang-dev@googlegroups.com),
>
> I'd like you to review this change to
> https://code.google.com/p/go.tools/
Yes, I think this will be useful. LLVM has a switch instruction
(http://llvm.org/docs/LangRef.html#switch-instruction) that can be used with
this.
Should the findswitch.go file now simple be called switch.go ? https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go File ssa/ssautil/findswitch.go (right): https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go#newcode18 ...
10 years, 4 months ago
(2013-12-05 18:04:35 UTC)
#7
> Should the findswitch.go file now simple be called switch.go ? Done. Also s/FindSwitches/Switches/g. https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go ...
10 years, 4 months ago
(2013-12-05 19:26:58 UTC)
#8
> Should the findswitch.go file now simple be called switch.go ?
Done. Also s/FindSwitches/Switches/g.
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go
File ssa/ssautil/findswitch.go (right):
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:18: // - a two-level switch (to partition constant
strings by their first byte).
On 2013/12/05 18:04:35, gri1 wrote:
> what happens if there are fallthroughs?
Comment is now:
// The optimal choice will
// depend on the data type, the specific case values, the code in the
// bodies of each case, and the hardware.
As far as this algorithm is concerned, the body of each case doesn't matter; it
can have arbitrary control flow. If the client cares, it can look at the body.
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:50: // Exactly one of ConstCases and TypeCases is
non-empty.
On 2013/12/05 18:04:35, gri1 wrote:
> non-empty or non-nil?
Changed to be excruciatingly specific:
// One of ConstCases and TypeCases has length at least two; the other
// is nil.
(There's no single word to express nil <=> empty.)
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:59: X ssa.Value // the switch operand
On 2013/12/05 18:04:35, gri1 wrote:
> s/X/Value/
We use X liberally in ast.Expr and ssa.Instruction; why not here too?
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:66: // We represent each block by the String() of its
On 2013/12/05 18:04:35, gri1 wrote:
> s/by/with/ ?
Isn't "by" better here? Merriam Webster has "represent by" but not "represent
with".
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:68: // This is a favour to the tests.
On 2013/12/05 18:04:35, gri1 wrote:
> leave last sentence away - no need
Removed. (My point was that using the basic block names is more consistent with
ssa.Instruction.String(), but makes testing harder.)
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/findswitch.go...
ssa/ssautil/findswitch.go:70: if sw.ConstCases != nil {
On 2013/12/05 18:04:35, gri1 wrote:
> here you're checking against nil, not len(sw.ConstCases) == 0 so the comment
> about non-empty lists should be clearer
Clarified as suggested.
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/testdata/find...
File ssa/ssautil/testdata/findswitches.go (right):
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/testdata/find...
ssa/ssautil/testdata/findswitches.go:6: // Each multiway conditional with pure
constant cases (FoundSwitch)
On 2013/12/05 18:04:35, gri1 wrote:
> FoundSwitch is now called Switch
Done.
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/testdata/find...
ssa/ssautil/testdata/findswitches.go:27: fallthrough
On 2013/12/05 18:04:35, gri1 wrote:
> I don't understand how the fallthrough is represented above
It doesn't---it's irrelevant to the test. It's there to ensure it doesn't affect
the result, but I could remove it if it's confusing.
https://codereview.appspot.com/36710043/diff/120001/ssa/ssautil/testdata/find...
ssa/ssautil/testdata/findswitches.go:84: // case 3:int: print(34:int)
On 2013/12/05 18:04:35, gri1 wrote:
> shouldn't the "body" of 3 and 4 be combined? (and as such reflected in the
> String form?)
I thought about it, but what if the first and third---but not second---cases
shared the same body? (This is possible for switches found from ad-hoc control
flow.) Should String() consolidate all such cases together, or only show
contiguous ones? Since this is really just for debugging and testing (not ssa
disassembly) I just did the simplest thing.
LGTM https://codereview.appspot.com/36710043/diff/160001/ssa/ssautil/switch.go File ssa/ssautil/switch.go (right): https://codereview.appspot.com/36710043/diff/160001/ssa/ssautil/switch.go#newcode51 ssa/ssautil/switch.go:51: // One of ConstCases and TypeCases has length ...
10 years, 4 months ago
(2013-12-05 20:19:02 UTC)
#9
Issue 36710043: code review 36710043: go.tools/ssa: FindSwitches() utility infers multiway br...
(Closed)
Created 10 years, 4 months ago by adonovan
Modified 10 years, 4 months ago
Reviewers:
Base URL:
Comments: 44