Skip to content

Commit

Permalink
Updated MLIR backend to the new build framework
Browse files Browse the repository at this point in the history
  • Loading branch information
sjalander committed Jan 14, 2024
1 parent 5002525 commit 9012a5c
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 67 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ jobs:
- name: Check format
run: clang-format-16 --Werror --dry-run --style="file:.clang-format" --verbose --files=sourceFiles.txt

build-mlir-dialect:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: "Install LLVM and Clang"
uses: ./.github/actions/InstallLlvmDependencies
- name: "Build MLIR RVSDG Dialect"
uses: ./.github/actions/BuildMlirDialect

build:
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -59,6 +70,22 @@ jobs:
- name: Run unit and C tests
run: make check -j `nproc`

mlir:
runs-on: ubuntu-22.04
needs: build-mlir-dialect
steps:
- uses: actions/checkout@v3
- name: "Install LLVM and Clang"
uses: ./.github/actions/InstallLlvmDependencies
- name: "Build MLIR RVSDG Dialect"
uses: ./.github/actions/BuildMlirDialect
- name: Configure jlm
run: ./configure.sh --mlir-path ./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 MLIR_PATH
include jlm/mlir/Makefile.sub
endif

include Makefile.rules
24 changes: 21 additions & 3 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Default values for all tunables.
CIRCT_PATH=
MLIR_PATH=
MLIR_LDFLAGS=
TARGET="release"
LLVM_CONFIG_BIN="llvm-config-16"
ENABLE_COVERAGE="no"
Expand All @@ -18,6 +20,8 @@ function usage()
echo " building with CIRCT support. [${CIRCT_PATH}]"
echo " --llvm-config PATH The llvm-config script used to determine up llvm"
echo " build dependencies. [${LLVM_CONFIG_BIN}]"
echo " --mlir-path PATH Sets the path for the MLIR RVSDG Dialect"
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 All @@ -44,6 +48,12 @@ while [[ "$#" -ge 1 ]] ; do
LLVM_CONFIG_BIN="$1"
shift
;;
--mlir-path)
shift
MLIR_PATH="$1"
MLIR_ENABLED="yes"
shift
;;
--enable-coverage)
ENABLE_COVERAGE="yes"
shift
Expand Down Expand Up @@ -86,7 +96,13 @@ fi

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

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

CLANG_BIN=$(${LLVM_CONFIG_BIN} --bindir)
Expand All @@ -102,9 +118,11 @@ rm -rf build ; ln -sf build-"${TARGET}" build

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

# Check if the MLIR RVSDG Dialect has been compiled by looking for the compile library
ifneq (, $(shell command -v $(MLIR_ROOT)/lib/libMLIRRVSDG.a 2> /dev/null))
$(info Found the MLIR RVSDG Dialect)
CPPFLAGS += \
-DMLIR_ENABLED=1
libmlir_SOURCES = \
jlm/mlir/backend/mlirgen.cpp \
jlm/mlir/frontend/rvsdggen.cpp \

MLIR_LDFLAGS = \
-lmlir \
-L$(MLIR_ROOT)/lib \
-lMLIR \
-lMLIRJLM \
-lMLIRRVSDG

LDFLAGS += $(MLIR_LDFLAGS)
endif
libmlir_HEADERS = \
jlm/mlir/backend/mlirgen.hpp \
jlm/mlir/frontend/rvsdggen.hpp \

LIBMLIR_SRC = \
jlm/mlir/backend/mlirgen.cpp \
jlm/mlir/frontend/rvsdggen.cpp \
libmlir_TESTS += \
tests/jlm/mlir/backend/TestMlirGen \
tests/jlm/mlir/frontend/TestRvsdgGen \

.PHONY: libmlir-debug
libmlir-debug: CXXFLAGS += $(CXXFLAGS_DEBUG)
libmlir-debug: $(JLM_BUILD)/libmlir.a
libmlir_TEST_LIBS += \
libmlir \
libllvm \
librvsdg \
libutil \
libjlmtest \

.PHONY: libmlir-release
libmlir-release: CXXFLAGS += -O3
libmlir-release: $(JLM_BUILD)/libmlir.a

