registerAllocation

registerAllocation - Register Allocation cs5363 1 Register...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
cs5363 1 Register Allocation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 2 Register Allocation And Assignment Values in registers are easier and faster to access than memory Reserve a few registers for stack pointers, base addresses etc Efficiently utilize the rest of general-purpose registers Register allocation At each program point, select a set of values to reside in registers Register assignment Pick a specific register for each value, subject to hardware constraints Register classes: not all registers are equal Optimal register allocation/assignment in general are NP-complete Register assignment in many cases can be solved in polynomial time …… i := 0 s0: if i < 50 goto s1 goto s2 s1: t1 := b * 2 a := a + t1 goto s0 S2: … • Un-aliased calar variables i, a, b, t1 (can stay in registers) • Need to know how variables will be used after each statement. Live variable analysis
Background image of page 2
cs5363 3 The Register Allocation Problem At each point of execution, a program may have an arbitrary number of live variables Only a subset may be kept in registers If a value cannot be kept in register, it must be stored in memory and loaded again when next needed spilling value to register Goal: make effective use of registers Minimize the number of loads and stores for spilling Register-to-register model Early translation stores all values in registers; select values to spill to memory later Memory-to-memory model Early translation stores all values in memory; promote values to register later Must decide which values do not require memory storage Register allocator Input program Output program Assumes infinite # of registers Uses registers on machine
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 4 Local Register Allocation Allocating registers for a single basic block Assumes register-to-register memory model Input program assumes infinite # of registers Assume all registers on target machine are equivalent Two approaches Top-down: count the number of references to each value the most heavily used values should reside in registers Weakness: dedicate a register to a value for entire duration of the block Bottom-up: spill the value that is needed the latest For each variable use, compute the distance of its next use process each instruction in evaluation order; when running out of
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

registerAllocation - Register Allocation cs5363 1 Register...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online