Welcome Simone Campanoni simoneceecs northwestern edu Outline Structure

  • Slides: 47
Download presentation
Welcome! Simone Campanoni simonec@eecs. northwestern. edu

Welcome! Simone Campanoni simonec@eecs. northwestern. edu

Outline • Structure of the course • Example of a code analysis and transformation

Outline • Structure of the course • Example of a code analysis and transformation (CAT) • CAT and compilers • CAT and computer architecture • CAT and programming language

CAT in a nutshell • About: understanding and transforming code automatically • EECS 395/495

CAT in a nutshell • About: understanding and transforming code automatically • EECS 395/495 • Satisfy the system depth for CS major • Tuesday/Thursday 2: 00 pm – 3: 20 pm at L 221 Tech (here ; )) • Office hours: Friday 2: 00 pm – 5: 00 pm • But feel free to stop by at my office (2. 217@Ford) any time • CAT is on Canvas • Materials/Calendar/Assignments/Grades on Canvas • You’ll upload your assignments on Canvas

CAT materials • Compilers: Principles, Techniques, and Tools • Slides and assigned papers •

CAT materials • Compilers: Principles, Techniques, and Tools • Slides and assigned papers • LLVM documentation http: //llvm. org

The CAT structure Topic & homework Today Project discussion Topic & project 11/12 11/19

The CAT structure Topic & homework Today Project discussion Topic & project 11/12 11/19 12/3 12/8 Week Tuesday Thursday Homework 12/10

The CAT structure Topic & homework Today 11/12 11/19 Week Tuesday Project Thursday Project

The CAT structure Topic & homework Today 11/12 11/19 Week Tuesday Project Thursday Project discussion Topic & project 12/3 12/8 12/10 Week Tuesday Thursday

The CAT structure Topic & homework Today Topic & project 11/12 11/19 Project discussion

The CAT structure Topic & homework Today Topic & project 11/12 11/19 Project discussion 12/3 12/8 12/10 Week Tuesday Whole class discussion Thursday Whole class discussion

The CAT grading • Homework: 70 points • 10 points per assignment • Project:

The CAT grading • Homework: 70 points • 10 points per assignment • Project: 20 points • Final result • Paper • Final discussion: 10 points Grade Points A AB+ B C D F 95 – 100 90 – 94 80 – 89 61 – 79 50 - 60 25 – 49 0 - 24

Rules for homework & final project • No copying of code is allowed •

Rules for homework & final project • No copying of code is allowed • Tool, infrastructure help is allowed • First try it on your own (google and tool documentation are your friend) • You must report who helped you and how on your reports • Avoid plagiarism www. northwestern. edu/provost/policies/academic-integrity/how-to-avoid-plagiarism. html • If you don’t know, please ask simonec@eecs. northwestern. edu

Summary • My duties x e m a • Teach you code analysis and

Summary • My duties x e m a • Teach you code analysis and transformation • Your duties l a if n • Learn code analysis and transformation • Implement a few of them in LLVM • Write code • Write reports for each homework o N • Implement a final project • Write code • Write a final document about your project • Prepare a presentation and be ready for discussion

Structure & flexibility • CAT is structured w/ topics • Best way to learn

Structure & flexibility • CAT is structured w/ topics • Best way to learn is to be excited about a topic • Interested in something? Speak I’ll do my best to include your topic on the fly

The CAT structure Topic & homework Topic & project Project discussion Week 1 Today

The CAT structure Topic & homework Topic & project Project discussion Week 1 Today • Welcome/Structure • Compiler/CAT F. E. M. E. B. E. Thursday LLVM

The role of compilers If there is no coffee, if I still have work

The role of compilers If there is no coffee, if I still have work to do, I’ll keep working, I’ll go to the coffee shop Code analysis and transformation If there is no coffee{ if I still have work to do{ I’ll keep working; } I’ll go to the coffee shop; } Compilers ? ? ? 0010111001010101011010

Theory Compilers & CATs ct ic Pr a fie terld s e In

Theory Compilers & CATs ct ic Pr a fie terld s e In

Example of CAT What will it print? var. X = 5 … … print

Example of CAT What will it print? var. X = 5 … … print var. X …

Example of CAT What will it print? var. X = 5 … … print

Example of CAT What will it print? var. X = 5 … … print 5 … print var. X

Example of CAT var. X = 5 … … print 5 … var. X

Example of CAT var. X = 5 … … print 5 … var. X = 5 … … print var. X … Is it worth transforming? Code Analysis Property Transformatio n Transformed code

Designing CATs • Choose a goal • Performance, energy, finding bugs, discovering properties •

Designing CATs • Choose a goal • Performance, energy, finding bugs, discovering properties • Design automatic analysis to obtain the required information • Occasionally design the code transformation

Use of CATs • Compilers • Optimize performance • energy efficiency • code generation

Use of CATs • Compilers • Optimize performance • energy efficiency • code generation • Developing tools • Understanding code • Computer architecture

Structure of a compiler Character stream (Source code) i n t ma i n

Structure of a compiler Character stream (Source code) i n t ma i n … Lexical analysis Tokens Syntactic & semantic analysis AST INT SPACE STRING SPACE … int main. Function (){ signature printf(“Hello World!n”); Function name Return type return 0; STRING } INT

Structure of a compiler Character stream (Source code) i n t ma i n

Structure of a compiler Character stream (Source code) i n t ma i n … Lexical analysis Tokens Syntactic & semantic analysis AST INT SPACE STRING SPACE … Function signature Return type INT Function name STRING

Structure of a compiler Syntactic & semantic analysis AST Function signature Return type INT

