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

Optimizing compiler Scalar optimizations

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

Control Flow Graph

A Control Flow Graph (CFG) represents all paths through a program control could travers during its execution. In a control flow graph each node represents a basic block (a straight-line piece of code without any jumps or jump targets). Jump target starts a block, and jump ends a block. Directed edges are used to represent jumps of the control. There are two specially designated blocks: the entry block, through which control enters into the flow graph, and the exit block, through which all control flow leaves.

The CFG is essential to many compiler optimizations.

 CFG example

Рис. 3.6. CFG example

Рис. 3.7.

Scalar optimizations

There are well-known scalar optimizations such as constant folding, constant propagation and copy propagation.

Constant folding is a process of calculating a constants at compile time.

Constant propagation is substitution of variables with known constant values by these values in the expression.

Рис. 3.8.

Copy propagation is substitution of variables by their values.

Рис. 3.9.

Common subexpressions elimination

Search for identical subexpressions and saving the calculation result in a temporary variable for later reuse.

Рис. 3.10.

Dead code elimination

Removal of code that does not change the output of the program.

Рис. 3.11.

There are many cases when dead code can appear. It can be the result of scalar optimizations, inlining, etc.

< Лекция 2 || Лекция 3: 12345 || Лекция 4 >
Еленеа Бобко
Еленеа Бобко
Беларусь, Минск
Dunduk Dunduk
Dunduk Dunduk