For the register allocator, the single registers need to be grouped into register classes. The sequence order of the registers defines the allocation order. The register allocator also needs other information about the registers such as, for example, the value types, which can be stored in a register, the spill size of a register in bits, and the required alignment …
Adding the register definition – The Target Description-1
Is adding support for an object file format mandatory? Integrating support for an architecture into the ELF file format implementation requires only a couple of lines of code. If the architecture for which you are creating an LLVM backend uses the ELF format, then you should take this route. On the other hand, adding support for a completely new binary …
Adding the new architecture to the Triple class – The Target Description
An instance of the Triple class represents the target platform LLVM is producing code for. To support a new architecture, the first task is to extend the Triple class. In the llvm/include/llvm/TargetParser/Triple.h file, add a member to the ArchType enumeration along with a new predicate:class Triple {public:enum ArchType {// Many more membersm88k, // M88000 (big endian): m88k};/// Tests whether the …
Setting the stage for a new backend – The Target Description
LLVM has a very flexible architecture. You can also add a new target backend to it. The core of a backend is the target description, from which most of the code is generated. In this chapter, you will learn how to add support for a historical CPU. In this chapter, you will cover the following: By the end of the …
Creating your own clang-based tool – Debugging Using LLVM Tools-4
This new implementation has the same functionality. The advantage is that it is easier to extend. For example, if you want to examine variable declarations, then you must implement the VisitVarDecl() method. Alternatively, if you want to work with a statement, then you must implement the VisitStmt() method. With this approach, you have a visitor method for each entity of …
Creating your own clang-based tool – Debugging Using LLVM Tools-3
On Windows, the plugin support is different from Unix, and the required LLVM and clang libraries must be linked in. The following code ensures this:if(WIN32 OR CYGWIN)set(LLVM_LINK_COMPONENTS Support)clang_target_link_libraries(NamingPlugin PRIVATEclangAST clangBasic clangFrontend clangLex)endif() Now, we can configure and build the plugin, assuming that the CMAKE_GENERATOR and CMAKE_BUILD_TYPE environment variables are set:$ cmake -DLLVM_DIR=~/LLVM/llvm-17/lib/cmake/llvm \-DClang_DIR=~/LLVM/llvm-17/lib/cmake/clang \-B build$ cmake –build build These steps …
Creating your own clang-based tool – Debugging Using LLVM Tools-2
If the function name does not start with a lowercase letter, then you’ll have a violation of the naming rule that was found:char &First = Name.at(0);if (!(First >= ‘a’ && First <= ‘z’)) { The first method you must implement is the CreateASTConsumer() method, which returns an instance of your NamingASTConsumer class. This method is called by clang, and the …
Creating your own clang-based tool – Debugging Using LLVM Tools-1
The static analyzer is an impressive example of what you can do with the clang infrastructure. It is also possible to extend clang with plugins so that you can add your own functionality to clang. The technique is very similar to adding a pass plugin to LLVM. Let’s explore the functionality with a simple plugin. The LLVM coding standard requires …
Adding a new checker to the clang static analyzer – Debugging Using LLVM Tools-5
This finishes the implementation of the new checker. To build the plugin, we also need to create a build description in the CMakeLists.txt file which lives in the same directory as IconvChecker.cpp: Now, we can configure and build the plugin, assuming that the CMAKE_GENERATOR and CMAKE_BUILD_TYPE environment variables are set:$ cmake -DLLVM_DIR=~/LLVM/llvm-17/lib/cmake/llvm \-DClang_DIR=~/LLVM/llvm-17/lib/cmake/clang \-B build$ cmake –build build You can …