Reorganize the global value kinds. (#490)

* Reorganize the global value kinds.

This:
 - renames "deref" global values to "load" and gives it a offset that works
   like the "load" instructions' does
 - adds an explicit "iadd_imm" global value kind, which replaces the
   builtin iadd in "vmctx" and "deref" global values.
 - also renames "globalsym" to "symbol"
This commit is contained in:
Dan Gohman
2018-09-04 21:09:04 -07:00
committed by GitHub
parent 59b83912ba
commit ca9da7702e
30 changed files with 467 additions and 320 deletions

View File

@@ -1,9 +1,10 @@
test verifier
function %add_members(i32, i64 vmctx) -> f32 baldrdash {
gv0 = vmctx+64
gv1 = vmctx+72
heap0 = dynamic gv0, min 0x1000, bound gv1, guard 0
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0+64
gv2 = load.i32 notrap aligned gv0+72
heap0 = dynamic gv1, min 0x1000, bound gv2, guard 0
ebb0(v0: i32, v6: i64):
v1 = heap_addr.i64 heap0, v0, 20

View File

@@ -1,8 +1,9 @@
test verifier
function %add_members(i32, i32 vmctx) -> f32 baldrdash {
gv0 = vmctx+64
heap0 = static gv0, min 0x1000, bound 0x10_0000, guard 0x1000
gv0 = vmctx
gv1 = load.i32 notrap aligned gv0+64
heap0 = static gv1, min 0x1000, bound 0x10_0000, guard 0x1000
ebb0(v0: i32, v5: i32):
v1 = heap_addr.i32 heap0, v0, 1

View File

@@ -1,8 +1,9 @@
test verifier
function %add_members(i32, i64 vmctx) -> f32 baldrdash {
gv0 = vmctx+64
heap0 = static gv0, min 0x1000, bound 0x1_0000_0000, guard 0x8000_0000
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0+64
heap0 = static gv1, min 0x1000, bound 0x1_0000_0000, guard 0x8000_0000
ebb0(v0: i32, v5: i64):
v1 = heap_addr.i64 heap0, v0, 1

View File

@@ -562,58 +562,58 @@ to have access to a *VM context pointer* which is used as the base address.
Typically, the VM context pointer is passed as a hidden function argument to
Cranelift functions.
.. inst:: GV = vmctx+Offset
Chains of global value expressions are possible, but cycles are not allowed.
They will be caught by the IR verifier.
Declare a global value of the address of a field in the VM context struct.
.. inst:: GV = vmctx
This declares a global value which is a constant offset from the
VM context pointer which is passed as a hidden argument to all functions
JIT-compiled for the VM.
Declare a global value of the address of the VM context struct.
Typically, the VM context is a C struct, and the declared global value
is the address of a member of the struct.
This declares a global value which is the VM context pointer which may
be passed as a hidden argument to functions JIT-compiled for a VM.
Typically, the VM context is a `#[repr(C, packed)]` struct.
:arg Offset: Byte offset from the VM context pointer to the global
value.
:result GV: Global value.
The address of a global value can also be derived by treating another global
variable as a struct pointer. This makes it possible to chase pointers into VM
runtime data structures.
A global value can also be derived by treating another global variable as a
struct pointer and loading from one of its fields. This makes it possible to
chase pointers into VM runtime data structures.
.. inst:: GV = deref(BaseGV)+Offset
.. inst:: GV = load.Type BaseGV [Offset]
Declare a global value in a struct pointed to by BaseGV.
Declare a global value pointed to by BaseGV plus Offset, with type Type.
The address of GV can be computed by first loading a pointer from BaseGV
and adding Offset to it.
It is assumed the BaseGV resides in accessible memory with the appropriate
alignment for storing a pointer.
Chains of ``deref`` global values are possible, but cycles are not
allowed. They will be caught by the IR verifier.
It is assumed the BaseGV plus Offset resides in accessible memory with the
appropriate alignment for storing a value with type Type.
:arg BaseGV: Global value providing the base pointer.
:arg Offset: Byte offset added to the loaded value.
:arg Offset: Offset added to the base before loading.
:result GV: Global value.
.. inst:: GV = [colocated] globalsym name
.. inst:: GV = iadd_imm BaseGV, Offset
Declare a global value at a symbolic address.
Declare a global value which has the value of BaseGV offset by Offset.
The address of GV is symbolic and will be assigned a relocation, so that
:arg BaseGV: Global value providing the base value.
:arg Offset: Offset added to the base value.
.. inst:: GV = [colocated] symbol Name
Declare a symbolic address global value.
The value of GV is symbolic and will be assigned a relocation, so that
it can be resolved by a later linking phase.
If the colocated keyword is present, the symbol's definition will be
defined along with the current function, such that it can use more
efficient addressing.
:arg name: External name.
:arg Name: External name.
:result GV: Global value.
.. autoinst:: global_value
.. autoinst:: globalsym_addr
.. autoinst:: symbol_value
Heaps