Ccs3207 Compiler Construction Assign - 2
Ccs3207 Compiler Construction Assign - 2
Techniques Chosen
2. Constant Propagation:
Replaces variables that have constant values with their actual constants at compile
time.
Eliminates unnecessary calculations and simplifies expressions.
def process(value):
# Placeholder for some computational logic
print(f"Processing value: {value}")
# Loop execution
for i in range(n):
z = distance + c # Use the precomputed invariant distance
process(z)
def process(value):
# Placeholder for some computational logic
print(f"Processing value: {value}")
● LICM:
○ distance = a + b moved outside the loop.
○ The computation distance = a + b is moved outside the loop since it
does not depend on the loop variable i.
○ This reduces redundant calculations in every iteration.
● Constant Propagation:
○ if (x == 5) evaluated at compile time if x is immutable.
○ The condition if x == 5 is evaluated at compile-time if x is known to be
constant. The y assignment is simplified outside the loop.
● Advantages:
○ Both techniques significantly improve execution speed, critical for real-time
systems.
○ Constant Propagation reduces memory overhead, a common constraint in
embedded environments.
● Disadvantages:
○ LICM may increase register pressure due to additional precomputed values.
○ Maintaining optimised code could become challenging if algorithms change
frequently.
Conclusion:
Yes, these optimizations are suitable for real-time systems because they strike a balance
between speed and memory efficiency, two primary constraints in embedded environments.
However, careful profiling is necessary to ensure register pressure does not degrade
performance in resource-constrained systems.