Use-define Chain - Execution Example For Def-use-chain

Execution Example For Def-use-chain

This example is based on a Java algorithm for finding the gcd. (It is not important to understand what this function does.)

int gcd(int a, int b){ int c = a; int d = b; if(c == 0) return d; while(d != 0){ if(c > d) c = c - d; else d = d - c; } return c; }

To find out all def-use-chains for variable d, do the following steps:

1.Search for the first time, the variable is defined (write access).

In this case it is "d=b" (l.3)

2.Search for the first time, the variable is read.

In this case it is "return d"

3.Write down this information in the following style:

In this case it is:

Repeat this steps in the following style: combine each write access with each read access (but NOT the other way round).

The result should be:

You have to take care, if the variable is changed by the time.
For example: From line 3 down to line 9, "d" is not redefined / changed.
At line 10, "d" could be redefined, this is, why you have to recombine this write access on "d" with all possible read access, which could be reached.
In this case, only the code beyond line 6 is relevant. Line 3 for example cannot be reached again.

For your understanding, you can imagine 2 different variables "d":

Read more about this topic:  Use-define Chain

Famous quotes containing the word execution:

    Those who govern, having much business on their hands, do not generally like to take the trouble of considering and carrying into execution new projects. The best public measures are therefore seldom adopted from previous wisdom, but forced by the occasion.
    Benjamin Franklin (1706–1790)