From 0048a5f16816936955ab9433cdcdc44c9225c378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Warzy=C5=84ski?= Date: Sat, 23 Nov 2024 15:07:48 +0000 Subject: [PATCH] Update to LLVM 19 In addtion, removes ConvertFCmpEq_exec.ll that started failing. Looks like run-time failure. This is not that surprising given that the test is doing equality comparison between two FP numbers. --- .github/workflows/apple-silicon.yml | 6 +- .github/workflows/docker-archlinux.yml | 2 +- .github/workflows/docker-fedora.yml | 2 +- .github/workflows/docker-ubuntu.yml | 2 +- .github/workflows/docker-ubunut-apt.yml | 2 +- .../x86-darwin-llvm-from-sources.yml | 2 +- .../x86-ubuntu-llvm-from-sources-static.yml | 2 +- .../x86-ubuntu-llvm-from-sources.yml | 2 +- .github/workflows/x86-ubuntu.yml | 8 +- CMakeLists.txt | 4 +- HelloWorld/CMakeLists.txt | 4 +- README.md | 100 +++++++++--------- include/DynamicCallCounter.h | 1 + include/InjectFuncCall.h | 1 + include/MBAAdd.h | 1 + include/MBASub.h | 1 + include/MergeBB.h | 1 + include/RIV.h | 2 +- lib/ConvertFCmpEq.cpp | 4 +- lib/DuplicateBB.cpp | 3 +- lib/FindFCmpEq.cpp | 2 +- lib/RIV.cpp | 1 + test/ConvertFCmpEq_exec.ll | 9 -- tools/StaticMain.cpp | 1 + 24 files changed, 80 insertions(+), 83 deletions(-) delete mode 100644 test/ConvertFCmpEq_exec.ll diff --git a/.github/workflows/apple-silicon.yml b/.github/workflows/apple-silicon.yml index 7389fd9b..faaf269c 100644 --- a/.github/workflows/apple-silicon.yml +++ b/.github/workflows/apple-silicon.yml @@ -27,18 +27,18 @@ jobs: - name: Install Dependencies run: | brew update - brew install llvm@18 + brew install llvm@19 brew install lit - name: Build HelloWorld run: | cd HelloWorld mkdir build && cd build - cmake -DLT_LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm@18/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ + cmake -DLT_LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm@19/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ make -j2 - name: Build llvm-tutor + run tests run: | cd $GITHUB_WORKSPACE mkdir build && cd build - cmake -DLT_LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm@18/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ + cmake -DLT_LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm@19/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ make -j2 lit test/ diff --git a/.github/workflows/docker-archlinux.yml b/.github/workflows/docker-archlinux.yml index a042b550..2fc2b6d0 100644 --- a/.github/workflows/docker-archlinux.yml +++ b/.github/workflows/docker-archlinux.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_archlinux --tag llvm-tutor:llvm-18 + run: docker build . --file Dockerfile_archlinux --tag llvm-tutor:llvm-19 diff --git a/.github/workflows/docker-fedora.yml b/.github/workflows/docker-fedora.yml index cd05254e..947626e1 100644 --- a/.github/workflows/docker-fedora.yml +++ b/.github/workflows/docker-fedora.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_fedora --tag llvm-tutor:llvm-18 + run: docker build . --file Dockerfile_fedora --tag llvm-tutor:llvm-19 diff --git a/.github/workflows/docker-ubuntu.yml b/.github/workflows/docker-ubuntu.yml index 4a681859..5846ea84 100644 --- a/.github/workflows/docker-ubuntu.yml +++ b/.github/workflows/docker-ubuntu.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_ubuntu --tag llvm-tutor:llvm-18 + run: docker build . --file Dockerfile_ubuntu --tag llvm-tutor:llvm-19 diff --git a/.github/workflows/docker-ubunut-apt.yml b/.github/workflows/docker-ubunut-apt.yml index 90573c40..f7a629f0 100644 --- a/.github/workflows/docker-ubunut-apt.yml +++ b/.github/workflows/docker-ubunut-apt.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_ubuntu_apt --tag llvm-tutor:llvm-18 + run: docker build . --file Dockerfile_ubuntu_apt --tag llvm-tutor:llvm-19 diff --git a/.github/workflows/x86-darwin-llvm-from-sources.yml b/.github/workflows/x86-darwin-llvm-from-sources.yml index 0f542d2d..a0d2dae0 100644 --- a/.github/workflows/x86-darwin-llvm-from-sources.yml +++ b/.github/workflows/x86-darwin-llvm-from-sources.yml @@ -21,7 +21,7 @@ jobs: echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH - name: Clone llvm-project run: | - git clone --depth 1 --single-branch --branch release/18.x https://github.com/llvm/llvm-project + git clone --depth 1 --single-branch --branch release/19.x https://github.com/llvm/llvm-project - name: Build LLVM run: | cd llvm-project diff --git a/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml b/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml index 2b95cafc..bad40a6d 100644 --- a/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml +++ b/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml @@ -21,7 +21,7 @@ jobs: echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH - name: Clone llvm-project run: | - git clone --depth 1 --single-branch --branch release/18.x https://github.com/llvm/llvm-project + git clone --depth 1 --single-branch --branch release/19.x https://github.com/llvm/llvm-project cd llvm-project - name: Register MBAAdd statically run: | diff --git a/.github/workflows/x86-ubuntu-llvm-from-sources.yml b/.github/workflows/x86-ubuntu-llvm-from-sources.yml index 31dfd639..b53947ff 100644 --- a/.github/workflows/x86-ubuntu-llvm-from-sources.yml +++ b/.github/workflows/x86-ubuntu-llvm-from-sources.yml @@ -23,7 +23,7 @@ jobs: echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH - name: Clone llvm-project run: | - git clone --depth 10 --single-branch --branch release/18.x https://github.com/llvm/llvm-project + git clone --depth 10 --single-branch --branch release/19.x https://github.com/llvm/llvm-project - name: Build LLVM run: | cd llvm-project diff --git a/.github/workflows/x86-ubuntu.yml b/.github/workflows/x86-ubuntu.yml index 4f6a4a60..9e4aa073 100644 --- a/.github/workflows/x86-ubuntu.yml +++ b/.github/workflows/x86-ubuntu.yml @@ -25,9 +25,9 @@ jobs: CXX: ${{ matrix.compiler.CXX }} run: | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" + sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main" sudo apt-get update - sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools clang-18 + sudo apt-get install -y llvm-19 llvm-19-dev llvm-19-tools clang-19 sudo apt-get install python3-setuptools sudo pip3 install lit - name: Build HelloWorld @@ -37,12 +37,12 @@ jobs: run: | cd HelloWorld mkdir build && cd build - cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-18/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ + cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-19/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ make -j2 - name: Build llvm-tutor + run tests run: | cd $GITHUB_WORKSPACE mkdir build && cd build - cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-18/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ + cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-19/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../ make -j2 lit -va test/ diff --git a/CMakeLists.txt b/CMakeLists.txt index c2d726e2..e5624346 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,8 @@ list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/") find_package(LLVM CONFIG) # We defer the version checking to this statement -if("${LLVM_VERSION_MAJOR}" VERSION_LESS 18) - message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 18 or above") +if("${LLVM_VERSION_MAJOR}" VERSION_LESS 19) + message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 19 or above") endif() message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") diff --git a/HelloWorld/CMakeLists.txt b/HelloWorld/CMakeLists.txt index 3416b294..201a8c37 100644 --- a/HelloWorld/CMakeLists.txt +++ b/HelloWorld/CMakeLists.txt @@ -12,8 +12,8 @@ set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory") list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/") find_package(LLVM CONFIG) -if("${LLVM_VERSION_MAJOR}" VERSION_LESS 18) - message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 18 or above") +if("${LLVM_VERSION_MAJOR}" VERSION_LESS 19) + message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 19 or above") endif() # HelloWorld includes headers from LLVM - update the include paths accordingly diff --git a/README.md b/README.md index c8ba8bb3..26d17d62 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ llvm-tutor [![x86-Ubuntu](https://github.com/banach-space/llvm-tutor/actions/workflows/x86-ubuntu.yml/badge.svg?branch=main)](https://github.com/banach-space/llvm-tutor/actions/workflows/x86-ubuntu.yml) -Example LLVM passes - based on **LLVM 18** +Example LLVM passes - based on **LLVM 19** **llvm-tutor** is a collection of self-contained reference LLVM passes. It's a tutorial that targets novice and aspiring LLVM developers. Key features: @@ -57,7 +57,7 @@ For every function defined in the input module, **HelloWorld** prints its name and the number of arguments that it takes. You can build it like this: ```bash -export LLVM_DIR= +export LLVM_DIR= mkdir build cd build cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR /HelloWorld/ @@ -97,30 +97,30 @@ Development Environment ## Platform Support And Requirements This project has been tested on **Ubuntu 22.04** and **Mac OS X 11.7**. In order to build **llvm-tutor** you will need: - * LLVM 18 + * LLVM 19 * C++ compiler that supports C++17 * CMake 3.20 or higher In order to run the passes, you will need: - * **clang-18** (to generate input LLVM files) + * **clang-19** (to generate input LLVM files) * [**opt**](http://llvm.org/docs/CommandGuide/opt.html) (to run the passes) There are additional requirements for tests (these will be satisfied by -installing LLVM 18): +installing LLVM 19): * [**lit**](https://llvm.org/docs/CommandGuide/lit.html) (aka **llvm-lit**, LLVM tool for executing the tests) * [**FileCheck**](https://llvm.org/docs/CommandGuide/FileCheck.html) (LIT requirement, it's used to check whether tests generate the expected output) -## Installing LLVM 18 on Mac OS X -On Darwin you can install LLVM 18 with [Homebrew](https://brew.sh/): +## Installing LLVM 19 on Mac OS X +On Darwin you can install LLVM 19 with [Homebrew](https://brew.sh/): ```bash -brew install llvm@18 +brew install llvm@19 ``` If you already have an older version of LLVM installed, you can upgrade it to -LLVM 18 like this: +LLVM 19 like this: ```bash brew upgrade llvm @@ -129,28 +129,28 @@ brew upgrade llvm Once the installation (or upgrade) is complete, all the required header files, libraries and tools will be located in `/opt/homebrew/opt/llvm/`. -## Installing LLVM 18 on Ubuntu +## Installing LLVM 19 on Ubuntu On Ubuntu Jammy Jellyfish, you can install modern LLVM from the official [repository](http://apt.llvm.org/): ```bash wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - -sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" +sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main" sudo apt-get update -sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools clang-18 +sudo apt-get install -y llvm-19 llvm-19-dev llvm-19-tools clang-19 ``` This will install all the required header files, libraries and tools in -`/usr/lib/llvm-18/`. +`/usr/lib/llvm-19/`. -## Building LLVM 18 From Sources +## Building LLVM 19 From Sources Building from sources can be slow and tricky to debug. It is not necessary, but -might be your preferred way of obtaining LLVM 18. The following steps will work +might be your preferred way of obtaining LLVM 19. The following steps will work on Linux and Mac OS X: ```bash git clone https://github.com/llvm/llvm-project.git cd llvm-project -git checkout release/18.x +git checkout release/19.x mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_PROJECTS=clang /llvm/ @@ -166,18 +166,18 @@ You can build **llvm-tutor** (and all the provided pass plugins) as follows: ```bash cd -cmake -DLT_LLVM_INSTALL_DIR= +cmake -DLT_LLVM_INSTALL_DIR= make ``` The `LT_LLVM_INSTALL_DIR` variable should be set to the root of either the -installation or build directory of LLVM 18. It is used to locate the +installation or build directory of LLVM 19. It is used to locate the corresponding `LLVMConfig.cmake` script that is used to set the include and library paths. ## Testing In order to run **llvm-tutor** tests, you need to install **llvm-lit** (aka -**lit**). It's not bundled with LLVM 18 packages, but you can install it with +**lit**). It's not bundled with LLVM 19 packages, but you can install it with **pip**: ```bash @@ -242,7 +242,7 @@ below. LLVM passes work with LLVM IR files. You can generate one like this: ```bash -export LLVM_DIR= +export LLVM_DIR= # Textual form $LLVM_DIR/bin/clang -O1 -emit-llvm input.c -S -o out.ll # Binary/bit-code form @@ -273,7 +273,7 @@ use the `*.so` extension for pass plugins. When working on Mac OS, use ## OpcodeCounter **OpcodeCounter** is an Analysis pass that prints a summary of the [LLVM IR -opcodes](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/IR/Instruction.cpp#L397-L480) +opcodes](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/IR/Instruction.cpp#L397-L480) encountered in every function in the input module. This pass can be [run automatically](#auto-registration-with-optimisation-pipelines) with one of the pre-defined optimisation pipelines. However, let's use our tried and tested method @@ -293,7 +293,7 @@ does not modify the input IR, the output module would be identical to the input anyway. ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate an LLVM file to analyze $LLVM_DIR/bin/clang -emit-llvm -c /inputs/input_for_cc.c -o input_for_cc.bc # Run the pass through opt @@ -353,7 +353,7 @@ We will use to test **InjectFuncCall**: ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate an LLVM file to analyze $LLVM_DIR/bin/clang -O0 -emit-llvm -c /inputs/input_for_hello.c -o input_for_hello.bc # Run the pass through opt @@ -424,7 +424,7 @@ We will use to test **StaticCallCounter**: ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate an LLVM file to analyze $LLVM_DIR/bin/clang -emit-llvm -c /inputs/input_for_cc.c -o input_for_cc.bc # Run the pass through opt @@ -478,7 +478,7 @@ We will use to test **DynamicCallCounter**: ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate an LLVM file to analyze $LLVM_DIR/bin/clang -emit-llvm -c /inputs/input_for_cc.c -o input_for_cc.bc # Instrument the input file @@ -544,7 +544,7 @@ We will use to test **MBASub**: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S /inputs/input_for_mba_sub.c -o input_for_sub.ll $LLVM_DIR/bin/opt -load-pass-plugin=/lib/libMBASub.so -passes="mba-sub" -S input_for_sub.ll -o out.ll ``` @@ -566,7 +566,7 @@ We will use to test **MBAAdd**: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -O1 -emit-llvm -S /inputs/input_for_mba.c -o input_for_mba.ll $LLVM_DIR/bin/opt -load-pass-plugin=/lib/libMBAAdd.so -passes="mba-add" -S input_for_mba.ll -o out.ll ``` @@ -594,7 +594,7 @@ We will use to test **RIV**: ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate an LLVM file to analyze $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_riv.c -o input_for_riv.ll # Run the pass through opt @@ -695,7 +695,7 @@ LEGEND: ``` As depicted above, **DuplicateBB** replaces qualifying basic blocks with 4 new basic blocks. This is implemented through LLVM's -[SplitBlockAndInsertIfThenElse](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h#L471). +[SplitBlockAndInsertIfThenElse](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h#L471). **DuplicateBB** does all the necessary preparation and clean-up. In other words, it's an elaborate wrapper for LLVM's `SplitBlockAndInsertIfThenElse`. @@ -706,7 +706,7 @@ This pass depends on the **RIV** pass, which also needs be loaded in order for as our sample input. First, generate the LLVM file: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_duplicate_bb.c -o input_for_duplicate_bb.ll ``` @@ -826,7 +826,7 @@ It is really interesting to see the effect of **MergeBB** on the output from **DuplicateBB**. Let's start with the same input as we used for **DuplicateBB**: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_duplicate_bb.c -o input_for_duplicate_bb.ll ``` @@ -874,7 +874,7 @@ We will use [input_for_fcmp_eq.ll](https://github.com/banach-space/llvm-tutor/bl to test **FindFCmpEq**: ```bash -export LLVM_DIR= +export LLVM_DIR= # Generate the input file $LLVM_DIR/bin/clang -emit-llvm -S -Xclang -disable-O0-optnone -c /inputs/input_for_fcmp_eq.c -o input_for_fcmp_eq.ll # Run the pass @@ -904,7 +904,7 @@ As with [**FindFCmpEq**](#FindFCmpEq), we will use to test **ConvertFCmpEq**: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -Xclang -disable-O0-optnone \ -c /inputs/input_for_fcmp_eq.c -o input_for_fcmp_eq.ll $LLVM_DIR/bin/opt --load-pass-plugin /lib/libFindFCmpEq.so \ @@ -958,7 +958,7 @@ and macros. For example, for **MBAAdd**: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_mba.c -o input_for_mba.ll $LLVM_DIR/bin/opt -S -load-pass-plugin /lib/libMBAAdd.so -passes=mba-add input_for_mba.ll -debug-only=mba-add -stats -o out.ll ``` @@ -989,7 +989,7 @@ The default debugger on OS X is [LLDB](http://lldb.llvm.org). You will normally use it like this: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_mba.c -o input_for_mba.ll lldb -- $LLVM_DIR/bin/opt -S -load-pass-plugin /lib/libMBAAdd.dylib -passes=mba-add input_for_mba.ll -o out.ll (lldb) breakpoint set --name MBAAdd::run @@ -998,7 +998,7 @@ lldb -- $LLVM_DIR/bin/opt -S -load-pass-plugin /lib/libMBAAdd.dylib - or, equivalently, by using LLDBs aliases: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_mba.c -o input_for_mba.ll lldb -- $LLVM_DIR/bin/opt -S -load-pass-plugin /lib/libMBAAdd.dylib -passes=mba-add input_for_mba.ll -o out.ll (lldb) b MBAAdd::run @@ -1011,7 +1011,7 @@ On most Linux systems, [GDB](https://www.gnu.org/software/gdb/) is the most popular debugger. A typical session will look like this: ```bash -export LLVM_DIR= +export LLVM_DIR= $LLVM_DIR/bin/clang -emit-llvm -S -O1 /inputs/input_for_mba.c -o input_for_mba.ll gdb --args $LLVM_DIR/bin/opt -S -load-pass-plugin /lib/libMBAAdd.so -passes=mba-add input_for_mba.ll -o out.ll (gdb) b MBAAdd.cpp:MBAAdd::run @@ -1024,14 +1024,14 @@ Analysis vs Transformation Pass The implementation of a pass depends on whether it is an Analysis or a Transformation pass: -* a transformation pass will normally inherit from [PassInfoMixin](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/include/llvm/IR/PassManager.h#L371), -* an analysis pass will inherit from [AnalysisInfoMixin](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/include/llvm/IR/PassManager.h#L394). +* a transformation pass will normally inherit from [PassInfoMixin](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/include/llvm/IR/PassManager.h#L371), +* an analysis pass will inherit from [AnalysisInfoMixin](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/include/llvm/IR/PassManager.h#L394). This is one of the key characteristics of the New Pass Managers - it makes the split into Analysis and Transformation passes very explicit. An Analysis pass requires a bit more bookkeeping and hence a bit more code. For example, you need to add an instance of -[AnalysisKey](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/include/llvm/IR/PassManager.h#L410) +[AnalysisKey](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/include/llvm/IR/PassManager.h#L410) so that it can be identified by the New Pass Manager. Note that for small standalone examples, the difference between Analysis and @@ -1135,13 +1135,13 @@ examples. | Name | Description | Test files in llvm-tutor | |-----------|-----------------|--------------------------| -|[**dce**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Scalar/DCE.cpp) | Dead Code Elimination | [dce.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/dce.ll) | -|[**memcpyopt**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp) | Optimise calls to `memcpy` (e.g. replace them with `memset`) | [memcpyopt.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/memcpyopt.ll) | -|[**reassociate**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Scalar/Reassociate.cpp) | Reassociate (e.g. 4 + (x + 5) -> x + (4 + 5)). This enables further optimisations, e.g. LICM. | [reassociate.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/reassociate.ll) | -|[**always-inline**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/IPO/AlwaysInliner.cpp) | Always inlines functions decorated with [`alwaysinline`](https://llvm.org/docs/LangRef.html#function-attributes) | [always-inline.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/always-inline.ll) | -|[**loop-deletion**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Scalar/LoopDeletion.cpp) | Delete unused loops | [loop-deletion.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/loop-deletion.ll) | -|[**licm**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Scalar/LICM.cpp) | [Loop-Invariant Code Motion](https://en.wikipedia.org/wiki/Loop-invariant_code_motion) (a.k.a. LICM) | [licm.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/licm.ll) | -|[**slp**](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp) | [Superword-level parallelism vectorisation](https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer) | [slp\_x86.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_x86.ll), [slp\_aarch64.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_aarch64.ll) | +|[**dce**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Scalar/DCE.cpp) | Dead Code Elimination | [dce.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/dce.ll) | +|[**memcpyopt**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp) | Optimise calls to `memcpy` (e.g. replace them with `memset`) | [memcpyopt.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/memcpyopt.ll) | +|[**reassociate**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Scalar/Reassociate.cpp) | Reassociate (e.g. 4 + (x + 5) -> x + (4 + 5)). This enables further optimisations, e.g. LICM. | [reassociate.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/reassociate.ll) | +|[**always-inline**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/IPO/AlwaysInliner.cpp) | Always inlines functions decorated with [`alwaysinline`](https://llvm.org/docs/LangRef.html#function-attributes) | [always-inline.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/always-inline.ll) | +|[**loop-deletion**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Scalar/LoopDeletion.cpp) | Delete unused loops | [loop-deletion.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/loop-deletion.ll) | +|[**licm**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Scalar/LICM.cpp) | [Loop-Invariant Code Motion](https://en.wikipedia.org/wiki/Loop-invariant_code_motion) (a.k.a. LICM) | [licm.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/licm.ll) | +|[**slp**](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp) | [Superword-level parallelism vectorisation](https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer) | [slp\_x86.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_x86.ll), [slp\_aarch64.ll](https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_aarch64.ll) | This list focuses on [LLVM's transform passes](https://llvm.org/docs/Passes.html#transform-passes) that are relatively @@ -1172,11 +1172,11 @@ Piovezan, EuroLLVM, ([slides](https://llvm.org/devmtg/2019-04/slides/Tutorial-Br * _"Mapping High Level Constructs to LLVM IR"_, M. Rodler ([link](https://mapping-high-level-constructs-to-llvm-ir.readthedocs.io/en/latest/)) * **Examples in LLVM** * Control Flow Graph simplifications: - [llvm/examples/IRTransforms/](https://github.com/llvm/llvm-project/tree/release/18.x/llvm/examples/IRTransforms) + [llvm/examples/IRTransforms/](https://github.com/llvm/llvm-project/tree/release/19.x/llvm/examples/IRTransforms) * Hello World Pass: - [llvm/lib/Transforms/Hello/](https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Transforms/Hello) + [llvm/lib/Transforms/Hello/](https://github.com/llvm/llvm-project/blob/release/19.x/llvm/lib/Transforms/Hello) * Good Bye World Pass: - [llvm/examples/Bye/](https://github.com/llvm/llvm-project/tree/release/18.x/llvm/examples/Bye) + [llvm/examples/Bye/](https://github.com/llvm/llvm-project/tree/release/19.x/llvm/examples/Bye) * **LLVM Pass Development** * _"Writing an LLVM Optimization"_, Jonathan Smith [video](https://www.youtube.com/watch?v=MagR2KY8MQI&t) * _"Getting Started With LLVM: Basics "_, J. Paquette, F. Hahn, LLVM Dev Meeting 2019 [video](https://www.youtube.com/watch?v=3QQuhL-dSys&t=826s) diff --git a/include/DynamicCallCounter.h b/include/DynamicCallCounter.h index b44712be..595733ba 100644 --- a/include/DynamicCallCounter.h +++ b/include/DynamicCallCounter.h @@ -11,6 +11,7 @@ #ifndef LLVM_TUTOR_INSTRUMENT_BASIC_H #define LLVM_TUTOR_INSTRUMENT_BASIC_H +#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/include/InjectFuncCall.h b/include/InjectFuncCall.h index f6c0369d..747a245d 100644 --- a/include/InjectFuncCall.h +++ b/include/InjectFuncCall.h @@ -10,6 +10,7 @@ #ifndef LLVM_TUTOR_INSTRUMENT_BASIC_H #define LLVM_TUTOR_INSTRUMENT_BASIC_H +#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/include/MBAAdd.h b/include/MBAAdd.h index 75341160..09fbf1f9 100644 --- a/include/MBAAdd.h +++ b/include/MBAAdd.h @@ -10,6 +10,7 @@ #ifndef LLVM_TUTOR_MBA_ADD_H #define LLVM_TUTOR_MBA_ADD_H +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/include/MBASub.h b/include/MBASub.h index 4034c915..cc5c0cbc 100644 --- a/include/MBASub.h +++ b/include/MBASub.h @@ -10,6 +10,7 @@ #ifndef LLVM_TUTOR_MBA_SUB_H #define LLVM_TUTOR_MBA_SUB_H +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/include/MergeBB.h b/include/MergeBB.h index fc1be7f5..581c8673 100644 --- a/include/MergeBB.h +++ b/include/MergeBB.h @@ -10,6 +10,7 @@ #ifndef LLVM_TUTOR_MERGEBBS_H #define LLVM_TUTOR_MERGEBBS_H +#include "llvm/IR/Instruction.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/include/RIV.h b/include/RIV.h index 85131157..af08de5d 100644 --- a/include/RIV.h +++ b/include/RIV.h @@ -15,8 +15,8 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Dominators.h" -#include "llvm/IR/ValueMap.h" #include "llvm/Pass.h" //------------------------------------------------------------------------------ diff --git a/lib/ConvertFCmpEq.cpp b/lib/ConvertFCmpEq.cpp index f10efae7..1291b6b3 100644 --- a/lib/ConvertFCmpEq.cpp +++ b/lib/ConvertFCmpEq.cpp @@ -114,8 +114,6 @@ static FCmpInst *convertFCmpEqInstruction(FCmpInst *FCmp) noexcept { } static constexpr char PassArg[] = "convert-fcmp-eq"; -static constexpr char PassName[] = - "Convert floating-point equality comparisons"; static constexpr char PluginName[] = "ConvertFCmpEq"; #define DEBUG_TYPE ::PassArg @@ -162,7 +160,7 @@ PassPluginLibraryInfo getConvertFCmpEqPluginInfo() { PB.registerPipelineParsingCallback( [&](StringRef Name, FunctionPassManager &FPM, ArrayRef) { - if (Name.equals(PassArg)) { + if (!Name.compare(PassArg)) { FPM.addPass(ConvertFCmpEq()); return true; } diff --git a/lib/DuplicateBB.cpp b/lib/DuplicateBB.cpp index 35623d45..f90beacb 100644 --- a/lib/DuplicateBB.cpp +++ b/lib/DuplicateBB.cpp @@ -80,11 +80,12 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Module.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassPlugin.h" +#include "llvm/Support/RandomNumberGenerator.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Support/RandomNumberGenerator.h" #include diff --git a/lib/FindFCmpEq.cpp b/lib/FindFCmpEq.cpp index befe2fb2..aad0557e 100644 --- a/lib/FindFCmpEq.cpp +++ b/lib/FindFCmpEq.cpp @@ -123,7 +123,7 @@ PassPluginLibraryInfo getFindFCmpEqPluginInfo() { ArrayRef) { std::string PrinterPassElement = formatv("print<{0}>", PassArg); - if (Name.equals(PrinterPassElement)) { + if (!Name.compare(PrinterPassElement)) { FPM.addPass(FindFCmpEqPrinter(llvm::outs())); return true; } diff --git a/lib/RIV.cpp b/lib/RIV.cpp index 7269f2c6..e8fb18d0 100644 --- a/lib/RIV.cpp +++ b/lib/RIV.cpp @@ -34,6 +34,7 @@ //============================================================================= #include "RIV.h" +#include "llvm/IR/Module.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassPlugin.h" #include "llvm/Support/Format.h" diff --git a/test/ConvertFCmpEq_exec.ll b/test/ConvertFCmpEq_exec.ll deleted file mode 100644 index 61810203..00000000 --- a/test/ConvertFCmpEq_exec.ll +++ /dev/null @@ -1,9 +0,0 @@ -; This should return 0 as `a == b` is going to be false for floating point numbers -; RUN: lli %S/Inputs/FCmpEqInput.ll - -; After the transformation, `a == b` is replaced with `a - b < eps`, which is -; going to be true for floating point numbers. -; RUN: opt --load-pass-plugin=%shlibdir/libFindFCmpEq%shlibext \ -; RUN: --load-pass-plugin=%shlibdir/libConvertFCmpEq%shlibext \ -; RUN: --passes="convert-fcmp-eq" -S %S/Inputs/FCmpEqInput.ll -o %t.bin -; RUN: not lli %t.bin diff --git a/tools/StaticMain.cpp b/tools/StaticMain.cpp index b179af65..0889a2e4 100644 --- a/tools/StaticMain.cpp +++ b/tools/StaticMain.cpp @@ -20,6 +20,7 @@ #include "llvm/IRReader/IRReader.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h"