1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:04:46 -07:00

cmd/compile: remove If type in rulegen

We only generate if statements via CondBreak, which is nice as the
control flow is simple and easy to work with. It seems like the If type
was added but never used, so remove it to avoid confusion.

We had a TODO about replacing CondBreak with If instead. I gave that a
try, but it doesn't seem worth the effort. The code gets more complex
and we don't really win anything in return.

While at it, don't use op strings as format strings in exprf. This
doesn't cause any issue at the moment, but it's best to be explicit
about the operator not containing any formatting verbs.

Change-Id: Ib59ad72d3628bf91594efc609e222232ad1e8748
Reviewed-on: https://go-review.googlesource.com/c/go/+/230257
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Daniel Martí 2020-04-26 21:44:36 +01:00
parent 20ed142861
commit 1cf357981e

View File

@ -186,14 +186,14 @@ func genRulesSuffix(arch arch, suff string) {
if strings.Contains(oprules[op][0].Rule, "=>") && opByName(arch, op).aux != opByName(arch, eop).aux {
panic(fmt.Sprintf("can't use ... for ops that have different aux types: %s and %s", op, eop))
}
swc := &Case{Expr: exprf(op)}
swc := &Case{Expr: exprf("%s", op)}
swc.add(stmtf("v.Op = %s", eop))
swc.add(stmtf("return true"))
sw.add(swc)
continue
}
swc := &Case{Expr: exprf(op)}
swc := &Case{Expr: exprf("%s", op)}
swc.add(stmtf("return rewriteValue%s%s_%s(v)", arch.name, suff, op))
sw.add(swc)
}
@ -623,16 +623,6 @@ func fprint(w io.Writer, n Node) {
fprint(w, n)
}
fmt.Fprintf(w, "}\n")
case *If:
fmt.Fprintf(w, "if ")
fprint(w, n.Cond)
fmt.Fprintf(w, " {\n")
fprint(w, n.Then)
if n.Else != nil {
fmt.Fprintf(w, "} else {\n")
fprint(w, n.Else)
}
fmt.Fprintf(w, "}\n")
case *Case:
fmt.Fprintf(w, "case ")
fprint(w, n.Expr)
@ -780,11 +770,6 @@ type (
Suffix string
ArgLen int32 // if kind == "Value", number of args for this op
}
If struct {
Cond ast.Expr
Then Statement
Else Statement
}
Switch struct {
BodyBase // []*Case
Expr ast.Expr
@ -807,7 +792,6 @@ type (
Name string
Value ast.Expr
}
// TODO: implement CondBreak as If + Break instead?
CondBreak struct {
Cond ast.Expr
InsideCommuteLoop bool