Remove reserved_reg functionality. (#424)
* Remove reserved_reg functionality. This wasn't implemented, and if we need it in the future, it seems like it would be better to extend the concept of global values to cover this. * Use GlobalValue::reserved_value() for sentinal values.
This commit is contained in:
@@ -689,16 +689,13 @@ trap when accessed.
|
|||||||
|
|
||||||
Declare a static heap in the preamble.
|
Declare a static heap in the preamble.
|
||||||
|
|
||||||
:arg Base: Global value holding the heap's base address or
|
:arg Base: Global value holding the heap's base address.
|
||||||
``reserved_reg``.
|
|
||||||
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
|
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
|
||||||
size will never trap.
|
size will never trap.
|
||||||
:arg BoundBytes: Fixed heap bound in bytes. This defines the amount of
|
:arg BoundBytes: Fixed heap bound in bytes. This defines the amount of
|
||||||
address space reserved for the heap, not including the guard pages.
|
address space reserved for the heap, not including the guard pages.
|
||||||
:arg GuardBytes: Size of the guard pages in bytes.
|
:arg GuardBytes: Size of the guard pages in bytes.
|
||||||
|
|
||||||
The ``reserved_reg`` option is not yet implemented.
|
|
||||||
|
|
||||||
Dynamic heaps
|
Dynamic heaps
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
@@ -710,15 +707,12 @@ is resized. The bound of a dynamic heap is stored in a global value.
|
|||||||
|
|
||||||
Declare a dynamic heap in the preamble.
|
Declare a dynamic heap in the preamble.
|
||||||
|
|
||||||
:arg Base: Global value holding the heap's base address or
|
:arg Base: Global value holding the heap's base address.
|
||||||
``reserved_reg``.
|
|
||||||
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
|
:arg MinBytes: Guaranteed minimum heap size in bytes. Accesses below this
|
||||||
size will never trap.
|
size will never trap.
|
||||||
:arg BoundGV: Global value 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.
|
:arg GuardBytes: Size of the guard pages in bytes.
|
||||||
|
|
||||||
The ``reserved_reg`` option is not yet implemented.
|
|
||||||
|
|
||||||
Heap examples
|
Heap examples
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ ebb0:
|
|||||||
|
|
||||||
; Declare static heaps.
|
; Declare static heaps.
|
||||||
function %sheap(i32, i64 vmctx) -> i64 {
|
function %sheap(i32, i64 vmctx) -> i64 {
|
||||||
heap1 = static reserved_reg, min 0x1_0000, bound 0x1_0000_0000, guard 0x8000_0000
|
heap1 = static gv5, min 0x1_0000, bound 0x1_0000_0000, guard 0x8000_0000
|
||||||
heap2 = static gv5, guard 0x1000, bound 0x1_0000
|
heap2 = static gv5, guard 0x1000, bound 0x1_0000
|
||||||
gv5 = vmctx+64
|
gv5 = vmctx+64
|
||||||
|
|
||||||
; check: heap1 = static reserved_reg, min 0x0001_0000, bound 0x0001_0000_0000, guard 0x8000_0000
|
; check: heap1 = static gv5, min 0x0001_0000, bound 0x0001_0000_0000, guard 0x8000_0000
|
||||||
; check: heap2 = static gv5, min 0, bound 0x0001_0000, guard 4096
|
; check: heap2 = static gv5, min 0, bound 0x0001_0000, guard 4096
|
||||||
ebb0(v1: i32, v2: i64):
|
ebb0(v1: i32, v2: i64):
|
||||||
v3 = heap_addr.i64 heap1, v1, 0
|
v3 = heap_addr.i64 heap1, v1, 0
|
||||||
@@ -66,12 +66,12 @@ ebb0(v1: i32, v2: i64):
|
|||||||
|
|
||||||
; Declare dynamic heaps.
|
; Declare dynamic heaps.
|
||||||
function %dheap(i32, i64 vmctx) -> i64 {
|
function %dheap(i32, i64 vmctx) -> i64 {
|
||||||
heap1 = dynamic reserved_reg, min 0x1_0000, bound gv6, guard 0x8000_0000
|
heap1 = dynamic gv5, min 0x1_0000, bound gv6, guard 0x8000_0000
|
||||||
heap2 = dynamic gv5, bound gv6, guard 0x1000
|
heap2 = dynamic gv5, bound gv6, guard 0x1000
|
||||||
gv5 = vmctx+64
|
gv5 = vmctx+64
|
||||||
gv6 = vmctx+72
|
gv6 = vmctx+72
|
||||||
|
|
||||||
; check: heap1 = dynamic reserved_reg, min 0x0001_0000, bound gv6, guard 0x8000_0000
|
; check: heap1 = dynamic gv5, min 0x0001_0000, bound gv6, guard 0x8000_0000
|
||||||
; check: heap2 = dynamic gv5, min 0, bound gv6, guard 4096
|
; check: heap2 = dynamic gv5, min 0, bound gv6, guard 4096
|
||||||
ebb0(v1: i32, v2: i64):
|
ebb0(v1: i32, v2: i64):
|
||||||
v3 = heap_addr.i64 heap2, v1, 0
|
v3 = heap_addr.i64 heap2, v1, 0
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ use std::fmt;
|
|||||||
/// Information about a heap declaration.
|
/// Information about a heap declaration.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HeapData {
|
pub struct HeapData {
|
||||||
/// Method for determining the heap base address.
|
/// The address of the start of the heap's storage.
|
||||||
pub base: HeapBase,
|
pub base: GlobalValue,
|
||||||
|
|
||||||
/// Guaranteed minimum heap size in bytes. Heap accesses before `min_size` don't need bounds
|
/// Guaranteed minimum heap size in bytes. Heap accesses before `min_size` don't need bounds
|
||||||
/// checking.
|
/// checking.
|
||||||
@@ -21,18 +21,6 @@ pub struct HeapData {
|
|||||||
pub style: HeapStyle,
|
pub style: HeapStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Method for determining the base address of a heap.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum HeapBase {
|
|
||||||
/// The heap base lives in a reserved register.
|
|
||||||
///
|
|
||||||
/// This feature is not yet implemented.
|
|
||||||
ReservedReg,
|
|
||||||
|
|
||||||
/// The heap base is a global value.
|
|
||||||
GlobalValue(GlobalValue),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Style of heap including style-specific information.
|
/// Style of heap including style-specific information.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum HeapStyle {
|
pub enum HeapStyle {
|
||||||
@@ -57,12 +45,7 @@ impl fmt::Display for HeapData {
|
|||||||
HeapStyle::Static { .. } => "static",
|
HeapStyle::Static { .. } => "static",
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
match self.base {
|
write!(f, " {}, min {}", self.base, self.min_size)?;
|
||||||
HeapBase::ReservedReg => write!(f, " reserved_reg")?,
|
|
||||||
HeapBase::GlobalValue(gv) => write!(f, " {}", gv)?,
|
|
||||||
}
|
|
||||||
|
|
||||||
write!(f, ", min {}", self.min_size)?;
|
|
||||||
match self.style {
|
match self.style {
|
||||||
HeapStyle::Dynamic { bound_gv } => write!(f, ", bound {}", bound_gv)?,
|
HeapStyle::Dynamic { bound_gv } => write!(f, ", bound {}", bound_gv)?,
|
||||||
HeapStyle::Static { bound } => write!(f, ", bound {}", bound)?,
|
HeapStyle::Static { bound } => write!(f, ", bound {}", bound)?,
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub use ir::extfunc::{AbiParam, ArgumentExtension, ArgumentPurpose, ExtFuncData,
|
|||||||
pub use ir::extname::ExternalName;
|
pub use ir::extname::ExternalName;
|
||||||
pub use ir::function::Function;
|
pub use ir::function::Function;
|
||||||
pub use ir::globalvalue::GlobalValueData;
|
pub use ir::globalvalue::GlobalValueData;
|
||||||
pub use ir::heap::{HeapBase, HeapData, HeapStyle};
|
pub use ir::heap::{HeapData, HeapStyle};
|
||||||
pub use ir::instructions::{InstructionData, Opcode, ValueList, ValueListPool, VariableArgs};
|
pub use ir::instructions::{InstructionData, Opcode, ValueList, ValueListPool, VariableArgs};
|
||||||
pub use ir::jumptable::JumpTableData;
|
pub use ir::jumptable::JumpTableData;
|
||||||
pub use ir::layout::Layout;
|
pub use ir::layout::Layout;
|
||||||
|
|||||||
@@ -154,11 +154,7 @@ fn offset_addr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the heap base address base
|
// Add the heap base address base
|
||||||
match pos.func.heaps[heap].base {
|
let base_gv = pos.func.heaps[heap].base;
|
||||||
ir::HeapBase::ReservedReg => unimplemented!(),
|
let base = pos.ins().global_value(addr_ty, base_gv);
|
||||||
ir::HeapBase::GlobalValue(base_gv) => {
|
pos.func.dfg.replace(inst).iadd(base, offset);
|
||||||
let base = pos.ins().global_value(addr_ty, base_gv);
|
|
||||||
pos.func.dfg.replace(inst).iadd(base, offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ use cranelift_codegen::ir::instructions::{InstructionData, InstructionFormat, Va
|
|||||||
use cranelift_codegen::ir::types::VOID;
|
use cranelift_codegen::ir::types::VOID;
|
||||||
use cranelift_codegen::ir::{
|
use cranelift_codegen::ir::{
|
||||||
AbiParam, ArgumentExtension, ArgumentLoc, Ebb, ExtFuncData, ExternalName, FuncRef, Function,
|
AbiParam, ArgumentExtension, ArgumentLoc, Ebb, ExtFuncData, ExternalName, FuncRef, Function,
|
||||||
GlobalValue, GlobalValueData, Heap, HeapBase, HeapData, HeapStyle, JumpTable, JumpTableData,
|
GlobalValue, GlobalValueData, Heap, HeapData, HeapStyle, JumpTable, JumpTableData, MemFlags,
|
||||||
MemFlags, Opcode, SigRef, Signature, StackSlot, StackSlotData, StackSlotKind, Type, Value,
|
Opcode, SigRef, Signature, StackSlot, StackSlotData, StackSlotKind, Type, Value, ValueLoc,
|
||||||
ValueLoc,
|
|
||||||
};
|
};
|
||||||
use cranelift_codegen::isa::{self, Encoding, RegUnit, TargetIsa};
|
use cranelift_codegen::isa::{self, Encoding, RegUnit, TargetIsa};
|
||||||
use cranelift_codegen::packed_option::ReservedValue;
|
use cranelift_codegen::packed_option::ReservedValue;
|
||||||
@@ -168,7 +167,7 @@ impl<'a> Context<'a> {
|
|||||||
self.map.def_heap(heap, loc)?;
|
self.map.def_heap(heap, loc)?;
|
||||||
while self.function.heaps.next_key().index() <= heap.index() {
|
while self.function.heaps.next_key().index() <= heap.index() {
|
||||||
self.function.create_heap(HeapData {
|
self.function.create_heap(HeapData {
|
||||||
base: HeapBase::ReservedReg,
|
base: GlobalValue::reserved_value(),
|
||||||
min_size: Imm64::new(0),
|
min_size: Imm64::new(0),
|
||||||
guard_size: Imm64::new(0),
|
guard_size: Imm64::new(0),
|
||||||
style: HeapStyle::Static {
|
style: HeapStyle::Static {
|
||||||
@@ -1123,8 +1122,7 @@ impl<'a> Parser<'a> {
|
|||||||
// heap-decl ::= * Heap(heap) "=" heap-desc
|
// heap-decl ::= * Heap(heap) "=" heap-desc
|
||||||
// heap-desc ::= heap-style heap-base { "," heap-attr }
|
// heap-desc ::= heap-style heap-base { "," heap-attr }
|
||||||
// heap-style ::= "static" | "dynamic"
|
// heap-style ::= "static" | "dynamic"
|
||||||
// heap-base ::= "reserved_reg"
|
// heap-base ::= GlobalValue(base)
|
||||||
// | GlobalValue(base)
|
|
||||||
// heap-attr ::= "min" Imm64(bytes)
|
// heap-attr ::= "min" Imm64(bytes)
|
||||||
// | "max" Imm64(bytes)
|
// | "max" Imm64(bytes)
|
||||||
// | "guard" Imm64(bytes)
|
// | "guard" Imm64(bytes)
|
||||||
@@ -1136,17 +1134,12 @@ impl<'a> Parser<'a> {
|
|||||||
let style_name = self.match_any_identifier("expected 'static' or 'dynamic'")?;
|
let style_name = self.match_any_identifier("expected 'static' or 'dynamic'")?;
|
||||||
|
|
||||||
// heap-desc ::= heap-style * heap-base { "," heap-attr }
|
// heap-desc ::= heap-style * heap-base { "," heap-attr }
|
||||||
// heap-base ::= * "reserved_reg"
|
// heap-base ::= * GlobalValue(base)
|
||||||
// | * GlobalValue(base)
|
|
||||||
let base = match self.token() {
|
let base = match self.token() {
|
||||||
Some(Token::Identifier("reserved_reg")) => HeapBase::ReservedReg,
|
Some(Token::GlobalValue(base_num)) => match GlobalValue::with_number(base_num) {
|
||||||
Some(Token::GlobalValue(base_num)) => {
|
Some(gv) => gv,
|
||||||
let base_gv = match GlobalValue::with_number(base_num) {
|
None => return err!(self.loc, "invalid global value number for heap base"),
|
||||||
Some(gv) => gv,
|
},
|
||||||
None => return err!(self.loc, "invalid global value number for heap base"),
|
|
||||||
};
|
|
||||||
HeapBase::GlobalValue(base_gv)
|
|
||||||
}
|
|
||||||
_ => return err!(self.loc, "expected heap base"),
|
_ => return err!(self.loc, "expected heap base"),
|
||||||
};
|
};
|
||||||
self.consume();
|
self.consume();
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
|
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
|
||||||
|
|
||||||
func.create_heap(ir::HeapData {
|
func.create_heap(ir::HeapData {
|
||||||
base: ir::HeapBase::GlobalValue(gv),
|
base: gv,
|
||||||
min_size: 0.into(),
|
min_size: 0.into(),
|
||||||
guard_size: 0x8000_0000.into(),
|
guard_size: 0x8000_0000.into(),
|
||||||
style: ir::HeapStyle::Static {
|
style: ir::HeapStyle::Static {
|
||||||
|
|||||||
Reference in New Issue
Block a user