Structure of a compiler Syntactic & semantic analysis AST Function signature Return type INT Function name STRING IR code generation IR ; Function Attrs: nounwind uwtable define int @main() {

Structure of a compiler Character stream (Source code) Front-end IR Middle-end IR i n

Structure of a compiler Character stream (Source code) Front-end IR Middle-end IR i n t ma i n … EECS 322: Compiler Construction ; Function Attrs: nounwind uwtable define int @main() { Code analysis and transformation ; Function Attrs: nounwind uwtable define int @main() { Back-end EECS 322: Compiler Construction Machine code 01010111010101

Structure of a compiler Character stream (Source code) Front-end IR Middle-end Character stream (Source

Structure of a compiler Character stream (Source code) Front-end IR Middle-end Character stream (Source code) Front-end Middle-end Back-end IR Back-end Machine code

Structure of a compiler C Front-end IR Middle-end Java C Front-end Middle-end Back-end IR

Structure of a compiler C Front-end IR Middle-end Java C Front-end Middle-end Back-end IR Back-end Machine code

Structure of a compiler C Front-end IR Middle-end Java Front-end Middle-end Back-end IR Back-end

Structure of a compiler C Front-end IR Middle-end Java Front-end Middle-end Back-end IR Back-end Machine code

Structure of a compiler C Java Front-end FE IR Middle-end Java Front-end Middle-end Back-end

Structure of a compiler C Java Front-end FE IR Middle-end Java Front-end Middle-end Back-end IR Back-end Machine code M 2 Machine code

Structure of a compiler C Java Front-end FE IR Middle-end Java Front-end Middle-end Back-end

Structure of a compiler C Java Front-end FE IR Middle-end Java Front-end Middle-end Back-end IR Back-end BE Machine code M 2

Structure of a compiler L 1 L 2 Front-end 1 Front-end 2 IR Middle-end

Structure of a compiler L 1 L 2 Front-end 1 Front-end 2 IR Middle-end IR Back-end A MA Back-end B MB

Multiple IRs • Abstract Syntax Tree R 1 + R 2 R 3 •

Multiple IRs • Abstract Syntax Tree R 1 + R 2 R 3 • Register-based representation (three-address code) R 1 = R 2 add R 3 • Stack-based representation push 5; push 3; add; pop ;

Example of LLVM IR define i 32 @main(i 32 %argc, i 8** %argv) {

Example of LLVM IR define i 32 @main(i 32 %argc, i 8** %argv) { entry: %add = add i 32 %argc, 1 ret i 32 %add }

Multiple IRs used together L 1 Static compiler IR 1 Dynamic compiler FE IR

Multiple IRs used together L 1 Static compiler IR 1 Dynamic compiler FE IR 2 Dynamic compiler BE Machine code

Multiple IRs used together Java compiler Java bytecode Java VM FE IR 2 Java

Multiple IRs used together Java compiler Java bytecode Java VM FE IR 2 Java VM BE Machine code

CATs that we’ll focus on • Semantics-preserving transformations • Correctness guaranteed • Goal: performance

CATs that we’ll focus on • Semantics-preserving transformations • Correctness guaranteed • Goal: performance • Automatic • Efficient

Evolution of CATs (hardware point of view) • Simple hardware (few resources), simple CATs

Evolution of CATs (hardware point of view) • Simple hardware (few resources), simple CATs Core Size Registers Latency Cache L 1 Cache L 2 Memory

Evolution of CATs (hardware point of view) • Simple hardware (few resources), simple CATs

Evolution of CATs (hardware point of view) • Simple hardware (few resources), simple CATs Compilers/CATs • Opportunities to improve programs • Challenging CATsare developed in the processor-design stage! • Execution model mismatch between • More hardware resources available to compilers source code and hardware • Challenging CATs

Evolution of CATs (hardware point of view) (2) 1960 - ? : Complex instruction

Evolution of CATs (hardware point of view) (2) 1960 - ? : Complex instruction set computing (CISC) 1980 - ? : Reduced instruction set computer (RISC)

Evolution of CATs (hardware point of view) (3) Very long instruction word (VLIW) Superscalar

Evolution of CATs (hardware point of view) (3) Very long instruction word (VLIW) Superscalar Inst 1 Inst 2 Inst 3 Inst 4 Inst 5 Inst 6 Inst 7 Inst 8 CATs Inst 1 Inst 4 Inst 7 Inst 8 Inst 2 Inst 5 Inst 3 Inst 6

Evolution of CATs (PL point of view) • Low level programming language, simple CATs

Evolution of CATs (PL point of view) • Low level programming language, simple CATs • Not very productive • More abstraction in programming language, more work for CATs to reduce their performance impact • CATs enable new programming languages

Evolution of CATs (PL point of view)(2) PL without procedures void main (){ String

Evolution of CATs (PL point of view)(2) PL without procedures void main (){ String s 1, s 2; s 1. append(‘c’); s 2. append(‘c’); }

Evolution of CATs (PL point of view)(3) Let’s add procedures to our PL •

Evolution of CATs (PL point of view)(3) Let’s add procedures to our PL • Call-by-Value void proc 1 (int a){…} proc 1(my. Var 1) • Call-by-Reference void proc 1 (String a){…} proc 1(my. String 1)

Evolution of CATs (PL point of view)(2) void my. Proc (String s 1, String

Evolution of CATs (PL point of view)(2) void my. Proc (String s 1, String s 2){ s 1. append(‘a’); s 2. append(‘c’); }

Conclusion • CATs used for multiple goals • Enable PLs • Enable hardware features

Conclusion • CATs used for multiple goals • Enable PLs • Enable hardware features • CATs are effected by • Their input language • The target hardware

Ideal CATs • Proved to be correct • Improve performance of many important programs

Ideal CATs • Proved to be correct • Improve performance of many important programs • Minor compilation time • Negligible implementation efforts

Demo time

Demo time