Presentation is loading. Please wait.

Presentation is loading. Please wait.

TARGET CODE -Next Usage

Similar presentations


Presentation on theme: "TARGET CODE -Next Usage"— Presentation transcript:

1 TARGET CODE -Next Usage
Rajat Sethi 04CS3022 TARGET CODE -Next Usage

2 Topics to be covered Next Use Information Code Generation
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
STEP 1 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 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: Statements Code Generated Register Descriptor Address t = a-b
d=(a-b) + (a-c) + (a-c) Statements Code Generated Register Descriptor Address t = a-b MOV a, R0 SUB b, R0 R0 -> t t -> R0 u= a-c MOV a, R1 SUB c, R1 R1 -> u u -> R1 v= t+u ADD R1,R0 R0 -> v v -> R0 d= v+u MOV R0,d R0 -> d d -> R0

9 THANK YOU


Download ppt "TARGET CODE -Next Usage"

Similar presentations


Ads by Google