Docsity

Compiler Architecture: Interaction between Compilers and Computer Architecture - Prof. Rak, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Compiler Architecture: Interaction between Compilers and Computer Architecture - Prof. Rak and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Lecture 16

Compiler-Architecture Interaction

Outline

  • Basic Compiler Structure
  • Very Long Instruction Word Architectures
  • Explicitly Parallel Instruction Computing

Sampling of Optimizations

  • High-Level Control-Flow Optimizations
    • in-lining, loop transformation, fetch

bandwidth optimizations

  • Local Optimizations
    • happen within a basic block
    • common subexpression elimination, constant

propagation, tree height reduction

Sampling of Optimizations, continued

  • Global Optimizations
    • applied across basic blocks
    • code motion, induction variable, dead code
  • Register Allocation
    • objective – minimize memory bandwidth
    • fewer spills, register coloring of register

interference graph

Basic Block

:

:

c = 10;

if (x != 0) {

a[x] = a[x-1] + c;

}

x++;

:

:

R1 = 10; STR R1,c R2 <- X BRnp L

R3 <- a[x-1] R2 <- c R1 <- R2+R STR R1, a[x]

R1 <- x R1 <- R1+ STR R1, x

Source Code

A

B C

D

•Block A always predecessor of Block D

•Block D always successor of Block A

•General: Control-flow analysis

Optimizations beyond Basic Blocks

VLIW

Mem Op ALU Op ALU Op BR Op

many bits

•The compiler arranges instructions into VLIWs

•If an op can’t be scheduled , a NOP is inserted

•The compiler also manages delays

•Now the hardware is really simple

•Example of VLIWs include Multiflow Trace, TI C

Burden on the Compiler

  • Basic objective: Have the compiler mitigate the effects of

data dependencies (using classical optimization) and

control dependencies (using techniques to be described).

  • Need to have a large pool of instructions from which we

can schedule. Need large regions!

  • Need to have a lot of registers to overcome false

dependencies.

Loop unrolling, continued

LOOP: LD r0 <- 0(r10) LD r1 <- 4(r10) LD r2 <- 8(r10) LD r4 <- 12(r10) LD r5 <- 16(r10) ADD r10, #20, r ADD r0, r1 -> r ADD r2, r4 -> r ADD r5, r3 -> r ADD r6, r7 -> r ADD r8, r3 -> r SUB r10, r11, r BNZ r12, LOOP

The loop is

now unrolled and scheduled

Software Pipelining

[Charlesworth 1981]

for (i = 0, i < 99, i++) sum = sum + y[i]x[i]; /^ prologue^ */

LOOP: ADD r2, r3 -> r MULT r0, r1 -> r LD r0 <- x[i] LD r1 <- y[i] ; iteration ctrl BRZ LOOP

/* epilogue

LOOP: LD r0 <- x[i] LD r1 <- y[i] MULT r1, r0 -> r ADD r2, r3 -> r ; iteration ctrl BRZ LOOP

Trace Scheduling

[Fisher 1981, Ellis 1985]

  • Compiler generates most

likely paths through the

control flow – called

Traces.

  • Alternate paths need

compensation code to

undo stuff within a trace.

  • Variations include

IMPACT Superblocks

A

C

E

B

D

F