- Gonçalo Matias: 33%
- Rodrigo Pombo: 33%
- Pedro Vieira: 33%
Constant Propagation and Constant Folding in sequence and in loop until they don't modify anything.
Register allocation control:
- n ≥ 1: The compiler will try to use at most local variables when generating Jasmin instructions. Report the mapping between the local variables of each method and the corresponding local variable of the JVM. If the value of n is not enough to store every variable of the method, the compiler will abort, report an error and indicate the minimum number of JVM local variables required.
- n = 0: The compiler will try to use as few local variables as it can. Report the mapping between the local variables of each method and the corresponding local variable of the JVM.
- n = −1: The compiler will use as many variables as originally present in the OLLIR representation. This is the default value.
All public tests passed.
These optimizations are applied during the generation or transformation of the OLLIR intermediate representation, typically at the AST level:
- Constant Folding: Simplifies expressions involving constants at compile time, reducing runtime computational overhead. For example, expressions like
2 + 3are replaced by5directly in the OLLIR code. This is applied iteratively with Constant Propagation under the-oflag. - Constant Propagation: Replaces variables that hold constant values with those values, and so eliminate unnecessary variable accesses and simplifying the OLLIR code. This is applied iteratively with Constant Folding under the
-oflag. - Register Allocation: Optimizes the use of registers to store variables, and minimizes memory accesses and improves execution speed. We used a graph coloring algorithm to allocate registers efficiently.
All public tests passed.
These optimizations are applied during the generation of Jasmin code from the OLLIR representation, optimizing the bytecode for the JVM:
- Specialized Load and Store Instructions: Uses efficient JVM instructions, such as
iload_x,istore_x,aload_x, andastore_x, to access variables at specific register indices, reducing code size and improving performance. - Optimized Constant Loading: Selects the most appropriate instructions for loading constants onto the stack, such as
iconst_0for the value 0,bipushfor one-byte constants,sipushfor 16-bit constants, andldcfor larger constants, optimizing code size and speed. - Use of the
iincInstruction: Replaces operations likei = i + 1with theiincinstruction, which is more efficient for incrementing integer variables by small constant values. - Specialized Comparison Instructions: Uses zero-comparison instructions, such as
ifltandifne, instead of generic instructions likeif_icmplt, for more efficient comparisons when one operand is zero. - Stack and Locals Limit Calculation: Calculates the
.limit stackand.limit localsvalues for each method, ensuring optimal resource usage and preventing JVM verification errors, such as "Stack size too large."
All JasminOptimizationsTest passed. 23/26 tests from JasminTest passed.