Skip to content

Commit

Permalink
MLIR RVSDG frontend (#349)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico Reissmann <[email protected]>
  • Loading branch information
sjalander and phate authored Feb 1, 2024
1 parent b4f02a4 commit efc4ea6
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/actions/BuildMlirDialect/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Build MLIR RVSDG Dialect"
description: "Restore MLIR RVSDG Dialect from cache and build if it's not in there"

runs:
using: "composite"
steps:
- name: "Clone MLIR RVSDG dialect"
run: git clone https://github.com/EECS-NTNU/mlir_rvsdg.git ${{ github.workspace }}/mlir-rvsdg
shell: bash

- name: "Extract the hash for latest commit for use in the cache key"
id: get-mlir-hash
run: |
cd ${{ github.workspace }}/mlir-rvsdg
echo "hash=$(git rev-parse main)" >> $GITHUB_OUTPUT
shell: bash

- name: "Try to fetch Dialect from the cache"
id: cache-mlir
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/lib/mlir-rvsdg
key: ${{ runner.os }}-mlir-${{ steps.get-mlir-hash.outputs.hash }}

- name: "Install LLVM and Clang"
uses: ./.github/actions/InstallLlvmDependencies

- name: "Build MLIR RVSDG Dialect if we didn't hit in the cache"
if: steps.cache-mlir.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/mlir-rvsdg
git checkout 6bfb270607f35b787bc849182f184e83548aa404
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_C_COMPILER=clang-16 \
-DCMAKE_CXX_COMPILER=clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/cmake/ \
-DMLIR_DIR=/usr/lib/llvm-16/lib/cmake/mlir \
-DCMAKE_INSTALL_PREFIX=../../lib/mlir-rvsdg
cmake --build .
ninja install
shell: bash

13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ jobs:
- name: Run unit and C tests
run: make check -j `nproc`

mlir:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: "Build MLIR RVSDG Dialect"
uses: ./.github/actions/BuildMlirDialect
- name: "Configure jlm"
run: ./configure.sh --enable-mlir ./lib/mlir-rvsdg CXX=clang++-16
- name: "Compile jlm"
run: make -O -j `nproc`
- name: "Run unit and C tests"
run: make check -O -j `nproc`

valgrind:
runs-on: ubuntu-22.04
needs: build
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ include tools/jhls/Makefile.sub
include tools/jlm-hls/Makefile.sub
endif

ifdef ENABLE_MLIR
include jlm/mlir/Makefile.sub
endif

include Makefile.rules
29 changes: 25 additions & 4 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ LLVM_CONFIG_BIN="llvm-config-16"
ENABLE_COVERAGE="no"
ENABLE_HLS=
CIRCT_PATH=
ENABLE_MLIR=
MLIR_PATH=
MLIR_LDFLAGS=

function usage()
{
Expand All @@ -21,6 +24,8 @@ function usage()
echo " CIRCT, which the backend depends on."
echo " --llvm-config PATH The llvm-config script used to determine up llvm"
echo " build dependencies. [${LLVM_CONFIG_BIN}]"
echo " --enable-mlir PATH Sets the path to the MLIR RVSDG Dialect and enables"
echo " building the MLIR backend and frontend. [${MLIR_PATH}]"
echo " --enable-coverage Enable test coverage computation target."
echo " --help Prints this message and stops."
echo
Expand Down Expand Up @@ -51,6 +56,12 @@ while [[ "$#" -ge 1 ]] ; do
LLVM_CONFIG_BIN="$1"
shift
;;
--enable-mlir)
shift
MLIR_PATH="$1"
ENABLE_MLIR="yes"
shift
;;
--enable-coverage)
ENABLE_COVERAGE="yes"
shift
Expand Down Expand Up @@ -94,10 +105,17 @@ if [ "${ENABLE_ASSERTS}" == "yes" ] ; then
fi

CPPFLAGS_CIRCT=""
CXXFLAGS_CIRCT=""
CXXFLAGS_NO_COMMENT=""
if [ "${ENABLE_HLS}" == "yes" ] ; then
CPPFLAGS_CIRCT="-I${CIRCT_PATH}/include"
CXXFLAGS_CIRCT="-Wno-error=comment"
CXXFLAGS_NO_COMMENT="-Wno-error=comment"
fi

CPPFLAGS_MLIR=""
if [ "${ENABLE_MLIR}" == "yes" ] ; then
CPPFLAGS_MLIR="-I${MLIR_PATH}/include"
CXXFLAGS_NO_COMMENT="-Wno-error=comment"
MLIR_LDFLAGS="-L${MLIR_PATH}/lib -lMLIR -lMLIRJLM -lMLIRRVSDG"
fi

if [ "${ENABLE_COVERAGE}" == "yes" ] ; then
Expand All @@ -111,10 +129,13 @@ rm -rf build ; ln -sf build-"${TARGET}" build

(
cat <<EOF
CXXFLAGS=${CXXFLAGS-} ${CXXFLAGS_COMMON} ${CXXFLAGS_TARGET} ${CXXFLAGS_CIRCT}
CPPFLAGS=${CPPFLAGS-} ${CPPFLAGS_COMMON} ${CPPFLAGS_LLVM} ${CPPFLAGS_ASSERTS} ${CPPFLAGS_CIRCT}
CXXFLAGS=${CXXFLAGS-} ${CXXFLAGS_COMMON} ${CXXFLAGS_TARGET} ${CXXFLAGS_NO_COMMENT}
CPPFLAGS=${CPPFLAGS-} ${CPPFLAGS_COMMON} ${CPPFLAGS_LLVM} ${CPPFLAGS_ASSERTS} ${CPPFLAGS_CIRCT} ${CPPFLAGS_MLIR}
ENABLE_HLS=${ENABLE_HLS}
CIRCT_PATH=${CIRCT_PATH}
ENABLE_MLIR=${ENABLE_MLIR}
MLIR_PATH=${MLIR_PATH}
MLIR_LDFLAGS=${MLIR_LDFLAGS}
LLVMCONFIG=${LLVM_CONFIG_BIN}
ENABLE_COVERAGE=${ENABLE_COVERAGE}
EOF
Expand Down
27 changes: 27 additions & 0 deletions jlm/mlir/Makefile.sub
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Magnus Sjalander <[email protected]>
# See COPYING for terms of redistribution.

libmlir_SOURCES = \
jlm/mlir/frontend/MlirToJlmConverter.cpp \

libmlir_HEADERS = \
jlm/mlir/frontend/MlirToJlmConverter.hpp \

libmlir_TESTS += \
tests/jlm/mlir/frontend/TestMlirToJlmConverter \

libmlir_TEST_LIBS += \
libmlir \
libllvm \
librvsdg \
libutil \
libjlmtest \

libmlir_TEST_EXTRA_LDFLAGS = \
$(shell $(LLVMCONFIG) --ldflags --libs --system-libs) \
-L$(MLIR_PATH)/lib \
-lMLIR \
-lMLIRJLM \
-lMLIRRVSDG \

$(eval $(call common_library,libmlir))
Loading

0 comments on commit efc4ea6

Please sign in to comment.