SlideShare a Scribd company logo
1 of 142
Download to read offline
馴龍⾼⼿101-淺談現代編譯技術
Min-Yih Hsu 許⺠易 <minyihh@uci.edu>
How to Train Your Dragon
- Intro to Modern Compiler Techniques
Who Am I?
Who Am I?
• Computer Science PhD @ UCI
Who Am I?
• Computer Science PhD @ UCI
• Interests: Compiler, Static Analysis,
System Software
Who Am I?
• Computer Science PhD @ UCI
• Interests: Compiler, Static Analysis,
System Software
• LLVM Contributor
Who Am I?
• Computer Science PhD @ UCI
• Interests: Compiler, Static Analysis,
System Software
• LLVM Contributor
• Chocolate and Coffee Junkies
Who Am I?
• Computer Science PhD @ UCI
• Interests: Compiler, Static Analysis,
System Software
• LLVM Contributor
• Chocolate and Coffee Junkies
• https://myhsu.xyz
What is Compiler?
What is Compiler?
void main() {
printf(“Hello World!n”);
}
What is Compiler?
void main() {
printf(“Hello World!n”);
}
What is Compiler?
void main() {
printf(“Hello World!n”);
}
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Computer Human
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
Computer Human
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
Computer Human
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
Computer Human
Computer Human
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
Undergrad Compiler Class Like…
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
Computer Human
Computer Human
What is Compiler?
void main() {
printf(“Hello World!n”);
}
C:/> my_first_program
Hello World!
Compiler
Computer Human
Computer Human
EASY
PEASY
THE END
THE END
Why Compilers are NOT Easy?
Why Dragon?
Why Dragon?
Why Dragon?
Why Dragon?
Why Dragon?
Why Dragon?
Why Dragon?
“Complexity of Compiler Design”
(Some) Sources of Complexities
(Some) Sources of Complexities
• Translation
• How do I translate source code into machine binary?
(Some) Sources of Complexities
• Translation
• How do I translate source code into machine binary?
• Optimization
• How do I generate machine binaries that run fast?
(Some) Sources of Complexities
• Translation
• How do I translate source code into machine binary?
• Optimization
• How do I generate machine binaries that run fast?
• Portability
• How do I support N different programming languages and M
different machines in the same compiler?
(Some) Sources of Complexities
• Translation
• How do I translate source code into machine binary?
• Optimization
• How do I generate machine binaries that run fast?
• Portability
• How do I support N different programming languages and M
different machines in the same compiler?
Optimizations
Why We Need Compiler Optimizations?
int foo(int x) {
return x + x + x + x +…(1000 times);
}
Source Code
Why We Need Compiler Optimizations?
int foo(int x) {
return x + x + x + x +…(1000 times);
}
Source Code
r0 = add x, x
r1 = add r0, x
r2 = add r1, x
r3 = add r2, x
…
result = add r997, x
“Naive” Machine Code
Why We Need Compiler Optimizations?
int foo(int x) {
return x + x + x + x +…(1000 times);
}
Source Code
r0 = add x, x
r1 = add r0, x
r2 = add r1, x
r3 = add r2, x
…
result = add r997, x
“Naive” Machine Code
result = mul x, 1000
Optimal Machine Code
Why We Need Compiler Optimizations?
int foo(int x) {
return x + x + x + x +…(1000 times);
}
Source Code
r0 = add x, x
r1 = add r0, x
r2 = add r1, x
r3 = add r2, x
…
result = add r997, x
“Naive” Machine Code
result = mul x, 1000
Optimal Machine Code
“IMPOSSIBLE for programmers to write these!”
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
a = 10 * 1000 = 10000
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
a = 10 * 1000 = 10000
b = 5 * 1000 = 5000
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
a = 10 * 1000 = 10000
b = 5 * 1000 = 5000
a + b = 10000 + 5000 = 15000
Why We Need Compiler Optimizations?
int bar() {
return 15000;
}
Expected
Why We Need Compiler Optimizations?
int bar() {
return 15000;
}
Expected
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
Compiler w/o
Optimization
Why We Need Compiler Optimizations?
int bar() {
return 15000;
}
Expected
int foo(int x) {
return x * 1000;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
Compiler w/o
Optimization
“IMPOSSIBLE for programmers to write these!”
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r > 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r > 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
………
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
if(n % 4 != 0) return 0;
return bar() * (n / 4);
}
Why We Need Compiler Optimizations?
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers.
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers. “IMPOSSIBLE!”
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers.
• Not every code can be “optimized” by human.
“IMPOSSIBLE!”
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r >= 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r >= 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
Another Number
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r >= 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
Another Number
Another Number
Why We Need Compiler Optimizations?
int foo(int x) {
return x * 1000;
}
int bar() {
return 15000;
}
int zoo(int n) {
int sum = 0;
if(n % 4 != 0) return 0;
for(int i=0; i < n; i++) {
int e = 1;
for(int r = i % 4; r >= 0; r-=1) {
e *= 2;
}
sum += foo(e);
}
return sum;
}
Another Number
Another Number
?
Why We Need Compiler Optimizations?
“IMPOSSIBLE!”
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers.
• Not every code can be “optimized” by human!
• Programmers can focus on program logics.
“IMPOSSIBLE!”
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers.
• Not every code can be “optimized” by human!
• Programmers can focus on program logics.
• Without putting too many attentions on optimizing code.
“IMPOSSIBLE!”
Why We Need Compiler Optimizations?
• Fix stupid code written by programmers.
• Not every code can be “optimized” by human!
• Programmers can focus on program logics.
• Without putting too many attentions on optimizing code.
• Compilers will optimize code for you if applicable.
“IMPOSSIBLE!”
Compiler Optimizations And More
Compiler Optimization and More
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
Compiler Optimization and More
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
Compiler Optimization and More
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
B: Simplify function calls
Compiler Optimization and More
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int bar() {
return 15000;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
What are the values?
Optimization Order Matters!
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int bar() {
int a = 0;
for(int I = 0; I < 1000; I++) {
a += 10;
}
int b = 0;
for(int I = 0; I < 1000; I++) {
b += 5;
}
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int bar() {
int a = 0;
for(int I = 0; I < 1000; I++) {
a += 10;
}
int b = 0;
for(int I = 0; I < 1000; I++) {
b += 5;
}
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Optimization Order Matters!
int bar() {
int a = 0;
for(int I = 0; I < 1000; I++) {
a += 10;
}
int b = 0;
for(int I = 0; I < 1000; I++) {
b += 5;
}
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
What are the values?
Compiler Optimization and More
int foo(int x) {
int sum = 0;
for(int I = 0; I < 8; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
Compiler Optimization and More
Computer
Compiler Optimization and More
Computer
Compiler Optimization and More
Computer
Really Fast
Summation usingVector Adds
x + x + x + x + x + x + x + x
Summation usingVector Adds
x + x + x + x + x + x + x + x
V1 = <x, x, x, x>
Summation usingVector Adds
x + x + x + x + x + x + x + x
V1 = <x, x, x, x> V2 = <x, x, x, x>
Summation usingVector Adds
x + x + x + x + x + x + x + x
V1 = <x, x, x, x> V2 = <x, x, x, x>
V1 + V2 = <2x, 2x, 2x, 2x>
Summation usingVector Adds
Original: 8 summations
x + x + x + x
+ x + x + x + x
= 8x
Summation usingVector Adds
<x, x, x, x, x, x, x, x>
<2x, 2x, 2x, 2x>
<4x, 4x>
<8x>
Original: 8 summations New: 3 summations
x + x + x + x
+ x + x + x + x
= 8x
Portability
C/C++
Go
Swift
X86
ARM
Multi-Language and Machine:Traditional Approach
C/C++
Go
Swift
X86
ARM
Individual compiler
Multi-Language and Machine:Traditional Approach
C/C++
Go
Swift
X86
ARM
Individual compiler
Multi-Language and Machine:Traditional Approach
C/C++
Go
Swift
X86
ARM
Individual compiler
?
Multi-Language and Machine
Multi-Language and Machine
Intermediate Representation (IR)
Multi-Language and Machine
C/C++ to IR
Go to IR
Swift to IR
Intermediate Representation (IR)
Multi-Language and Machine
Optimizer
Working on IR
C/C++ to IR
Go to IR
Swift to IR
Intermediate Representation (IR)
Multi-Language and Machine
Optimizer
Working on IR
C/C++ to IR
Go to IR
Swift to IR
Intermediate Representation (IR)
IR to X86
IR to ARM
Recap: Compiler Optimizations
int foo(int x) {
int sum = 0;
for(int I = 0; I < 1000; I++) {
sum += x;
}
return sum;
}
int bar() {
int a = foo(10);
int b = foo(5);
return a + b;
}
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
C/C++
Go
Swift
X86
ARM
Individual compiler
Multi-Language and Machine:Traditional Approach
Need 6 versions of
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
Multi-Language and Machine
Optimizer
Working on IR
C/C++ to IR
Go to IR
Swift to IR
Intermediate Representation (IR)
IR to X86
IR to ARM
A: Simplify the loop
B: Simplify function calls
C: Simplify constants
(Only ONE version!)
The IR in Previous Page
The IR in Previous Page
• “Machine Independent”
• Describe the operations instead of telling How to perform them
in different machines.
The IR in Previous Page
• “Machine Independent”
• Describe the operations instead of telling How to perform them
in different machines.
• “IR to X86” and “IR to ARM” .etc would translate IR to specific
machine code.
• This process is usually called lowering.
The IR in Previous Page
• “Machine Independent”
• Describe the operations instead of telling How to perform them
in different machines.
• “IR to X86” and “IR to ARM” .etc would translate IR to specific
machine code.
• This process is usually called lowering.
• Developers of optimizations don’t need to worry too much about
the target machine.
PROBLEM SOLVED
PROBLEM SOLVED
Recap:The “Magic”Vector Computer
Computer
Recap:The “Magic”Vector Computer
Computer
What If A Machine
DOESN’T Have This Feature?
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Do you have ?
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Do you have ?
Do you have feature X ?
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Do you have ?
Do you have feature X ?
Do you have feature Y ?
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Do you have ?
Do you have feature X ?
Do you have feature Y ?
Do you have… ?
Common
Optimizer
Language
Intermediate Representation (IR)
Machine
Do you have ?
Do you have feature X ?
Do you have feature Y ?
Do you have… ?
Multiply Rule for Inverse Matrix
A x A-1 = I
Matrix foo(Matrix A) {
return A * inverse(A);
}
A Code Snippet
Case 1: IR Specialized for Certain Machine
proc foo(Matrix $a)-> Matrix {
$b = call inverse($a)
$c = mul $a, $b
return $c
}
Case 1: IR Specialized for Certain Machine
proc foo(Matrix $a)-> Matrix {
$b = call inverse($a)
$c = mul $a, $b
return $c
}
The optimizer says:
“A matrix multiplied with inverted version of itself”
“That’s easy: $c can be replaced with identity matrix!”
Case 2: General IR
int[][] foo(int[][] %a) {
%b = call inverse(%a)
for(…) {
for(…) {
for(…) {…}
}
}
}
Case 2: General IR
int[][] foo(int[][] %a) {
%b = call inverse(%a)
for(…) {
for(…) {
for(…) {…}
}
}
}
Matrix Multiplication
Case 2: General IR
int[][] foo(int[][] %a) {
%b = call inverse(%a)
for(…) {
for(…) {
for(…) {…}
}
}
}
The optimizer says:
“WTF”
“This is too difficult to optimize”
Matrix Multiplication
High engineering cost
Optimizations are specialized
for certain language / machine
High engineering cost
Optimizations are specialized
for certain language / machine
High engineering cost
Shared large portion of
optimization code base
among languages and machine.
Optimizations are specialized
for certain language / machine
High engineering cost
Shared large portion of
optimization code base
among languages and machine.
IR is usually too high-level.
Hard to describe machine
or language-specific optimizations
Compiler Design:Abstraction Level
Specialized
for certain machine / language
General / Re-usable
across different machines / languages
Epilogue
I Hope NowYou BelieveThat…
Compiler
is EASY… 並沒有
I HopeYou Learned…
I HopeYou Learned…
• What is Compiler
I HopeYou Learned…
• What is Compiler
• Why we need compiler optimizations
• Developers can focus on program logics without worrying too
much on runtime performance
I HopeYou Learned…
• What is Compiler
• Why we need compiler optimizations
• Developers can focus on program logics without worrying too
much on runtime performance
• Some details of optimizations I introduced earlier
I HopeYou Learned…
• What is Compiler
• Why we need compiler optimizations
• Developers can focus on program logics without worrying too
much on runtime performance
• Some details of optimizations I introduced earlier
• Difficulty of supporting a compiler for different languages and
machines
I HopeYou Learned…
• What is Compiler
• Why we need compiler optimizations
• Developers can focus on program logics without worrying too
much on runtime performance
• Some details of optimizations I introduced earlier
• Difficulty of supporting a compiler for different languages and
machines
• Difficulty of compilers to choose a proper abstraction level
Compiler
Research
Me
Finally, I HopeYou…
ENJOYED
THE MEMES
~ Thank You ~

More Related Content

What's hot

Programação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesProgramação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesLucas Borsatto
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyRalph Johnson
 
Javascript Styles and some tips
Javascript Styles and some tipsJavascript Styles and some tips
Javascript Styles and some tipsVítor Baptista
 
Mca 2nd sem u-4 operator overloading
Mca 2nd  sem u-4 operator overloadingMca 2nd  sem u-4 operator overloading
Mca 2nd sem u-4 operator overloadingRai University
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de donnéesRomain Lecomte
 
Advanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to FreeAdvanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to FreeLuka Jacobowitz
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)IoT Code Lab
 

What's hot (16)

Programação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesProgramação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin Coroutines
 
Swift School #1
Swift School #1Swift School #1
Swift School #1
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
gd
gdgd
gd
 
Functions
FunctionsFunctions
Functions
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Javascript Styles and some tips
Javascript Styles and some tipsJavascript Styles and some tips
Javascript Styles and some tips
 
F(2)
F(2)F(2)
F(2)
 
F[1]
F[1]F[1]
F[1]
 
F sh3tdkeq
F sh3tdkeqF sh3tdkeq
F sh3tdkeq
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
 
Mca 2nd sem u-4 operator overloading
Mca 2nd  sem u-4 operator overloadingMca 2nd  sem u-4 operator overloading
Mca 2nd sem u-4 operator overloading
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
 
Advanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to FreeAdvanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to Free
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)
 

Similar to [TGSA Academic Friday] How To Train Your Dragon - Intro to Modern Compiler Techniques

The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++Alexander Granin
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Artur Rodrigues
 
JavaScript ∩ WebAssembly
JavaScript ∩ WebAssemblyJavaScript ∩ WebAssembly
JavaScript ∩ WebAssemblyTadeu Zagallo
 
AOP in Python API design
AOP in Python API designAOP in Python API design
AOP in Python API designmeij200
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++Alexander Granin
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystifiedJeroen Resoort
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressionsStoian Kirov
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfmurtuzadahadwala3
 
Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Scott Wlaschin
 
Intel JIT Talk
Intel JIT TalkIntel JIT Talk
Intel JIT Talkiamdvander
 

Similar to [TGSA Academic Friday] How To Train Your Dragon - Intro to Modern Compiler Techniques (20)

The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook

 
JavaScript ∩ WebAssembly
JavaScript ∩ WebAssemblyJavaScript ∩ WebAssembly
JavaScript ∩ WebAssembly
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
AOP in Python API design
AOP in Python API designAOP in Python API design
AOP in Python API design
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystified
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
 
Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
Intel JIT Talk
Intel JIT TalkIntel JIT Talk
Intel JIT Talk
 

More from Min-Yih Hsu

Debug Information And Where They Come From
Debug Information And Where They Come FromDebug Information And Where They Come From
Debug Information And Where They Come FromMin-Yih Hsu
 
MCA Daemon: Hybrid Throughput Analysis Beyond Basic Blocks
MCA Daemon: Hybrid Throughput Analysis Beyond Basic BlocksMCA Daemon: Hybrid Throughput Analysis Beyond Basic Blocks
MCA Daemon: Hybrid Throughput Analysis Beyond Basic BlocksMin-Yih Hsu
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMMin-Yih Hsu
 
How to write a TableGen backend
How to write a TableGen backendHow to write a TableGen backend
How to write a TableGen backendMin-Yih Hsu
 
[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly
[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly
[COSCUP 2021] LLVM Project: The Good, The Bad, and The UglyMin-Yih Hsu
 
Paper Study - Demand-Driven Computation of Interprocedural Data Flow
Paper Study - Demand-Driven Computation of Interprocedural Data FlowPaper Study - Demand-Driven Computation of Interprocedural Data Flow
Paper Study - Demand-Driven Computation of Interprocedural Data FlowMin-Yih Hsu
 
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et al
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et alPaper Study - Incremental Data-Flow Analysis Algorithms by Ryder et al
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et alMin-Yih Hsu
 
Souper-Charging Peepholes with Target Machine Info
Souper-Charging Peepholes with Target Machine InfoSouper-Charging Peepholes with Target Machine Info
Souper-Charging Peepholes with Target Machine InfoMin-Yih Hsu
 
From V8 to Modern Compilers
From V8 to Modern CompilersFrom V8 to Modern Compilers
From V8 to Modern CompilersMin-Yih Hsu
 
Introduction to Khronos SYCL
Introduction to Khronos SYCLIntroduction to Khronos SYCL
Introduction to Khronos SYCLMin-Yih Hsu
 
Trace Scheduling
Trace SchedulingTrace Scheduling
Trace SchedulingMin-Yih Hsu
 
Polymer Start-Up (SITCON 2016)
Polymer Start-Up (SITCON 2016)Polymer Start-Up (SITCON 2016)
Polymer Start-Up (SITCON 2016)Min-Yih Hsu
 
War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)Min-Yih Hsu
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSPMin-Yih Hsu
 

More from Min-Yih Hsu (14)

Debug Information And Where They Come From
Debug Information And Where They Come FromDebug Information And Where They Come From
Debug Information And Where They Come From
 
MCA Daemon: Hybrid Throughput Analysis Beyond Basic Blocks
MCA Daemon: Hybrid Throughput Analysis Beyond Basic BlocksMCA Daemon: Hybrid Throughput Analysis Beyond Basic Blocks
MCA Daemon: Hybrid Throughput Analysis Beyond Basic Blocks
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVM
 
How to write a TableGen backend
How to write a TableGen backendHow to write a TableGen backend
How to write a TableGen backend
 
[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly
[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly
[COSCUP 2021] LLVM Project: The Good, The Bad, and The Ugly
 
Paper Study - Demand-Driven Computation of Interprocedural Data Flow
Paper Study - Demand-Driven Computation of Interprocedural Data FlowPaper Study - Demand-Driven Computation of Interprocedural Data Flow
Paper Study - Demand-Driven Computation of Interprocedural Data Flow
 
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et al
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et alPaper Study - Incremental Data-Flow Analysis Algorithms by Ryder et al
Paper Study - Incremental Data-Flow Analysis Algorithms by Ryder et al
 
Souper-Charging Peepholes with Target Machine Info
Souper-Charging Peepholes with Target Machine InfoSouper-Charging Peepholes with Target Machine Info
Souper-Charging Peepholes with Target Machine Info
 
From V8 to Modern Compilers
From V8 to Modern CompilersFrom V8 to Modern Compilers
From V8 to Modern Compilers
 
Introduction to Khronos SYCL
Introduction to Khronos SYCLIntroduction to Khronos SYCL
Introduction to Khronos SYCL
 
Trace Scheduling
Trace SchedulingTrace Scheduling
Trace Scheduling
 
Polymer Start-Up (SITCON 2016)
Polymer Start-Up (SITCON 2016)Polymer Start-Up (SITCON 2016)
Polymer Start-Up (SITCON 2016)
 
War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSP
 

Recently uploaded

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

[TGSA Academic Friday] How To Train Your Dragon - Intro to Modern Compiler Techniques

  • 1. 馴龍⾼⼿101-淺談現代編譯技術 Min-Yih Hsu 許⺠易 <minyihh@uci.edu> How to Train Your Dragon - Intro to Modern Compiler Techniques
  • 3. Who Am I? • Computer Science PhD @ UCI
  • 4. Who Am I? • Computer Science PhD @ UCI • Interests: Compiler, Static Analysis, System Software
  • 5. Who Am I? • Computer Science PhD @ UCI • Interests: Compiler, Static Analysis, System Software • LLVM Contributor
  • 6. Who Am I? • Computer Science PhD @ UCI • Interests: Compiler, Static Analysis, System Software • LLVM Contributor • Chocolate and Coffee Junkies
  • 7. Who Am I? • Computer Science PhD @ UCI • Interests: Compiler, Static Analysis, System Software • LLVM Contributor • Chocolate and Coffee Junkies • https://myhsu.xyz
  • 9. What is Compiler? void main() { printf(“Hello World!n”); }
  • 10. What is Compiler? void main() { printf(“Hello World!n”); }
  • 11. What is Compiler? void main() { printf(“Hello World!n”); }
  • 12. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World!
  • 13. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler
  • 14. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World!
  • 15. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Computer Human
  • 16. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Computer Human
  • 17. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Computer Human Computer Human
  • 18. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler Computer Human Computer Human
  • 19. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler Computer Human Computer Human
  • 20. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler Computer Human Computer Human
  • 28. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler Computer Human Computer Human
  • 29. What is Compiler? void main() { printf(“Hello World!n”); } C:/> my_first_program Hello World! Compiler Computer Human Computer Human EASY PEASY
  • 32. Why Compilers are NOT Easy?
  • 39. Why Dragon? “Complexity of Compiler Design”
  • 40. (Some) Sources of Complexities
  • 41. (Some) Sources of Complexities • Translation • How do I translate source code into machine binary?
  • 42. (Some) Sources of Complexities • Translation • How do I translate source code into machine binary? • Optimization • How do I generate machine binaries that run fast?
  • 43. (Some) Sources of Complexities • Translation • How do I translate source code into machine binary? • Optimization • How do I generate machine binaries that run fast? • Portability • How do I support N different programming languages and M different machines in the same compiler?
  • 44. (Some) Sources of Complexities • Translation • How do I translate source code into machine binary? • Optimization • How do I generate machine binaries that run fast? • Portability • How do I support N different programming languages and M different machines in the same compiler?
  • 46. Why We Need Compiler Optimizations? int foo(int x) { return x + x + x + x +…(1000 times); } Source Code
  • 47. Why We Need Compiler Optimizations? int foo(int x) { return x + x + x + x +…(1000 times); } Source Code r0 = add x, x r1 = add r0, x r2 = add r1, x r3 = add r2, x … result = add r997, x “Naive” Machine Code
  • 48. Why We Need Compiler Optimizations? int foo(int x) { return x + x + x + x +…(1000 times); } Source Code r0 = add x, x r1 = add r0, x r2 = add r1, x r3 = add r2, x … result = add r997, x “Naive” Machine Code result = mul x, 1000 Optimal Machine Code
  • 49. Why We Need Compiler Optimizations? int foo(int x) { return x + x + x + x +…(1000 times); } Source Code r0 = add x, x r1 = add r0, x r2 = add r1, x r3 = add r2, x … result = add r997, x “Naive” Machine Code result = mul x, 1000 Optimal Machine Code “IMPOSSIBLE for programmers to write these!”
  • 50. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; }
  • 51. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; } a = 10 * 1000 = 10000
  • 52. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; } a = 10 * 1000 = 10000 b = 5 * 1000 = 5000
  • 53. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; } a = 10 * 1000 = 10000 b = 5 * 1000 = 5000 a + b = 10000 + 5000 = 15000
  • 54. Why We Need Compiler Optimizations? int bar() { return 15000; } Expected
  • 55. Why We Need Compiler Optimizations? int bar() { return 15000; } Expected int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; } Compiler w/o Optimization
  • 56. Why We Need Compiler Optimizations? int bar() { return 15000; } Expected int foo(int x) { return x * 1000; } int bar() { int a = foo(10); int b = foo(5); return a + b; } Compiler w/o Optimization “IMPOSSIBLE for programmers to write these!”
  • 57. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r > 0; r-=1) { e *= 2; } sum += foo(e); } return sum; }
  • 58. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r > 0; r-=1) { e *= 2; } sum += foo(e); } return sum; } ………
  • 59. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { if(n % 4 != 0) return 0; return bar() * (n / 4); }
  • 60. Why We Need Compiler Optimizations?
  • 61. Why We Need Compiler Optimizations? • Fix stupid code written by programmers.
  • 62. Why We Need Compiler Optimizations? • Fix stupid code written by programmers. “IMPOSSIBLE!”
  • 63. Why We Need Compiler Optimizations? • Fix stupid code written by programmers. • Not every code can be “optimized” by human. “IMPOSSIBLE!”
  • 64. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r >= 0; r-=1) { e *= 2; } sum += foo(e); } return sum; }
  • 65. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r >= 0; r-=1) { e *= 2; } sum += foo(e); } return sum; } Another Number
  • 66. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r >= 0; r-=1) { e *= 2; } sum += foo(e); } return sum; } Another Number Another Number
  • 67. Why We Need Compiler Optimizations? int foo(int x) { return x * 1000; } int bar() { return 15000; } int zoo(int n) { int sum = 0; if(n % 4 != 0) return 0; for(int i=0; i < n; i++) { int e = 1; for(int r = i % 4; r >= 0; r-=1) { e *= 2; } sum += foo(e); } return sum; } Another Number Another Number ?
  • 68. Why We Need Compiler Optimizations? “IMPOSSIBLE!”
  • 69. Why We Need Compiler Optimizations? • Fix stupid code written by programmers. • Not every code can be “optimized” by human! • Programmers can focus on program logics. “IMPOSSIBLE!”
  • 70. Why We Need Compiler Optimizations? • Fix stupid code written by programmers. • Not every code can be “optimized” by human! • Programmers can focus on program logics. • Without putting too many attentions on optimizing code. “IMPOSSIBLE!”
  • 71. Why We Need Compiler Optimizations? • Fix stupid code written by programmers. • Not every code can be “optimized” by human! • Programmers can focus on program logics. • Without putting too many attentions on optimizing code. • Compilers will optimize code for you if applicable. “IMPOSSIBLE!”
  • 73. Compiler Optimization and More int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; }
  • 74. Compiler Optimization and More int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop
  • 75. Compiler Optimization and More int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop B: Simplify function calls
  • 76. Compiler Optimization and More int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 77. Optimization Order Matters! A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 78. Optimization Order Matters! int bar() { return 15000; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 79. Optimization Order Matters! int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 80. Optimization Order Matters! int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants What are the values?
  • 81. Optimization Order Matters! A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 82. Optimization Order Matters! int bar() { int a = 0; for(int I = 0; I < 1000; I++) { a += 10; } int b = 0; for(int I = 0; I < 1000; I++) { b += 5; } return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 83. Optimization Order Matters! int bar() { int a = 0; for(int I = 0; I < 1000; I++) { a += 10; } int b = 0; for(int I = 0; I < 1000; I++) { b += 5; } return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 84. Optimization Order Matters! int bar() { int a = 0; for(int I = 0; I < 1000; I++) { a += 10; } int b = 0; for(int I = 0; I < 1000; I++) { b += 5; } return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants What are the values?
  • 85. Compiler Optimization and More int foo(int x) { int sum = 0; for(int I = 0; I < 8; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; }
  • 86. Compiler Optimization and More Computer
  • 87. Compiler Optimization and More Computer
  • 88. Compiler Optimization and More Computer Really Fast
  • 89. Summation usingVector Adds x + x + x + x + x + x + x + x
  • 90. Summation usingVector Adds x + x + x + x + x + x + x + x V1 = <x, x, x, x>
  • 91. Summation usingVector Adds x + x + x + x + x + x + x + x V1 = <x, x, x, x> V2 = <x, x, x, x>
  • 92. Summation usingVector Adds x + x + x + x + x + x + x + x V1 = <x, x, x, x> V2 = <x, x, x, x> V1 + V2 = <2x, 2x, 2x, 2x>
  • 93. Summation usingVector Adds Original: 8 summations x + x + x + x + x + x + x + x = 8x
  • 94. Summation usingVector Adds <x, x, x, x, x, x, x, x> <2x, 2x, 2x, 2x> <4x, 4x> <8x> Original: 8 summations New: 3 summations x + x + x + x + x + x + x + x = 8x
  • 101. Multi-Language and Machine C/C++ to IR Go to IR Swift to IR Intermediate Representation (IR)
  • 102. Multi-Language and Machine Optimizer Working on IR C/C++ to IR Go to IR Swift to IR Intermediate Representation (IR)
  • 103. Multi-Language and Machine Optimizer Working on IR C/C++ to IR Go to IR Swift to IR Intermediate Representation (IR) IR to X86 IR to ARM
  • 104. Recap: Compiler Optimizations int foo(int x) { int sum = 0; for(int I = 0; I < 1000; I++) { sum += x; } return sum; } int bar() { int a = foo(10); int b = foo(5); return a + b; } A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 105. C/C++ Go Swift X86 ARM Individual compiler Multi-Language and Machine:Traditional Approach Need 6 versions of A: Simplify the loop B: Simplify function calls C: Simplify constants
  • 106. Multi-Language and Machine Optimizer Working on IR C/C++ to IR Go to IR Swift to IR Intermediate Representation (IR) IR to X86 IR to ARM A: Simplify the loop B: Simplify function calls C: Simplify constants (Only ONE version!)
  • 107. The IR in Previous Page
  • 108. The IR in Previous Page • “Machine Independent” • Describe the operations instead of telling How to perform them in different machines.
  • 109. The IR in Previous Page • “Machine Independent” • Describe the operations instead of telling How to perform them in different machines. • “IR to X86” and “IR to ARM” .etc would translate IR to specific machine code. • This process is usually called lowering.
  • 110. The IR in Previous Page • “Machine Independent” • Describe the operations instead of telling How to perform them in different machines. • “IR to X86” and “IR to ARM” .etc would translate IR to specific machine code. • This process is usually called lowering. • Developers of optimizations don’t need to worry too much about the target machine.
  • 114. Recap:The “Magic”Vector Computer Computer What If A Machine DOESN’T Have This Feature?
  • 118. Common Optimizer Language Intermediate Representation (IR) Machine Do you have ? Do you have feature X ? Do you have feature Y ?
  • 119. Common Optimizer Language Intermediate Representation (IR) Machine Do you have ? Do you have feature X ? Do you have feature Y ? Do you have… ?
  • 120. Common Optimizer Language Intermediate Representation (IR) Machine Do you have ? Do you have feature X ? Do you have feature Y ? Do you have… ?
  • 121. Multiply Rule for Inverse Matrix A x A-1 = I Matrix foo(Matrix A) { return A * inverse(A); } A Code Snippet
  • 122. Case 1: IR Specialized for Certain Machine proc foo(Matrix $a)-> Matrix { $b = call inverse($a) $c = mul $a, $b return $c }
  • 123. Case 1: IR Specialized for Certain Machine proc foo(Matrix $a)-> Matrix { $b = call inverse($a) $c = mul $a, $b return $c } The optimizer says: “A matrix multiplied with inverted version of itself” “That’s easy: $c can be replaced with identity matrix!”
  • 124. Case 2: General IR int[][] foo(int[][] %a) { %b = call inverse(%a) for(…) { for(…) { for(…) {…} } } }
  • 125. Case 2: General IR int[][] foo(int[][] %a) { %b = call inverse(%a) for(…) { for(…) { for(…) {…} } } } Matrix Multiplication
  • 126. Case 2: General IR int[][] foo(int[][] %a) { %b = call inverse(%a) for(…) { for(…) { for(…) {…} } } } The optimizer says: “WTF” “This is too difficult to optimize” Matrix Multiplication
  • 127.
  • 129. Optimizations are specialized for certain language / machine High engineering cost
  • 130. Optimizations are specialized for certain language / machine High engineering cost Shared large portion of optimization code base among languages and machine.
  • 131. Optimizations are specialized for certain language / machine High engineering cost Shared large portion of optimization code base among languages and machine. IR is usually too high-level. Hard to describe machine or language-specific optimizations
  • 132. Compiler Design:Abstraction Level Specialized for certain machine / language General / Re-usable across different machines / languages
  • 134. I Hope NowYou BelieveThat… Compiler is EASY… 並沒有
  • 136. I HopeYou Learned… • What is Compiler
  • 137. I HopeYou Learned… • What is Compiler • Why we need compiler optimizations • Developers can focus on program logics without worrying too much on runtime performance
  • 138. I HopeYou Learned… • What is Compiler • Why we need compiler optimizations • Developers can focus on program logics without worrying too much on runtime performance • Some details of optimizations I introduced earlier
  • 139. I HopeYou Learned… • What is Compiler • Why we need compiler optimizations • Developers can focus on program logics without worrying too much on runtime performance • Some details of optimizations I introduced earlier • Difficulty of supporting a compiler for different languages and machines
  • 140. I HopeYou Learned… • What is Compiler • Why we need compiler optimizations • Developers can focus on program logics without worrying too much on runtime performance • Some details of optimizations I introduced earlier • Difficulty of supporting a compiler for different languages and machines • Difficulty of compilers to choose a proper abstraction level
  • 142. Finally, I HopeYou… ENJOYED THE MEMES ~ Thank You ~