From e63771f2d921cdce440620dbf38bd3e186747b1e Mon Sep 17 00:00:00 2001 From: Trevor Elliott Date: Tue, 4 Oct 2022 15:59:30 -0700 Subject: [PATCH] More consistent use of `add_inst` (#5012) Use the InstId returned by add_inst rather than creating it eagerly, when possible. --- cranelift/isle/isle/src/ir.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cranelift/isle/isle/src/ir.rs b/cranelift/isle/isle/src/ir.rs index 4eb23f044b..ae89b89554 100644 --- a/cranelift/isle/isle/src/ir.rs +++ b/cranelift/isle/isle/src/ir.rs @@ -262,8 +262,7 @@ impl PatternSequence { } fn add_arg(&mut self, index: usize, ty: TypeId) -> Value { - let inst = InstId(self.insts.len()); - self.add_inst(PatternInst::Arg { index, ty }); + let inst = self.add_inst(PatternInst::Arg { index, ty }); Value::Pattern { inst, output: 0 } } @@ -496,14 +495,12 @@ impl ExprSequence { } fn add_const_int(&mut self, ty: TypeId, val: i128) -> Value { - let inst = InstId(self.insts.len()); - self.add_inst(ExprInst::ConstInt { ty, val }); + let inst = self.add_inst(ExprInst::ConstInt { ty, val }); Value::Expr { inst, output: 0 } } fn add_const_prim(&mut self, ty: TypeId, val: Sym) -> Value { - let inst = InstId(self.insts.len()); - self.add_inst(ExprInst::ConstPrim { ty, val }); + let inst = self.add_inst(ExprInst::ConstPrim { ty, val }); Value::Expr { inst, output: 0 } } @@ -513,9 +510,8 @@ impl ExprSequence { ty: TypeId, variant: VariantId, ) -> Value { - let inst = InstId(self.insts.len()); let inputs = inputs.iter().cloned().collect(); - self.add_inst(ExprInst::CreateVariant { + let inst = self.add_inst(ExprInst::CreateVariant { inputs, ty, variant, @@ -531,9 +527,8 @@ impl ExprSequence { infallible: bool, multi: bool, ) -> Value { - let inst = InstId(self.insts.len()); let inputs = inputs.iter().cloned().collect(); - self.add_inst(ExprInst::Construct { + let inst = self.add_inst(ExprInst::Construct { inputs, ty, term,