Writing LLVM Bitcode
For this assignment you should create a program in the LLVM human-readable bitcode format (i.e. a .ll file) that takes n command line arguments and exits with a return code equal to the nth number in the Fibonnaci sequence. Your program does not need to worry about overflow in the return code, but it should be written in such a way that it can calculate an arbitrary Fibonnaci number via an iterative algorihm. Only use the bitcode instructions discussed in class, i.e. Phi nodes, branch instructions, compares, and basic arithmetic. You should code this assignment by hand, directly writing the LLVM IR instructions.
Requirements
Your submission must include a program fib.ll
that is composed only of valid LLVM IR instructions/operands
that we described in class. Thus, you will need to use virtual registers and PHI nodes in your computation.
Submission Format
In order to simplify the task of grading, your code will be batch downloaded and extracted via a script. For this reason, the format of your submission is very particular:
You should turn in a gzipped tarball named p1.tgz
. This tarball should contain 1 directory, named p1
, and under that directory you should place your fib.ll
as well as a file named TEAM.md, which contains the names, in the format lastname,firstname
of each person that worked on the assignment.
In other words, the directory structure is like:
- p1 (root directory)
- fib.ll
- TEAM.md
tar -czf p1.tgz p1
Testing your Code
The easiest way to test your program is using the lli
command from LLVM. You can install this program multiple ways on your own machine via the llvm packages in your package manager. On an Ubuntu machine, you could install lli using
apt install llvm-runtime
or
apt install clang
cycle2.eecs.ku.edu
, cycle3.eecs.ku.edu
, and cycle4.eecs.ku.edu
, using your ku username and password as login credentials. Note that the cycle servers do have the LLVM framework code installed. However, to make the version of LLVM explicit, commands are all suffixed with -14
. Thus, to invoke lli
on the cycle servers, you would run
lli-14 fib.ll a b c
This program should set the exit code to 2, since supplying 3 arguments should compute the 3rd Fibonacci number (which is 2).