$(JLM_BUILD)/libmlir.a: CPPFLAGS += -I$(JLM_ROOT) -I$(shell $(LLVMCONFIG) --includedir)
$(JLM_BUILD)/libmlir.a: $(patsubst %.cpp, $(JLM_BUILD)/%.la, $(LIBMLIR_SRC))
libmlir_TEST_EXTRA_LDFLAGS = \
$(shell $(LLVMCONFIG) --ldflags --libs --system-libs) \
-L$(MLIR_PATH)/lib \
-lMLIR \
-lMLIRJLM \
-lMLIRRVSDG \

.PHONY: libmlir-clean
libmlir-clean:
@rm -rf $(JLM_BUILD)/libmlir.a
$(eval $(call common_library,libmlir))
4 changes: 0 additions & 4 deletions jlm/mlir/backend/mlirgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "jlm/mlir/backend/mlirgen.hpp"

#ifdef MLIR_ENABLED

#include <jlm/rvsdg/bitstring/comparison.hpp>
#include <jlm/rvsdg/bitstring/constant.hpp>
#include <jlm/rvsdg/node.hpp>
Expand Down Expand Up @@ -283,5 +281,3 @@ MLIRGen::convertType(const rvsdg::type & type)
}

} // namespace jlm::rvsdgmlir

#endif // MLIR_ENABLED
4 changes: 0 additions & 4 deletions jlm/mlir/backend/mlirgen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifndef JLM_MLIR_BACKEND_MLIRGEN_HPP
#define JLM_MLIR_BACKEND_MLIRGEN_HPP

#ifdef MLIR_ENABLED

// JLM
#include <jlm/llvm/ir/operators/lambda.hpp>
#include <jlm/llvm/ir/RvsdgModule.hpp>
Expand Down Expand Up @@ -79,6 +77,4 @@ class MLIRGen final

} // namespace jlm::rvsdgmlir

#endif // MLIR_ENABLED

#endif // JLM_MLIR_BACKEND_MLIRGEN_HPP
4 changes: 0 additions & 4 deletions jlm/mlir/frontend/rvsdggen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* See COPYING for terms of redistribution.
*/

#ifdef MLIR_ENABLED

#include "jlm/mlir/frontend/rvsdggen.hpp"

#include <jlm/rvsdg/bitstring/comparison.hpp>
Expand Down Expand Up @@ -277,5 +275,3 @@ RVSDGGen::getOperandIndex(mlir::Operation * producer, mlir::Value & operand)
}

} // jlm::mlirrvsdg

#endif // MLIR_ENABLED
4 changes: 0 additions & 4 deletions jlm/mlir/frontend/rvsdggen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifndef JLM_MLIR_FRONTEND_RVSDGGEN_HPP
#define JLM_MLIR_FRONTEND_RVSDGGEN_HPP

#ifdef MLIR_ENABLED

// #include <jlm/llvm/ir/operators/GetElementPtr.hpp>
// #include <jlm/llvm/ir/operators/load.hpp>
// #include <jlm/llvm/ir/operators/operators.hpp>
Expand Down Expand Up @@ -143,6 +141,4 @@ class RVSDGGen final

} // namespace jlm::mlirrvsdg

#endif // MLIR_ENABLED

#endif // JLM_MLIR_FRONTEND_RVSDGGEN_HPP
7 changes: 5 additions & 2 deletions jlm/tooling/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#include <jlm/llvm/ir/ipgraph-module.hpp>
#include <jlm/llvm/ir/RvsdgModule.hpp>
#include <jlm/llvm/opt/OptimizationSequence.hpp>
#include <jlm/mlir/backend/mlirgen.hpp>
#include <jlm/mlir/frontend/rvsdggen.hpp>
#include <jlm/rvsdg/view.hpp>
#include <jlm/tooling/Command.hpp>
#include <jlm/tooling/CommandPaths.hpp>

#ifdef MLIR_ENABLED
#include <jlm/mlir/backend/mlirgen.hpp>
#include <jlm/mlir/frontend/rvsdggen.hpp>
#endif

#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IRReader/IRReader.h>
Expand Down
12 changes: 11 additions & 1 deletion jlm/tooling/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ libtooling_TEST_LIBS = \
libtooling \
libhls \
libllvm \
libmlir \
librvsdg \
libutil \
libjlmtest \

