lecture 23 basic blocks n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 23 Basic Blocks PowerPoint Presentation
Download Presentation
Lecture 23 Basic Blocks

Loading in 2 Seconds...

play fullscreen
1 / 23

Lecture 23 Basic Blocks - PowerPoint PPT Presentation


  • 94 Views
  • Uploaded on

Lecture 23 Basic Blocks. CSCE 531 Compiler Construction. Topics Code Generation Readings: 9. April 17, 2006. Overview. Last Time – Lec22 slides 1-14, 15-16 Finishing touches on Arrays in expressions Project 5 Today’s Lecture Questions on Project 5 – Functions Code Generation

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 23 Basic Blocks' - jaime-avery


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
lecture 23 basic blocks
Lecture 23 Basic Blocks

CSCE 531 Compiler Construction

  • Topics
    • Code Generation
  • Readings: 9

April 17, 2006

overview
Overview
  • Last Time – Lec22 slides 1-14, 15-16
    • Finishing touches on Arrays in expressions
    • Project 5
  • Today’s Lecture
    • Questions on Project 5 – Functions
    • Code Generation
  • References: Chapter 9
code generation
Code Generation
  • Chapter 9
  • Issues in Code Generation
  • Input to code generator
  • Target programs
  • Memory management
  • Instruction selection
  • Register allocation
input to code generator
Input to code generator
  • Quadruples
  • Triples
  • Indirect triples
  • Parse trees
  • Syntax trees
  • Mixtures – some trees some quads
target programs
Target programs
  • Target Architectures
  • CISC
  • RISC
  • Target Architectures
  • Object modules
  • Assembly
target machine architecture
Target Machine Architecture
  • RISC vs CISC
  • Byte addressable, word addressable?
  • Byte order? Big Endian vs little
  • Address Modes supported by architecture
    • Absolute
    • Register
    • Indexed d(R) d + contents(R)
    • Indirect register *d(R) contents(d + contents(R))
  • Cost of address modes in references to memory
instruction costs
Instruction Costs
  • Floating point costs
    • FPadd = 2 time units
    • FPmultiply = 5 time units
    • FPdivide=9 time units
  • Page 521 – costs measured in instruction length (somewhat dated, but simple to understand)
  • mov R0, R1 - cost = 1
  • mov R5, mem - cost = 2
  • add $1, r3 - cost = 2
  • sub 4(R0), *12(R1) - cost =3
instruction costs of blocks a b c
Instruction Costs of Blocks: a = b + c
  • mov b, R0
  • add c, R0
  • mov R0, a
slide13
Heap
  • Really Operating System Problem not Compilers job
  • System Calls
    • ptr = malloc(size)
    • free(ptr)
    • Free space list
  • What functionality the compiler needs to supply?
    • Just pointers, function calls
basic blocks and flow graphs
Basic Blocks and Flow Graphs
  • To generate better code, we will need to analyze the structure of code written as list of quadruples
  • A Basic Block is a sequence of consecutive statements in which flow of control enters at the beginning and leaves at the end without possibility of branching except at the end
  • Define/Use: a:= b + c
    • This statement defines “a”
    • It uses “b” and “c”
  • A name (identifier) is said to be live at a given point if its value is after that point in the program
leaders of the block
Leaders of the Block
  • A leader is the first statement of a basic block.
  • The algorithm for Basic Blocks
  • Determine the leaders first.
    • The first statement is a leader.
    • Any statement that is the target of a branch is a leader.
    • Any statement immediately following a branch is a leader.
  • For each leader the block extends from the leader up to the statement just prior to the next leader.
transformations on basic blocks
Transformations on Basic Blocks
  • Common subexpression elimination
  • Dead-code elimination
  • Renaming temporary variables
  • Reordering independent statements
flow graphs
Flow Graphs
  • Successor block
  • Predecessor block
  • Loops
  • Strongly connected
  • Inner loop
computing next uses
Computing Next Uses
  • Scan block backwards from last statement to leader
  • For statement (i) x := y op z
    • Attach to statement I, current info from symbol table on the liveness of x y and z
    • In the symbol table Mark x “not live” = “no next use”
    • In the symbol table change next uses of y and z to (i) “statement number i”