1 / 10

Three-Address Implementation

Three-Address Implementation. Triples Quads N-tuples (my choice) Lhs = oper(op 1 , op 2 , …, op n ) Lhs = call(func, arg 1 , arg 2 , … arg n ) If condOper(op 1 , op 2 , Label) br Label. a = ((c-1) * b) + (-c * b). Example “ Source ”. t1 = c - 1 t2 = b * t1 t3 = -c t4 = t3 * b

Download Presentation

Three-Address Implementation

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. Three-Address Implementation • Triples • Quads • N-tuples (my choice) • Lhs = oper(op1, op2, …, opn) • Lhs = call(func, arg1, arg2, … argn) • If condOper(op1, op2, Label) • br Label

  2. a = ((c-1) * b) + (-c * b) Example “Source”

  3. t1 = c - 1 t2 = b * t1 t3 = -c t4 = t3 * b t5 = t2 + t4 a = t5 Example 3-Address

  4. Control Flow Graph • Nodes are Basic Blocks • Single entry, single exit • No branch exempt (possibly) at bottom • Edges represent one possible flow of execution between two basic blocks • Whole CFG represents a function

  5. begin; int A[10]; main(){ int i,j; Do 10 i = 0, 9, 1 10 A[i] = random(); Do 20 i = 1, 9, 1 Do 20 j = 1, 9, 1 20 if( A[j] > A[j+1]) swap(j); } Bubble Sort

  6. int swap(int i) { int temp; temp = A[i]; A[i] = A[i+1]; A[i+1] = temp; } end; Bubble Sort (cont.)

  7. Building CFG • Starting with 3-addr code • Each leader starts a basic block which ends immediately before the next leader • ID “leaders” (heads of basic blocks) • First statement is a leader • Any statement that is the target of a conditional of unconditional goto is a leader • Any statement immediately following a goto or conditional goto is a leader • Each leader starts a basic block which ends immediately before the next leader

  8. Live Variables – Basic Block • For each block, BB, compute • Written, read, readB4written • Initialize each BB • Live-in = readB4written, Live-out = Ø • Repeat until neither live-in, live-out change • For each BB • Live-out(BB) U= U Live-in(Successor) • Live-in(BB) U= Live-out(BB) – written(BB)

  9. Live Analysis – Statements

  10. Live Variables – Statement • For each block, BB, compute, in any order • Maintain “local” set, Live • Live = BB->live_out • For each Statement, S, in BB, in reverse order • Live = Live – S->written • S->live = Live • Live = Live U S->read

More Related