This project implements a framework for converting Python code into Static Single Assignment (SSA) form by parsing the Abstract Syntax Tree (AST). It includes various optimization techniques to enhance the quality and efficiency of the generated code.
-
AST to SSA Conversion:
- Efficiently converts Python AST into SSA form.
- Supports basic assignments, arithmetic operations, conditional branching, and loops.
-
Optimization Techniques:
- Local Value Numbering (LVN)
- Global Value Numbering (GVN)
- Arithmetic simplifications
- Constant folding
- Removal of trivial Phi functions
- Common subexpression elimination with caching
-
Code Efficiency:
- Reduces redundant instructions.
- Dynamically handles variable tracking with Phi function insertion.
-
SSAInstruction: Represents individual SSA instructions such asadd,phi, andassign. -
SSABlock: Represents a basic block in the SSA form, containing instructions and control flow details. -
SSAConverter: Core class responsible for:- Parsing Python AST nodes.
- Generating SSA instructions.
- Performing optimizations during SSA construction.
- Python 3.7+
- Standard libraries:
ast,collections
The framework includes several predefined source code examples to test SSA conversion. To run the script:
python project2.py