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 …
Category: Performance profiling with XRay
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-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-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 …
Performance profiling with XRay – Debugging Using LLVM Tools-2
A stack frame is the sequence of how a function is called. The func2() function is called by the main() function, and this is the stack frame with the largest accumulated time. The depth depends on how many functions are called, and the stack frames are usually large. This sub-command can also be used to create a flame graph from …
Performance profiling with XRay – Debugging Using LLVM Tools-1
If your application seems to run slow, then you might want to know where the time is spent in the code. Here, instrumenting the code with XRay can assist with this task. Basically, at each function entry and exit, a special call is inserted into the runtime library. This allows you to count how often a function is called, and …
Limitations and alternatives – Debugging Using LLVM Tools
The libFuzzer implementation is fast but poses several restrictions on the test target. They are as follows: The first two restrictions are an implication of the implementation of libFuzzer as a library. The latter two restrictions are needed to avoid confusion in the evaluation algorithm. If one of these restrictions is not met, then two identical calls to the fuzz …
Finding bugs with libFuzzer – Debugging Using LLVM Tools-1
To test your application, you’ll need to write unit tests. This is a great way to make sure your software behaves correctly and as you might expect. However, because of the exponential number of possible inputs, you’ll probably miss certain weird inputs, and a few bugs as well. Fuzz testing can help here. The idea is to present your application …
Pointing out data races with the thread sanitizer – Debugging Using LLVM Tools
To leverage the power of modern CPUs, applications now use multiple threads. This is a powerful technique, but it also introduces new sources of errors. A very common problem in multi-threaded applications is that the access to global data is not protected, for example, with a mutex or semaphore. This is called a data race. The thread sanitizer can detect …