To further motivate the techniques described in this book, we demonstrate the situations in which they are useful and the manner in which they fit into the design flow. Arithmetic optimizations are applicable when writing software as well as during the design of hardware components. This chapter gives a high-level overview of the software compilation process. We start by describing the basic structure of a modern compiler. Then we provide more detail about the compilation process including the place where arithmetic optimizations can be implemented. Finally, we describe the algebraic transformations that are used in current compilers. These include dataflow optimization, CSE, value numbering, loop invariant code motion, partial redundancy elimination (PRE), operator strength reduction, and the Horner form.
Basic software compiler structure
A compiler is used to reduce the complexity of designing digital systems. Quite simply, it transforms an input specification written in some high-level language into another language which is almost always at a lower level of abstraction. Perhaps the most common example is a software compiler, which takes source code written in some high-level programming language (e.g., C/C++, Java) into object code specified by an assembly or machine language for programming a microprocessor (e.g., Intel x86, SPARC, MIPS).
A compiler provides several benefits including:
(1) Raising the level of abstraction to allow the programmer to reason about the problem in a high-level language, which is often more efficient.
(2) Performing trivial and/or tedious transformations, e.g., converting assembly code into binary code.
(3) Finding obvious semantic and syntactic mistakes in the specification.