Add SideEffects::new().

This commit is contained in:
Dan Gohman
2017-08-07 13:59:26 -07:00
parent 52186b8390
commit 46fb64cbb4

View File

@@ -57,6 +57,15 @@ pub struct SideEffects {
pub instructions_added_to_ebbs: Vec<Ebb>, pub instructions_added_to_ebbs: Vec<Ebb>,
} }
impl SideEffects {
fn new() -> SideEffects {
SideEffects {
split_ebbs_created: Vec::new(),
instructions_added_to_ebbs: Vec::new(),
}
}
}
// Describes the current position of a basic block in the control flow graph. // Describes the current position of a basic block in the control flow graph.
enum BlockData<Variable> { enum BlockData<Variable> {
// A block at the top of an `Ebb`. // A block at the top of an `Ebb`.
@@ -209,11 +218,7 @@ impl<Variable> SSABuilder<Variable>
// First we lookup for the current definition of the variable in this block // First we lookup for the current definition of the variable in this block
if let Some(var_defs) = self.variables.get(var) { if let Some(var_defs) = self.variables.get(var) {
if let Some(val) = var_defs.get(&block) { if let Some(val) = var_defs.get(&block) {
return (*val, return (*val, SideEffects::new());
SideEffects {
split_ebbs_created: Vec::new(),
instructions_added_to_ebbs: Vec::new(),
});
} }
}; };
// At this point if we haven't returned it means that we have to search in the // At this point if we haven't returned it means that we have to search in the
@@ -252,11 +257,7 @@ impl<Variable> SSABuilder<Variable>
// definition for the variable. // definition for the variable.
UseVarCases::Unsealed(val) => { UseVarCases::Unsealed(val) => {
self.def_var(var, val, block); self.def_var(var, val, block);
(val, (val, SideEffects::new())
SideEffects {
split_ebbs_created: Vec::new(),
instructions_added_to_ebbs: Vec::new(),
})
} }
UseVarCases::SealedMultiplePredecessors(preds, val, ebb) => { UseVarCases::SealedMultiplePredecessors(preds, val, ebb) => {
// If multiple predecessor we look up a use_var in each of them: // If multiple predecessor we look up a use_var in each of them:
@@ -377,10 +378,7 @@ impl<Variable> SSABuilder<Variable>
} }
}; };
let mut side_effects = SideEffects { let mut side_effects = SideEffects::new();
split_ebbs_created: Vec::new(),
instructions_added_to_ebbs: Vec::new(),
};
// For each undef var we look up values in the predecessors and create an Ebb argument // For each undef var we look up values in the predecessors and create an Ebb argument
// only if necessary. // only if necessary.
for (var, val) in undef_vars { for (var, val) in undef_vars {
@@ -420,10 +418,7 @@ impl<Variable> SSABuilder<Variable>
// TODO: find a way not not allocate a vector // TODO: find a way not not allocate a vector
let mut jump_args_to_append: Vec<(Block, Inst, Value)> = Vec::new(); let mut jump_args_to_append: Vec<(Block, Inst, Value)> = Vec::new();
let ty = dfg.value_type(temp_arg_val); let ty = dfg.value_type(temp_arg_val);
let mut side_effects = SideEffects { let mut side_effects = SideEffects::new();
split_ebbs_created: Vec::new(),
instructions_added_to_ebbs: Vec::new(),
};
for &(pred, last_inst) in preds.iter() { for &(pred, last_inst) in preds.iter() {
// For undef value and each predecessor we query what is the local SSA value // For undef value and each predecessor we query what is the local SSA value
// corresponding to var and we put it as an argument of the branch instruction. // corresponding to var and we put it as an argument of the branch instruction.