Опубликован: 12.07.2012 | Доступ: свободный | Студентов: 293 / 18 | Оценка: 4.00 / 4.20 | Длительность: 11:07:00
Специальности: Программист
Лекция 3:

# Optimizing compiler Scalar optimizations

< Лекция 2 || Лекция 3: 12345 || Лекция 4 >

### Removal of excessive branching, broaching conditions

Sometimes conditional branches can be deleted because of previous conditions Рис. 3.12.

### Why Control Flow Graph is important for scalar optimizations? Рис. 3.13.

When we can propagate the information about the values of X? For straight-line piece of code the answer is trivial. CFG resolves ambiguity.

### Data Flow analysis

Data Flow Analysis is a technique for gathering information about a possible set of values for each variable calculated at various points of a program. Control flow graph (CFG) is used to identify those parts of the program in which a certain value is assigned to a variable can be propagated.

A definition-use graph is a graph that contains the edges from each variable definition point in the program to every point of its use.

Construction of def-use chain for the base block is trivial. Each variable definition is associated with all subsequent uses of it. Each subsequent redefinition stops and starts a new chain.

In order to use this local graph CFG computed using several sets those characterize the behavior of the block:

• Uses (b): A set of variables used in the block, but have no definitions within the block.
• Defsout (b): A set of definitions that have been made in b, and reached the end of the block.
• Killed (b): A set of definitions that were canceled within a block by other definitions.
• Reaches (b): The set of all definitions made in other units, including b, which can reach b.

To understand what definition will be used in our basic block, it is important to know reaches (b).

It can be constructed via an iterative process that will calculate the reaches (b) through the sets of previous blocks.

```Reaches (b) = U for all predecessors (defsout (p) U (reaches (p) ? ¬ killed (p))
```

The problem is that in the presence of loops, the set reaches(b) may depend on the reaches (b). If we will repeat this equation many times for each basic block CFG – final decision can be get.

Constructed sets are used for many scalar optimizations such as dead code elimination, constant propagation and etc. The main problem of this approach is a large number of edges in the Def-Use graph and a great time for calculation of these sets. As result a lot of resources are needed for processing. Рис. 3.14.

This example illustrates the problem. Definitions of S1, S2, S3 pass through the top of S4. Since each definition reaches every use, there are nine edges. Static single assignment form (SSA) was proposed to simplify DEF/USE chain.

< Лекция 2 || Лекция 3: 12345 || Лекция 4 >

### Студенты

Еленеа Бобко
 Беларусь, Минск
Dunduk Dunduk
 Россия