Update more references to "global variables".

This continues the transition to "global values", which aren't
implicitly dereferenced.
This commit is contained in:
Dan Gohman
2018-06-26 13:54:46 -07:00
parent 99b9b96eee
commit 8f3c49bc6c
9 changed files with 32 additions and 112 deletions

View File

@@ -575,18 +575,18 @@ Cretonne functions.
.. inst:: GV = vmctx+Offset
Declare a global value in the VM context struct.
Declare a global value of the address of a field in the VM context struct.
This declares a global value whose address is a constant offset from the
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.
Typically, the VM context is a C struct, and the declared global value
is a member of the struct.
is the address of a member of the struct.
:arg Offset: Byte offset from the VM context pointer to the global
variable.
:result GV: Global variable.
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
@@ -599,16 +599,15 @@ runtime data structures.
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 readable memory with the appropriate
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.
:arg BaseGV: Global variable containing the base pointer.
:arg Offset: Byte offset from the loaded base pointer to the global
variable.
:result GV: Global variable.
:arg BaseGV: Global value providing the base pointer.
:arg Offset: Byte offset added to the loaded value.
:result GV: Global value.
.. inst:: GV = [colocated] globalsym name
@@ -622,7 +621,7 @@ runtime data structures.
efficient addressing.
:arg name: External name.
:result GV: Global variable.
:result GV: Global value.
.. autoinst:: global_value
.. autoinst:: globalsym_addr
@@ -690,7 +689,7 @@ trap when accessed.
Declare a static heap in the preamble.
:arg Base: Global variable holding the heap's base address or
:arg Base: Global value holding the heap's base address or
``reserved_reg``.
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
size will never trap.
@@ -698,9 +697,6 @@ trap when accessed.
address space reserved for the heap, not including the guard pages.
:arg GuardBytes: Size of the guard pages in bytes.
When the base is a global value, it must be :term:`accessible` and naturally
aligned for a pointer value.
The ``reserved_reg`` option is not yet implemented.
Dynamic heaps
@@ -714,16 +710,13 @@ is resized. The bound of a dynamic heap is stored in a global value.
Declare a dynamic heap in the preamble.
:arg Base: Global variable holding the heap's base address or
:arg Base: Global value holding the heap's base address or
``reserved_reg``.
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
size will never trap.
:arg BoundGV: Global variable containing the current heap bound in bytes.
:arg BoundGV: Global value containing the current heap bound in bytes.
:arg GuardBytes: Size of the guard pages in bytes.
When the base is a global value, it must be :term:`accessible` and naturally
aligned for a pointer value.
The ``reserved_reg`` option is not yet implemented.
Heap examples

View File

@@ -488,7 +488,7 @@ stack_addr = Instruction(
ins=(SS, Offset), outs=addr)
#
# Global variables.
# Global values.
#
GV = Operand('GV', entities.global_value)

View File

