@@ -15,14 +15,14 @@ garbage collector.** You must provide your own.
15
15
Quick Start
16
16
============
17
17
18
- First, you should pick a collector strategy. LLVM includes a number of built
19
- in ones, but you can also implement a loadable plugin with a custom definition.
18
+ First, you should pick a collector strategy. LLVM includes a number of built-in
19
+ ones, but you can also implement a loadable plugin with a custom definition.
20
20
Note that the collector strategy is a description of how LLVM should generate
21
21
code such that it interacts with your collector and runtime, not a description
22
22
of the collector itself.
23
23
24
24
Next, mark your generated functions as using your chosen collector strategy.
25
- From c ++, you can call:
25
+ From C ++, you can call:
26
26
27
27
.. code-block :: c++
28
28
@@ -40,7 +40,7 @@ When generating LLVM IR for your functions, you will need to:
40
40
41
41
* Use ``@llvm.gcread `` and/or ``@llvm.gcwrite `` in place of standard load and
42
42
store instructions. These intrinsics are used to represent load and store
43
- barriers. If you collector does not require such barriers, you can skip
43
+ barriers. If your collector does not require such barriers, you can skip
44
44
this step.
45
45
46
46
* Use the memory allocation routines provided by your garbage collector's
@@ -49,7 +49,7 @@ When generating LLVM IR for your functions, you will need to:
49
49
* If your collector requires them, generate type maps according to your
50
50
runtime's binary interface. LLVM is not involved in the process. In
51
51
particular, the LLVM type system is not suitable for conveying such
52
- information though the compiler.
52
+ information through the compiler.
53
53
54
54
* Insert any coordination code required for interacting with your collector.
55
55
Many collectors require running application code to periodically check a
@@ -59,7 +59,7 @@ When generating LLVM IR for your functions, you will need to:
59
59
You will need to identify roots (i.e. references to heap objects your collector
60
60
needs to know about) in your generated IR, so that LLVM can encode them into
61
61
your final stack maps. Depending on the collector strategy chosen, this is
62
- accomplished by using either the ``@llvm.gcroot `` intrinsics or an
62
+ accomplished by using either the ``@llvm.gcroot `` intrinsics or a
63
63
``gc.statepoint `` relocation sequence.
64
64
65
65
Don't forget to create a root for each intermediate value that is generated when
@@ -142,11 +142,11 @@ Perl, Python, Lua, Ruby, other scripting languages, and more.
142
142
143
143
Note that LLVM **does not itself provide a garbage collector ** --- this should
144
144
be part of your language's runtime library. LLVM provides a framework for
145
- describing the garbage collectors requirements to the compiler. In particular,
145
+ describing the garbage collector's requirements to the compiler. In particular,
146
146
LLVM provides support for generating stack maps at call sites, polling for a
147
147
safepoint, and emitting load and store barriers. You can also extend LLVM -
148
148
possibly through a loadable :ref: `code generation plugins <plugin >` - to
149
- generate code and data structures which conforms to the *binary interface *
149
+ generate code and data structures which conform to the *binary interface *
150
150
specified by the *runtime library *. This is similar to the relationship between
151
151
LLVM and DWARF debugging info, for example. The difference primarily lies in
152
152
the lack of an established standard in the domain of garbage collection --- thus
@@ -185,10 +185,10 @@ adequately addressed with other features of the IR and does not specify a
185
185
particular binary interface. On the plus side, this means that you should be
186
186
able to integrate LLVM with an existing runtime. On the other hand, it can
187
187
have the effect of leaving a lot of work for the developer of a novel
188
- language. We try to mitigate this by providing built in collector strategy
188
+ language. We try to mitigate this by providing built- in collector strategy
189
189
descriptions that can work with many common collector designs and easy
190
190
extension points. If you don't already have a specific binary interface
191
- you need to support, we recommend trying to use one of these built in collector
191
+ you need to support, we recommend trying to use one of these built- in collector
192
192
strategies.
193
193
194
194
.. _gc_intrinsics :
@@ -257,16 +257,16 @@ associated with the pointer, and **must** be a constant or global value
257
257
address. If your target collector uses tags, use a null pointer for metadata.
258
258
259
259
A compiler which performs manual SSA construction **must ** ensure that SSA
260
- values representing GC references are stored in to the alloca passed to the
260
+ values representing GC references are stored into the alloca passed to the
261
261
respective ``gcroot `` before every call site and reloaded after every call.
262
262
A compiler which uses mem2reg to raise imperative code using ``alloca `` into
263
263
SSA form need only add a call to ``@llvm.gcroot `` for those variables which
264
264
are pointers into the GC heap.
265
265
266
266
It is also important to mark intermediate values with ``llvm.gcroot ``. For
267
267
example, consider ``h(f(), g()) ``. Beware leaking the result of ``f() `` in the
268
- case that ``g() `` triggers a collection. Note, that stack variables must be
269
- initialized and marked with ``llvm.gcroot `` in function's prologue.
268
+ case that ``g() `` triggers a collection. Note that stack variables must be
269
+ initialized and marked with ``llvm.gcroot `` in the function's prologue.
270
270
271
271
The ``%metadata `` argument can be used to avoid requiring heap objects to have
272
272
'isa' pointers or tag bits. [Appel89 _, Goldberg91 _, Tolmach94 _] If specified,
@@ -388,10 +388,10 @@ greater performance impact since pointer reads are more frequent than writes.
388
388
389
389
.. _builtin-gc-strategies :
390
390
391
- Built In GC Strategies
391
+ Built- In GC Strategies
392
392
======================
393
393
394
- LLVM includes built in support for several varieties of garbage collectors.
394
+ LLVM includes built- in support for several varieties of garbage collectors.
395
395
396
396
The Shadow Stack GC
397
397
----------------------
@@ -481,17 +481,17 @@ data structure, but there are only 20 lines of meaningful code.)
481
481
}
482
482
483
483
484
- The 'Erlang' and 'Ocaml ' GCs
484
+ The 'Erlang' and 'OCaml ' GCs
485
485
-----------------------------
486
486
487
487
LLVM ships with two example collectors which leverage the ``gcroot ``
488
488
mechanisms. To our knowledge, these are not actually used by any language
489
489
runtime, but they do provide a reasonable starting point for someone interested
490
490
in writing an ``gcroot `` compatible GC plugin. In particular, these are the
491
- only in tree examples of how to produce a custom binary stack map format using
491
+ only in- tree examples of how to produce a custom binary stack map format using
492
492
a ``gcroot `` strategy.
493
493
494
- As there names imply, the binary format produced is intended to model that
494
+ As their names imply, the binary format produced is intended to model that
495
495
used by the Erlang and OCaml compilers respectively.
496
496
497
497
.. _statepoint_example_gc :
@@ -544,14 +544,14 @@ certain aspects like:
544
544
Custom GC Strategies
545
545
====================
546
546
547
- If none of the built in GC strategy descriptions met your needs above, you will
547
+ If none of the built- in GC strategy descriptions met your needs above, you will
548
548
need to define a custom GCStrategy and possibly, a custom LLVM pass to perform
549
549
lowering. Your best example of where to start defining a custom GCStrategy
550
- would be to look at one of the built in strategies.
550
+ would be to look at one of the built- in strategies.
551
551
552
552
You may be able to structure this additional code as a loadable plugin library.
553
553
Loadable plugins are sufficient if all you need is to enable a different
554
- combination of built in functionality, but if you need to provide a custom
554
+ combination of built- in functionality, but if you need to provide a custom
555
555
lowering pass, you will need to build a patched version of LLVM. If you think
556
556
you need a patched build, please ask for advice on llvm-dev. There may be an
557
557
easy way we can extend the support to make it work for your use case without
@@ -576,7 +576,7 @@ You should be able to leverage any existing collector library that includes the
576
576
#. A mechanism for identifying references in global locations (e.g. global
577
577
variables).
578
578
579
- #. If you collector requires them, an LLVM IR implementation of your collectors
579
+ #. If your collector requires them, an LLVM IR implementation of your collector's
580
580
load and store barriers. Note that since many collectors don't require
581
581
barriers at all, LLVM defaults to lowering such barriers to normal loads
582
582
and stores unless you arrange otherwise.
@@ -598,7 +598,7 @@ runtime library). This can be accomplished in about 100 lines of code.
598
598
This is not the appropriate place to implement a garbage collected heap or a
599
599
garbage collector itself. That code should exist in the language's runtime
600
600
library. The compiler plugin is responsible for generating code which conforms
601
- to the binary interface defined by library, most essentially the :ref: `stack map
601
+ to the binary interface defined by the library, most essentially the :ref: `stack map
602
602
<stack-map>`.
603
603
604
604
To subclass ``llvm::GCStrategy `` and register it with the compiler:
@@ -850,11 +850,11 @@ Custom lowering of intrinsics
850
850
------------------------------
851
851
852
852
For GCs which use barriers or unusual treatment of stack roots, the
853
- implementor is responsibly for providing a custom pass to lower the
853
+ implementor is responsible for providing a custom pass to lower the
854
854
intrinsics with the desired semantics. If you have opted in to custom
855
855
lowering of a particular intrinsic your pass **must ** eliminate all
856
856
instances of the corresponding intrinsic in functions which opt in to
857
- your GC. The best example of such a pass is the ShadowStackGC and it's
857
+ your GC. The best example of such a pass is the ShadowStackGC and its
858
858
ShadowStackGCLowering pass.
859
859
860
860
There is currently no way to register such a custom lowering pass
0 commit comments