Skip to content

Commit 01a0444

Browse files
committed
SIL.rst: Document new alloc_global instruction
1 parent d4a19cb commit 01a0444

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

docs/SIL.rst

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,12 @@ Global Variables
11071107

11081108
SIL representation of a global variable.
11091109

1110-
FIXME: to be written.
1110+
Global variable access is performed by the ``alloc_global`` and ``global_addr``
1111+
SIL instructions. Prior to performing any access on the global, the
1112+
``alloc_global`` instruction must be performed to initialize the storage.
1113+
1114+
Once a global's storage has been initialized, ``global_addr`` is used to
1115+
project the value.
11111116

11121117
Dataflow Errors
11131118
---------------
@@ -1719,6 +1724,20 @@ behavior if the value buffer is currently allocated.
17191724

17201725
The type operand must be a lowered object type.
17211726

1727+
alloc_global
1728+
````````````
1729+
1730+
::
1731+
1732+
sil-instruction ::= 'alloc_global' sil-global-name
1733+
1734+
alloc_global @foo
1735+
1736+
Initialize the storage for a global variable. This instruction has
1737+
undefined behavior if the global variable has already been initialized.
1738+
1739+
The type operand must be a lowered object type.
1740+
17221741
dealloc_stack
17231742
`````````````
17241743
::
@@ -2384,15 +2403,18 @@ function_ref
23842403
Creates a reference to a SIL function.
23852404

23862405
global_addr
2387-
```````````````
2406+
```````````
23882407

23892408
::
23902409

23912410
sil-instruction ::= 'global_addr' sil-global-name ':' sil-type
23922411

23932412
%1 = global_addr @foo : $*Builtin.Word
23942413

2395-
Creates a reference to the address of a global variable.
2414+
Creates a reference to the address of a global variable which has been
2415+
previously initialized by ``alloc_global``. It is undefined behavior to
2416+
perform this operation on a global variable which has not been
2417+
initialized.
23962418

23972419
integer_literal
23982420
```````````````

0 commit comments

Comments
 (0)