1 / 11

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 Label:. Example “Source”. a = ((c-1) * b) + (-c * b). Example 3-Address. t1 = c - 1 t2 = b * t1

louie
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 • Label:

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

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

  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. Bubble Sort 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); }

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

  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 or 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 • Written, read for each 3-addr statement in block • 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 Variable Analysis (BB) • Live = BB->live-out • For each stmt in BB, in reverse order • Live = Live - stmt->written • stmt->live = Live • Live = Live U stmt->read

  11. Building Register Interference Graph • Make node for each symbolic register, sr • Foreach Statement, stmt, in function • Foreach symbolic reg, srl, in stmt->live • Foreach sym reg, srw, in stmt->written • Add edge from srw to srl

More Related