-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fixes #25687; optimizes seq assignment for orc #25689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
d4f5271
8290f6d
9182c03
1e837ca
0c55eb3
0d511fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,11 +620,34 @@ proc checkSelfAssignment(c: var TLiftCtx; t: PType; body, x, y: PNode) = | |
| cond.typ = getSysType(c.g, c.info, tyBool) | ||
| body.add genIf(c, cond, newTreeI(nkReturnStmt, c.info, newNodeI(nkEmpty, c.info))) | ||
|
|
||
| proc genBulkCopySeq(c: var TLiftCtx; t: PType; body, x, y: PNode) = | ||
| ## Generates a call to nimCopySeqPayload for bulk memcpy of seq data. | ||
| let elemType = t.elementType | ||
| let sym = magicsys.getCompilerProc(c.g, "nimCopySeqPayload") | ||
| if sym == nil: | ||
| localError(c.g.config, c.info, "system module needs: nimCopySeqPayload") | ||
| return | ||
| var sizeOf = genBuiltin(c, mSizeOf, "sizeof", newNodeIT(nkType, c.info, elemType)) | ||
| sizeOf.typ = getSysType(c.g, c.info, tyInt) | ||
| var alignOf = genBuiltin(c, mAlignOf, "alignof", newNodeIT(nkType, c.info, elemType)) | ||
| alignOf.typ = getSysType(c.g, c.info, tyInt) | ||
| let call = newNodeI(nkCall, c.info) | ||
| call.add newSymNode(sym) | ||
| call.add newTreeIT(nkAddr, c.info, makePtrType(c.fn, x.typ, c.idgen), x) | ||
| call.add newTreeIT(nkAddr, c.info, makePtrType(c.fn, y.typ, c.idgen), y) | ||
| call.add sizeOf | ||
| call.add alignOf | ||
| call.typ = sym.typ.returnType | ||
| body.add call | ||
|
|
||
| proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = | ||
| case c.kind | ||
| of attachedDup: | ||
| body.add setLenSeqCall(c, t, x, y) | ||
| forallElements(c, t, body, x, y) | ||
| if supportsCopyMem(t.elementType): | ||
| genBulkCopySeq(c, t, body, x, y) | ||
| else: | ||
| forallElements(c, t, body, x, y) | ||
| of attachedAsgn, attachedDeepCopy: | ||
| # we generate: | ||
| # if x.p == y.p: | ||
|
|
@@ -633,9 +656,13 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = | |
| # var i = 0 | ||
| # while i < y.len: dest[i] = y[i]; inc(i) | ||
| # This is usually more efficient than a destroy/create pair. | ||
| # For trivially copyable types, use bulk copyMem instead of element loop. | ||
| checkSelfAssignment(c, t, body, x, y) | ||
| body.add setLenSeqCall(c, t, x, y) | ||
| forallElements(c, t, body, x, y) | ||
| if supportsCopyMem(t.elementType): | ||
| genBulkCopySeq(c, t, body, x, y) | ||
| else: | ||
| forallElements(c, t, body, x, y) | ||
|
Comment on lines
643
to
+665
|
||
| of attachedSink: | ||
| let moveCall = genBuiltin(c, mMove, "move", x) | ||
| moveCall.add y | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why generate this in the compiler? can't it be library code?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
=copyhook for seq is still special magic in Nim 2. Mostly caused by the fact that people expectseqto work within Nim's VM which doesn't support the required cast/alloc/etc stuff. There is alsoconst s = @["abc"]which is valid Nim code (makes no sense here but comes up for Table in const sections).