Skip to content

Commit

Permalink
Upgrade to LLVM 17
Browse files Browse the repository at this point in the history
Apart from basic updates, this patch removes any remaining references to
the legacy pass manager,  which is no longer supported.

While the links are updated to point to LLVM Release 17, line numbers
are kept in tact and likely out of sync. Leaving this as a TODO for
later.
  • Loading branch information
banach-space committed Nov 12, 2023
1 parent 513506c commit c068d58
Show file tree
Hide file tree
Showing 66 changed files with 104 additions and 795 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-15
run: docker build . --file Dockerfile_fedora --tag llvm-tutor:llvm-17
2 changes: 1 addition & 1 deletion .github/workflows/docker-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-16
run: docker build . --file Dockerfile_ubuntu --tag llvm-tutor:llvm-17
2 changes: 1 addition & 1 deletion .github/workflows/docker-ubunut-apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-16
run: docker build . --file Dockerfile_ubuntu_apt --tag llvm-tutor:llvm-17
2 changes: 1 addition & 1 deletion .github/workflows/x86-darwin-llvm-from-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH
- name: Clone llvm-project
run: |
git clone --depth 1 --single-branch --branch release/16.x https://github.com/llvm/llvm-project
git clone --depth 1 --single-branch --branch release/17.x https://github.com/llvm/llvm-project
- name: Build LLVM
run: |
cd llvm-project
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/x86-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ jobs:
- name: Install Dependencies
run: |
brew update
brew install llvm@16
brew install llvm@17
brew install lit
- name: Build HelloWorld
run: |
cd HelloWorld
mkdir build && cd build
cmake -DLT_LLVM_INSTALL_DIR="/usr/local/opt/llvm@16/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../
cmake -DLT_LLVM_INSTALL_DIR="/usr/local/opt/llvm@17/" -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/local/opt/llvm@16/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../
cmake -DLT_LLVM_INSTALL_DIR="/usr/local/opt/llvm@17/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../
make -j2
lit test/
2 changes: 1 addition & 1 deletion .github/workflows/x86-ubuntu-llvm-from-sources-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH
- name: Clone llvm-project
run: |
git clone --depth 1 --single-branch --branch release/16.x https://github.com/llvm/llvm-project
git clone --depth 1 --single-branch --branch release/17.x https://github.com/llvm/llvm-project
cd llvm-project
- name: Register MBAAdd statically
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/x86-ubuntu-llvm-from-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
echo "${GITHUB_WORKSPACE}/ninja" >> $GITHUB_PATH
- name: Clone llvm-project
run: |
git clone --depth 10 --single-branch --branch release/16.x https://github.com/llvm/llvm-project
git clone --depth 10 --single-branch --branch release/17.x https://github.com/llvm/llvm-project
- name: Build LLVM
run: |
cd llvm-project
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/x86-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-16 main"
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
sudo apt-get update
sudo apt-get install -y llvm-16 llvm-16-dev llvm-16-tools clang-16
sudo apt-get install -y llvm-17 llvm-17-dev llvm-17-tools clang-17
sudo apt-get install python3-setuptools
sudo pip3 install lit
- name: Build HelloWorld
Expand All @@ -43,6 +43,6 @@ jobs:
run: |
cd $GITHUB_WORKSPACE
mkdir build && cd build
cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-16/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../
cmake -DLT_LLVM_INSTALL_DIR="/usr/lib/llvm-17/" -DCMAKE_BUILD_TYPE=${{ matrix.type }} ../
make -j2
lit -va test/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.20)
project(llvm-tutor)

#===============================================================================
Expand Down Expand Up @@ -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 16)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 16 or above")
if("${LLVM_VERSION_MAJOR}" VERSION_LESS 17)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 17 or above")
endif()

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile_ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN pip3 install lit
# reason, we need to add `-DLLVM_INSTALL_UTILS=ON` CMake flag when building
# LLVM.
ENV LLVM_DIR /opt/llvm
RUN git clone --branch release/16.x --depth 1 https://github.com/llvm/llvm-project \
RUN git clone --branch release/17.x --depth 1 https://github.com/llvm/llvm-project \
&& mkdir -p $LLVM_DIR \
&& mkdir -p llvm-project/build \
&& cd llvm-project/build \
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile_ubuntu_apt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
# USAGE:
# ```bash
# wget https://raw.githubusercontent.com/banach-space/llvm-tutor/main/Dockerfile_ubuntu_apt
# docker build -t=llvm-tutor:llvm-16 .
# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-16 /bin/bash
# docker build -t=llvm-tutor:llvm-17 .
# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-17 /bin/bash
# ```
# =============================================================================

FROM ubuntu:22.04

ENV LLVM_DIR /usr/lib/llvm-16/
ENV LLVM_DIR /usr/lib/llvm-17/
ENV TUTOR_DIR /llvm-tutor

# 1. INSTALL DEPENDENCIES
Expand All @@ -34,9 +34,9 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
RUN apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
RUN apt-get update
RUN apt-get install -y llvm-16 llvm-16-dev llvm-16-tools clang-16
RUN apt-get install -y llvm-17 llvm-17-dev llvm-17-tools clang-17
RUN apt-get install -y python3-setuptools

# 2. INSTALL LIT
Expand All @@ -50,8 +50,8 @@ RUN mkdir -p $TUTOR_DIR/hello-world-build \
&& cd $TUTOR_DIR/hello-world-build \
&& cmake -G Ninja -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../HelloWorld \
&& ninja
RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/clang-16 -S -O1 -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll
RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/opt-16 -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll 2>&1 | grep "(llvm-tutor) Hello from: foo"
RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/clang-17 -S -O1 -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll
RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/opt-17 -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll 2>&1 | grep "(llvm-tutor) Hello from: foo"

# 5. BUILD AND RUN LLVM-TUTOR
RUN mkdir -p $TUTOR_DIR/build \
Expand Down
7 changes: 3 additions & 4 deletions HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.20)
project(llvm-tutor-hello-world)

#===============================================================================
Expand All @@ -11,10 +11,9 @@ set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory")
# find_package can locate it)
list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/")

# FIXME: This is a warkaround for #25. Remove once resolved and use
find_package(LLVM CONFIG)
if("${LLVM_VERSION_MAJOR}" VERSION_LESS 16)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 16 or above")
if("${LLVM_VERSION_MAJOR}" VERSION_LESS 17)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 17 or above")
endif()

# HelloWorld includes headers from LLVM - update the include paths accordingly
Expand Down
Loading

0 comments on commit c068d58

Please sign in to comment.