Upwards exposed uses


Upwards exposed uses or reachable uses, is a concept in compiler theory which occurs in the copy propagation stage of compilation.

Uses

During the copy propagation stage of program compilation, instances of a target are replaced with assignments to their values. During this process, it is necessary for the compiler to understand which instances of a target are being accessed so that appropriate substitution may occur, related to the concept of reaching definition in reaching analysis. This is done with the purpose of simplifying code before execution: if the number of upwards exposed uses of an assignment is zero, it does not contribute to the end result of the code and can be safely removed. This is also useful for improving code security during the compilation stages.

Example

Consider the following pseudocode:

x = 1
y = z
if False:
x = 0
else:
x = y + 2

It is safe to assume that line 5 will never occur, as demonstrated by the number of upwards exposed uses for this point being zero. This can therefore be simplified:

y = z
x = z + 2

This leads to an end result which is less complex to compile, and more efficient to run. This also meets the definition of reaching definition: In this context, upwards flow analysis was the technique used to demonstrate the needs for reaching definition. Additional techniques allow for more complex analysis of more deeply intertwined or complex control flow problems, such as those with various forms of loops.