def _handle_matches(self): """Iterate over the matches, trying to find which instructions should be rewritten, deleted, or moved. """ replace_map = {} dead_vars = set() used_vars = defaultdict(int) for instr in self.array_assigns.values(): expr = instr.value arr_inps = [] arr_expr = self._get_array_operator(expr), arr_inps new_expr = ir.Expr( op="arrayexpr", loc=expr.loc, expr=arr_expr, ty=self.typemap[instr.target.name], ) new_instr = ir.Assign(new_expr, instr.target, instr.loc) replace_map[instr] = new_instr self.array_assigns[instr.target.name] = new_instr for operand in self._get_operands(expr): operand_name = operand.name if operand_name in self.array_assigns: child_assign = self.array_assigns[operand_name] child_expr = child_assign.value child_operands = child_expr.list_vars() for operand in child_operands: used_vars[operand.name] += 1 arr_inps.append(self._translate_expr(child_expr)) if child_assign.target.is_temp: dead_vars.add(child_assign.target.name) replace_map[child_assign] = None elif operand_name in self.const_assigns: arr_inps.append(self.const_assigns[operand_name]) else: used_vars[operand.name] += 1 arr_inps.append(operand) return replace_map, dead_vars, used_vars
def test_expr(self): a = ir.Expr('some_op', self.loc1) b = ir.Expr('some_op', self.loc1) c = ir.Expr('some_op', self.loc2) d = ir.Expr('some_other_op', self.loc1) self.check(a, same=[b, c], different=[d])