libtooling_TEST_EXTRA_LDFLAGS = $(shell $(LLVMCONFIG) --ldflags --libs --system-libs)
libtooling_TEST_EXTRA_LDFLAGS = \
$(shell $(LLVMCONFIG) --ldflags --libs --system-libs) \

ifdef MLIR_PATH
libtooling_TEST_EXTRA_LDFLAGS += \
-L$(MLIR_PATH)/lib \
-lMLIR \
-lMLIRJLM \
-lMLIRRVSDG
endif

$(eval $(call common_library,libtooling))
3 changes: 0 additions & 3 deletions tests/jlm/mlir/Makefile.sub

This file was deleted.

4 changes: 0 additions & 4 deletions tests/jlm/mlir/backend/TestMlirGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
static void
TestLambda()
{
#ifdef MLIR_ENABLED

using namespace jlm::llvm;

auto rvsdgModule = RvsdgModule::Create(jlm::util::filepath(""), "", "");
Expand Down Expand Up @@ -93,8 +91,6 @@ TestLambda()

omega->destroy();
}

#endif // MLIR_ENABLED
}

static int
Expand Down
4 changes: 0 additions & 4 deletions tests/jlm/mlir/frontend/TestRvsdgGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
static void
TestLambda()
{
#ifdef MLIR_ENABLED

{
auto context = std::make_unique<mlir::MLIRContext>();
// Load the RVSDG dialect
Expand Down Expand Up @@ -127,8 +125,6 @@ TestLambda()
assert(!jlm::rvsdg::region::Contains<jlm::rvsdg::bitconstant_op>(*region, false));
assert(jlm::rvsdg::region::Contains<jlm::rvsdg::bitconstant_op>(*region, true));
}

#endif // MLIR_ENABLED
}

static int
Expand Down
17 changes: 14 additions & 3 deletions tools/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ jlc_SOURCES = \
jlc_LIBS += \
libtooling \
libllvm \
libmlir \
librvsdg \
libutil \

jlc_EXTRA_CPPFLAGS += -I$(shell $(LLVMCONFIG) --includedir)

jlc_LDFLAGS += $(shell $(LLVMCONFIG) --libs core irReader) $(shell $(LLVMCONFIG) --ldflags) $(shell $(LLVMCONFIG) --system-libs)
jlc_LDFLAGS += \
$(shell $(LLVMCONFIG) --libs core irReader) \
$(shell $(LLVMCONFIG) --ldflags) \
$(shell $(LLVMCONFIG) --system-libs) \
${MLIR_LDFLAGS} \

$(eval $(call common_executable,jlc))

Expand All @@ -23,11 +28,17 @@ jlm-opt_SOURCES = \
jlm-opt_LIBS = \
libtooling \
libllvm \
libmlir \
librvsdg \
libutil \

jlm-opt_LDFLAGS = $(shell $(LLVMCONFIG) --libs core irReader) $(shell $(LLVMCONFIG) --ldflags) $(shell $(LLVMCONFIG) --system-libs)
jlm-opt_LDFLAGS = \
$(shell $(LLVMCONFIG) --libs core irReader) \
$(shell $(LLVMCONFIG) --ldflags) \
$(shell $(LLVMCONFIG) --system-libs) \
${MLIR_LDFLAGS} \

jlm-opt_CPPFLAGS = -I$(shell $(LLVMCONFIG) --includedir)
jlm-opt_CPPFLAGS = \
-I$(shell $(LLVMCONFIG) --includedir) \

$(eval $(call common_executable,jlm-opt))
6 changes: 5 additions & 1 deletion tools/jhls/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ jhls_LIBS = \
libtooling \
libhls \
libllvm \
libmlir \
librvsdg \
libutil \

jhls_EXTRA_CPPFLAGS = -I$(shell $(LLVMCONFIG) --includedir)

jhls_LDFLAGS = $(shell $(LLVMCONFIG) --libs core irReader) $(shell $(LLVMCONFIG) --ldflags) \
jhls_LDFLAGS = \
$(shell $(LLVMCONFIG) --libs core irReader) \
$(shell $(LLVMCONFIG) --ldflags) \
${MLIR_LDFLAGS}

$(eval $(call common_executable,jhls))

0 comments on commit 9012a5c

Please sign in to comment.