Before we start...
If you have just stumbled upon my SPO600 series of blog posts, it has been created to document and share my learnings as I progress through my Software Portability and Optimization college course.
In this blog post, I’ll start sharing the progress I made after transitioning to Stage 2 of our class project: implementing a new experimental feature in the GNU Compiler Collection (GCC) — Automatic Function Multi-Versioning.
What is Automatic Function Multi-Versioning?
As promised in my
/src- contains the source code of the GCC compiler
/build- used to configure and build the compiler
/install- serves as the destination directory for installing the GCC binaries
The server where I initially built the compiler was put down, so I rebuilt it on our class x86_64 server. The clean build took about 22 minutes.
Adding a New Pass
Before conducting any code experiments, I made sure that I could successfully integrate new passes into GCC.
Our professor, Chris Tyler, gave us his demo pass as a starter code for Project Stage 2. The pass was located in the public folder (/public/spo600-gcc-pass-demo.tgz). I moved it to my home directory and extracted it using the following command:
tar -xvzf spo600-gcc-pass-demo.tgz
Rebuilding GCC with a New Pass
After wrapping my head around the changes required to add the sample pass, I integrated it into the source code and rebuilt the project.
I started by copying the necessary source code files using the following commands:
[akolodeznikova@x86-001 gcc]$ pwd
/home/akolodeznikova/Stage-2/src/gcc
cp ../../../test/gcc/Makefile.in .
cp ../../../test/gcc/passes.def .
cp ../../../test/gcc/tree-pass.h .
cp ../../../test/gcc/tree-ctyler.cc .
Then, I went into the build folder and ran the make command to rebuild the project with applied changes.
The build process took approximately five minutes. Once completed, I ran the make install command to install the newly built GCC compiler into the /install folder.
Note: the
makeutility efficiently rebuilds a codebase by comparing the timestamps of dependencies (inputs) and targets (outputs). It determines which source files have been modified and rebuilds only the affected targets (Chris Tyler’s Wiki).
With the build and installation complete, I tested the setup to verify that the sample pass was working.
To do this, I quickly created a sample file in the test folder:
hello.c
#include<stdio.h>
int main(){
printf("Hello");
return 0;
}
And then compiled it, triggering the newly added pass using the following command:
~/Stage-2/install/bin/gcc hello.c -fdump-tree-ctyler
After running the command, a file named a-hello.c.263t.ctyler was generated. The file contained the following output:
//a-hello.c.263t.ctyler
;; Function main (main, funcdef_no=0, decl_uid=3267, cgraph_uid=1, symbol_order=0)
===== Basic block count: 1 =====
----- Statement count: 1 -----
# .MEM_2 = VDEF <.MEM_1(D)>
printf ("Hello");
----- Statement count: 2 -----
_3 = 0;
===== Basic block count: 2 =====
----- Statement count: 3 -----
<L0>:
----- Statement count: 4 -----
# VUSE <.MEM_2>
return _3;
int main ()
{
int D.3270;
int _3;
<bb 2> :
printf ("Hello");
_3 = 0;
<bb 3> :
<L0>:
return _3;
}
The output confirmed the added pass was working as expected. It successfully iterated through the code, producing diagnostic information about basic blocks and statements.
🎉 🎉 🎉
Stay tuned...
In my next post, I’ll share the code experiments I conducted to implement the proposed functionality. So, stay tuned for more updates on my progress!
SOCIAL SHARE CARD GENERATOR