Professional Documents
Culture Documents
w = a + b;
x1 = a – c;
y = x1 + d;
x2 = a + c;
z = y + e;
Figure 5-4 . The basic block in single-assignment form .
The single-assignment form is important because itallows us to identify a unique
location in the code where each namedlocation is computed. As an introduction
to the data flow graph, we usetwo types of nodes in the graph— round nodes
denote operators andsquare nodes represent values. The value nodes may be
either inputs tothe basic block, such as a and b , or variables assigned to within
theblock, such as w and x1 . The data flow graph for our single-assignmentcode is
shown in Figure 5-5 below.
The single-assignment form means that thedata flow graph is acyclic—if we
assigned to x multiple times, then thesecond assignment would form a cycle in
the graph including x and theoperators used to compute x .
Keeping the data flow graph acyclic isimportant in many types of analyses we
want to do on the graph. (Ofcourse, it is important to know whether the source
code actuallyassigns to a variable multiple times, because some of those
assignmentsmay be mistakes. We consider the analysis of source code for proper
useof assignments later in this series.)
Figure5-5. An extended data flow graph for our sample block
The data flow graph is generally drawn in the formshown in Figure 5-6 below.
Here, the variables are not explicitlyrepresented by nodes. Instead, the edges are
labeled with the variablesthey represent. As a result, a variable can be
represented by more thanone edge. However, the edges are directed and all the
edges for avariable must come from a single source. We use this form for
itssimplicity and compactness.
<="" strong="" style="box-sizing: inherit; font-weight: normal;">
<="" strong="" style="box-sizing: inherit; font-weight: normal;">
Figure5-6. Standard data flow graph for sample basic block
The data flowgraph for the code makes the order inwhich the operations are
performed in the C code much less obvious.This is one of the advantages of the
data flow graph. We can use it todetermine feasible reorderings of the
operations, which may help us toreduce pipeline or cache conflicts.
We can also useit when the exact order of operationssimply doesn't matter. The
data flow graph defines a partial orderingof the operations in the basic block. We
must ensure that a value iscomputed before it is used, but generally there are
several possibleorderings of evaluating expressions that satisfy this requirement.
Control/DataFlow Graphs
A CDFG uses a data flow graph as an element, adding constructs todescribe
control. In a basic CDFG, we have two types of nodes: decisionnodes and data
flow nodes.
A data flow nodeencapsulates a complete data flowgraph to represent a basic
block. We can use one type of decision nodeto describe all the types of control in
a sequential program. (Thejump/branch is, after all, the way we implement all
those high-levelcontrol constructs.)
Figure 5-7 below shows a bit of C code with controlconstructs and the CDFG
constructed from it. The rectangular nodes inthe graph represent the basic
blocks. The basic blocks in the C codehave been represented by function calls for
simplicity. Thediamond-shaped nodes represent the conditionals. The node's
conditionis given by the label, and the edges are labeled with the
possibleoutcomes of evaluating the condition.
Building a CDFGfor a while loop is straightforward,as shown in Figure 5-8
below .The while loop consists of both a test and aloop body, each of which we
know how to represent in a CDFG. We canrepresent for loops by remembering
that, in C, a for loop is defined interms of a while loop. The following for loop
Encapsulation
Encapsulation is a process of information hiding. It is simply the combination of process
and data into a single entity. Data of an object is hidden from the rest of the system and
available only through the services of the class. It allows improvement or modification of
methods used by objects without affecting other parts of a system.
Abstraction
It is a process of taking or selecting necessary method and attributes to specify the
object. It focuses on essential characteristics of an object relative to perspective of user.
Relationships
All the classes in the system are related with each other. The objects do not exist in
isolation, they exist in relationship with other objects.
There are three types of object relationships −
Aggregation − It indicates relationship between a whole and its parts.
Association − In this, two classes are related or connected in some way such as
one class works with another to perform a task or one class acts upon other class.
Generalization − The child class is based on parent class. It indicates that two
classes are similar but have some differences