def transform(self): # insert copy statements for phi expressions for phi in iterators.operand_iterator_t(self.function, klass=phi_t): groups = self.find_intersection_groups(phi) self.rename_groups(phi, groups) # clear indices from all operands, remove def-use chains for op in iterators.operand_iterator_t(self.function, klass=assignable_t): op.index = None op.unlink() return
def verify(self): """ verify that the ssa form is coherent. """ for op in iterators.operand_iterator_t(self.function): if not isinstance(op, assignable_t): continue if op.definition: assert op.is_def is False, "%s: expected is_def=False" % ( repr(op), ) self.verify_definition_has_use(op.definition, op) if not op.definition.is_uninitialized: stmt = op.definition.parent_statement assert stmt, "%s: has a definition which is unlinked from the tree\n def: %s" % ( repr(op), repr(op.definition)) assert stmt is self.function.uninitialized_stmt or stmt.container, "%s: has a definition which is unlinked from the tree" % ( repr(op), ) assert op.definition.index == op.index, "%s: expected to have the same index as its definition: %s" % ( op, op.definition) for use in op.uses: assert use.definition, '%s: has a use without definition' assert use.definition is op, '%s: has a use that points to another definition\n use: %s\n wrong def: %s\n should be: %s' % ( repr(op), repr(use.parent_statement), repr(use.definition.parent_statement), repr(op.parent_statement)) stmt = use.parent_statement assert stmt, "%s: has a use (%s) which is unlinked from the tree" % ( repr(op), repr(use)) assert stmt is self.function.uninitialized_stmt or use.parent_statement.container, "%s: has a use (%s) which is unlinked from the tree" % ( repr(op), repr(use)) assert use.definition.index == use.index, "%s: expected to have the same index as its definition: %s" % ( use.parent_statement, use.definition.parent_statement) return
def rename(self): for op in iterators.operand_iterator_t(self.function, filter=self.should_rename): new = self.rename_with(op) op.replace(new) op.unlink() # clear out phi statements with operands that do not have indexes anymore. for phi in iterators.operand_iterator_t(self.function, klass=phi_t): for op in list(phi.operands): if op.index is None: phi.remove(op) op.unlink() for stmt in iterators.statement_iterator_t(self.function): if isinstance(stmt.expr, assign_t) and isinstance(stmt.expr.op2, phi_t) and len(stmt.expr.op2) == 0: stmt.expr.unlink() stmt.remove() return
def rename(self): for op in iterators.operand_iterator_t(self.function, filter=self.should_rename): new = self.rename_with(op) op.replace(new) op.unlink() # clear out phi statements with operands that do not have indexes anymore. for phi in iterators.operand_iterator_t(self.function, klass=phi_t): for op in list(phi.operands): if op.index is None: phi.remove(op) op.unlink() for stmt in iterators.statement_iterator_t(self.function): if isinstance(stmt.expr, assign_t) and isinstance( stmt.expr.op2, phi_t) and len(stmt.expr.op2) == 0: stmt.expr.unlink() stmt.remove() return
def remove_ssa_form(self): """ transform the flow out of ssa form. """ if self.has_theta_expressions(): return #raise RuntimeError('not yet implemented') for op in iterators.operand_iterator_t(self.flow): if isinstance(op, assignable_t): op.index = None return
def remove_ssa_form(self): """ transform the flow out of ssa form. """ if not self.has_theta_expressions(): for op in iterators.operand_iterator_t(self.flow): if isinstance(op, assignable_t): op.index = None else: pass return
def verify(self): """ verify that the ssa form is coherent. """ for op in iterators.operand_iterator_t(self.flow): if not isinstance(op, assignable_t): continue if op.definition: self.verify_definition_has_use(op.definition, op) assert op.definition.parent_statement, "%s: has a definition which is unlinked from the tree" % (repr(op), ) assert op.definition.parent_statement.container, "%s: has a definition which is unlinked from the tree" % (repr(op), ) for use in op.uses: assert use.definition, '%s: has a use without definition' assert use.definition is op, '%s: has a use that points to another definition\n use: %s\n wrong def: %s\n should be: %s' % (repr(op), repr(use.parent_statement), repr(use.definition.parent_statement), repr(op.parent_statement)) assert use.parent_statement, "%s: has a use (%s) which is unlinked from the tree" % (repr(op), repr(use)) assert use.parent_statement.container, "%s: has a use (%s) which is unlinked from the tree" % (repr(op), repr(use)) return
def verify(self): """ verify that the ssa form is coherent. """ for op in iterators.operand_iterator_t(self.function): if not isinstance(op, assignable_t): continue if op.definition: assert op.is_def is False, "%s: expected is_def=False" % (repr(op), ) self.verify_definition_has_use(op.definition, op) if not op.definition.is_uninitialized: stmt = op.definition.parent_statement assert stmt, "%s: has a definition which is unlinked from the tree\n def: %s" % (repr(op), repr(op.definition)) assert stmt is self.function.uninitialized_stmt or stmt.container, "%s: has a definition which is unlinked from the tree" % (repr(op), ) assert op.definition.index == op.index, "%s: expected to have the same index as its definition: %s" % (op, op.definition) for use in op.uses: assert use.definition, '%s: has a use without definition' assert use.definition is op, '%s: has a use that points to another definition\n use: %s\n wrong def: %s\n should be: %s' % (repr(op), repr(use.parent_statement), repr(use.definition.parent_statement), repr(op.parent_statement)) stmt = use.parent_statement assert stmt, "%s: has a use (%s) which is unlinked from the tree" % (repr(op), repr(use)) assert stmt is self.function.uninitialized_stmt or use.parent_statement.container, "%s: has a use (%s) which is unlinked from the tree" % (repr(op), repr(use)) assert use.definition.index == use.index, "%s: expected to have the same index as its definition: %s" % (use.parent_statement, use.definition.parent_statement) return
def verify(self): """ verify that the ssa form is coherent. """ for op in iterators.operand_iterator_t(self.function): if not isinstance(op, assignable_t): continue if op.definition: self.verify_definition_has_use(op.definition, op) assert op.definition.parent_statement, "%s: has a definition which is unlinked from the tree\n def: %s" % ( repr(op), repr(op.definition)) assert op.definition.parent_statement.container, "%s: has a definition which is unlinked from the tree" % ( repr(op), ) for use in op.uses: assert use.definition, '%s: has a use without definition' assert use.definition is op, '%s: has a use that points to another definition\n use: %s\n wrong def: %s\n should be: %s' % ( repr(op), repr(use.parent_statement), repr(use.definition.parent_statement), repr(op.parent_statement)) assert use.parent_statement, "%s: has a use (%s) which is unlinked from the tree" % ( repr(op), repr(use)) assert use.parent_statement.container, "%s: has a use (%s) which is unlinked from the tree" % ( repr(op), repr(use)) return
def has_theta_expressions(self): for op in iterators.operand_iterator_t(self.flow): if isinstance(op, theta_t): return True return False