18
Investigation of flow graphs optimization methods used in optimizing compilers Eugene Gavrin – MSc student

Investigation of flow graphs optimization methods used in optimizing compilers

Embed Size (px)

DESCRIPTION

Investigation of flow graphs optimization methods used in optimizing compilers. Eugene Gavrin – MSc student. Universal compiler back-end. Tasks. Develop an universal internal representation of the program based on formal computational model - PowerPoint PPT Presentation

Citation preview

Page 1: Investigation of flow graphs optimization methods used in optimizing compilers

Investigation of flow graphs optimization methods used in optimizing compilers

Eugene Gavrin – MSc student

Page 2: Investigation of flow graphs optimization methods used in optimizing compilers

Universal compiler back-end

Load IR

Common optimizations

Program analysis

Unload to IR

IR

IR

Program analysis

Page 3: Investigation of flow graphs optimization methods used in optimizing compilers

Tasks

• Develop an universal internal representation of the program based on formal computational model

• Implement the set of common compiler optimizations

Page 4: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 5: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 6: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 7: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 8: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 9: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• AST• Control flow graph• Data flow graph• Call graph• Dependency graph• ...

Page 10: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation

• Oriented graph• Nodes are functional

operators• Vertexes are data

dependencies• Each operator stores:

– Operation name– Input and output data

links– Meta data

31 86

10

Functional40

10

Functional197

69

81

116

7

Condition

TRUE100

P

3

106

114

4

X

Left

FALSE66

P

7

94

99

4

X

Right

TRUE FALSE

TRUE

3

7

If47

Page 11: Investigation of flow graphs optimization methods used in optimizing compilers

Internal representation (branching)

• Extended data flow model by Davis & Keller

• Selector and Distributor represents conditional statements

• Enough to represent any control operator– If / Switch– For / While

Page 12: Investigation of flow graphs optimization methods used in optimizing compilers

Optimizing transformations

• Constant folding;• Sub-expression evaluation;• Strength reduction;• Null sequences;• Combine operators;• Loop optimizations;• Branch Elimination;

Page 13: Investigation of flow graphs optimization methods used in optimizing compilers

Constant folding

Before After

printf

6

7 5

+

*

printf

3 2

Page 14: Investigation of flow graphs optimization methods used in optimizing compilers

Sub-expression evaluation

Before After

1

1

2

2

3

3

4

5

1

2

3

4

5

[1] (0/1)

var

Page 15: Investigation of flow graphs optimization methods used in optimizing compilers

Dead code elimination

Before

In

Hello World

Out

main

R

R

Dead code

After

In

Hello World

Out

main

R

R

Page 16: Investigation of flow graphs optimization methods used in optimizing compilers

Direct conversion

Before After

1

Slow op

Slow op

2

1

Fast op

2

Page 17: Investigation of flow graphs optimization methods used in optimizing compilers

Future plans

• СIL processing (.NET assembly)– Load– Unload– Compare results with MSFT .NET compiler

• Static program analysis

Page 18: Investigation of flow graphs optimization methods used in optimizing compilers

Q&A