1 / 23

Lecture 23 Basic Blocks

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

jaime-avery
Download Presentation

Lecture 23 Basic Blocks

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 23 Basic Blocks CSCE 531 Compiler Construction • Topics • Code Generation • Readings: 9 April 17, 2006

  2. 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

  3. Code Generation • Chapter 9 • Issues in Code Generation • Input to code generator • Target programs • Memory management • Instruction selection • Register allocation

  4. Input to code generator • Quadruples • Triples • Indirect triples • Parse trees • Syntax trees • Mixtures – some trees some quads

  5. Target programs • Target Architectures • CISC • RISC • Target Architectures • Object modules • Assembly

  6. 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

  7. Memory management

  8. Instruction selection

  9. 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

  10. Instruction Costs of Blocks: a = b + c • mov b, R0 • add c, R0 • mov R0, a

  11. Other Cost Metrics

  12. Run-Time Storage Managment

  13. 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

  14. 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

  15. 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.

  16. Example 9.3 – Dot Product

  17. Basic Blocks for Dot Product Code

  18. Transformations on Basic Blocks • Common subexpression elimination • Dead-code elimination • Renaming temporary variables • Reordering independent statements

  19. Flow Graphs • Successor block • Predecessor block • Loops • Strongly connected • Inner loop

  20. Example

  21. 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”

  22. A Simple Code Generation Algorithm

  23. GetReg

More Related