Fix legalization of heap_addrs with 32-bit indices. (#480)
This makes several changes: - It adds an index_type to heap declarations, allowing heaps to specify the type for indexing. This also anticipates 64-bit heap support. - It adds a memory_type to deref global values, allowing deref globals to have types other than pointers. This is used to allow the bound variable in dynamic heaps to have type i32, to match the index type in heaps with i32 index type. - And, it fixes heap legalization to do the bounds check in the heap's index type.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! Global values.
|
||||
|
||||
use ir::immediates::Offset32;
|
||||
use ir::{ExternalName, GlobalValue};
|
||||
use ir::{ExternalName, GlobalValue, Type};
|
||||
use isa::TargetIsa;
|
||||
use std::fmt;
|
||||
|
||||
/// Information about a global value declaration.
|
||||
@@ -18,13 +19,16 @@ pub enum GlobalValueData {
|
||||
///
|
||||
/// 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.
|
||||
/// be accessible, and naturally aligned to hold a value of the type.
|
||||
Deref {
|
||||
/// The base pointer global value.
|
||||
base: GlobalValue,
|
||||
|
||||
/// Byte offset to be added to the loaded value.
|
||||
offset: Offset32,
|
||||
|
||||
/// Type of the loaded value.
|
||||
memory_type: Type,
|
||||
},
|
||||
|
||||
/// Value is identified by a symbolic name. Cranelift itself does not interpret this name;
|
||||
@@ -48,13 +52,25 @@ impl GlobalValueData {
|
||||
_ => panic!("only symbols have names"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the type of this global.
|
||||
pub fn global_type(&self, isa: &TargetIsa) -> Type {
|
||||
match *self {
|
||||
GlobalValueData::VMContext { .. } | GlobalValueData::Sym { .. } => isa.pointer_type(),
|
||||
GlobalValueData::Deref { memory_type, .. } => memory_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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::Deref {
|
||||
base,
|
||||
offset,
|
||||
memory_type,
|
||||
} => write!(f, "deref({}){}: {}", base, offset, memory_type),
|
||||
GlobalValueData::Sym {
|
||||
ref name,
|
||||
colocated,
|
||||
|
||||
Reference in New Issue
Block a user