Code Generation/Optimization Flashcards

1
Q

What is x = y - z translated to?

A

LD R1, y
LD R2, z
SUB R1, R1, R2
ST x, R1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is if x < y goto L translated to?

A

LD R1, x
LD R2, y
SUB R1, R1, R2
BLTZ R1, L

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is x = *p translated to?

A

LD R1, p
LD R2, 0(R1)
ST x, R2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is *p = x translated to?

A

LD R1, p
LD R2, x
ST 0(R1), R2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is b = a[i] translated to?

A

LD R1, i
MUL R1, R1, 8 - 8 byte elements
LD R2, a(R1) - a=array
ST b, R2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a[j] = c translated to?

A

LD R1, c
LD R2, j
MUL R2, R2, 8
ST a(R2), R1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the Cost Function for code generation?

A

All instructions have cost 1.
Register access has cost 0.
Accessing memory location has cost 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does a procedure call look like in assembly?

A

Initialization - ST SP, #stackStart

ADD SP, SP, #caller.recordSize
ST *SP, #next
BR callee.codeArea
SUB SP, SP, #caller.recordSize

Return - BR *0(SP)

Where SP = p.static area, p’s activation record where the return address is stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a basic block?

A

A sequence of three-address instructions such that there are no jumps in the middle of the block and no instruction in the block halts or branches, except the last.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a flow graph?

A

Has basic blocks as nodes and edges that caputre control flow between the blocks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to convert a basic block into a DAG?

A

Initial values of variables are nodes.
For each statement, create a node:
- Labelled by operator
- Annotated with variable which is assigned in statement
- Children are nodes used in statement

Reconstitute a TAC once generated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the local optimizations that can take place?

A
  • Local common subexpressions
  • Dead code elimination
  • Arithmetic transformations
  • Copy propagation
  • Elimination of redundant loads/stores
  • Flow of control optimizations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a data-flow analysis?

A
  • Global optimizations depend on these.
  • Derive information about the flow of data along program execution paths in a flow graph.
  • Analyse state of a program before and after each statement.

Data-flow value = abstraction of the state before/after a statement.
IN[s] = data flow values before s, OUT[s] = after.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly