Project for CSC 255/455, Spring 2009


In the project, you will add your own optimization passes in the Gnu C Compiler, GCC 4.2.2. It is not the most recent GCC, but should be sufficient for our project. You have to know the basic framework of GCC and how to manipulate the intermediate form, the gimple tree, for program analysis and transformation. This page includes many suggestions that will help you in the process. Please read the entire page and the pages about source browsing and debugging before you start.

Compilation, Installation and Run

  • Check out the code by using subversion, and install.
        mkdir gcc
        cd gcc
        svn co file:///p/compiler/repos/gcc-4.2.2/trunk gcc-4.2.2
           // if outside the firewall, use
           // svn co svn+ssh:// gcc-4.2.2
        mkdir obj
        cd obj
        ../gcc-4.2.2/configure --prefix=$INSTALL_DIR
          // $INSTALL_DIR is the directory you want to install your compiler
        make install
  • For those who have no access to department research network, please download gcc-4.2.2.tar.bz2 and unzip it with the command tar -jxvf gcc-4.2.2.tar.bz2. There is also a copy on undergrad network at /home/hoover/u1/cs255/.
  • Use either our desktop or personal machine or one of the public use machines in the CS department. When using department machines, due to the shortage of space for the /home directory, it is better to put your code under /localdisk .
  • Invoke your pass: use -O2 -fcs255
  • Put your own code into gcc-4.2.2/gcc/cs255.c
  • Use make for your testing: see An Example for Makefile
  • About turn in: You need to turn in the file containing source code (normally only cs255.c), along with the README document describing the design, implementation and testing results when applicable. README is a very important part of your project, so lease take it seriously. To submit your work, make a new folder, put cs255.c and README into it, and then call /home/vax2/p28/compiler2/xiaoming/csc255/src_scripts/turn-in in the folder. If you have problem with the submit script, feel free to send the two files to me by email.

Browsing GCC code

  • Gnu's wiki page on GCC getting started.
    • You can open in a web browser the following file /p/compiler/built/gcc-4.2.2/doxygen/ and start with index.html for a local copy of Gcc 4.2.2 documentation by doxygen. If you copy, the directory needs about 600MB disk space.
    • Installing and using Doxygen to generate your own documentation
    • Good Assorted Topics Page from developer site also has a decent overview.
  • Using Emacs (especially useful when you work remotely)
  • Using Eclipse (w/ CDT). You can download Eclipse IDE for C/C++ Developers (68 MB) from here.


GCC Data Structures and Internal Representations

Part 1: Trivial (5%) (Due: Feb. 4)

In this part, you will add a pass that will insert code into a program to count and output the number of executed statements when the program executes. You need to first add a call at the beginning of the main function, which has a global counter initialized to 0; then add a call before each gimple statement, which increments the counter; and finally add a call at the exit, which reports the run-time instruction counts. The three functions are provided in cs255-lib.c and cs255-lib.h:
  • Initialization: you'll need to add it at the entry of the main function
  • Increment: to be added before each real gimple statements (all except for labels)
  • Report: to be added at all possible exits of the program
  • Remember to add #include "cs255-lib.h" in your own testing programs.

This part should take at most tens of lines of code and no more than a day (including half an hour compiling the compiler for the first time). The purpose is to get you familiar with GCC and the basic GCC functions that you'll need for adding your optimization passes. Reading the relevant, existing code (in gcc-4.2.2/gcc/cs255.c) is the best way to help you writing your new code in an existing system. For instance, the code for counting the number of basic blocks and statements statically is already in the file. The code for getting the dynamic count of the basic blocks is also given.

For testing, there are some open test cases. You may use the results from them to check your code with your classmates. And they are very useful in following parts and final competition.


Topic attachments
I Attachment History Action Size Date Who Comment
PDFpdf Project_Introduction.pdf r1 manage 120.9 K 2009-01-28 - 22:07 BinBao a general introduction to course project, given on Jan. 28
Edit | Attach | Watch | Print version | History: r30 | r16 < r15 < r14 < r13 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r14 - 2009-01-30 - BinBao
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback