Code Optimization Compiler Construction
Code Optimization Compiler Construction
OPTIMIZATION
GROUP MEMBERS
Rose Ongili - C026-01-0951/22
Festus Gitahi - C026-01-0913/2022
Anerico Kakai - C026-01-0969/2022
Faith Irungu - C026-01-0736/2020
Leo Chege- C026-01-0912/2022
Evans Mwaura - C026-01-0911/2022
th
DUE - 25 NOVEMBER, 2024
1. Synthesis
The Techniques used are Loop -Invariant Code Motion and Register Allocation.
Loop Invariant is ideal for moving calculations that do not change within a loop outside the
loop, reducing redundant computations during execution
Register Allocation Techniques optimises the use of CPU registers instead of relying on
slower memory access.
After Optimization:
The constants calculations are placed outside the loop to avoid repetition
function findPath(grid, start, end) {
2. Evaluation
Trade-offs of Chosen Techniques:
Synthesis (Create)
2. Register Allocation:
Minimising memory accesses is critical in embedded systems. Assigning frequently used
variables to registers ensures faster execution, particularly for variables repeatedly accessed
within tight loops.
Relevance: Embedded systems often have limited memory bandwidth, making
register optimization vital for maintaining real-time performance.
Plan Details:
1. Analyze Code:
- Identify nested loops and their operations.
- Locate calculations within loops that depend on constants or values unchanged across
iterations.
- Identify frequently accessed variables for register allocation.
4. Validate Optimizations:
- Use automated and manual testing to verify correctness.
- Benchmark execution time and memory usage before and after applying optimizations.
Recommendation
Potential Risks:
i. Increased memory usage for storing precomputed data (LICM) should be carefully
managed.
ii. Register allocation is limited by the number of registers in the system, which may
necessitate spilling.
Recommendation:
These optimizations are both feasible and effective for the given scenario. The trade-offs are
manageable within embedded system constraints. The company should proceed with
implementing these optimizations and rigorously test the system under real-world conditions.