LLVM, in Greater Detail
Thanks to Gabe Weisz for some content.
1
Outline
Navigating and changing the IR
The machine type system
Using and writing passes
2
LLVM Overview
C+-based compiler framework
(Fairly) well documented API
Structures to help you proces
Lecture
Lecture 7
More Examples of Data Flow Analysis:
Global Common Subexpression Elimination;
Constant Propagation/Folding
I. Available Expressions Analysis
II. Eliminating CSEs
CSE
III.Constant Propagation/Folding
Reading: 9.2.6, 9.4
Carnegie Mellon
To
Lecture 8
Loop
Loop Invariant Computation
and Code Motion
I.
Finding loops
II. Loop-invariant computation
III. Algorithm for code motion
Carnegie Mellon
Todd C. Mowry
15-745: Loop Invariance
1
What is a Loop?
Goals:
Define a loop in graph-theoretic terms
Lecture 9
Induction
Induction Variables and
Strength Reduction
I.
Overview of optimization
II. Algorithm to find induction variables
Carnegie Mellon
Todd C. Mowry
15-745: Strength Reduction
1
Example
FOR i = 0 to 100
A[i] = 0;
i=0
L2: IF i>=100 GOTO L1
t1
Lecture 10
Partial Redundancy Elimination
Global code motion optimization
Remove partially redundant expressions
Loop invariant code motion
Can be extended to do Strength Reduction
No loop analysis needed
Bidirectional flow problem
Carnegie Mellon
Todd
Lecture 11
Lazy Code Motion
I.
Forms of redundancy (quick review)
global common subexpression elimination
loop invariant code motion
partial redundancy
II. Lazy Code Motion Algorithm
Al
Mathematical concept: a cut set
Basic technique (anticipation)
3 more
Lecture 12
Region-Based Analysis
I. Basic Idea
II. Algorithm
III. Optimization and Complexity
IV. Comparing region-based analysis with iterative
algorithms
algorithms
Reading: ALSU 9.7
Carnegie Mellon
Todd C. Mowry
15-745: Region-Based Analysis
1
Motivati
Lecture 13
Introduction
Introduction to
Static Single Assignment (SSA)
(Slides courtesy of Seth Goldstein.)
Carnegie Mellon
Todd C. Mowry
15-745: Intro to SSA
1
Values Locations
for (i=0; i+; i<10) cfw_
= i ;
Def-use chains help solve the problem.
for (
Lecture 14
SSA-Style Optimizations
(Slides courtesy of Seth Goldstein.)
Carnegie Mellon
Todd C. Mowry
15-745: SSA-Style Optimizations
1
Review: Minimal SSA
Each assignment generates a fresh variable.
At each join point insert functions for all live variab
Lecture 15
Register Allocation & Spilling
I. Introduction
II. Abstraction and the Problem
III. Algorithm
IV. Spilling
Reading: ALSU 8.8.4
Carnegie Mellon
Todd C. Mowry
15-745: Register Allocation
1
I. Motivation
Problem
Allocation of variables (pseudo-re
Lecture 16
Register Allocation:
Coalescing
(Slides courtesy of Seth Goldstein and David Koes.)
Carnegie Mellon
Todd C. Mowry
15-745: Register Spilling
1
Review: An Example, k=4
v <-
1
w <-
v+3
x <-
w+v
u <-
v
t <-
u+x
<-
w
<-
t
<-
u
Carnegie Mellon
Todd C