Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Activation Record(stackframe) – manages informed needed by single activation of procedure

-temporary values
-local data/variables
-saved machine status information
-parameters
-returned values
-control link(implement functions) – points to activation record of caller – return from functions and
restore stacks as it should be. Always point to previous to POP STACK
-access link – for access to non-local names(globals)

frame ptr(used for accessing)


stack ptr(used for offsets)

calling sequence – can be split | before and after transfer control | caller / callee

1. Allocates activation record


2. Local actual parameters
3. Saves machine state(return address) can return
4. Transfer control to callee

Return sequence – puts return value where caller knows where to find it(top of active record)

1. Deallocates activation record


2. Set up return value(if any)
3. Restore machine state

Nonlocal variable – not in own activication record, in others activation record (access to non-local
names)

Access link- access link points to outside levels(nonlocal + global) – access variables your allowed to
access. Use nesting levels to set up access links. When do you set up chain? When you do calls and
returns. POINT TO LATEST that calls

Static Q(like a global) – rip out stack, allocate it with globals, never lose value, permantely allocated

Access link - Can only access variables visible to you

When you call X your actually calling S. bypassing static scope

Pass x as parameter and so branch.

If you pass procedure as parameter it Crosses access links(normally doesn’t happen)

Dyanmic arrays – maintain constant offsets

Don’t put in stack put in heap. Each time you come, pick up pointer and go to HEAP;

_____________________________________________________________________________________
Final Code Generation and code optimization –last topic

Translate 3-address code to final code(translate into assembly)

Load and stores are expensive, but quick and dirty will work(how to optimize?) – get rid load/store

**Instead of going to end then going to top, just go to top.

Know semantic rules for final

Peephole optimization(only looking at specific part)

Multiplication is more exnepsie then addition

2*y < y+y

-Is it okay to optimize this? Yes then go ahaeads

Basics of Code Optimization and Machine Code Generation

1) construct Control Flow Graph Representation(CFG)


2) Perform Data Flow Analysis – collection information needed for performing optimization
3) Perform Optimizations and generate machine code

Turn basic blocks into graph system(with nodes and edges)

Turn code -> Graph

Branches need to be at END


Basic block – enter from top and leave from bottom(when you leave block your entering another)

(First instruction =always leader)

Target of a branch/follows a branch = leaders

Everything between 2 leaders goes in block.

Adding edges

Fall through

Done building control flow graph---

2—Imprving code quality

Allocate variables to registers for a FIXED length of time

Keep FREQUENTLY used values IN REGISTERS

Live(being used later) – as long as there is a future use for value else NOT live(dead, so FREE register)

Stops being live when you use it for last time. (begins live with assignment, last use becomes dead)
Live range – an isolated and connected group of basic blocks in which a variable is live.

Use(reading)

You might also like