@@ -185,7 +185,7 @@ pub enum AnyEntity {
Value(Value),
/// A stack slot.
StackSlot(StackSlot),
/// A Global variable.
/// A Global value.
GlobalValue(GlobalValue),
/// A jump table.
JumpTable(JumpTable),

View File

@@ -36,7 +36,7 @@ pub struct Function {
/// be checked against.
pub stack_limit: Option<ir::GlobalValue>,
/// Global variables referenced.
/// Global values referenced.
pub global_values: PrimaryMap<ir::GlobalValue, ir::GlobalValueData>,
/// Heaps referenced.

View File

@@ -1,4 +1,4 @@
//! Global variables.
//! Global values.
use ir::immediates::Offset32;
use ir::{ExternalName, GlobalValue};
@@ -7,34 +7,33 @@ use std::fmt;
/// Information about a global value declaration.
#[derive(Clone)]
pub enum GlobalValueData {
/// Variable is part of the VM context struct, it's address is a constant offset from the VM
/// Value is the address of a field in the VM context struct, a constant offset from the VM
/// context pointer.
VMContext {
/// Offset from the `vmctx` pointer to this global.
/// Offset from the `vmctx` pointer.
offset: Offset32,
},
/// Variable is part of a struct pointed to by another global value.
/// Value is pointed to by another global value.
///
/// The `base` global value is assumed to contain a pointer to a struct. This global
/// variable lives at an offset into the struct. The memory must be accessible, and
/// naturally aligned to hold a pointer value.
/// The `base` global value is assumed to contain a pointer. This global value is computed
/// by loading from memory at that pointer value, and then adding an offset. The memory must
/// be accessible, and naturally aligned to hold a pointer value.
Deref {
/// The base pointer global value.
base: GlobalValue,
/// Byte offset to be added to the pointer loaded from `base`.
/// Byte offset to be added to the loaded value.
offset: Offset32,
},
/// Variable is at an address identified by a symbolic name. Cretonne itself
/// does not interpret this name; it's used by embedders to link with other
/// data structures.
/// Value is identified by a symbolic name. Cretonne itself does not interpret this name;
/// it's used by embedders to link with other data structures.
Sym {
/// The symbolic name.
name: ExternalName,
/// Will this variable be defined nearby, such that it will always be a certain distance
/// Will this symbol be defined nearby, such that it will always be a certain distance
/// away, after linking? If so, references to it can avoid going through a GOT. Note that
/// symbols meant to be preemptible cannot be colocated.
colocated: bool,

View File

@@ -1,70 +0,0 @@
//! Global variables.
use ir::immediates::Offset32;
use ir::{ExternalName, GlobalValue};
use std::fmt;
/// Information about a global value declaration.
#[derive(Clone)]
pub enum GlobalValueData {
/// Variable is part of the VM context struct, it's address is a constant offset from the VM
/// context pointer.
VMContext {
/// Offset from the `vmctx` pointer to this global.
offset: Offset32,
},
/// Variable is part of a struct pointed to by another global value.
///
/// The `base` global value is assumed to contain a pointer to a struct. This global
/// variable lives at an offset into the struct. The memory must be accessible, and
/// naturally aligned to hold a pointer value.
Deref {
/// The base pointer global value.
base: GlobalValue,
/// Byte offset to be added to the pointer loaded from `base`.
offset: Offset32,
},
/// Variable is at an address identified by a symbolic name. Cretonne itself
/// does not interpret this name; it's used by embedders to link with other
/// data structures.
Sym {
/// The symbolic name.
name: ExternalName,
/// Will this variable be defined nearby, such that it will always be a certain distance
/// away, after linking? If so, references to it can avoid going through a GOT. Note that
/// symbols meant to be preemptible cannot be colocated.
colocated: bool,
},
}
impl GlobalValueData {
/// Assume that `self` is an `GlobalValueData::Sym` and return its name.
pub fn symbol_name(&self) -> &ExternalName {
match *self {
GlobalValueData::Sym { ref name, .. } => name,
_ => panic!("only symbols have names"),
}
}
}
impl fmt::Display for GlobalValueData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
GlobalValueData::VMContext { offset } => write!(f, "vmctx{}", offset),
GlobalValueData::Deref { base, offset } => write!(f, "deref({}){}", base, offset),
GlobalValueData::Sym {
ref name,
colocated,
} => {
if colocated {
write!(f, "colocated ")?;
}
write!(f, "globalsym {}", name)
}
}
}
}

View File

@@ -29,8 +29,7 @@ pub enum HeapBase {
/// This feature is not yet implemented.
ReservedReg,
/// The heap base is in a global value. The variable must be accessible and naturally
/// aligned for a pointer.
/// The heap base is a global value.
GlobalValue(GlobalValue),
}
@@ -39,8 +38,7 @@ pub enum HeapBase {
pub enum HeapStyle {
/// A dynamic heap can be relocated to a different base address when it is grown.
Dynamic {
/// Global variable holding the current bound of the heap in bytes. It is
/// required to be accessible and naturally aligned for a pointer-sized integer.
/// Global value providing the current bound of the heap in bytes.
bound_gv: GlobalValue,
},

View File

@@ -41,7 +41,7 @@
//! - All return instructions must have return value operands matching the current
//! function signature.
//!
//! Global variables
//! Global values
//!
//! - Detect cycles in deref(base) declarations.
//!

View File

@@ -1080,8 +1080,8 @@ impl<'a> Parser<'a> {
// Parse a global value decl.
//
// global-var-decl ::= * GlobalValue(gv) "=" global-var-desc
// global-var-desc ::= "vmctx" offset32
// global-val-decl ::= * GlobalValue(gv) "=" global-val-desc
// global-val-desc ::= "vmctx" offset32
// | "deref" "(" GlobalValue(base) ")" offset32
// | globalsym ["colocated"] name
//