Skip to content

Commit e4009ed

Browse files
authored
[clang][docs] Update bytecode interpreter docs (#124252)
Just a light update, not adding a lot of new information.
1 parent d9b8120 commit e4009ed

File tree

2 files changed

+16
-114
lines changed

2 files changed

+16
-114
lines changed

clang/docs/ConstantInterpreter.rst

Lines changed: 16 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ by the evaluator. The interpreter is activated using the following flags:
1818
Bytecode Compilation
1919
====================
2020

21-
Bytecode compilation is handled in ``ByteCodeStmtGen.h`` for statements
22-
and ``ByteCodeExprGen.h`` for expressions. The compiler has two different
21+
Bytecode compilation is handled in ``Compiler.h`` for statements
22+
and for expressions. The compiler has two different
2323
backends: one to generate bytecode for functions (``ByteCodeEmitter``) and
2424
one to directly evaluate expressions as they are compiled, without
2525
generating bytecode (``EvalEmitter``). All functions are compiled to
@@ -44,11 +44,11 @@ Primitive Types
4444
Signed or unsigned integers of a specific bit width, implemented using
4545
the ```Integral``` type.
4646

47-
* ``PT_{U|S}intFP``
47+
* ``PT_IntAP{S}``
4848

4949
Signed or unsigned integers of an arbitrary, but fixed width used to
5050
implement integral types which are required by the target, but are not
51-
supported by the host. Under the hood, they rely on APValue. The
51+
supported by the host. Under the hood, they rely on ``APInt``. The
5252
``Integral`` specialisation for these types is required by opcodes to
5353
share an implementation with fixed integrals.
5454

@@ -57,38 +57,29 @@ Primitive Types
5757
Representation for boolean types, essentially a 1-bit unsigned
5858
``Integral``.
5959

60-
* ``PT_RealFP``
60+
* ``PT_Float``
6161

6262
Arbitrary, but fixed precision floating point numbers. Could be
6363
specialised in the future similarly to integers in order to improve
6464
floating point performance.
6565

6666
* ``PT_Ptr``
6767

68-
Pointer type, defined in ``"Pointer.h"``. A pointer can be either null,
69-
reference interpreter-allocated memory (``BlockPointer``) or point to an
70-
address which can be derived, but not accessed (``ExternPointer``).
68+
Pointer type, defined in ``"Pointer.h"``. The most common type of
69+
pointer is a "BlockPointer", which points to an ``interp::Block``.
70+
But other pointer types exist, such as typeid pointers or
71+
integral pointers.
7172

7273
* ``PT_FnPtr``
7374

7475
Function pointer type, can also be a null function pointer. Defined
75-
in ``"FnPointer.h"``.
76+
in ``"FunctionPointer.h"``.
7677

77-
* ``PT_MemPtr``
78+
* ``PT_MemberPtr``
7879

7980
Member pointer type, can also be a null member pointer. Defined
8081
in ``"MemberPointer.h"``
8182

82-
* ``PT_VoidPtr``
83-
84-
Void pointer type, can be used for round-trip casts. Represented as
85-
the union of all pointers which can be cast to void.
86-
Defined in ``"VoidPointer.h"``.
87-
88-
* ``PT_ObjCBlockPtr``
89-
90-
Pointer type for ObjC blocks. Defined in ``"ObjCBlockPointer.h"``.
91-
9283
Composite types
9384
---------------
9485

@@ -219,35 +210,21 @@ Pointers
219210
--------
220211

221212
Pointers, implemented in ``Pointer.h`` are represented as a tagged union.
222-
Some of these may not yet be available in upstream ``clang``.
223213

224214
* **BlockPointer**: used to reference memory allocated and managed by the
225215
interpreter, being the only pointer kind which allows dereferencing in the
226216
interpreter
227-
* **ExternPointer**: points to memory which can be addressed, but not read by
228-
the interpreter. It is equivalent to APValue, tracking a declaration and a path
229-
of fields and indices into that allocation.
230-
* **TargetPointer**: represents a target address derived from a base address
231-
through pointer arithmetic, such as ``((int *)0x100)[20]``. Null pointers are
232-
target pointers with a zero offset.
233-
* **TypeInfoPointer**: tracks information for the opaque type returned by
217+
* **TypeIDPointer**: tracks information for the opaque type returned by
234218
``typeid``
235-
* **InvalidPointer**: is dummy pointer created by an invalid operation which
236-
allows the interpreter to continue execution. Does not allow pointer
237-
arithmetic or dereferencing.
219+
* **IntegralPointer**: a pointer formed from an integer,
220+
think ``(int*)123``.
238221

239222
Besides the previously mentioned union, a number of other pointer-like types
240223
have their own type:
241224

242-
* **ObjCBlockPointer** tracks Objective-C blocks
243-
* **FnPointer** tracks functions and lazily caches their compiled version
225+
* **FunctionPointer** tracks functions.
244226
* **MemberPointer** tracks C++ object members
245227

246-
Void pointers, which can be built by casting any of the aforementioned
247-
pointers, are implemented as a union of all pointer types. The ``BitCast``
248-
opcode is responsible for performing all legal conversions between these
249-
types and primitive integers.
250-
251228
BlockPointer
252229
~~~~~~~~~~~~
253230

@@ -311,73 +288,9 @@ of ``a.c``, but its offset would point to ``&a.c[1]``. The
311288
array-to-pointer decay operation adjusts a pointer to an array (where
312289
the offset is equal to the base) to a pointer to the first element.
313290

314-
ExternPointer
315-
~~~~~~~~~~~~~
316-
317-
Extern pointers can be derived, pointing into symbols which are not
318-
readable from constexpr. An external pointer consists of a base
319-
declaration, along with a path designating a subobject, similar to
320-
the ``LValuePath`` of an APValue. Extern pointers can be converted
321-
to block pointers if the underlying variable is defined after the
322-
pointer is created, as is the case in the following example:
323-
324-
.. code-block:: c
325-
326-
extern const int a;
327-
constexpr const int *p = &a;
328-
const int a = 5;
329-
static_assert(*p == 5, "x");
330-
331-
TargetPointer
332-
~~~~~~~~~~~~~
333-
334-
While null pointer arithmetic or integer-to-pointer conversion is
335-
banned in constexpr, some expressions on target offsets must be folded,
336-
replicating the behaviour of the ``offsetof`` builtin. Target pointers
337-
are characterised by 3 offsets: a field offset, an array offset and a
338-
base offset, along with a descriptor specifying the type the pointer is
339-
supposed to refer to. Array indexing adjusts the array offset, while the
340-
field offset is adjusted when a pointer to a member is created. Casting
341-
an integer to a pointer sets the value of the base offset. As a special
342-
case, null pointers are target pointers with all offsets set to 0.
343-
344291
TypeInfoPointer
345292
~~~~~~~~~~~~~~~
346293

347294
``TypeInfoPointer`` tracks two types: the type assigned to
348295
``std::type_info`` and the type which was passed to ``typeinfo``.
349-
350-
InvalidPointer
351-
~~~~~~~~~~~~~~
352-
353-
Such pointers are built by operations which cannot generate valid
354-
pointers, allowing the interpreter to continue execution after emitting
355-
a warning. Inspecting such a pointer stops execution.
356-
357-
TODO
358-
====
359-
360-
Missing Language Features
361-
-------------------------
362-
363-
* Changing the active field of unions
364-
* ``volatile``
365-
* ``__builtin_constant_p``
366-
* ``dynamic_cast``
367-
* ``new`` and ``delete``
368-
* Fixed Point numbers and arithmetic on Complex numbers
369-
* Several builtin methods, including string operations and
370-
``__builtin_bit_cast``
371-
* Continue-after-failure: a form of exception handling at the bytecode
372-
level should be implemented to allow execution to resume. As an example,
373-
argument evaluation should resume after the computation of an argument fails.
374-
* Pointer-to-Integer conversions
375-
* Lazy descriptors: the interpreter creates a ``Record`` and ``Descriptor``
376-
when it encounters a type: ones which are not yet defined should be lazily
377-
created when required
378-
379-
Known Bugs
380-
----------
381-
382-
* If execution fails, memory storing APInts and APFloats is leaked when the
383-
stack is cleared
296+
It is part of the taged union in ``Pointer``.

clang/www/OpenProjects.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,6 @@ <h1>Open Clang Projects</h1>
9090
performance as well as to find ways to proactively alert us when we've
9191
introduced a change that has significant negative impact on build times.</li>
9292

93-
<li><b>Complete support for the experimental constant expression interpreter
94-
</b>: Clang's production constant expression interpreter computes a constant
95-
expression result by walking over AST nodes, performing calculations as it
96-
goes. This does not have good performance properties, and so we've begun work
97-
on an <a href="https://clang.llvm.org/docs/ConstantInterpreter.html">
98-
experimental constant expression interpreter</a> that works by converting the
99-
AST into bytecode that is interpreted. This effort has a long tail of work left
100-
to complete because it requires implementing byte code for every kind of
101-
expression and type that can be used in a constant expression for C++ and C.
102-
</li>
103-
10493
<li><b>Improve clang-doc</b>: Clang's library-based design allows it to be used
10594
by a variety of tools that reason about source code.
10695
<a href="https://clang.llvm.org/extra/clang-doc.html">clang-doc</a> is one

0 commit comments

Comments
 (0)