HOME

TheInfoList



OR:

In
compiler theory In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
, a reaching definition for a given instruction is an earlier instruction whose target variable can reach (be assigned to) the given one without an intervening assignment. For example, in the following code: d1 : y := 3 d2 : x := y d1 is a reaching definition for d2. In the following, example, however: d1 : y := 3 d2 : y := 4 d3 : x := y d1 is no longer a reaching definition for d3, because d2 kills its reach: the value defined in d1 is no longer available and cannot reach d3.


As analysis

The similarly named reaching definitions is a
data-flow analysis In computing, dataflow is a broad concept, which has various meanings depending on the application and context. In the context of software architecture, data flow relates to stream processing or reactive programming. Software architecture Dataf ...
which statically determines which definitions may reach a given point in the code. Because of its simplicity, it is often used as the canonical example of a data-flow analysis in textbooks. The
data-flow confluence operator In computing, dataflow is a broad concept, which has various meanings depending on the application and context. In the context of software architecture, data flow relates to stream processing or reactive programming. Software architecture Dataf ...
used is set union, and the analysis is forward flow. Reaching definitions are used to compute
use-def chain Within computer science, a Use-Definition Chain (''UD Chain'') is a data structure that consists of a use, U, of a variable, and all the definitions, D, of that variable that can reach that use without any other intervening definitions. A UD Chain ...
s. The data-flow equations used for a given basic block S in reaching definitions are: * _ = \bigcup_ _ /math> * _ = \cup (_ - In other words, the set of reaching definitions going into S are all of the reaching definitions from S's predecessors, pred /math>. pred /math> consists of all of the basic blocks that come before S in the
control-flow graph In computer science, a control-flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. The control-flow graph was discovered by Frances E. Allen, who noted that ...
. The reaching definitions coming out of S are all reaching definitions of its predecessors minus those reaching definitions whose variable is killed by S plus any new definitions generated within S. For a generic instruction, we define the and sets as follows: * : y \leftarrow f(x_1,\cdots,x_n)= \ , a set of locally available definitions in a basic block * : y \leftarrow f(x_1,\cdots,x_n)= - \, a set of definitions (not locally available, but in the rest of the program) killed by definitions in the basic block. where /math> is the set of all definitions that assign to the variable y. Here d is a unique label attached to the assigning instruction; thus, the domain of values in reaching definitions are these instruction labels.


Worklist algorithm

Reaching definition is usually calculated using an iterative worklist algorithm. Input: control-flow graph CFG = (Nodes, Edges, Entry, Exit) // Initialize for all CFG nodes n in N, OUT = emptyset; // can optimize by OUT = GEN // put all nodes into the changed set // N is all nodes in graph, Changed = N; // Iterate while (Changed != emptyset)


See also

*
Dead-code elimination In compiler theory, dead-code elimination (also known as DCE, dead-code removal, dead-code stripping, or dead-code strip) is a compiler optimization to remove code which does not affect the program results. Removing such code has several benefit ...
*
Loop-invariant code motion In computer programming, loop-invariant code consists of statements or expressions (in an imperative programming language) that can be moved outside the body of a loop without affecting the semantics of the program. Loop-invariant code motion ( ...
*
Reachable uses Upwards exposed uses or reachable uses, is a concept in compiler theory In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''ta ...
*
Static single assignment form In compiler design, static single assignment form (often abbreviated as SSA form or simply SSA) is a property of an intermediate representation (IR) that requires each variable to be assigned exactly once and defined before it is used. Existing var ...


Further reading

* * * * *{{cite book , author1=Nielson F., H.R. Nielson , author2=, C. Hankin , title=Principles of Program Analysis , publisher=Springer , year=2005 , isbn=3-540-65410-0 Data-flow analysis Program analysis