Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.glue.toir

Convert to Intermediate Representation (IR) for the back-end.
Authors:
Walter Bright
License:
Boost License 1.0

Sourcetoir.d

Documentationhttps://dlang.org/phobos/dmd_gule_toir.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/glue/toir.d

structLabel;
Our label symbol
structIRState;
Collect state variables needed by the intermediate representation (IR)
boolarrayBoundsCheck();
Returns:
true if do array bounds checking for the current function
@safe boolisNothrow();
Returns:
true if in a nothrow section of code
package(dmd.glue) elem*incUsageElem(ref IRStateirs, Locloc);
Produce elem which increments the usage count for a particular line. Sets corresponding bit in bitmapm.covb[linnum]. Used to implement -cov switch (coverage analysis).
Parameters:
IRStateirscontext
Loclocline and file of what line to show usage for
Returns:
elem that increments the line count

Referenceshttps://dlang.org/dmd-windows.html#switch-cov

package(dmd.glue) elem*getEthis(Locloc, ref IRStateirs, Dsymbolfd, Dsymbolfdp = null, DsymbolorigSc = null);
Return elem that evaluates to the static frame pointer for function fd. If fd is a member function, the returned expression will compute the value of fd's 'this' variable. 'fdp' is the parent of 'fd' if the frame pointer is being used to call 'fd'. 'origSc' is the original scope we inlined from. This routine is critical for implementing nested functions.
package(dmd.glue) elem*fixEthis2(elem*ethis, FuncDeclarationfd, boolctxt2 = false);
Select one context pointer from a dual-context array
Returns:
*(ethis + offset);
package(dmd.glue) elem*setEthis(Locloc, ref IRStateirs, elem*ey, AggregateDeclarationad, boolsetthis2 = false);
Initialize the hidden aggregate member, vthis, with the context pointer.
Returns:
*(ey + (ethis2 ? ad.vthis2 : ad.vthis).offset) = this;
package(dmd.glue) intintrinsic_op(FuncDeclarationfd);
Convert intrinsic function to operator.
Returns:
the operator as backend OPER, NotIntrinsic if not an intrinsic function, OPtoPrec if frontend-only intrinsic
package(dmd.glue) elem*resolveLengthVar(VarDeclarationlengthVar, elem**pe, Typet1);
Given an expression e that is an array, determine and set the 'length' variable.

InputlengthVar Symbol of 'length' variable &e expression that is the array t1 Type of the array

Outpute is rewritten to avoid side effects

Returns:
expression that initializes 'length'
package(dmd.glue) TYPE*getParentClosureType(Symbol*sthis, FuncDeclarationfd);
for a nested function 'fd' return the type of the closure of an outer function or aggregate. If the function is a member function the 'this' type is expected to be stored in 'sthis.Sthis'. It is always returned if it is not a void pointer. buildClosure() must have been called on the outer function before.
Parameters:
Symbol*sthisthe symbol of the current 'this' derived from fd.vthis
FuncDeclarationfdthe nested function
package(dmd.glue) uintsetClosureVarOffset(FuncDeclarationfd);
Go through the variables in function fd that are to be allocated in a closure, and set the .offset fields for those variables to their positions relative to the start of the closure instance. Also turns off nrvo for closure variables.
Parameters:
FuncDeclarationfdfunction
Returns:
overall alignment of the closure
package(dmd.glue) voidbuildClosure(FuncDeclarationfd, ref IRStateirs);
Closures are implemented by taking the local variables that need to survive the scope of the function, and copying them into a gc allocated chuck of memory. That chunk, called the closure here, is inserted into the linked list of stack frames instead of the usual stack frame.
buildClosure() inserts code just after the function prolog is complete. It allocates memory for the closure, allocates a local variable (sclosure) to point to it, inserts into it the link to the enclosing frame, and copies into it the parameters that are referred to in nested functions. In VarExp::toElem and SymOffExp::toElem, when referring to a variable that is in a closure, takes the offset from sclosure rather than from the frame pointer.
getEthis() and NewExp::toElem need to use sclosure, if set, rather than the current frame pointer.
package(dmd.glue) voidbuildAlignSection(FuncDeclarationfd, ref IRStateirs);
Aligned sections are implemented by taking the local variables that need alignment that is larger than the stack alignment. They are allocated into a separate chunk of memory on the stack called an align section, which is aligned on function entry.
buildAlignSection() inserts code just after the function prolog is complete. It allocates memory for the align closure by making a local stack variable to contain that memory, allocates a local variable (salignSection) to point to it. In VarExp::toElem and SymOffExp::toElem, when referring to a variable that is in an align closure, take the offset from salignSection rather than from the frame pointer. A variable cannot be in both a closure and an align section. They go in the closure and then that closure is aligned.
getEthis() and NewExp::toElem need to use sclosure, if set, rather than the current frame pointer??
Run after buildClosure, as buildClosure gets first dibs on inAlignSection variables
Parameters:
FuncDeclarationfdfunction in which all this occurs
IRStateirsstate of the intermediate code generation

ReferencebuildClosure() is very similar.

https://github.com/dlang/dmd/pull/9143 was an incomplete attempt to solve this problem that was merged. It should probably be removed.

package(dmd.glue) voidbuildCapture(FuncDeclarationfd);
build a debug info struct for variables captured by nested functions, but not in a closure. must be called after generating the function to fill stack offsets
Parameters:
FuncDeclarationfdfunction
package(dmd.glue) RETretStyle(TypeFunctiontf, boolneedsThis);
Determine return style of function - whether in registers or through a hidden pointer to the caller's stack.
Parameters:
TypeFunctiontffunction type to check
boolneedsThistrue if the function type is for a non-static member function
Returns:
RET.stack if return value from function is on the stack, RET.regs otherwise
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 06:41:02 2026

[8]ページ先頭

©2009-2026 Movatter.jp