The Design and Implementation of Gnu Compiler Collectionuday/courses/cs715-08/gcc-intro-1.pdf ·...
Transcript of The Design and Implementation of Gnu Compiler Collectionuday/courses/cs715-08/gcc-intro-1.pdf ·...
The Design and Implementation of GnuCompiler Collection
Uday Khedker
(www.cse.iitb.ac.in/̃ uday)
Department of Computer Science and Engineering,
Indian Institute of Technology, Bombay
July 2008
Part 1
Outline
cs 715 GCC: Outline 1/22
Outline
• Open Source Vs. Free Software
• An Introduction to Compilation
• An overview of Gnu Compiler Collection
• Our work in GCC
• Conclusions
UPK IIT Bombay
Part 2
Open Source Vs. Free Software
cs 715 GCC: Open Source Vs. Free Software 2/22
Open Source Vs. Free Software
• The open source initiative: (http://www.opensource.org/)
Emphasis on development methodology
• The Free Software Foundation: (http://www.fsf.org/)
Emphasis on freedom of the user
• In some cases, open source software has restricted user freedom
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 2/22
Open Source Vs. Free Software
• The open source initiative: (http://www.opensource.org/)
Emphasis on development methodology
• The Free Software Foundation: (http://www.fsf.org/)
Emphasis on freedom of the user
• In some cases, open source software has restricted user freedom
◮ May cooperate with restrictive systems◮ eg. DRM (Digital Rights Management)
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 3/22
Open Source and Free Software Development Model
• The Cathedral and the Bazaar
Eric S Raymond, 1997.
• Cathedral: Total Centralized Control
Design, implement, test, release
• Bazaar: Total Decentralization
Release early, release often, let users fix bugs
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
◮ 12 man month effort
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
◮ 12 man month effort◮ 1 person working for 12 months
OR12 persons working for 1 month?
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
◮ 12 man month effort◮ 1 person working for 12 months
OR12 persons working for 1 month?
• Bazaar approach believes that the two somewhat equivalent ininternet-based distributed development.
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
◮ 12 man month effort◮ 1 person working for 12 months
OR12 persons working for 1 month?
• Bazaar approach believes that the two somewhat equivalent ininternet-based distributed development.
• “Given enough eyeballs, all bugs are shallow”.
Code errors, logical errors, and architectural errors.
UPK IIT Bombay
cs 715 GCC: Open Source Vs. Free Software 4/22
The Bazaar Approach
Release early, release often, let users fix bugs
• Brooks’ law (The Mythical Man Month, 1975)
◮ 12 man month effort◮ 1 person working for 12 months
OR12 persons working for 1 month?
• Bazaar approach believes that the two somewhat equivalent ininternet-based distributed development.
• “Given enough eyeballs, all bugs are shallow”.
Code errors, logical errors, and architectural errors.
A combination of the two seems more sensible
UPK IIT Bombay
Part 3
Introduction to Compilation
cs 715 GCC: Introduction to Compilation 5/22
Implementation Mechanisms
Source Program
Translator
Target Program
Machine
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 5/22
Implementation Mechanisms
Source Program
Translator
Target Program
Machine
Input Data
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 5/22
Implementation Mechanisms
Source Program
Translator
Target Program
Machine
Input Data
Source Program
Interpreter
Machine
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 6/22
Implementation Mechanisms as “Bridges”
• “Gap” between the “levels” of program specification and execution
Program Specification
Machine
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 6/22
Implementation Mechanisms as “Bridges”
• “Gap” between the “levels” of program specification and execution
Program Specification
Machine
Translation
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 6/22
Implementation Mechanisms as “Bridges”
• “Gap” between the “levels” of program specification and execution
Program Specification
Machine
Translation Interpretation
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 6/22
Implementation Mechanisms as “Bridges”
• “Gap” between the “levels” of program specification and execution
Program Specification
Machine
Translation Interpretation
State : VariablesOperations: Expressions,
Control Flow
State : Memory,Registers
Operations: MachineInstructions
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 7/22
High and Low Level Abstractions
• A source statement
a = b < 10 ? b : c;
• Spim assembly equivalent
lw $t0, 4($fp) # $t0 <- b
slti $t0, $t0, 10 # $t0 <- $t0 < b
not $t0, $t0 # $t0 <- ! $t0
bgtz $t0, L0: # if $t0 >= 0 goto L0:
lw $t0, 4($fp) # $t0 <- b
b L1: # goto L1:
L0: lw $t0, 8($fp) # L0: $t0 <- c
L1: sw 0($fp), $t0 # L1: a <- $t0
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Overall Strategy, algorithm, data structure etc
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Functions, variables, their types etc
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Machine instructions registers etc
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Virtual addresses of global variables, functions etc.
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Actual addresses of code and data
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 8/22
Binding
Conceptualisation Coding Compiling Linking Loading Execution
Time
No.ofunboundobjects
Values of variables
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 9/22
Implementation Mechanisms
• Translation = Analysis + Synthesis
Interpretation = Analysis + Execution
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 9/22
Implementation Mechanisms
• Translation = Analysis + Synthesis
Interpretation = Analysis + Execution
• Translation InstructionsEquivalent
Instructions
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 9/22
Implementation Mechanisms
• Translation = Analysis + Synthesis
Interpretation = Analysis + Execution
• Translation InstructionsEquivalent
Instructions
Interpretation InstructionsActions Implied
by Instructions
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 10/22
Language Implementation Models
Analysis
Synthesis
Execution
Compilation
Interpretation
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 11/22
Language Processor Models
C,C++
Java,C#
FrontEnd
Optimizer
BackEnd
VirtualMachine
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 12/22
Translation Sequence in Our Example: Parsing
a=b<10?b:c;
Input
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 12/22
Translation Sequence in Our Example: Parsing
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
Issues:
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 12/22
Translation Sequence in Our Example: Parsing
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
Issues:
• Grammar rules, terminals, non-terminals
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 12/22
Translation Sequence in Our Example: Parsing
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
Issues:
• Grammar rules, terminals, non-terminals
• Order of application of grammar rules
eg. is it (a = b<10?) followed by (b:c)?
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 12/22
Translation Sequence in Our Example: Parsing
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
Issues:
• Grammar rules, terminals, non-terminals
• Order of application of grammar rules
eg. is it (a = b<10?) followed by (b:c)?
• Values of terminal symbols
eg. string “10” vs. integer number 10.
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 13/22
Translation Sequence in Our Example: Semantic Analysis
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 13/22
Translation Sequence in Our Example: Semantic Analysis
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
Issues:
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 13/22
Translation Sequence in Our Example: Semantic Analysis
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
Issues:
• Symbol tables
Have variables been declared? What are their types?What is their scope?
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 13/22
Translation Sequence in Our Example: Semantic Analysis
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
Issues:
• Symbol tables
Have variables been declared? What are their types?What is their scope?
• Type consistency of operators and operands
The result of computing b<10? is bool and not int
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 14/22
Translation Sequence in Our Example: IR Generation
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 14/22
Translation Sequence in Our Example: IR Generation
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
Issues:
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 14/22
Translation Sequence in Our Example: IR Generation
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
Issues:
• Convert to maximal trees which can beimplemented without altering control flow
Simplifies instruction selection and scheduling,register allocation etc.
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 14/22
Translation Sequence in Our Example: IR Generation
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
Issues:
• Convert to maximal trees which can beimplemented without altering control flow
Simplifies instruction selection and scheduling,register allocation etc.
• Linearise control flow by flattening nestedcontrol constructs
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 15/22
Translation Sequence in Our Example: Instruction Selection
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 15/22
Translation Sequence in Our Example: Instruction Selection
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List Issues:
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 15/22
Translation Sequence in Our Example: Instruction Selection
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List Issues:
• Cover trees with as fewmachine instructions aspossible
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 15/22
Translation Sequence in Our Example: Instruction Selection
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List Issues:
• Cover trees with as fewmachine instructions aspossible
• Use temporaries and localregisters
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:
L0: lw $t0, 8($fp)L1: sw 0($fp), $t0
Assembly Code
Issues:
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:
L0: lw $t0, 8($fp)L1: sw 0($fp), $t0
Assembly Code
Issues:
• Offsets of variables in thestack frame
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:
L0: lw $t0, 8($fp)L1: sw 0($fp), $t0
Assembly Code
Issues:
• Offsets of variables in thestack frame
• Actual register numbersand assembly mnemonics
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:
L0: lw $t0, 8($fp)L1: sw 0($fp), $t0
Assembly Code
Issues:
• Offsets of variables in thestack frame
• Actual register numbersand assembly mnemonics
• Code to construct anddiscard activation records
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 16/22
Translation Sequence in Our Example: Emitting Instructions
a=b<10?b:c;
Input
AsgnStmnt
Lhs = E ;
E ? E : E
E < E
name
name name
name numParse Tree
=name(a,int) ?: (int)
<
(bool)name(b,int)
name(c,int)
name(b,int)
num(10,int)
Abstract Syntax Tree(with attributes)
=
T0<
b 10IfGoto
Not L0:
T0
=
T1 bGoto
L1:=
T1 c
L0:
=
T1a
L1:
Tree List
T0 ← bT0 ← T0 < bT0 ← ! T0
if T0 ≥ 0 goto L0:T1 ← bgoto L1:
L0: T1 ← cL1: a ← T1
Instruction List
lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:
L0: lw $t0, 8($fp)L1: sw 0($fp), $t0
Assembly Code
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 17/22
Typical Front Ends
Parser
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 17/22
Typical Front Ends
ParserSourceProgram
Scanner
Tokens
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 17/22
Typical Front Ends
ParserSourceProgram
Scanner
Tokens
SemanticAnalyzer
AST
ParseTree
AST or Linear IR+
Symbol Table
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 17/22
Typical Front Ends
ParserSourceProgram
Scanner
Tokens
SemanticAnalyzer
AST
ParseTree
AST or Linear IR+
Symbol Table
ErrorHandler
SymtabHandler
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 18/22
Typical Back Ends
M/c Ind.IR
M/c Ind.Optimizer
− Compile timeevaluations
− Eliminatingredundantcomputations
M/cInd.IR
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 18/22
Typical Back Ends
M/c Ind.IR
M/c Ind.Optimizer
− Compile timeevaluations
− Eliminatingredundantcomputations
M/cInd.IR
CodeGenerator
M/cDep.IR
− Instruction Selection− Local Reg Allocation− Choice of Order of
Evaluation
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 18/22
Typical Back Ends
M/c Ind.IR
M/c Ind.Optimizer
− Compile timeevaluations
− Eliminatingredundantcomputations
M/cInd.IR
CodeGenerator
M/cDep.IR
− Instruction Selection− Local Reg Allocation− Choice of Order of
Evaluation
M/c Dep.Optimizer
Assembly Code
UPK IIT Bombay
cs 715 GCC: Introduction to Compilation 18/22
Typical Back Ends
M/c Ind.IR
M/c Ind.Optimizer
− Compile timeevaluations
− Eliminatingredundantcomputations
M/cInd.IR
CodeGenerator
M/cDep.IR
− Instruction Selection− Local Reg Allocation− Choice of Order of
Evaluation
Assembly Code
RegisterAllocator
InstructionScheduler
PeepholeOptimizer
UPK IIT Bombay
Part 4
Introduction to GCC
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
cc1
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
cc1 cpp
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
cc1 cpp
as
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
cc1 cpp
as
ld
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 19/22
The GNU Tool Chain
gcc
Source Program
Target Program
cc1 cpp
as
ld
glibc/newlib
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 20/22
The GCC Framework
LanguageSpecific Code
Language andMachine
IndependentGeneric Code
MachinedependentGenerator
Code
MachineDescrip-
tionsGCC
Input Language Machine Description
Parser Genericizer GimplifierTree SSAOptimizer
RTLGenerator
OptimizerCode
Generator
cc1/gcc
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 20/22
The GCC Framework
LanguageSpecific Code
Language andMachine
IndependentGeneric Code
MachinedependentGenerator
Code
MachineDescrip-
tionsGCC
Input Language Machine Description
Parser Genericizer GimplifierTree SSAOptimizer
RTLGenerator
OptimizerCode
Generator
cc1/gcc
Source Program
Assembly Program
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 20/22
The GCC Framework
LanguageSpecific Code
Language andMachine
IndependentGeneric Code
MachinedependentGenerator
Code
MachineDescrip-
tionsGCC
Input Language Machine Description
Parser Genericizer GimplifierTree SSAOptimizer
RTLGenerator
OptimizerCode
Generator
Selected
cc1/gcc
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 20/22
The GCC Framework
LanguageSpecific Code
Language andMachine
IndependentGeneric Code
MachinedependentGenerator
Code
MachineDescrip-
tionsGCC
Input Language Machine Description
Parser Genericizer GimplifierTree SSAOptimizer
RTLGenerator
OptimizerCode
Generator
Selected Copied
Copied
cc1/gcc
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 20/22
The GCC Framework
LanguageSpecific Code
Language andMachine
IndependentGeneric Code
MachinedependentGenerator
Code
MachineDescrip-
tionsGCC
Input Language Machine Description
Parser Genericizer GimplifierTree SSAOptimizer
RTLGenerator
OptimizerCode
Generator
Selected Copied
CopiedGenerated
Generated
cc1/gcc
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 21/22
The cc1 Phase Sequence as IR Chain
The GCC Phase Sequence
Generic GIMPLE RTL ASM
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 21/22
The cc1 Phase Sequence as IR Chain
The GCC Phase Sequence
Generic GIMPLE RTL ASM
HLL
Scope ExplicationLower controlflow
Lower procedures& data
Target
UPK IIT Bombay
cs 715 GCC: Introduction to GCC 21/22
The cc1 Phase Sequence as IR Chain
The GCC Phase Sequence
Generic GIMPLE RTL ASM
HLL
Scope ExplicationLower controlflow
Lower procedures& data
TargetOptimization Opportunities
Rescoping SSA Scheduling
UPK IIT Bombay
Part 5
Configuration and Building
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in config/*
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in config/*
config.sub
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in config/*
config.sub
config.log config.cache config.status
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in config/*
config.sub
config.log config.cache config.status
config.h.in makefile.in
UPK IIT Bombay
cs 715 GCC: Configuration and Building 22/22
Configuring GCC
configure
config.guess
configure.in config/*
config.sub
config.log config.cache config.status
config.h.in makefile.in
Makefile config.h
UPK IIT Bombay
Part 6
About The Course