]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove If type in rulegen
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 26 Apr 2020 20:44:36 +0000 (21:44 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 27 Apr 2020 17:08:03 +0000 (17:08 +0000)
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>
src/cmd/compile/internal/ssa/gen/rulegen.go

index 1f9fcc74ab5a8cd9baefbf6c0990081bebf40218..9cfd4474135f9b0d3b549692d3e3e3624837ef6b 100644 (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