The goal of this assignment is to familiarize you with the LLVM compiler by implementing a simple LLVM pass to analyze loops in programs.
A compiler analyzes and optimizes programs in passes; each pass scans or traverses the intermediate code to analyze or transform it. Analysis passes are typically used to collect information about a program that helps in ensuring that an optimization pass is safe (not alter the meaning of the program) or determining whether an optimization pass could be beneficial. In this assignment, you will implement an analysis pass to learn interesting properties about the loops in a program. Your pass should report the following information about all loops that are present in a program:
llvm::BranchInst
, llvm::IndirectBrInst
, llvm::SwitchInst
.For each loop, print a line to standard error in the following format (case and space sensitive):
<ID>: func=<str>, depth=<no>, subLoops=<str>, BBs=<no>, instrs=<no>, atomics=<no>, branches=<no>
<ID>
represents a global counter for each loop encountered, starting at 0. <str>
represents a string for function name or boolean value - “true” or “false”. <no>
represents a number.
Please go through the above guide thoroughly. It has all the details to setup LLVM and write/run your own LLVM passes.
You are responsible for writing test cases to test your pass. Write test cases such that you can test various aspects of your pass; start with simple ones and then add more complex ones. Feel free to use LLVM test programs. We can use any program for testing your pass. Your program must be robust (no crashes or undefined behavior) and precise (correct output). So, please test your code thoroughly.
IMPORTANT: DO NOT READ ~/llvm/llvm/lib/Transforms/Scalar/LICM.cpp
You are not allowed to copy source code from anywhere, including other LLVM source files. You can include the header files and call those functions if you think it does precisely what you want. If you are not sure whether you can use something or if you think some LLVM source code is making the assignment trivial, then please let us know on Piazza (you can use a private note).
The following is performed during evaluation:
~/llvm/llvm/lib/Transforms
folder, which will contain a CMakeLists.txt that adds your directory as a sub-directory.~/llvm/llvm/lib/Transforms
folder.opt
as mentioned in the LLVM guide to test your pass on a few input programs. Your program should not crash.Please note that 10 points out of 100 points are assigned for code quality. Code quality will include the following: 1. making sure that your submission conforms to the submission guidelines mentioned below, 2. proper code formatting to make your code readable, and 3. proper code documentation to ensure ease of navigation. Ensuring good code quality is always appreciated throughout the software industry. You can use this opportunity to learn more about the good coding practices and incorporating them into your submission.
llvmpass.zip
: LLVM pass directory containing ONLY your pass should be uploaded. For instance, ~/llvm/llvm/lib/Transforms/SG12345
directory. The name of this directory should be your EID in the upper case. Please ensure that the naming is correct. Do not just rename the directory. The name of the pass is used in multiple places including CMakeLists and inside source files. Refer to the LLVM guide to know the exact places where renaming is necessary.README.md
: The README file should mention all the materials that you have read or used for this assignment, including LLVM documentation and source files.