Don't renumber entities in the parser.
This makes it easier to debug testcases: - the entity numbers in a .cton file match the entity numbers used within Cretonne. - serializing and deserializing doesn't cause indices to change. One disadvantage is that if a .cton file uses sparse entity numbers, deserializing to the in-memory form doesn't compact it. However, the text format is not intended to be performance-critical, so this isn't expected to be a big burden.
This commit is contained in:
@@ -8,6 +8,7 @@ use ir::extfunc::ExtFuncData;
|
||||
use ir::instructions::{InstructionData, CallInfo, BranchInfo};
|
||||
use ir::types;
|
||||
use ir::{Ebb, Inst, Value, Type, SigRef, Signature, FuncRef, ValueList, ValueListPool};
|
||||
use packed_option::ReservedValue;
|
||||
use write::write_operands;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
@@ -287,16 +288,6 @@ impl DataFlowGraph {
|
||||
|
||||
self.clear_results(dest_inst);
|
||||
}
|
||||
|
||||
/// Create a new value alias.
|
||||
///
|
||||
/// Note that this function should only be called by the parser.
|
||||
pub fn make_value_alias(&mut self, src: Value) -> Value {
|
||||
let ty = self.value_type(src);
|
||||
|
||||
let data = ValueData::Alias { ty, original: src };
|
||||
self.make_value(data)
|
||||
}
|
||||
}
|
||||
|
||||
/// Where did a value come from?
|
||||
@@ -370,14 +361,6 @@ impl DataFlowGraph {
|
||||
self.insts.push(data)
|
||||
}
|
||||
|
||||
/// Get the instruction reference that will be assigned to the next instruction created by
|
||||
/// `make_inst`.
|
||||
///
|
||||
/// This is only really useful to the parser.
|
||||
pub fn next_inst(&self) -> Inst {
|
||||
self.insts.next_key()
|
||||
}
|
||||
|
||||
/// Returns an object that displays `inst`.
|
||||
pub fn display_inst<'a, I: Into<Option<&'a TargetIsa>>>(
|
||||
&'a self,
|
||||
@@ -870,6 +853,91 @@ impl<'a> fmt::Display for DisplayInst<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parser routines. These routines should not be used outside the parser.
|
||||
impl DataFlowGraph {
|
||||
/// Set the type of a value. This is only for use in the parser, which needs
|
||||
/// to create invalid values for index padding which may be reassigned later.
|
||||
#[cold]
|
||||
fn set_value_type_for_parser(&mut self, v: Value, t: Type) {
|
||||
debug_assert!(
|
||||
self.value_type(v) == types::VOID,
|
||||
"this function is only for assigning types to previously invalid values"
|
||||
);
|
||||
match self.values[v] {
|
||||
ValueData::Inst { ref mut ty, .. } |
|
||||
ValueData::Param { ref mut ty, .. } |
|
||||
ValueData::Alias { ref mut ty, .. } => *ty = t,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create result values for `inst`, reusing the provided detached values.
|
||||
/// This is similar to `make_inst_results_reusing` except it's only for use
|
||||
/// in the parser, which needs to reuse previously invalid values.
|
||||
#[cold]
|
||||
pub fn make_inst_results_for_parser(
|
||||
&mut self,
|
||||
inst: Inst,
|
||||
ctrl_typevar: Type,
|
||||
reuse: &[Value],
|
||||
) -> usize {
|
||||
// Get the call signature if this is a function call.
|
||||
if let Some(sig) = self.call_signature(inst) {
|
||||
debug_assert_eq!(self.insts[inst].opcode().constraints().fixed_results(), 0);
|
||||
for res_idx in 0..self.signatures[sig].returns.len() {
|
||||
let ty = self.signatures[sig].returns[res_idx].value_type;
|
||||
if let Some(v) = reuse.get(res_idx) {
|
||||
self.set_value_type_for_parser(*v, ty);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let constraints = self.insts[inst].opcode().constraints();
|
||||
for res_idx in 0..constraints.fixed_results() {
|
||||
let ty = constraints.result_type(res_idx, ctrl_typevar);
|
||||
if let Some(v) = reuse.get(res_idx) {
|
||||
self.set_value_type_for_parser(*v, ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.make_inst_results_reusing(inst, ctrl_typevar, reuse.iter().map(|x| Some(*x)))
|
||||
}
|
||||
|
||||
/// Similar to `append_ebb_param`, append a parameter with type `ty` to
|
||||
/// `ebb`, but using value `val`. This is only for use by the parser to
|
||||
/// create parameters with specific values.
|
||||
#[cold]
|
||||
pub fn append_ebb_param_for_parser(&mut self, ebb: Ebb, ty: Type, val: Value) {
|
||||
let num = self.ebbs[ebb].params.push(val, &mut self.value_lists);
|
||||
assert!(num <= u16::MAX as usize, "Too many parameters on EBB");
|
||||
self.values[val] = ValueData::Param {
|
||||
ty,
|
||||
num: num as u16,
|
||||
ebb,
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a new value alias. This is only for use by the parser to create
|
||||
/// aliases with specific values.
|
||||
#[cold]
|
||||
pub fn make_value_alias_for_parser(&mut self, src: Value, dest: Value) {
|
||||
let ty = self.value_type(src);
|
||||
|
||||
let data = ValueData::Alias { ty, original: src };
|
||||
self.values[dest] = data;
|
||||
}
|
||||
|
||||
/// Create an invalid value, to pad the index space. This is only for use by
|
||||
/// the parser to pad out the value index space.
|
||||
#[cold]
|
||||
pub fn make_invalid_value_for_parser(&mut self) {
|
||||
let data = ValueData::Alias {
|
||||
ty: types::VOID,
|
||||
original: Value::reserved_value(),
|
||||
};
|
||||
self.make_value(data);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -885,9 +953,7 @@ mod tests {
|
||||
opcode: Opcode::Iconst,
|
||||
imm: 0.into(),
|
||||
};
|
||||
let next = dfg.next_inst();
|
||||
let inst = dfg.make_inst(idata);
|
||||
assert_eq!(next, inst);
|
||||
|
||||
dfg.make_inst_results(inst, types::I32);
|
||||
assert_eq!(inst.to_string(), "inst0");
|
||||
|
||||
@@ -65,6 +65,19 @@ entity_impl!(Inst, "inst");
|
||||
pub struct StackSlot(u32);
|
||||
entity_impl!(StackSlot, "ss");
|
||||
|
||||
impl StackSlot {
|
||||
/// Create a new stack slot reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<StackSlot> {
|
||||
if n < u32::MAX {
|
||||
Some(StackSlot(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque reference to a global variable.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct GlobalVar(u32);
|
||||
@@ -88,21 +101,61 @@ impl GlobalVar {
|
||||
pub struct JumpTable(u32);
|
||||
entity_impl!(JumpTable, "jt");
|
||||
|
||||
impl JumpTable {
|
||||
/// Create a new jump table reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<JumpTable> {
|
||||
if n < u32::MAX {
|
||||
Some(JumpTable(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to an external function.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FuncRef(u32);
|
||||
entity_impl!(FuncRef, "fn");
|
||||
|
||||
impl FuncRef {
|
||||
/// Create a new external function reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<FuncRef> {
|
||||
if n < u32::MAX { Some(FuncRef(n)) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to a function signature.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SigRef(u32);
|
||||
entity_impl!(SigRef, "sig");
|
||||
|
||||
impl SigRef {
|
||||
/// Create a new function signature reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<SigRef> {
|
||||
if n < u32::MAX { Some(SigRef(n)) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to a heap.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Heap(u32);
|
||||
entity_impl!(Heap, "heap");
|
||||
|
||||
impl Heap {
|
||||
/// Create a new heap reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Heap> {
|
||||
if n < u32::MAX { Some(Heap(n)) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to any of the entities defined in this module.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AnyEntity {
|
||||
|
||||
@@ -8,7 +8,7 @@ use ir::{Type, StackSlot};
|
||||
use packed_option::PackedOption;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::ops::Index;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// The size of an object on the stack, or the size of a stack frame.
|
||||
@@ -228,6 +228,12 @@ impl Index<StackSlot> for StackSlots {
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<StackSlot> for StackSlots {
|
||||
fn index_mut(&mut self, ss: StackSlot) -> &mut StackSlotData {
|
||||
&mut self.slots[ss]
|
||||
}
|
||||
}
|
||||
|
||||
/// Higher-level stack frame manipulation functions.
|
||||
impl StackSlots {
|
||||
/// Create a new spill slot for spilling values of type `ty`.
|
||||
|
||||
Reference in New Issue
Block a user