Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Code Generator] Simplify Expressions (#318)
* Create draft PR for #25 * Implement substitute_visitor * Replace expression_simplification with expression_simplification_rules * Implement expression simplification rules * Add documentation to visit_mem_phi in substitute_visitor.py Co-authored-by: Manuel Blatt <[email protected]> * Add docstring to modification.py/normalize_int(int,int,bool) * Rename modification.py/FOLDABLE_CONSTANTS to FOLDABLE_OPERATIONS * Rename modification.py/_FOLD_HANDLER to _OPERATION_TO_FOLD_FUNCTION * Move _simplify_instructions and _simplify_instructions_with_rule_set into _ExpressionSimplificationRulesBase * Extract code from _simplify_instructions_with_rule_set to _simplify_instruction_with_rule * Improve documentation in default.json for expression simplification max_iterations * Add documentation to substitute_visitor.py * Add additional test cases to test_substitute_visitor.py - Assignment lhs - UnaryOperation - UnaryOperation ArrayInfo - Phi * Improve readability of _visit_operation(self,Operation) in substitute_visitor.py * Improve readability of visit_unary_operation(self,UnaryOperation) in substitute_visitor.py * Use visit instead of mapper function in visit_phi(self,Phi) * Lift constraints of SubstituteVisitor that tried to uphold validity of the dataflow tree Lift some constraints of what can be substituted. These constraints where in place in an attempt to prevent erroneous modifications to the dataflow tree, resulting in invalid states. This commit shifts the responsibility of keeping the dataflow graph in a valid state to the user allowing for a more flexible implementation. * Slight syntax changes to test_substitute_visitor.py * Improve syntax in _OPERATION_TO_FOLD_FUNCTION * Assert that instructions are not substituted in expression_simplification_rules.py * Add clarifying comment to _simplify_instruction_with_rule * Rename ExpressionSimplificationRules to ExpressionSimplification * Create copies while substituting with SubstituteVisitor.equality * Remove unused function multiply_int_with_constant * Add documentation to modification.py * Rename modification.py to constant_folding.py * Extract method from visit_unary_operation * Add documentation to collect_terms.py * Add tests for ExpressionSimplification stage * Update documentation for '_constant_fold_arithmetic_binary' Co-authored-by: Manuel Blatt <[email protected]> * Update documentation for 'normalize_int' Co-authored-by: Manuel Blatt <[email protected]> * Add comment explaining 'max_iterations' Co-authored-by: Manuel Blatt <[email protected]> * Improve documentation of CollectTerms Co-authored-by: Manuel Blatt <[email protected]> * Rename variable in collect_terms.py for readability Co-authored-by: Manuel Blatt <[email protected]> * Rename variable in simplify_redundant_reference.py for readability Co-authored-by: Manuel Blatt <[email protected]> * Improve documentation of TermOrder Co-authored-by: Manuel Blatt <[email protected]> * Remove unused collapse_mult_neg_one.py * Fix test in test_substitute_visitor.py * Rename simplification rule FixAddSubSign to PositiveConstants * Rename variables in positive_constants.py * Rename operands to constant in collect_terms.py * Rename CollectTerms to CollapseNestedConstants * Add missing unsigned multiply case to simplify_trivial_arithmetic.py * Use 'neg' operation in SubToAdd * Delete test_collapse_mult_neg_one.py * Fix test_stage.py * Slight change to test_stage.py * Ignore MemPhi in SubstituteVisitor --------- Co-authored-by: rihi <[email protected]> Co-authored-by: rihi <[email protected]> Co-authored-by: Manuel Blatt <[email protected]> Co-authored-by: Manuel Blatt <[email protected]>
- Loading branch information