Skip to content

RodrigoPombo1/projeto-compiladores

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

272 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Project 2024-25

Contributions

  • Gonçalo Matias: 33%
  • Rodrigo Pombo: 33%
  • Pedro Vieira: 33%

Optimizations

"-o"

Constant Propagation and Constant Folding in sequence and in loop until they don't modify anything.

"-r="

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.

OLLIR Optimizations

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 + 3 are replaced by 5 directly in the OLLIR code. This is applied iteratively with Constant Propagation under the -o flag.
  • 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 -o flag.
  • 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.

Jasmin Optimizations

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, and astore_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_0 for the value 0, bipush for one-byte constants, sipush for 16-bit constants, and ldc for larger constants, optimizing code size and speed.
  • Use of the iinc Instruction: Replaces operations like i = i + 1 with the iinc instruction, which is more efficient for incrementing integer variables by small constant values.
  • Specialized Comparison Instructions: Uses zero-comparison instructions, such as iflt and ifne, instead of generic instructions like if_icmplt, for more efficient comparisons when one operand is zero.
  • Stack and Locals Limit Calculation: Calculates the .limit stack and .limit locals values 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •