Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 426 Lecture 1: Course Overview, Lecture notes of Programming Languages

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

2022/2023

Uploaded on 05/11/2023

oliver97
oliver97 🇺🇸

4.4

(43)

324 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 426 Lecture 1: Course Overview
University of Illinois at Urbana-Champaign
What is a Compiler?
Compiler 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 . . .
Lecture 1: Course Overview p. 1/12
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CS 426 Lecture 1: Course Overview and more Lecture notes Programming Languages in PDF only on Docsity!

CS 426 Lecture 1: Course Overview

What is a Compiler?^ Compiler University of Illinois at Urbana-Champaign

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

... Lecture 1: Course Overview – p. 1/

CS 426 Lecture 1: Course Overview

Uses of Compiler Technology University of Illinois at Urbana-Champaign

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

A Code Optimization Example: Result University of Illinois at Urbana-Champaign

1

X = ...

2

N = 1;

3

j = 4;

Induction Variable Substitution (SUBST),

4

Strength Reduction

5

Y = X * 2.0;

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

Classical Structure of a Compiler University of Illinois at Urbana-Champaign

!"#$%&$'()#$

*+'$ ,$"$%)#(+"-

!

*+'$ ./#(&(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

Topical Outline University of Illinois at Urbana-Champaign

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

Programming Projects University of Illinois at Urbana-Champaign

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

Getting The Most Out Of Any Class^ “Education is what survives when what has been learnedUniversity of Illinois at Urbana-Champaign

has been forgotten.”

–B. F. Skinner,

New Scientist

, May 21, 1964.

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

Getting The Most Out Of This Class University of Illinois at Urbana-Champaign

“Sir, I can give you an explanation

but not an understanding!”

–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