investigation of flow graphs optimization methods used in optimizing compilers
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 PresentationTRANSCRIPT
![Page 1: Investigation of flow graphs optimization methods used in optimizing compilers](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/1.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/13.jpg)
Constant folding
Before After
printf
6
7 5
+
–
*
printf
3 2
![Page 14: Investigation of flow graphs optimization methods used in optimizing compilers](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062720/5681351a550346895d9c6f68/html5/thumbnails/18.jpg)
Q&A