






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
University of Illinois at Urbana-Champaign. What is a Compiler? Compiler ≡ A program that translates code in one language (source code) to code in.
Typology: Lecture notes
1 / 12
This page cannot be seen from the preview
Don't miss anything!
CS 426 Lecture 1: Course Overview
A program that translates code in one language (source code
) to code in
another language (target code
).
Usually, target code is semantically equivalent to source code, but not always! Examples
C++ to Sparc assembly C++ to C (some C++ compilers work this way) Java to JVM bytecode High Performance Fortran (HPF: a parallel Fortran language)to Fortran: a parallelizing compiler C to C (or any language to itself): Why? Make code faster, or smaller, or instrument for performance
CS 426 Lecture 1: Course Overview
Code generation:
To translate a program in a high-level language to machine
code for a particular processor Optimization:
Improve program performance for a given target machine
Text formatters:
translate TeX to dvi, dvi to postscript, etc.
Interpreters:
“on-the-fly” translation of code, e.g., Java, Perl, csh, Postscript
Automatic parallelization or vectorization Debugging aids:
e.g., purify for debugging memory access errors
Performance instrumentation:
e.g., -pg option of cc or gcc for profiling
Security:
JavaVM uses compiler analysis to prove safety of Java code
Many more cool uses!
Hardware design / synthesis, power management,
code compression, fast simulation of architectures, transparentfault-tolerance,
Key:
Ability to extract properties of a program (analysis),
and optionally transform it (synthesis)
CS 426 Lecture 1: Course Overview
1
2
3
j = 4;
Induction Variable Substitution (SUBST),
4
Strength Reduction
5
Loop-Invariant Code Motion (LICM)
6
while (j <= 400) {
Linear Function Test Replacement (LFTR)
7
Dead Code Elimination (DCE) for i * 4
8
N = j * N;
9
DCE of A, since A not aliased to B or C
10
tmp = Y * N;
11
B[j] =
tmp;
12
C[j] =
tmp * C[j];
Common Subexpression Elimination (CSE)
13
j = j + 4;
Induction Variable Substitution,
14
Strength Reduction
15
16
printArray(B, 400); 17
printArray(C, 400);
CS 426 Lecture 1: Course Overview
!"#$%&$'()#$
*+'$ ,$"$%)#(+"-
!
*+'$ ./#(&(0)#(+"
"#$% &%'%()*+#'
,%-+.)/0')/12+
31'*)-0')/12+
3%4)'*+.0')/12+2!
!"#$%&'"(&
)*$+&,'"(&
5$%'*+6178#($ 1$23+%'45-('$"#(6($%45-+/$%)#+%45-"7&8$%
5$%'+6172(9.*9(% 9:/%$44(+"45-4#)#$&$"#45-'$;<)%)#(+"45-67";#(+"
5$%'*+6174%)'+':^ =2/$45-+>$%<+)'("?
&%'%()*%75; @2"#A$4(0$-("#$%")<-%$/%$4$"#)#(+"-6%+&/)%4$-#%$$
<()'26#(475;^ B+'(62-;+'$#+-(&/%+>$/$%6+%&)";$
&%'%()%7<)(:%7"#$%^ =%)"4<)#$-!C-#+-#)%?$#<)"?7)?$-D$E?E5-)44$&8<2F
!"#$%&
'()&$*)$$
+,
+,
'()&$-)$$-./012"3-(23$
!" !"#$"%&'"($)
CS 426 Lecture 1: Course Overview
The structure of a compiler
Intermediate representations
Runtime storage management (excluding garbage collection)
Intermediate code generation
Machine code generation
Overview: Instruction selection, register allocation, instruction scheduling Global register allocation by graph coloring
Code Optimization
Peephole optimizations Control flow graphs and analysis Static Single Assignment (SSA) form Introduction to iterative dataflow analysis SSA and iterative dataflow optimizations
CS 426 Lecture 1: Course Overview
An Optimizing Compiler for COOL using C++
Source Language: COOL
Object-oriented language similar to Java But small and very well-defined: syntax
and
semantics
Target Language: LLVM Virtual Instruction Set
Both
intermediate representation
and
assembly language
Designed for effective language-independent optimization
Project phases
MP1:
Scanning and Parsing
: COOL to Abstract Syntax Tree (AST)
MP2:
Intermediate code gen., Part 1
: AST to LLVM, local expressions only
MP3:
Intermediate code gen., Part 2
: AST to LLVM, all of COOL
MP4:
Native code gen
: Basic graph-coloring regalloc for LLVM to X86-
Unit Project:
A mid-level dataflow optimization pipeline using SSA: ADCE,
ConstProp, LICM, DomTreeCSE, plus optional passes (e.g., store hoisting,SROA, devirtualization+inlining)
CS 426 Lecture 1: Course Overview
Get the big picture:
Why are we doing this? Why is it important?
Understand the basic principles:
If you know how to apply them, you can work out the details
Learn why things work a certain way:
Automatic vs. manual, elegant vs. ad hoc,solved problem vs. open
Think about the cost-benefit trade-offs:
Performance vs. correctness, compile-time vs. payoff
CS 426 Lecture 1: Course Overview
–British parliamentarian
Do the exercises in class; read the text and notes Start the assignment the day it’s handed out,not the day it’s due Pay attention to the discussions Ask questions, and participate