new move analyser2 (#20471)

* produce better code for closure environment creation
* new 'first write' analysis; 
* scope based move analyser
* code cleanup

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
Andreas Rumpf 2022-10-01 16:46:51 +02:00 • committed by GitHub
commit 8d47bf1822
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 472 additions and 684 deletions

View file

@ -104,9 +104,11 @@ proc transformSons(c: PTransf, n: PNode): PNode =
for i in 0..<n.len:
result[i] = transform(c, n[i])
proc newAsgnStmt(c: PTransf, kind: TNodeKind, le: PNode, ri: PNode): PNode =
proc newAsgnStmt(c: PTransf, kind: TNodeKind, le: PNode, ri: PNode; isFirstWrite: bool): PNode =
result = newTransNode(kind, ri.info, 2)
result[0] = le
if isFirstWrite:
le.flags.incl nfFirstWrite2
result[1] = ri
proc transformSymAux(c: PTransf, n: PNode): PNode =
@ -365,9 +367,9 @@ proc transformYield(c: PTransf, n: PNode): PNode =
case lhs.kind
of nkSym:
internalAssert c.graph.config, lhs.sym.kind == skForVar
result = newAsgnStmt(c, nkFastAsgn, lhs, rhs)
result = newAsgnStmt(c, nkFastAsgn, lhs, rhs, false)
of nkDotExpr:
result = newAsgnStmt(c, nkAsgn, lhs, rhs)
result = newAsgnStmt(c, nkAsgn, lhs, rhs, false)
else:
internalAssert c.graph.config, false
result = newTransNode(nkStmtList, n.info, 0)
@ -734,7 +736,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
# generate a temporary and produce an assignment statement:
var temp = newTemp(c, t, formal.info)
addVar(v, temp)
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true))
idNodeTablePut(newC.mapping, formal, temp)
of paVarAsgn:
assert(skipTypes(formal.typ, abstractInst).kind in {tyVar})
@ -744,7 +746,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
# arrays will deep copy here (pretty bad).
var temp = newTemp(c, arg.typ, formal.info)
addVar(v, temp)
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true))
idNodeTablePut(newC.mapping, formal, temp)
let body = transformBody(c.graph, c.idgen, iter, true)