380C Last Time Today Announcements

advertisement
380C
Last Time
– Course organization
– Read Backus et al.
Today
Announcements
– Hadi lab Q&A Wed
1-2 in Painter 5.38N
– UT Texas Learning
Center: 5 hours of
free writing
consultation,
$13per hour
Lecture 1
CS 380C
– Questions on course
organization?
– What’s a compiler?
– How does it work?
1
What is a compiler?
• A program that translates a program in one
language to another language
– The essential interface between applications &
architectures
• Typically lowers the level of abstraction
– analyzes and reasons about the program &
architecture
• We expect the program to be optimized, i.e.,
better than the original
– ideally exploiting architectural strengths and
hiding weaknesses
Lecture 1
CS 380C
2
When should we compile?
Ahead-of-time: before you run the
program
Offline profiling: compile several times
compile/run/profile.... then run again
Just-in-time: while you run the program
required for dynamic class loading, i.e.,
Java, Python, etc.
Lecture 1
CS 380C
3
Aren’t compilers
a solved problem?
“Optimization for scalar machines is a problem
that was solved ten years ago.”
David Kuck, Fall 1990
Lecture 1
CS 380C
4
Aren’t compilers
a solved problem?
“Optimization for scalar machines is a problem
that was solved ten years ago.”
David Kuck, Fall 1990
•
•
•
•
Lecture 1
Architectures keep changing
Languages keep changing
Applications keep changing - SPEC CPU?
When to compile keeps changing
CS 380C
5
Role of compilers
Bridge complexity and evolution in
architecture, languages, & applications
Help programmers with correctness,
reliability, program understanding
Compiler optimizations can significantly
improve performance
– 1 to 10x on conventional processors
Performance stability: one line change
can dramatically alter performance
– unfortunate, but true
Lecture 1
CS 380C
6
Optimization
What should it do?
Lecture 1
CS 380C
7
Optimization
What should it do?
1. improve running time, or
2. decrease space requirements
3. decrease power consumption
How does it do it?
Lecture 1
CS 380C
8
Analysis
Scope of program analysis
1. within a basic block (local)
2. within a method (global)
3. across methods (interprocedural)
Analysis
1. control flow graph - dominators, loops, etc.
2. dataflow analysis - flow of values
3. static-single-assignment – transform
programs such that each variable has a unique
definition
4. alias analysis - pointer memory usage
5. dependence analysis - array memory usage
Lecture 1
CS 380C
9
Example optimizations
Division of optimizations
1. Machine independent
2. Machine dependent
Faster code optimizations
– common subexpression elimination
– constant folding
– dead code elimination
– register allocation
– scheduling
– loop transformations
Lecture 1
CS 380C
10
Basic Compiler Structure
Higher to lower level
representations, analyses, & transformations
Program
Structural
Scalar Memory Reg. Scheduling
inlining
cse scalar repl Alloc peephole
unrolling
constants ptrs
loop perm expressions
Lecture 1
CS 380C
Machine
code
11
Exciting times
New and changing architectures
 Hitting the microprocessor wall
 multicore, tiled architectures, tiled memory systems
Object-oriented languages becoming dominant paradigm
 Java and C# coming to your OS soon - Jnode, Singularity
 Security and reliability, ease of programming
Key challenges and approaches




Latency & parallelism still key to performance
Language & runtime implementation efficiency
Orchestrating a new software/hardware dance
Break down artificial system boundaries
Feedback
Programmer
Code
H/S Profiling
Compiler
Specification
Lecture 1
CS 380C
Code
Runtime
Future behavior
12
Questions?
Lecture 1
CS 380C
13
Programming Assignment #1
• 380C Lab 1
• Due: Friday 9/11 5pm
• Translate from 3 address code to C
– We provide a high-level language:
• SC: a C-Subset that has functions, recursion, one type
of integer (long==8 bytes), arrays, structs, no floating
point, no pointers, etc.
– We provide “csc” a C-subset compiler that
translates from SC to valid 3 address code
– You translate it back to C code
• Hadi will be available for Q&A Wednesday
9/2 1-2pm (special location).
Lecture 1
CS 380C
14
Overview
Today
– Introduction to
compilers
Lecture 1
Next Time
– program
representation
– control flow
– Read wiki--No
critique on wiki
reading!
CS 380C
15
Download