Principles of Compiler Design - Tutorial 9
Principles of Compiler Design - Tutorial 9
Principles of Compiler Design - Tutorial 9
Tutorial 9
Name :
PRN :
1. Introduction
Lance is a software platform for fast implementation of C compilers. It includes a C
frontend, a set of code optimization passes on IR level, a C++ library for IR analysis
and manipulation, and a backend interface for assembly code generation.
LANCE is mainly intended for C compiler development for embedded processors. The
system has been applied both in academic and industrial compiler development
projects for a variety of different target architectures.
Main features:
ANSI C frontend (C89)
Extensible, modular compiler architecture
Executable three address code IR
Library of standard ("Dragon Book style") IR optimizations
C++ API for IR access and analysis
Visualization of control and data flow graphs
Backend interface for code selection
Code instrumentation interface
Free licensing for research purposes
2. Software Architecture
LANCE consists of a C++ library and compiler tools. The C++ library provides an API
for IR access and manipulation. In addition, it comprises numerous algorithms and
data structures needed for building compiler tools, ranging from simple structures
(e.g. lists, stacks, graphs) to advanced code analysis routines (e.g. control and data
flow analysis).
All LANCE tools are built on the C++ library. They operate on a common
intermediate representation in the "IR-C" format in a plug-and-play fashion. While
LANCE already comprises a set of IR optimization tools, new IR transformations can
be easily added anytime.
3.ANSI C Frontend
LANCE comprises a frontend for full ANSI C (C89 language version). It requires a
separate C pre-processor , though, and standard header files and libraries are NOT
included. Normally, these components are reused from the GNU C compiler.
LANCE's ANSI C frontend source code has been automatically generated by means
of the attribute grammar compiling system OX (available
from: ftp://ftp.cs.iastate.edu/pub/ox/). OX reads an attribute grammar and generates
lex and yacc source files. The use of generated C frontend code significantly
reduces the coding effort and improves reliability. The C frontend is called via the
"compile" shell command. It translates each C source file into a separate IR file.
4. Intermediate Representation (IR)
LANCE uses a three address code intermediate representation (IR). Complex
expressions are decomposed into three address code by means of insertion of
temporary variables. High-level control flow statements (loops, switch etc.) are
replaced by equivalent jump constructs close to the assembly level.
The IR can be dumped to a file in low level ANSI C syntax. This implies a clear and
easy-to-learn IR semantics (subset of C semantics) and enables executability of the
IR, which enables verification of new IR transformation passes and fine-grained code
instrumentation for profiling purposes.
5. IR-level code optimization engines
LANCE includes a number of both classical ("Dragon Book") and advanced IR-
level code optimization engines. They are implemented as separate tools and can
be combined and iterated by a predefined IR optimization script that can be
modified or extended to optimize code quality for a specific class of target
machines or to plug in new optimization tools. Currently, the following optimization
engines are available:
constant folding
constant propagation
copy propagation
dead code elimination
common subexpression elimination
function inlining
induction variable elimination
jump optimization
loop invariant code motion
SSA conversion
Reassociation
The LANCE C++ library comprises functions for control and data flow analysis. They
allow for visualization of control and data flow graphs, e.g. for debugging purposes.
LANCE emits flow graphs per C function in a textual format that can be visualized e.g.
with the VCG graph display tool.
7. Verification
LANCE permits plug-and-play integration of new IR transformation and optimization
passes. Naturally, such new passes need to be extensively verified. LANCE supports
verification of any IR transformation by means of its executable IR format, without the
need for a compiler backend or an instruction set simulator. This is achieved with the
methodology illustrated below: Both an original reference IR code of a test application
and the IR code generated from it by a new transformation are compiled with a native
C compiler (CC) for the development host. The resulting binaries are checked for
equivalence by execution for a set of test input data. Deviations in the outputs indicate
bugs in the new IR transformation.
9. Backend Interface
LANCE can convert its three address code IR into a tree data
structure that is compatible to popular code generator generator
tools like iburg and olive. This feature facilitates compiler
retargeting, as the designer can directly start by writing a target-
specific code selector specification.