Language Implementation Flashcards

1
Q

The phases of compilation are commonly grouped in which two categories?

A
  • Front end responsible for the analysis of source code
  • Back end responsible for the synthesis of target code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name the 7 conventional phases of a compiler.

A

First 3 phases (Language dependent)

  • Scanning
  • Parsing
  • Semantic Analysis

Middle 2 (Compiler technology dependent)

  • Intermediate code generation
  • Machine independent code improvement

Last 2 (Machine dependent)

  • Target code generation
  • Machine specifig code improvement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use intermediate code generation?

A

Most code improvement can be done more easily on less hierarchical structure than AST. In other words, ASTs are too hierarchical to hadle code improvement.

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

How can an intermediate code generator be created?

A

The typical appoarch is to group nodes into basic blocks and then create a control flow graph.

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

In intermediate code generation, what is a Basic Block?

A

Maximal-length set of instructions that should execute sequentially at runtime, with no branches in or out.

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

In Intermediate code generation, what is a Control flow graph?

A

This is used to show the relationship among the nodes.

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

Name two types of transformations that can be done to the control flow graph for machine independent code improvement.

A
  • Local code improvement - modifies the instruction sequence within each basic block to eliminate redundant loads, stores, and arithmetic computations
  • Global code improvement - identifies and removes a variety of redundancies across the boundaries between basic blocks within a subroutine
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Machine Dependent

What does target code generation do?

A
  • Strings the basic blocks together into a linear program
  • Tanslates each block into the instruction set of the target machine
  • Generates branch instructions (or “fall-throughs”) that correspond to the arcs of the control flow graph.
  • The output of this phase differs from real assembly language primarily in its continued reliance on virtual registers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Machine Dependent

What are some machine specific code improvements?

A

Register allocation

  • Map the unlimited virtual registers onto the bounded set of registers available in the target machine
  • If there aren’t enough architectural registers to go around, we may need to generate additional loads and stores to multiplex a given architectural register among two or more virtual registers

Instruction scheduling

  • Reordering the instructions of each basic block to fill the pipeline(s) of the target machine

Code improvement

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

What is IF Intermediate responsible for?

A
  • Link between front and back end of compilers
  • Can be classified by their level—degree of machine independence
  • Common examples:
    • Trees or DAGs (Directed Acyclic Graphs)
    • Stack-based
    • 3-address instructions
  • Many compilers use more than one intermediate form
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In the intermediate stage, what are the responsibilities of trees or DAGs?

A
  • Reflect structure of language
  • Facilitates
    • Incremental program updates (e.g. in a language-based editor)
    • Direct interpretation
    • Can be specified by attribute grammars
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In the intermediate form stage, what is stack based?

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

In the intermediate form stage, what is 3 address instructions?

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

Elaborate on address space organization.

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

What does a relocatable object include?

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

What info can be organized in memory when the program is loaded into memory?

A
  • Code
  • Constants
  • Initialized Data
  • Uninitialized Data
  • Stack
  • Heap
  • Files
  • Dynamic Libraries
17
Q

The linker supports separate compilation.

Elaborate on linking.

A
18
Q

Describe Static and Dynamic Linkers

A
19
Q

What are the two subtasks that linking is involved with?

A
  • Relocation (AKA Loading)
  • Resolution of external references
20
Q

Picture of Relocatable Objects

A
21
Q

On a multi-user system, it is common for several instances of a program to be executing simultaneously. What do operating systems do to keep track of the different instances.

A
22
Q

What are the three separate phases of machine independent code improvement?

A
23
Q

What is peephole optimization?

A
24
Q

Give an example of a redundant load or store that can be eliminated by peephole optimization.

A
25
Q

Peephole Optimization

Give an example of replacing load with dup.

A
26
Q

Peephole Optimization

Give an example constant folding (condensing constant arithmetic).

A
27
Q

Peephole Optimization

Give an example of constant propagation.

A
28
Q

Peephole Optimization

Give an example of a common subexpression elimination.

A
29
Q

Peephole Optimization

Give an example of copy propagation.

A
30
Q

Peephole Optimization

Give an example of strength reduction.

A
31
Q

What are other types of optimizations?

A
32
Q

Name two classes of loop improvement.

A
33
Q

What are induction variables?

A
34
Q

What is loop unrolling?

A
35
Q

Describe Loop Reordering

A