The LLVM Intermediate Representation and Compiler
This assignment will help you get acquainted with the Low Level Virtual Machine (LLVM) compiler. LLVM is a modular compiler framework and intermediate representation (IR) that uses a static-single-assignment (SSA) form to represent programs at a level suitable for both target-specific and target-agnostic program optimizations. Our work is all built on top of the LLVM compiler framework, so it will be critical that you familiarize yourself with LLVM. In order to learn the internals of LLVM, we have provided a list of useful resources below. Start with the Getting Started guide and the Programmer¡¯s manual, while also looking at the Writing an LLVM Pass guide. ¡¯s LLVM tutorial linked below will also be useful for this assignment. The other links are optional useful resources for you to learn more about LLVM:
¡ñ LLVM Getting Started: https://llvm.org/docs/GettingStarted.html
¡ñ LLVM Installation Guide: https://llvm.org/docs/CMake.html
Copyright By PowCoder代写 加微信 powcoder
¡ñ LLVM Programmers Manual: https://llvm.org/docs/ProgrammersManual.html
¡ñ Writing an LLVM Pass: https://llvm.org/docs/WritingAnLLVMPass.html
¡ñ ¡¯s LLVM Tutorial: https://www.cs.cornell.edu/~asampson/blog/llvm.html
¡ñ LLVM Loops: https://llvm.org/docs/LoopTerminology.html
¡ñ A list of LLVM¡¯s built-in passes: https://llvm.org/docs/Passes.html
¡ñ LLVM Language Reference: https://llvm.org/docs/LangRef.html
¡ñ Another third-party tutorial: https://github.com/banach-space/llvm-tutor
Note that for the purpose of this assignment, we will be using version 9.0.0 of LLVM. The Getting Started Guide / Installation Guide has information on how to checkout a specific release of LLVM. Make sure to use this version while going through any guides/tutorials, as well as while working on this assignment.
Some Pointers
¡ñ When building LLVM, with CMAKE make sure you use GNU Make.
¡ñ In order to have a consistent environment with what we work on, use Ubuntu 18.04 as
¡ñ If you do not have a native Ubuntu machine, I recommend you set up a virtual machine
using Virtual Box: https://www.virtualbox.org. The ISO for Ubuntu 18.04 can be obtained
from here: https://releases.ubuntu.com/18.04/.
¡ñ LLVM 9.0.0 has some very huge binaries that take a lot of memory when linking. As
such, it is recommended that you use an environment with at least 4 GB of RAM and 1 GB of swap space. Also, if you try to build with multiple threads (i.e. make -jN) and it crashes, try building with 1 thread and see if it will pass. To reduce the memory usage, you could set the build type to Release instead of Debug (see CMAKE_BUILD_TYPE).
¡ñ If you do not have access to a machine/environment that matches the above, please contact us ASAP to figure out a solution.
The Assignment
Once you have gone over the tutorials and gotten yourself familiar with LLVM, your first assignment will be to write an LLVM pass as described:
Our goal is to write an LLVM pass that inspects the body of a function (function pass) and prints out all the different types of binary operations found (see the Language Reference for the definition of binary operations), and the number of occurrences of each (e.g. 4 mults, 3 adds, 2 subtracts, …). Make sure you write at least 3 appropriate test cases to test your pass (refer to the guides for more information).
Bonus: As an extra challenge, identify the operations that are located inside loops, and if the loop bounds are constant, provide the dynamic count of those operations. (i.e. the number of operations taking into account all the loop iterations). Note that this should be implemented as a modification to the original pass, not a new one. Use comments to mark your code appropriately to identify where the bonus code begins/ends. Provide one additional test case for the bonus.
Bonus 2: As an additional challenge, modify your pass to be a transformation that, after counting the binary ops and displaying them, goes through and replaces all additions with subtractions. Note that the actual application code will no longer be functionally equivalent to your input application; so this can only be tested by inspecting the generated bitcode.
The deadline for this assignment is Sunday March 13, 11:59 PM. Please make sure to upload your assignment to the box folder that I shared with you. You are required to upload the new pass as well as any test cases you created along with the Makefiles you used to invoke your pass on the test cases. Make sure you upload the pass folder as a whole, not just the C++ source file. Please DO NOT upload the entire LLVM source tree!
Important Notes:
¡ñ The purpose of this assignment is to test your skills and ability to learn. As such, please refrain from sending questions unless you are truly stuck on something and can¡¯t figure it out. Questions about clarity of the assignment are allowed.
¡ñ For the same reason as above, please refrain from working on the assignment together. However, I will leave it to your discretion if you want to help each other out when you get stuck on something.
¡ñ Make sure you document your code and thought process. Even if you are not successful in getting the pass to work within the given time limit, our goal is to judge your problem solving skills, so make sure you submit your assignment anyway!
¡ñ Regarding code organization, note that the LLVM¡¯s tutorial on writing a pass uses an in-tree approach, whereas Adiran Sampson¡¯s approach uses an out-of-tree approach. Both are acceptable solutions, so feel free to choose whichever you prefer.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com