def visit_Assign(self, stmt): consumes, reads = self.visit_expr(stmt.rhs) _, writes = self.visit_expr(stmt.lhs) for write_expr_set in writes.itervalues(): for write_expr in write_expr_set: consumes.update(collect_var_names(write_expr)) produces = collect_binding_names(stmt.lhs) return StmtNode(stmt, consumes, produces, reads, writes)
def collect_loop_vars(self, loop_vars, loop_body): """Gather the variables whose values change between loop iterations""" for stmt in loop_body: assert stmt.__class__ not in (ForLoop, While, Return) if stmt.__class__ is Assign: lhs_names = collect_binding_names(stmt.lhs) rhs_names = collect_var_names(stmt.rhs) if any(name in loop_vars for name in rhs_names): loop_vars.update(lhs_names)
def visit_Assign(self, stmt): assert stmt.lhs.type is not None, \ "Missing LHS type for assignment %s" % stmt assert stmt.rhs.type is not None, \ "Missing RHS type for assignment %s" % stmt self.visit_lhs(stmt.lhs) lhs_names = collect_binding_names(stmt.lhs) for lhs_name in lhs_names: self.bind_var(lhs_name) self.visit_expr(stmt.rhs) assert stmt.lhs.type == stmt.rhs.type, \ "Mismatch between LHS type %s and RHS %s in '%s'" % \ (stmt.lhs.type, stmt.rhs.type, stmt)
def transform_Assign(self, stmt): if stmt.lhs.__class__ is Var: name = stmt.lhs.name if name in self.safe_to_move: deps = self.analysis.depends_on[name] if all(d in self.binding_depth for d in deps): if len(deps) > 0: target_level = max(self.binding_depth[d] for d in deps) else: target_level = 0 if target_level >= 0 and target_level < self.blocks.depth(): self.blocks._blocks[target_level].append(stmt) self.binding_depth[name] = target_level return None self.mark_binding_depths(collect_binding_names(stmt.lhs)) return stmt
def transform_Assign(self, stmt): # TODO: Allow possibility of indexing into variables that are read-only if stmt.lhs.__class__ is Var and stmt.rhs.__class__ is not Index: name = stmt.lhs.name if name in self.safe_to_move: deps = self.analysis.depends_on[name] if all(d in self.binding_depth for d in deps): if len(deps) > 0: target_level = max(self.binding_depth[d] for d in deps) else: target_level = 0 if target_level >= 0 and target_level < self.blocks.depth(): self.blocks._blocks[target_level].append(stmt) self.binding_depth[name] = target_level return None self.mark_binding_depths(collect_binding_names(stmt.lhs)) return stmt
def visit_Assign(self, stmt): assert stmt.lhs.type is not None, \ "Missing LHS type for assignment %s" % stmt assert stmt.rhs.type is not None, \ "Missing RHS type for assignment %s" % stmt self.visit_lhs(stmt.lhs) lhs_names = collect_binding_names(stmt.lhs) for lhs_name in lhs_names: self.bind_var(lhs_name) self.visit_expr(stmt.rhs) rhs_t = stmt.rhs.type if stmt.lhs.__class__ is Index: array_t = stmt.lhs.value.type assert stmt.lhs.type == rhs_t or rhs_t == array_t.elt_type, \ "Mismatch between LHS type %s and RHS %s in '%s'" % \ (stmt.lhs.type, stmt.rhs.type, stmt) else: assert stmt.lhs.type == stmt.rhs.type, \ "Mismatch between LHS type %s and RHS %s in '%s'" % \ (stmt.lhs.type, stmt.rhs.type, stmt)
def visit_Assign(self, stmt): lhs_names = collect_binding_names(stmt.lhs) rhs_names = collect_var_names(stmt.rhs) for x in lhs_names: dependencies = self.depends_on.get(x, set([])) dependencies.update(rhs_names) self.depends_on[x] = dependencies if any(x in self.volatile_vars for x in rhs_names): self.volatile_vars.update(lhs_names) elif self.is_mutable_alloc(stmt.rhs): if len(lhs_names) == 1 and \ len(self.may_alias.get(lhs_names[0], [])) <= 1: pass else: self.volatile_vars.update(lhs_names) # mark any array writes as volatile if stmt.lhs.__class__ is Index: assert stmt.lhs.value.__class__ is Var self.volatile_vars.add(stmt.lhs.value.name)
def transform_Assign(self, expr): for name in collect_binding_names(expr.lhs): self.rename(name) new_lhs = self.transform_expr(expr.lhs) new_rhs = self.transform_expr(expr.rhs) return Assign(new_lhs, new_rhs)