|
|
|
@@ -13,13 +13,13 @@ use cretonne::packed_option::PackedOption;
|
|
|
|
/// Structure used for translating a series of functions into Cretonne IL.
|
|
|
|
/// Structure used for translating a series of functions into Cretonne IL.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// In order to reduce memory reallocations when compiling multiple functions,
|
|
|
|
/// In order to reduce memory reallocations when compiling multiple functions,
|
|
|
|
/// `ILBuilder` holds various data structures which are cleared between
|
|
|
|
/// `FunctionBuilderContext` holds various data structures which are cleared between
|
|
|
|
/// functions, rather than dropped, preserving the underlying allocations.
|
|
|
|
/// functions, rather than dropped, preserving the underlying allocations.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The `Variable` parameter can be any index-like type that can be made to
|
|
|
|
/// The `Variable` parameter can be any index-like type that can be made to
|
|
|
|
/// implement `EntityRef`. For frontends that don't have an obvious type to
|
|
|
|
/// implement `EntityRef`. For frontends that don't have an obvious type to
|
|
|
|
/// use here, `variable::Variable` can be used.
|
|
|
|
/// use here, `variable::Variable` can be used.
|
|
|
|
pub struct ILBuilder<Variable>
|
|
|
|
pub struct FunctionBuilderContext<Variable>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
Variable: EntityRef,
|
|
|
|
Variable: EntityRef,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -41,7 +41,7 @@ where
|
|
|
|
/// Source location to assign to all new instructions.
|
|
|
|
/// Source location to assign to all new instructions.
|
|
|
|
srcloc: ir::SourceLoc,
|
|
|
|
srcloc: ir::SourceLoc,
|
|
|
|
|
|
|
|
|
|
|
|
builder: &'a mut ILBuilder<Variable>,
|
|
|
|
func_ctx: &'a mut FunctionBuilderContext<Variable>,
|
|
|
|
position: Position,
|
|
|
|
position: Position,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -77,12 +77,12 @@ impl Position {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<Variable> ILBuilder<Variable>
|
|
|
|
impl<Variable> FunctionBuilderContext<Variable>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
Variable: EntityRef,
|
|
|
|
Variable: EntityRef,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// Creates a ILBuilder structure. The structure is automatically cleared after each
|
|
|
|
/// Creates a FunctionBuilderContext structure. The structure is automatically cleared after
|
|
|
|
/// [`FunctionBuilder`](struct.FunctionBuilder.html) completes translating a function.
|
|
|
|
/// each [`FunctionBuilder`](struct.FunctionBuilder.html) completes translating a function.
|
|
|
|
pub fn new() -> Self {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
ssa: SSABuilder::new(),
|
|
|
|
ssa: SSABuilder::new(),
|
|
|
|
@@ -172,7 +172,7 @@ impl<'short, 'long, Variable> InstBuilderBase<'short> for FuncInstBuilder<'short
|
|
|
|
.entries()
|
|
|
|
.entries()
|
|
|
|
.map(|(_, ebb)| ebb)
|
|
|
|
.map(|(_, ebb)| ebb)
|
|
|
|
.filter(|dest_ebb| unique.insert(*dest_ebb)) {
|
|
|
|
.filter(|dest_ebb| unique.insert(*dest_ebb)) {
|
|
|
|
self.builder.builder.ssa.declare_ebb_predecessor(
|
|
|
|
self.builder.func_ctx.ssa.declare_ebb_predecessor(
|
|
|
|
dest_ebb,
|
|
|
|
dest_ebb,
|
|
|
|
self.builder.position.basic_block.unwrap(),
|
|
|
|
self.builder.position.basic_block.unwrap(),
|
|
|
|
inst,
|
|
|
|
inst,
|
|
|
|
@@ -213,9 +213,10 @@ impl<'short, 'long, Variable> InstBuilderBase<'short> for FuncInstBuilder<'short
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// At creation, a `FunctionBuilder` instance borrows an already allocated `Function` which it
|
|
|
|
/// At creation, a `FunctionBuilder` instance borrows an already allocated `Function` which it
|
|
|
|
/// modifies with the information stored in the mutable borrowed
|
|
|
|
/// modifies with the information stored in the mutable borrowed
|
|
|
|
/// [`ILBuilder`](struct.ILBuilder.html). The function passed in argument should be newly created
|
|
|
|
/// [`FunctionBuilderContext`](struct.FunctionBuilderContext.html). The function passed in
|
|
|
|
/// with [`Function::with_name_signature()`](../function/struct.Function.html), whereas the
|
|
|
|
/// argument should be newly created with
|
|
|
|
/// `ILBuilder` can be kept as is between two function translations.
|
|
|
|
/// [`Function::with_name_signature()`](../function/struct.Function.html), whereas the
|
|
|
|
|
|
|
|
/// `FunctionBuilderContext` can be kept as is between two function translations.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Errors
|
|
|
|
/// # Errors
|
|
|
|
///
|
|
|
|
///
|
|
|
|
@@ -228,16 +229,16 @@ where
|
|
|
|
Variable: EntityRef,
|
|
|
|
Variable: EntityRef,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// Creates a new FunctionBuilder structure that will operate on a `Function` using a
|
|
|
|
/// Creates a new FunctionBuilder structure that will operate on a `Function` using a
|
|
|
|
/// `IlBuilder`.
|
|
|
|
/// `FunctionBuilderContext`.
|
|
|
|
pub fn new(
|
|
|
|
pub fn new(
|
|
|
|
func: &'a mut Function,
|
|
|
|
func: &'a mut Function,
|
|
|
|
builder: &'a mut ILBuilder<Variable>,
|
|
|
|
func_ctx: &'a mut FunctionBuilderContext<Variable>,
|
|
|
|
) -> FunctionBuilder<'a, Variable> {
|
|
|
|
) -> FunctionBuilder<'a, Variable> {
|
|
|
|
debug_assert!(builder.is_empty());
|
|
|
|
debug_assert!(func_ctx.is_empty());
|
|
|
|
FunctionBuilder {
|
|
|
|
FunctionBuilder {
|
|
|
|
func: func,
|
|
|
|
func: func,
|
|
|
|
srcloc: Default::default(),
|
|
|
|
srcloc: Default::default(),
|
|
|
|
builder: builder,
|
|
|
|
func_ctx: func_ctx,
|
|
|
|
position: Position::default(),
|
|
|
|
position: Position::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -250,8 +251,8 @@ where
|
|
|
|
/// Creates a new `Ebb` and returns its reference.
|
|
|
|
/// Creates a new `Ebb` and returns its reference.
|
|
|
|
pub fn create_ebb(&mut self) -> Ebb {
|
|
|
|
pub fn create_ebb(&mut self) -> Ebb {
|
|
|
|
let ebb = self.func.dfg.make_ebb();
|
|
|
|
let ebb = self.func.dfg.make_ebb();
|
|
|
|
self.builder.ssa.declare_ebb_header_block(ebb);
|
|
|
|
self.func_ctx.ssa.declare_ebb_header_block(ebb);
|
|
|
|
self.builder.ebbs[ebb] = EbbData {
|
|
|
|
self.func_ctx.ebbs[ebb] = EbbData {
|
|
|
|
filled: false,
|
|
|
|
filled: false,
|
|
|
|
pristine: true,
|
|
|
|
pristine: true,
|
|
|
|
user_param_count: 0,
|
|
|
|
user_param_count: 0,
|
|
|
|
@@ -275,11 +276,11 @@ where
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// We cannot switch to a filled block
|
|
|
|
// We cannot switch to a filled block
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
!self.builder.ebbs[ebb].filled,
|
|
|
|
!self.func_ctx.ebbs[ebb].filled,
|
|
|
|
"you cannot switch to a block which is already filled"
|
|
|
|
"you cannot switch to a block which is already filled"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let basic_block = self.builder.ssa.header_block(ebb);
|
|
|
|
let basic_block = self.func_ctx.ssa.header_block(ebb);
|
|
|
|
// Then we change the cursor position.
|
|
|
|
// Then we change the cursor position.
|
|
|
|
self.position = Position::at(ebb, basic_block);
|
|
|
|
self.position = Position::at(ebb, basic_block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -290,7 +291,7 @@ where
|
|
|
|
/// created. Forgetting to call this method on every block will cause inconsistencies in the
|
|
|
|
/// created. Forgetting to call this method on every block will cause inconsistencies in the
|
|
|
|
/// produced functions.
|
|
|
|
/// produced functions.
|
|
|
|
pub fn seal_block(&mut self, ebb: Ebb) {
|
|
|
|
pub fn seal_block(&mut self, ebb: Ebb) {
|
|
|
|
let side_effects = self.builder.ssa.seal_ebb_header_block(ebb, self.func);
|
|
|
|
let side_effects = self.func_ctx.ssa.seal_ebb_header_block(ebb, self.func);
|
|
|
|
self.handle_ssa_side_effects(side_effects);
|
|
|
|
self.handle_ssa_side_effects(side_effects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -301,22 +302,22 @@ where
|
|
|
|
/// function can be used at the end of translating all blocks to ensure
|
|
|
|
/// function can be used at the end of translating all blocks to ensure
|
|
|
|
/// that everything is sealed.
|
|
|
|
/// that everything is sealed.
|
|
|
|
pub fn seal_all_blocks(&mut self) {
|
|
|
|
pub fn seal_all_blocks(&mut self) {
|
|
|
|
let side_effects = self.builder.ssa.seal_all_ebb_header_blocks(self.func);
|
|
|
|
let side_effects = self.func_ctx.ssa.seal_all_ebb_header_blocks(self.func);
|
|
|
|
self.handle_ssa_side_effects(side_effects);
|
|
|
|
self.handle_ssa_side_effects(side_effects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// In order to use a variable in a `use_var`, you need to declare its type with this method.
|
|
|
|
/// In order to use a variable in a `use_var`, you need to declare its type with this method.
|
|
|
|
pub fn declare_var(&mut self, var: Variable, ty: Type) {
|
|
|
|
pub fn declare_var(&mut self, var: Variable, ty: Type) {
|
|
|
|
self.builder.types[var] = ty;
|
|
|
|
self.func_ctx.types[var] = ty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the Cretonne IL value corresponding to the utilization at the current program
|
|
|
|
/// Returns the Cretonne IL value corresponding to the utilization at the current program
|
|
|
|
/// position of a previously defined user variable.
|
|
|
|
/// position of a previously defined user variable.
|
|
|
|
pub fn use_var(&mut self, var: Variable) -> Value {
|
|
|
|
pub fn use_var(&mut self, var: Variable) -> Value {
|
|
|
|
let ty = *self.builder.types.get(var).expect(
|
|
|
|
let ty = *self.func_ctx.types.get(var).expect(
|
|
|
|
"this variable is used but its type has not been declared",
|
|
|
|
"this variable is used but its type has not been declared",
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let (val, side_effects) = self.builder.ssa.use_var(
|
|
|
|
let (val, side_effects) = self.func_ctx.ssa.use_var(
|
|
|
|
self.func,
|
|
|
|
self.func,
|
|
|
|
var,
|
|
|
|
var,
|
|
|
|
ty,
|
|
|
|
ty,
|
|
|
|
@@ -329,7 +330,7 @@ where
|
|
|
|
/// Register a new definition of a user variable. Panics if the type of the value is not the
|
|
|
|
/// Register a new definition of a user variable. Panics if the type of the value is not the
|
|
|
|
/// same as the type registered for the variable.
|
|
|
|
/// same as the type registered for the variable.
|
|
|
|
pub fn def_var(&mut self, var: Variable, val: Value) {
|
|
|
|
pub fn def_var(&mut self, var: Variable, val: Value) {
|
|
|
|
self.builder.ssa.def_var(
|
|
|
|
self.func_ctx.ssa.def_var(
|
|
|
|
var,
|
|
|
|
var,
|
|
|
|
val,
|
|
|
|
val,
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
@@ -382,14 +383,14 @@ where
|
|
|
|
/// Make sure that the current EBB is inserted in the layout.
|
|
|
|
/// Make sure that the current EBB is inserted in the layout.
|
|
|
|
pub fn ensure_inserted_ebb(&mut self) {
|
|
|
|
pub fn ensure_inserted_ebb(&mut self) {
|
|
|
|
let ebb = self.position.ebb.unwrap();
|
|
|
|
let ebb = self.position.ebb.unwrap();
|
|
|
|
if self.builder.ebbs[ebb].pristine {
|
|
|
|
if self.func_ctx.ebbs[ebb].pristine {
|
|
|
|
if !self.func.layout.is_ebb_inserted(ebb) {
|
|
|
|
if !self.func.layout.is_ebb_inserted(ebb) {
|
|
|
|
self.func.layout.append_ebb(ebb);
|
|
|
|
self.func.layout.append_ebb(ebb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.builder.ebbs[ebb].pristine = false;
|
|
|
|
self.func_ctx.ebbs[ebb].pristine = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
!self.builder.ebbs[ebb].filled,
|
|
|
|
!self.func_ctx.ebbs[ebb].filled,
|
|
|
|
"you cannot add an instruction to a block already filled"
|
|
|
|
"you cannot add an instruction to a block already filled"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -412,7 +413,7 @@ where
|
|
|
|
pub fn append_ebb_params_for_function_params(&mut self, ebb: Ebb) {
|
|
|
|
pub fn append_ebb_params_for_function_params(&mut self, ebb: Ebb) {
|
|
|
|
// These parameters count as "user" parameters here because they aren't
|
|
|
|
// These parameters count as "user" parameters here because they aren't
|
|
|
|
// inserted by the SSABuilder.
|
|
|
|
// inserted by the SSABuilder.
|
|
|
|
let user_param_count = &mut self.builder.ebbs[ebb].user_param_count;
|
|
|
|
let user_param_count = &mut self.func_ctx.ebbs[ebb].user_param_count;
|
|
|
|
for argtyp in &self.func.signature.params {
|
|
|
|
for argtyp in &self.func.signature.params {
|
|
|
|
*user_param_count += 1;
|
|
|
|
*user_param_count += 1;
|
|
|
|
self.func.dfg.append_ebb_param(ebb, argtyp.value_type);
|
|
|
|
self.func.dfg.append_ebb_param(ebb, argtyp.value_type);
|
|
|
|
@@ -425,7 +426,7 @@ where
|
|
|
|
pub fn append_ebb_params_for_function_returns(&mut self, ebb: Ebb) {
|
|
|
|
pub fn append_ebb_params_for_function_returns(&mut self, ebb: Ebb) {
|
|
|
|
// These parameters count as "user" parameters here because they aren't
|
|
|
|
// These parameters count as "user" parameters here because they aren't
|
|
|
|
// inserted by the SSABuilder.
|
|
|
|
// inserted by the SSABuilder.
|
|
|
|
let user_param_count = &mut self.builder.ebbs[ebb].user_param_count;
|
|
|
|
let user_param_count = &mut self.func_ctx.ebbs[ebb].user_param_count;
|
|
|
|
for argtyp in &self.func.signature.returns {
|
|
|
|
for argtyp in &self.func.signature.returns {
|
|
|
|
*user_param_count += 1;
|
|
|
|
*user_param_count += 1;
|
|
|
|
self.func.dfg.append_ebb_param(ebb, argtyp.value_type);
|
|
|
|
self.func.dfg.append_ebb_param(ebb, argtyp.value_type);
|
|
|
|
@@ -438,21 +439,21 @@ where
|
|
|
|
pub fn finalize(&mut self) {
|
|
|
|
pub fn finalize(&mut self) {
|
|
|
|
// Check that all the `Ebb`s are filled and sealed.
|
|
|
|
// Check that all the `Ebb`s are filled and sealed.
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
self.builder.ebbs.keys().all(|ebb| {
|
|
|
|
self.func_ctx.ebbs.keys().all(|ebb| {
|
|
|
|
self.builder.ebbs[ebb].pristine || self.builder.ssa.is_sealed(ebb)
|
|
|
|
self.func_ctx.ebbs[ebb].pristine || self.func_ctx.ssa.is_sealed(ebb)
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
"all blocks should be sealed before dropping a FunctionBuilder"
|
|
|
|
"all blocks should be sealed before dropping a FunctionBuilder"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
self.builder.ebbs.keys().all(|ebb| {
|
|
|
|
self.func_ctx.ebbs.keys().all(|ebb| {
|
|
|
|
self.builder.ebbs[ebb].pristine || self.builder.ebbs[ebb].filled
|
|
|
|
self.func_ctx.ebbs[ebb].pristine || self.func_ctx.ebbs[ebb].filled
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
"all blocks should be filled before dropping a FunctionBuilder"
|
|
|
|
"all blocks should be filled before dropping a FunctionBuilder"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Clear the state (but preserve the allocated buffers) in preparation
|
|
|
|
// Clear the state (but preserve the allocated buffers) in preparation
|
|
|
|
// for translation another function.
|
|
|
|
// for translation another function.
|
|
|
|
self.builder.clear();
|
|
|
|
self.func_ctx.clear();
|
|
|
|
|
|
|
|
|
|
|
|
// Reset srcloc and position to initial states.
|
|
|
|
// Reset srcloc and position to initial states.
|
|
|
|
self.srcloc = Default::default();
|
|
|
|
self.srcloc = Default::default();
|
|
|
|
@@ -486,12 +487,12 @@ where
|
|
|
|
/// **Note:** this function has to be called at the creation of the `Ebb` before adding
|
|
|
|
/// **Note:** this function has to be called at the creation of the `Ebb` before adding
|
|
|
|
/// instructions to it, otherwise this could interfere with SSA construction.
|
|
|
|
/// instructions to it, otherwise this could interfere with SSA construction.
|
|
|
|
pub fn append_ebb_param(&mut self, ebb: Ebb, ty: Type) -> Value {
|
|
|
|
pub fn append_ebb_param(&mut self, ebb: Ebb, ty: Type) -> Value {
|
|
|
|
debug_assert!(self.builder.ebbs[ebb].pristine);
|
|
|
|
debug_assert!(self.func_ctx.ebbs[ebb].pristine);
|
|
|
|
debug_assert_eq!(
|
|
|
|
debug_assert_eq!(
|
|
|
|
self.builder.ebbs[ebb].user_param_count,
|
|
|
|
self.func_ctx.ebbs[ebb].user_param_count,
|
|
|
|
self.func.dfg.num_ebb_params(ebb)
|
|
|
|
self.func.dfg.num_ebb_params(ebb)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
self.builder.ebbs[ebb].user_param_count += 1;
|
|
|
|
self.func_ctx.ebbs[ebb].user_param_count += 1;
|
|
|
|
self.func.dfg.append_ebb_param(ebb, ty)
|
|
|
|
self.func.dfg.append_ebb_param(ebb, ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -508,9 +509,9 @@ where
|
|
|
|
let old_dest = self.func.dfg[inst].branch_destination_mut().expect(
|
|
|
|
let old_dest = self.func.dfg[inst].branch_destination_mut().expect(
|
|
|
|
"you want to change the jump destination of a non-jump instruction",
|
|
|
|
"you want to change the jump destination of a non-jump instruction",
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let pred = self.builder.ssa.remove_ebb_predecessor(*old_dest, inst);
|
|
|
|
let pred = self.func_ctx.ssa.remove_ebb_predecessor(*old_dest, inst);
|
|
|
|
*old_dest = new_dest;
|
|
|
|
*old_dest = new_dest;
|
|
|
|
self.builder.ssa.declare_ebb_predecessor(
|
|
|
|
self.func_ctx.ssa.declare_ebb_predecessor(
|
|
|
|
new_dest,
|
|
|
|
new_dest,
|
|
|
|
pred,
|
|
|
|
pred,
|
|
|
|
inst,
|
|
|
|
inst,
|
|
|
|
@@ -525,8 +526,8 @@ where
|
|
|
|
None => false,
|
|
|
|
None => false,
|
|
|
|
Some(entry) => self.position.ebb.unwrap() == entry,
|
|
|
|
Some(entry) => self.position.ebb.unwrap() == entry,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
!is_entry && self.builder.ssa.is_sealed(self.position.ebb.unwrap()) &&
|
|
|
|
!is_entry && self.func_ctx.ssa.is_sealed(self.position.ebb.unwrap()) &&
|
|
|
|
self.builder
|
|
|
|
self.func_ctx
|
|
|
|
.ssa
|
|
|
|
.ssa
|
|
|
|
.predecessors(self.position.ebb.unwrap())
|
|
|
|
.predecessors(self.position.ebb.unwrap())
|
|
|
|
.is_empty()
|
|
|
|
.is_empty()
|
|
|
|
@@ -535,13 +536,13 @@ where
|
|
|
|
/// Returns `true` if and only if no instructions have been added since the last call to
|
|
|
|
/// Returns `true` if and only if no instructions have been added since the last call to
|
|
|
|
/// `switch_to_block`.
|
|
|
|
/// `switch_to_block`.
|
|
|
|
pub fn is_pristine(&self) -> bool {
|
|
|
|
pub fn is_pristine(&self) -> bool {
|
|
|
|
self.builder.ebbs[self.position.ebb.unwrap()].pristine
|
|
|
|
self.func_ctx.ebbs[self.position.ebb.unwrap()].pristine
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns `true` if and only if a terminator instruction has been inserted since the
|
|
|
|
/// Returns `true` if and only if a terminator instruction has been inserted since the
|
|
|
|
/// last call to `switch_to_block`.
|
|
|
|
/// last call to `switch_to_block`.
|
|
|
|
pub fn is_filled(&self) -> bool {
|
|
|
|
pub fn is_filled(&self) -> bool {
|
|
|
|
self.builder.ebbs[self.position.ebb.unwrap()].filled
|
|
|
|
self.func_ctx.ebbs[self.position.ebb.unwrap()].filled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns a displayable object for the function as it is.
|
|
|
|
/// Returns a displayable object for the function as it is.
|
|
|
|
@@ -558,17 +559,17 @@ where
|
|
|
|
Variable: EntityRef,
|
|
|
|
Variable: EntityRef,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fn move_to_next_basic_block(&mut self) {
|
|
|
|
fn move_to_next_basic_block(&mut self) {
|
|
|
|
self.position.basic_block = PackedOption::from(self.builder.ssa.declare_ebb_body_block(
|
|
|
|
self.position.basic_block = PackedOption::from(self.func_ctx.ssa.declare_ebb_body_block(
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn fill_current_block(&mut self) {
|
|
|
|
fn fill_current_block(&mut self) {
|
|
|
|
self.builder.ebbs[self.position.ebb.unwrap()].filled = true;
|
|
|
|
self.func_ctx.ebbs[self.position.ebb.unwrap()].filled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn declare_successor(&mut self, dest_ebb: Ebb, jump_inst: Inst) {
|
|
|
|
fn declare_successor(&mut self, dest_ebb: Ebb, jump_inst: Inst) {
|
|
|
|
self.builder.ssa.declare_ebb_predecessor(
|
|
|
|
self.func_ctx.ssa.declare_ebb_predecessor(
|
|
|
|
dest_ebb,
|
|
|
|
dest_ebb,
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
self.position.basic_block.unwrap(),
|
|
|
|
jump_inst,
|
|
|
|
jump_inst,
|
|
|
|
@@ -577,10 +578,10 @@ where
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_ssa_side_effects(&mut self, side_effects: SideEffects) {
|
|
|
|
fn handle_ssa_side_effects(&mut self, side_effects: SideEffects) {
|
|
|
|
for split_ebb in side_effects.split_ebbs_created {
|
|
|
|
for split_ebb in side_effects.split_ebbs_created {
|
|
|
|
self.builder.ebbs[split_ebb].filled = true
|
|
|
|
self.func_ctx.ebbs[split_ebb].filled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for modified_ebb in side_effects.instructions_added_to_ebbs {
|
|
|
|
for modified_ebb in side_effects.instructions_added_to_ebbs {
|
|
|
|
self.builder.ebbs[modified_ebb].pristine = false
|
|
|
|
self.func_ctx.ebbs[modified_ebb].pristine = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -591,7 +592,7 @@ mod tests {
|
|
|
|
use cretonne::entity::EntityRef;
|
|
|
|
use cretonne::entity::EntityRef;
|
|
|
|
use cretonne::ir::{ExternalName, Function, CallConv, Signature, AbiParam, InstBuilder};
|
|
|
|
use cretonne::ir::{ExternalName, Function, CallConv, Signature, AbiParam, InstBuilder};
|
|
|
|
use cretonne::ir::types::*;
|
|
|
|
use cretonne::ir::types::*;
|
|
|
|
use frontend::{ILBuilder, FunctionBuilder};
|
|
|
|
use frontend::{FunctionBuilderContext, FunctionBuilder};
|
|
|
|
use cretonne::verifier::verify_function;
|
|
|
|
use cretonne::verifier::verify_function;
|
|
|
|
use cretonne::settings;
|
|
|
|
use cretonne::settings;
|
|
|
|
use Variable;
|
|
|
|
use Variable;
|
|
|
|
@@ -601,10 +602,10 @@ mod tests {
|
|
|
|
sig.returns.push(AbiParam::new(I32));
|
|
|
|
sig.returns.push(AbiParam::new(I32));
|
|
|
|
sig.params.push(AbiParam::new(I32));
|
|
|
|
sig.params.push(AbiParam::new(I32));
|
|
|
|
|
|
|
|
|
|
|
|
let mut il_builder = ILBuilder::<Variable>::new();
|
|
|
|
let mut fn_ctx = FunctionBuilderContext::<Variable>::new();
|
|
|
|
let mut func = Function::with_name_signature(ExternalName::testcase("sample"), sig);
|
|
|
|
let mut func = Function::with_name_signature(ExternalName::testcase("sample"), sig);
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut il_builder);
|
|
|
|
let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut fn_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
let block0 = builder.create_ebb();
|
|
|
|
let block0 = builder.create_ebb();
|
|
|
|
let block1 = builder.create_ebb();
|
|
|
|
let block1 = builder.create_ebb();
|
|
|
|
|