Avoid a heap allocation for a block's undef_variables.

This commit is contained in:
Dan Gohman
2017-08-31 14:56:27 -07:00
parent 79f257060f
commit 539a5b3378

View File

@@ -16,6 +16,7 @@ use std::u32;
use cretonne::ir::types::{F32, F64}; use cretonne::ir::types::{F32, F64};
use cretonne::ir::immediates::{Ieee32, Ieee64}; use cretonne::ir::immediates::{Ieee32, Ieee64};
use std::collections::HashMap; use std::collections::HashMap;
use std::mem;
/// Structure containing the data relevant the construction of SSA for a given function. /// Structure containing the data relevant the construction of SSA for a given function.
/// ///
@@ -352,11 +353,11 @@ where
BlockData::EbbBody { .. } => panic!("this should not happen"), BlockData::EbbBody { .. } => panic!("this should not happen"),
BlockData::EbbHeader(ref mut data) => { BlockData::EbbHeader(ref mut data) => {
assert!(!data.sealed); assert!(!data.sealed);
( // Extract the undef_variables data from the block so that we
data.predecessors.clone(), // can iterate over it without borrowing the whole builder.
data.undef_variables.clone(), let mut undef_variables = Vec::new();
data.ebb, mem::swap(&mut data.undef_variables, &mut undef_variables);
) (data.predecessors.clone(), undef_variables, data.ebb)
} }
}; };
@@ -375,12 +376,12 @@ where
); );
} }
// Then we clear the undef_vars and mark the block as sealed. // Then we mark the block as sealed.
match self.blocks[block] { match self.blocks[block] {
BlockData::EbbBody { .. } => panic!("this should not happen"), BlockData::EbbBody { .. } => panic!("this should not happen"),
BlockData::EbbHeader(ref mut data) => { BlockData::EbbHeader(ref mut data) => {
assert!(!data.sealed); assert!(!data.sealed);
data.undef_variables.clear(); assert!(data.undef_variables.is_empty());
data.sealed = true; data.sealed = true;
} }
}; };