1 / 9

TARGET CODE -Next Usage

Rajat Sethi 04CS3022. TARGET CODE -Next Usage. Topics to be covered. Next Use Information Computation using Backward Scan Code Generation Register and Address Descriptor Algorithm getreg() function Example. Next Usage.

Download Presentation

TARGET CODE -Next Usage

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. Rajat Sethi 04CS3022 TARGET CODE -Next Usage

  2. Topics to be covered • Next Use Information • Computation using Backward Scan • Code Generation • Register and Address Descriptor • Algorithm • getreg() function • Example

  3. Next Usage • This technique is employed in dead code optimization. The instructions with no ‘next use’ are removed from the block. • If the name in a register is no longer needed, then the register can be assigned to some other name. • We collect next-use information about names in a basic block. Note that we consider only the variables in the same block.

  4. Backward Scan: statement i : x := y op z STEP 1: Attach to statement i, attribute information of next use of x, y and z. STEP 2: In symbol table, set x to “no next use” and “not live” STEP 3: In symbol table set the next uses of y and z to I and also to “live” NOTE : The orders of Step 2 and Step 3 should not be interchanged because x may be y or z. e.g.:- x := x+1

  5. Register & Address Descriptors Register Descriptor:It keeps track of what is in each register. It is consulted whenever a new register is needed. E.g.: R0 contains t, y, z. Address Descriptor: It keeps tract of the location(s) where the current value of the name can be found at the runtime. The location might be register, stack or memory location.

  6. Code Generation Algorithm • Find space L to store value of x using function getreg(). • For Y, see whether it is stored in L. If yes, perform op Z,L • Else perform mov Y,L; op Z,L • Generate : op Z,L • Update address descriptor of X. If X stored in any other register, remove it. • If the current values of Y and Z have no next use then free the registers. STEP 1 STEP 2 STEP 3 STEP 4

  7. Function getreg(); • STEP 1: If the name y is in a register , that holds the value of no other names (in other words no other names point to the same register as y does), and y is not live and has no next use after the execution of y = x op z, then :- • return L. • Update the address descriptor of y , so that y is no longer in L. • STEP 2: Failing (1), return an empty register for L if it exists. • STEP 3: Failing (2), if x has a next use in the block, or if op requires a register then :- • find an occupied register R. • MOV(R,M) if value of R is not in proper M. If R holds value of many variables, generate a MOV for each of the variables. • STEP 4: Failing (3), select the memory location of x as L.

  8. Example: d=(a-b) + (a-c) + (a-c)

  9. THANK YOU

More Related