diff --git a/lib/cretonne/src/ir/dfg.rs b/lib/cretonne/src/ir/dfg.rs index 240c5377c0..b81bbe96fc 100644 --- a/lib/cretonne/src/ir/dfg.rs +++ b/lib/cretonne/src/ir/dfg.rs @@ -74,6 +74,17 @@ impl DataFlowGraph { } } + /// Clear everything. + pub fn clear(&mut self) { + self.insts.clear(); + self.results.clear(); + self.ebbs.clear(); + self.value_lists.clear(); + self.values.clear(); + self.signatures.clear(); + self.ext_funcs.clear(); + } + /// Get the total number of instructions created in this function, whether they are currently /// inserted in the layout or not. /// diff --git a/lib/cretonne/src/ir/extfunc.rs b/lib/cretonne/src/ir/extfunc.rs index 2606ebe19e..353d49256e 100644 --- a/lib/cretonne/src/ir/extfunc.rs +++ b/lib/cretonne/src/ir/extfunc.rs @@ -47,6 +47,14 @@ impl Signature { } } + /// Clear the signature so it is identical to a fresh one returned by `new()`. + pub fn clear(&mut self, call_conv: CallConv) { + self.argument_types.clear(); + self.return_types.clear(); + self.call_conv = call_conv; + self.argument_bytes = None; + } + /// Compute the size of the stack arguments and mark signature as legalized. /// /// Even if there are no stack arguments, this will set `argument_types` to `Some(0)` instead diff --git a/lib/cretonne/src/ir/function.rs b/lib/cretonne/src/ir/function.rs index 0f1599d6bd..95b6458558 100644 --- a/lib/cretonne/src/ir/function.rs +++ b/lib/cretonne/src/ir/function.rs @@ -74,6 +74,20 @@ impl Function { } } + /// Clear all data structures in this function. + pub fn clear(&mut self) { + self.signature.clear(ir::CallConv::Native); + self.stack_slots.clear(); + self.global_vars.clear(); + self.heaps.clear(); + self.jump_tables.clear(); + self.dfg.clear(); + self.layout.clear(); + self.encodings.clear(); + self.locations.clear(); + self.offsets.clear(); + } + /// Create a new empty, anonymous function with a native calling convention. pub fn new() -> Function { Self::with_name_signature(FunctionName::default(), Signature::new(CallConv::Native)) diff --git a/lib/cretonne/src/ir/layout.rs b/lib/cretonne/src/ir/layout.rs index 33fbaf943d..6d16b004e1 100644 --- a/lib/cretonne/src/ir/layout.rs +++ b/lib/cretonne/src/ir/layout.rs @@ -51,6 +51,14 @@ impl Layout { last_ebb: None, } } + + /// Clear the layout. + pub fn clear(&mut self) { + self.ebbs.clear(); + self.insts.clear(); + self.first_ebb = None; + self.last_ebb = None; + } } // Sequence numbers.