Compilation Techniques
Compilation Techniques
• The characteristics of the code our compiler generates: its speed, its size, and its
power consumption.
• A large amount of the code in a typical application consists of arithmetic and logical
expressions.
• 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
• 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.