From 1cf357981ee9ec838555585d52f86ca60097c6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 26 Apr 2020 21:44:36 +0100 Subject: [PATCH] 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 --- src/cmd/compile/internal/ssa/gen/rulegen.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 1f9fcc74ab..9cfd447413 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -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