Define stack_load, stack_store, and stack_addr instructions.
This commit is contained in:
@@ -8,8 +8,8 @@ in this module.
|
||||
from __future__ import absolute_import
|
||||
from cdsl.formats import InstructionFormat
|
||||
from cdsl.operands import VALUE, VARIABLE_ARGS
|
||||
from .immediates import imm64, uimm8, ieee32, ieee64, intcc, floatcc
|
||||
from .entities import ebb, sig_ref, func_ref, jump_table
|
||||
from .immediates import imm64, uimm8, ieee32, ieee64, offset32, intcc, floatcc
|
||||
from .entities import ebb, sig_ref, func_ref, jump_table, stack_slot
|
||||
|
||||
Nullary = InstructionFormat()
|
||||
|
||||
@@ -52,5 +52,8 @@ IndirectCall = InstructionFormat(
|
||||
sig_ref, VALUE, VARIABLE_ARGS,
|
||||
multiple_results=True)
|
||||
|
||||
StackLoad = InstructionFormat(stack_slot, offset32)
|
||||
StackStore = InstructionFormat(VALUE, stack_slot, offset32)
|
||||
|
||||
# Finally extract the names of global variables in this module.
|
||||
InstructionFormat.extract_names(globals())
|
||||
|
||||
@@ -21,7 +21,10 @@ uimm8 = ImmediateKind('uimm8', 'An 8-bit immediate unsigned integer.')
|
||||
#:
|
||||
#: This is used to represent an immediate address offset in load/store
|
||||
#: instructions.
|
||||
offset32 = ImmediateKind('offset32', 'A 32-bit immediate signed offset.')
|
||||
offset32 = ImmediateKind(
|
||||
'offset32',
|
||||
'A 32-bit immediate signed offset.',
|
||||
default_member='offset')
|
||||
|
||||
#: A 32-bit immediate floating point operand.
|
||||
#:
|
||||
|
||||
@@ -9,7 +9,7 @@ from cdsl.operands import Operand, VARIABLE_ARGS
|
||||
from cdsl.typevar import TypeVar
|
||||
from cdsl.instructions import Instruction, InstructionGroup
|
||||
from base.types import i8, f32, f64, b1
|
||||
from base.immediates import imm64, uimm8, ieee32, ieee64
|
||||
from base.immediates import imm64, uimm8, ieee32, ieee64, offset32
|
||||
from base.immediates import intcc, floatcc
|
||||
from base import entities
|
||||
import base.formats # noqa
|
||||
@@ -28,6 +28,12 @@ TxN = TypeVar(
|
||||
Any = TypeVar(
|
||||
'Any', 'Any integer, float, or boolean scalar or vector type',
|
||||
ints=True, floats=True, bools=True, scalars=True, simd=True)
|
||||
Mem = TypeVar(
|
||||
'Mem', 'Any type that can be stored in memory',
|
||||
ints=True, floats=True, simd=True)
|
||||
MemTo = TypeVar(
|
||||
'MemTo', 'Any type that can be stored in memory',
|
||||
ints=True, floats=True, simd=True)
|
||||
|
||||
#
|
||||
# Control flow
|
||||
@@ -195,6 +201,52 @@ call_indirect = Instruction(
|
||||
""",
|
||||
ins=(SIG, callee, args), outs=rvals, is_call=True)
|
||||
|
||||
#
|
||||
# Memory operations
|
||||
#
|
||||
|
||||
SS = Operand('SS', entities.stack_slot)
|
||||
Offset = Operand('Offset', offset32, 'In-bounds offset into stack slot')
|
||||
x = Operand('x', Mem, doc='Value to be stored')
|
||||
a = Operand('a', Mem, doc='Value loaded')
|
||||
addr = Operand('addr', iAddr)
|
||||
|
||||
stack_load = Instruction(
|
||||
'stack_load', r"""
|
||||
Load a value from a stack slot at the constant offset.
|
||||
|
||||
This is a polymorphic instruction that can load any value type which
|
||||
has a memory representation.
|
||||
|
||||
The offset is an immediate constant, not an SSA value. The memory
|
||||
access cannot go out of bounds, i.e.
|
||||
:math:`sizeof(a) + Offset <= sizeof(SS)`.
|
||||
""",
|
||||
ins=(SS, Offset), outs=a)
|
||||
|
||||
stack_store = Instruction(
|
||||
'stack_store', r"""
|
||||
Store a value to a stack slot at a constant offset.
|
||||
|
||||
This is a polymorphic instruction that can store any value type with a
|
||||
memory representation.
|
||||
|
||||
The offset is an immediate constant, not an SSA value. The memory
|
||||
access cannot go out of bounds, i.e.
|
||||
:math:`sizeof(a) + Offset <= sizeof(SS)`.
|
||||
""",
|
||||
ins=(x, SS, Offset))
|
||||
|
||||
stack_addr = Instruction(
|
||||
'stack_addr', r"""
|
||||
Get the address of a stack slot.
|
||||
|
||||
Compute the absolute address of a byte in a stack slot. The offset must
|
||||
refer to a byte inside the stack slot:
|
||||
:math:`0 <= Offset < sizeof(SS)`.
|
||||
""",
|
||||
ins=(SS, Offset), outs=addr)
|
||||
|
||||
#
|
||||
# Materializing constants.
|
||||
#
|
||||
@@ -1095,13 +1147,6 @@ nearest = Instruction(
|
||||
# Conversions
|
||||
#
|
||||
|
||||
Mem = TypeVar(
|
||||
'Mem', 'Any type that can be stored in memory',
|
||||
ints=True, floats=True, simd=True)
|
||||
MemTo = TypeVar(
|
||||
'MemTo', 'Any type that can be stored in memory',
|
||||
ints=True, floats=True, simd=True)
|
||||
|
||||
x = Operand('x', Mem)
|
||||
a = Operand('a', MemTo, 'Bits of `x` reinterpreted')
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
use ir::types;
|
||||
use ir::{InstructionData, DataFlowGraph, Cursor};
|
||||
use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, ValueList};
|
||||
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64};
|
||||
use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, StackSlot, ValueList};
|
||||
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, Offset32};
|
||||
use ir::condcodes::{IntCC, FloatCC};
|
||||
|
||||
/// Base trait for instruction builders.
|
||||
|
||||
@@ -10,8 +10,8 @@ use std::fmt::{self, Display, Formatter};
|
||||
use std::str::FromStr;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use ir::{Value, Type, Ebb, JumpTable, SigRef, FuncRef};
|
||||
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64};
|
||||
use ir::{Value, Type, Ebb, JumpTable, SigRef, FuncRef, StackSlot};
|
||||
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, Offset32};
|
||||
use ir::condcodes::*;
|
||||
use ir::types;
|
||||
use ir::DataFlowGraph;
|
||||
@@ -227,6 +227,19 @@ pub enum InstructionData {
|
||||
sig_ref: SigRef,
|
||||
args: ValueList,
|
||||
},
|
||||
StackLoad {
|
||||
opcode: Opcode,
|
||||
ty: Type,
|
||||
stack_slot: StackSlot,
|
||||
offset: Offset32,
|
||||
},
|
||||
StackStore {
|
||||
opcode: Opcode,
|
||||
ty: Type,
|
||||
arg: Value,
|
||||
stack_slot: StackSlot,
|
||||
offset: Offset32,
|
||||
},
|
||||
}
|
||||
|
||||
/// A variable list of `Value` operands used for function call arguments and passing arguments to
|
||||
|
||||
@@ -57,7 +57,8 @@ use dominator_tree::DominatorTree;
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use ir::entities::AnyEntity;
|
||||
use ir::instructions::{InstructionFormat, BranchInfo, ResolvedConstraint, CallInfo};
|
||||
use ir::{types, Function, ValueDef, Ebb, Inst, SigRef, FuncRef, ValueList, JumpTable, Value, Type};
|
||||
use ir::{types, Function, ValueDef, Ebb, Inst, SigRef, FuncRef, ValueList, JumpTable, StackSlot,
|
||||
Value, Type};
|
||||
use Context;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::result;
|
||||
@@ -248,6 +249,11 @@ impl<'a> Verifier<'a> {
|
||||
self.verify_sig_ref(inst, sig_ref)?;
|
||||
self.verify_value_list(inst, args)?;
|
||||
}
|
||||
&StackLoad { stack_slot, .. } |
|
||||
&StackStore { stack_slot, .. } => {
|
||||
self.verify_stack_slot(inst, stack_slot)?;
|
||||
}
|
||||
|
||||
// Exhaustive list so we can't forget to add new formats
|
||||
&Nullary { .. } |
|
||||
&Unary { .. } |
|
||||
@@ -293,6 +299,14 @@ impl<'a> Verifier<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_stack_slot(&self, inst: Inst, ss: StackSlot) -> Result<()> {
|
||||
if !self.func.stack_slots.is_valid(ss) {
|
||||
err!(inst, "invalid stack slot {}", ss)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_value_list(&self, inst: Inst, l: &ValueList) -> Result<()> {
|
||||
if !l.is_valid(&self.func.dfg.value_lists) {
|
||||
err!(inst, "invalid value list reference {:?}", l)
|
||||
|
||||
@@ -313,6 +313,13 @@ pub fn write_operands(w: &mut Write, dfg: &DataFlowGraph, inst: Inst) -> Result
|
||||
args[0],
|
||||
DisplayValues(&args[1..]))
|
||||
}
|
||||
StackLoad { stack_slot, offset, .. } => write!(w, " {}{}", stack_slot, offset),
|
||||
StackStore {
|
||||
arg,
|
||||
stack_slot,
|
||||
offset,
|
||||
..
|
||||
} => write!(w, " {}, {}{}", arg, stack_slot, offset),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user