0% found this document useful (0 votes)
51 views15 pages

Compilation Techniques

The document discusses compilation techniques including: 1) The compilation process involves translating high-level code into machine instructions through optimization techniques. 2) Basic compilation methods translate high-level code into machine instructions with little optimization by walking the data flow graph and generating code for each operation. 3) Techniques for generating code for conditionals include drawing control flow graphs and techniques for arrays include using pointers to reference memory locations.

Uploaded by

vsureshkumar0809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views15 pages

Compilation Techniques

The document discusses compilation techniques including: 1) The compilation process involves translating high-level code into machine instructions through optimization techniques. 2) Basic compilation methods translate high-level code into machine instructions with little optimization by walking the data flow graph and generating code for each operation. 3) Techniques for generating code for conditionals include drawing control flow graphs and techniques for arrays include using pointers to reference memory locations.

Uploaded by

vsureshkumar0809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Compilation Techniques

• The characteristics of the code our compiler generates: its speed, its size, and its
power consumption.

• It is useful to understand how a high-level language program is translated into


instructions:
 interrupt handling instructions,
 placement of data,
 instructions in memory, etc.

• We can summarize the compilation process with a formula:


compilation = translation + optimization
The high-level language program is translated into the lower-level form of
instructions.
 optimizations try to generate better instruction sequences.
 Optimization techniques to ensure that one statement are not unnecessarily
problematic for other parts of the program.
Basic compilation methods
• The basic job of translating the high-level language program with little or no
optimization.

• A large amount of the code in a typical application consists of arithmetic and logical
expressions.

• Consider this arithmetic expression:


x = a*b + 5*(c − d)
The code for the expression can be built by walking the data flow graph. Here is the data
flow graph for the expression.
• The temporary variables for the intermediate values and final result have been
named w, x, y, and z.
• The nodes are numbered in the order in • ADR r4,d ; get address for d
which code is generated. Because • MOV r5,[r4] ; load d
every node in the data flow graph
corresponds to an operation that is • SUB r6,r4,r5 ; put z into r6
directly supported by the instruction • ; operator 3 (*)
set.
• MUL r7,r6,#5 ; operator 3, puts y into
r7
• ; operator 1 (+) • ; operator 4 (+)
• ADR r4,a ; get address for a • ADD r8,r7,r3 ; operator 4, puts x into
• MOV r1,[r4] ; load a r8
• ADR r4,b ; get address for b • ; assign to x
• MOV r2,[r4] ; load b • ADR r1,x
• ADD r3,r1,r2 ; put w into r3 • STR r8,[r1] ; assigns to x location
• ; operator 2 (−)
• ADR r4,c ; get address for c
• MOV r4,[r4] ; load c
Program Design and Analysis
Generating Code for a Conditional
• Drawing a control flow graph based on the while form of the loop helps us
understand how to translate it into instructions.
Arrays
• One dimensional array:
a[i]

• We can create a pointer for the array that points to the array’s head, namely, a[0].

• If we call that pointer aptr for convenience, then we can rewrite the reading of a[i] as
*(aptr + i)

• Two-dimensional arrays are more challenging. There are multiple possible ways to lay
out a two-dimensional array in memory
a[i,j]
Compiler optimizations

• A simple but useful transformation is known as loop unrolling.

• Loop fusion combines two or more loops into a single loop.

• Loop distribution is the opposite of loop fusion, that is, decomposing a single loop
into multiple loops.

• Loop tiling breaks up a loop into a set of nested loops, with each inner loop
performing the operations on a subset of the data.

• Array padding adds dummy data elements to a loop in order to change the layout
of the array in the cache.
• Dead code is code that can never be executed. Dead code can be generated by
programmers, either inadvertently or purposefully. Dead code can also be
generated by compilers.

• Register allocation is a very important compilation phase

You might also like