diff --git a/src/cmd/compile/internal/midway/analysis.go b/src/cmd/compile/internal/midway/analysis.go
index d977957..45c8ded 100644
--- a/src/cmd/compile/internal/midway/analysis.go
+++ b/src/cmd/compile/internal/midway/analysis.go
@@ -74,11 +74,9 @@
return false
}
// Walk the body and check identifiers
+ // This will also note any variable references that are dependent.
found := false
syntax.Inspect(fn.Body, func(n syntax.Node) bool {
- if found {
- return false
- }
if id, ok := n.(*syntax.Name); ok {
obj := a.info.Uses[id]
if obj == nil {
@@ -98,6 +96,10 @@
}
}
if a.isDependentType(obj.Type()) {
+ if obj, ok := obj.(*types2.Var); ok && !a.dependentObj[obj] {
+ // For some reason, variable references need this special treatment
+ a.dependentObj[obj] = true
+ }
found = true
return false
}
diff --git a/src/cmd/compile/internal/midway/rewrite.go b/src/cmd/compile/internal/midway/rewrite.go
index 34269e6..022b036 100644
--- a/src/cmd/compile/internal/midway/rewrite.go
+++ b/src/cmd/compile/internal/midway/rewrite.go
@@ -93,7 +93,12 @@
}
if r.analyzer.HasDependentSignature(sig) {
- // Drop dependent signatures entirely
+ if o := r.info.Defs[d.Name]; o != nil && !o.Exported() {
+ // Drop unexported dependent signatures entirely
+ continue
+ }
+ d.Body = r.blockOf(d.Pos(), r.panicStmt(d.Pos(), "Unexpected call of original function rewritten to specialized SIMD"))
+ newDecls = append(newDecls, d)
continue
}
@@ -110,7 +115,7 @@
break // Keep entire var decl if any name is clean, else drop
}
}
- if keep {
+ if keep || true {
newDecls = append(newDecls, d)
}
case *syntax.TypeDecl:
@@ -285,20 +290,33 @@
switchStmt.Body = append(switchStmt.Body, caseClause)
}
- fnName := "panic"
- fnIdent := pe(syntax.NewName(d.Pos(), fnName))
+ panicStmt := r.panicStmt(d.Pos(), "unsupported vector size in simd-rewritten code")
+ return r.blockOf(d.Pos(), switchStmt, panicStmt)
+}
+func (r *Rewriter) blockOf(p syntax.Pos, stmts ...syntax.Stmt) *syntax.BlockStmt {
+ for _, s := range stmts {
+ s.SetPos(p)
+ }
+ blockStmt := &syntax.BlockStmt{List: stmts}
+ blockStmt.SetPos(p)
+ return blockStmt
+}
+
+func (r *Rewriter) panicStmt(p syntax.Pos, unquotedMessage string) *syntax.ExprStmt {
+ pe := func(e syntax.Expr) syntax.Expr {
+ e.SetPos(p)
+ return e
+ }
+ fnName := "panic"
+ fnIdent := pe(syntax.NewName(p, fnName))
callExpr := pe(&syntax.CallExpr{
Fun: fnIdent,
- ArgList: []syntax.Expr{pe(&syntax.BasicLit{Value: "\"unsupported vector size in simd-rewritten code\"", Kind: syntax.StringLit})},
+ ArgList: []syntax.Expr{pe(&syntax.BasicLit{Value: `"` + unquotedMessage + `"`, Kind: syntax.StringLit})},
})
-
panicStmt := &syntax.ExprStmt{X: callExpr}
- blockStmt := &syntax.BlockStmt{List: []syntax.Stmt{ps(switchStmt), ps(panicStmt)}}
-
- blockStmt.SetPos(d.Pos())
-
- return blockStmt
+ panicStmt.SetPos(p)
+ return panicStmt
}
func (r *Rewriter) generateForSize(fileAST *syntax.File, k int, newDecls []syntax.Decl) []syntax.Decl {