An Overview to Compiler Design - PowerPoint PPT Presentation

About This Presentation
Title:

An Overview to Compiler Design

Description:

Middle-end: machine independent code analysis and (scalar, and sometimes loop ... Back-end: Machine dependent code analysis and optimization. 9/10/09 ... – PowerPoint PPT presentation

Number of Views:109
Avg rating:3.0/5.0
Slides: 14
Provided by: guang4
Category:

less

Transcript and Presenter's Notes

Title: An Overview to Compiler Design


1
An Overview toCompiler Design
2
Outline
  • An Overview of Compiler Structure
  • Front End
  • Middle End
  • Back End

3
Reading
  • Slides and Lecture Notes
  • Aho,Lam,Sethi,Ullman
  • Chapter 1.4 1.5
  • Chapter 2.1 2.7
  • Chapter 3.1 3.5
  • Chapter 4.1 4.5

4
A Review on CompilerStructure/Design
  • Overall structure
  • Front-end lexical and syntax analysis
  • Middle-end machine independent code analysis and
    (scalar, and sometimes loop nest ) optimization
  • Back-end Machine dependent code analysis and
    optimization

5
Motivation for Compiler optimization
COMPILER
Source Program
Machine Code
Input program example
  • int foo( )
  • int x
  • return (x x)

6
Output Assembly Code (non-optimized)
  • foo
  • sub sp, sp, 8
  • sw fp, 8(sp)
  • add fp, sp, 8
  • sw ra, -4(fp)
  • add t0, a0 a0
  • move v0, t0
  • lw ra, -4(fp)
  • lw fp, 0(fp)
  • add sp, sp, 8
  • jr ra

7
Output Assembly Code (non-optimized)
  • foo
  • sub sp, sp, 8 Push stack frame
  • sw fp, 8(sp) Save old frame pointer
  • add fp, sp, 8 Set new frame pointer
  • sw ra, -4(fp) Save return address
  • add t0, a0 a0 Addition
  • move v0, t0 Copy return value
  • lw ra, -4(fp) Restore return address
  • lw fp, 0(fp) Restore frame pointer
  • add sp, sp, 8 Pop stack frame
  • jr ra Jump to return address

8
Output Assembly Code -- Revisited (non-optimized)
  • foo
  • sub sp, sp, 8 Push stack frame (for what?)
  • sw fp, 8(sp) Save old frame pointer (for
    what?)
  • add fp, sp, 8 Set new frame pointer
  • sw ra, -4(fp) Save return address (for
    what?)
  • add t0, a0, a0 Addition
  • move v0, t0 Copy return value
  • lw ra, -4(fp) Restore return address
  • lw fp, 0(fp) Restore frame pointer
  • add sp, sp, 8 Pop stack frame
  • jr ra Jump to return address

9
Output Assembly Code(optimized)
  • foo
  • add v0, a0, a0 Set result
  • jr ra Jump to return address

10
Runtime Memory Organization
frame-1
code for procedure 1
Entry point for procedure 1
Space for arguments (parameters)
frame-2
code area
Space for bookkeeping Information,
including Return address
frame-3
code for procedure 2
global/static area
Entry point for procedure 2

stack
Space in local data

free space
Space for local temporaries
code for procedure n
Runtime stack
Entry point for procedure n
A stack frame
heap
Code memory
Address space
11
Phases of a Compiler
Source program
Intermediate-code Generator
Lexical Analyzer (Scanner)
Non-optimized Intermediate Code
Tokens
Intermediate-code Optimizer
Syntax Analyzer (Parser)
Optimized Intermediate Code
Parse tree
Target-code Generator/Opt
Semantic Analyzer
Target machine code
Abstract Syntax Tree w/ Attributes
12
Low-level Model
Mixed-level Model
Lexical analyzer
Lexical analyzer
Parser
Parser
Semantic analyzer
Semantic analyzer
Intermediate-code generator
Translator
Optimizer
Optimizer
Code generator
Final assembly
Postpass optimizer
Two models of compiler structures (Muchnick, pp.
08)
13
A Good Compiler Infrastructure Needed A modern
View
Front end
Interprocedural Analysis and Optimization
Good IR
Loop Nest Optimization and Parallelization
Global (Scalar) Optimization
Middle-End
Backend Code Generation
Write a Comment
User Comments (0)
About PowerShow.com