Essential Abstractions in GCC
Total Page:16
File Type:pdf, Size:1020Kb
Essential Abstractions in GCC Uday Khedker (www.cse.iitb.ac.in/˜uday) GCC Resource Center, Department of Computer Science and Engineering, Indian Institute of Technology, Bombay 13 June 2014 EAGCC-PLDI-14 EAGCC: Outline 1/1 Outline • Compilation Models • GCC: The Great Compiler Challenge • Meeting the GCC Challenge: CS 715 The course plan Uday Khedker GRC, IIT Bombay Part 1 Compilation Models EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program AST Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program AST Optimizer Target Indep. IR Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program AST Optimizer Target Indep. IR Code Generator Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program Front End AST AST Optimizer Target Indep. IR Code Generator Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program Front End AST AST Expander Optimizer Register Transfers Target Indep. IR Code Generator Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program Front End AST AST Expander Optimizer Register Transfers Target Indep. IR Optimizer Code Generator Register Transfers Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Input Source Program Front End AST AST Expander Optimizer Register Transfers Target Indep. IR Optimizer Code Generator Register Transfers Recognizer Target Program Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 2/1 Compilation Models Aho Ullman Davidson Fraser Model Model Front End Aho Ullman: Instruction selection Front End • over optimized IR using AST AST • cost based tree tiling matching Expander Optimizer Davidson Fraser: Instruction selection • Register Transfers Target Indep. IR over AST using • simple full tree matching based Optimizer algorithms that generate Code Generator • naive code which is Register Transfers ◮ target dependent, and is Recognizer Target Program ◮ optimized subsequently Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 3/1 Typical Front Ends Parser Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 3/1 Typical Front Ends Source Parser Program Tokens Scanner Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 3/1 Typical Front Ends AST or Linear IR Source Parser + Program Symbol Table AST Parse Tokens Tree Semantic Scanner Analyzer Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 3/1 Typical Front Ends AST or Linear IR Source Parser + Program Symbol Table AST Parse Tokens Tree Semantic Scanner Analyzer Symtab Error Handler Handler Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 4/1 Typical Back Ends in Aho Ullman Model m/c Ind. IR m/c Ind. m/c Ind. Optimizer IR − Compile time evaluations − Eliminating redundant computations Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 4/1 Typical Back Ends in Aho Ullman Model m/c Ind. IR m/c Ind. m/c Code m/c Ind. Dep. Optimizer IR Generator IR − Compile time − Instruction Selection evaluations − Local Reg Allocation − Eliminating − Choice of Order of redundant Evaluation computations Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 4/1 Typical Back Ends in Aho Ullman Model m/c Ind. IR m/c Ind. m/c Code m/c m/c Dep. Ind. Dep. Optimizer IR Generator IR Optimizer − Compile time − Instruction Selection evaluations − Local Reg Allocation − Eliminating − Choice of Order of redundant Evaluation computations Assembly Code Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 4/1 Typical Back Ends in Aho Ullman Model m/c Ind. IR Register Allocator m/c Ind. m/c Code m/c Instruction Ind. Dep. Optimizer IR Generator IR Scheduler − Compile time − Instruction Selection Peephole evaluations − Local Reg Allocation Optimizer − Eliminating − Choice of Order of redundant Evaluation computations Assembly Code Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Optimization Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Cost based tree pattern matching Optimization Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Cost based tree pattern Structural tree pattern matching matching Optimization Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Cost based tree pattern Structural tree pattern matching matching Optimization Machine independent Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Cost based tree pattern Structural tree pattern matching matching Machine dependent Optimization Machine independent Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: Compilation Models 5/1 Retargetability in Aho Ullman and Davidson Fraser Models Aho Ullman Model Davidson Fraser Model • Machine independent IR is expressed in the form of trees • Machine instructions are described in the form of trees Instruction • Trees in the IR are “covered” using the instruction trees Selection Cost based tree pattern Structural tree pattern matching matching Machine dependent Optimization Machine independent Key Insight: Register transfers are target specific but their form is target independent Uday Khedker GRC, IIT Bombay Part 2 GCC ≡ The Great Compiler Challenge EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 6/1 What is GCC? • For the GCC developer community: The GNU Compiler Collection • For other compiler writers: The Great Compiler Challenge Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program gcc Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc as Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc as ld Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc as glibc/newlib ld Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 7/1 The GNU Tool Chain for C Source Program cc1 cpp gcc as glibc/newlib ld Target Program Uday Khedker GRC, IIT Bombay EAGCC-PLDI-14 EAGCC: GCC ≡ The Great Compiler Challenge 8/1 Why is Understanding GCC Difficult? Some of the obvious reasons: • Comprehensiveness GCC is a production quality framework in terms of completeness and practical usefulness • Open development model Could lead to heterogeneity. Design flaws may be difficult to correct • Rapid versioning GCC maintenance is a race against time.