topic 8: control flow · basic block - run of code with single entry and exit. control flow graph...

28
1 Topic 8: Control Flow COS 320 Compiling Techniques Princeton University Spring 2015 Prof. David August

Upload: others

Post on 23-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

1

Topic 8: Control Flow

COS 320

Compiling Techniques

Princeton University Spring 2015

Prof. David August

Page 2: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

The Front End

Page 3: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

The Back End

Page 4: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Optimization

Page 5: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Register Allocation

Page 6: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Scheduling

Page 7: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Analysis

Page 8: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Control Flow Analysis

Page 9: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Control Flow Analysis Example

Page 10: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Basic Blocks

Page 11: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Basic Block Example

Page 12: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Domination Motivation

Page 13: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Dominator Analysis

Page 14: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Dominator Analysis

Page 15: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Dominator Analysis Example

Page 16: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Immediate Dominator/Dominator Tree

Page 17: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Immediate Dominator Example

Page 18: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Post Dominator

Page 19: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Loop Optimization

Page 20: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Examples of Loops

Page 21: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Back Edges

Page 22: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Natural Loops

Page 23: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Loop Optimization

Page 24: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Loop Optimization

Page 25: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Loop Optimization

Page 26: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Non-Loop Cycles

Page 27: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Non-Loop Cycles

Page 28: Topic 8: Control Flow · Basic Block - run of code with single entry and exit. Control flow graph of basic blocks more convenient. Determine by the following: l. Find leaders: (a)

Node Splitting