diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c7a90d73d..e84d5bb5c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 diff --git a/Makefile b/Makefile index 1aebbd793..05a234bbd 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/configure.sh b/configure.sh index 8c294c988..b25b47839 100755 --- a/configure.sh +++ b/configure.sh @@ -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" @@ -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 @@ -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 @@ -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) @@ -102,9 +118,11 @@ rm -rf build ; ln -sf build-"${TARGET}" build ( cat < +# Copyright 2024 Magnus Sjalander # 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)) diff --git a/jlm/mlir/backend/mlirgen.cpp b/jlm/mlir/backend/mlirgen.cpp index c74091df7..cabe7c321 100644 --- a/jlm/mlir/backend/mlirgen.cpp +++ b/jlm/mlir/backend/mlirgen.cpp @@ -5,8 +5,6 @@ #include "jlm/mlir/backend/mlirgen.hpp" -#ifdef MLIR_ENABLED - #include #include #include @@ -283,5 +281,3 @@ MLIRGen::convertType(const rvsdg::type & type) } } // namespace jlm::rvsdgmlir - -#endif // MLIR_ENABLED diff --git a/jlm/mlir/backend/mlirgen.hpp b/jlm/mlir/backend/mlirgen.hpp index a3809bc71..d331e9b5c 100644 --- a/jlm/mlir/backend/mlirgen.hpp +++ b/jlm/mlir/backend/mlirgen.hpp @@ -6,8 +6,6 @@ #ifndef JLM_MLIR_BACKEND_MLIRGEN_HPP #define JLM_MLIR_BACKEND_MLIRGEN_HPP -#ifdef MLIR_ENABLED - // JLM #include #include @@ -79,6 +77,4 @@ class MLIRGen final } // namespace jlm::rvsdgmlir -#endif // MLIR_ENABLED - #endif // JLM_MLIR_BACKEND_MLIRGEN_HPP diff --git a/jlm/mlir/frontend/rvsdggen.cpp b/jlm/mlir/frontend/rvsdggen.cpp index c7a9a7bf8..4fb018282 100644 --- a/jlm/mlir/frontend/rvsdggen.cpp +++ b/jlm/mlir/frontend/rvsdggen.cpp @@ -3,8 +3,6 @@ * See COPYING for terms of redistribution. */ -#ifdef MLIR_ENABLED - #include "jlm/mlir/frontend/rvsdggen.hpp" #include @@ -277,5 +275,3 @@ RVSDGGen::getOperandIndex(mlir::Operation * producer, mlir::Value & operand) } } // jlm::mlirrvsdg - -#endif // MLIR_ENABLED diff --git a/jlm/mlir/frontend/rvsdggen.hpp b/jlm/mlir/frontend/rvsdggen.hpp index 8098fbe72..2eda3a3c2 100644 --- a/jlm/mlir/frontend/rvsdggen.hpp +++ b/jlm/mlir/frontend/rvsdggen.hpp @@ -6,8 +6,6 @@ #ifndef JLM_MLIR_FRONTEND_RVSDGGEN_HPP #define JLM_MLIR_FRONTEND_RVSDGGEN_HPP -#ifdef MLIR_ENABLED - // #include // #include // #include @@ -143,6 +141,4 @@ class RVSDGGen final } // namespace jlm::mlirrvsdg -#endif // MLIR_ENABLED - #endif // JLM_MLIR_FRONTEND_RVSDGGEN_HPP diff --git a/jlm/tooling/Command.cpp b/jlm/tooling/Command.cpp index f9c125aff..dc4b01811 100644 --- a/jlm/tooling/Command.cpp +++ b/jlm/tooling/Command.cpp @@ -10,12 +10,15 @@ #include #include #include -#include -#include #include #include #include +#ifdef MLIR_ENABLED +#include +#include +#endif + #include #include #include diff --git a/jlm/tooling/Makefile.sub b/jlm/tooling/Makefile.sub index 7433816f9..9647f6151 100644 --- a/jlm/tooling/Makefile.sub +++ b/jlm/tooling/Makefile.sub @@ -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)) diff --git a/tests/jlm/mlir/Makefile.sub b/tests/jlm/mlir/Makefile.sub deleted file mode 100644 index 0f45d5314..000000000 --- a/tests/jlm/mlir/Makefile.sub +++ /dev/null @@ -1,3 +0,0 @@ -TESTS += \ - jlm/mlir/backend/TestMlirGen \ - jlm/mlir/frontend/TestRvsdgGen \ diff --git a/tests/jlm/mlir/backend/TestMlirGen.cpp b/tests/jlm/mlir/backend/TestMlirGen.cpp index 9dec54a75..dcb2a88da 100644 --- a/tests/jlm/mlir/backend/TestMlirGen.cpp +++ b/tests/jlm/mlir/backend/TestMlirGen.cpp @@ -13,8 +13,6 @@ static void TestLambda() { -#ifdef MLIR_ENABLED - using namespace jlm::llvm; auto rvsdgModule = RvsdgModule::Create(jlm::util::filepath(""), "", ""); @@ -93,8 +91,6 @@ TestLambda() omega->destroy(); } - -#endif // MLIR_ENABLED } static int diff --git a/tests/jlm/mlir/frontend/TestRvsdgGen.cpp b/tests/jlm/mlir/frontend/TestRvsdgGen.cpp index 3f33c8787..effc71090 100644 --- a/tests/jlm/mlir/frontend/TestRvsdgGen.cpp +++ b/tests/jlm/mlir/frontend/TestRvsdgGen.cpp @@ -15,8 +15,6 @@ static void TestLambda() { -#ifdef MLIR_ENABLED - { auto context = std::make_unique(); // Load the RVSDG dialect @@ -127,8 +125,6 @@ TestLambda() assert(!jlm::rvsdg::region::Contains(*region, false)); assert(jlm::rvsdg::region::Contains(*region, true)); } - -#endif // MLIR_ENABLED } static int diff --git a/tools/Makefile.sub b/tools/Makefile.sub index 253e0c587..0621a2e97 100644 --- a/tools/Makefile.sub +++ b/tools/Makefile.sub @@ -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)) @@ -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)) diff --git a/tools/jhls/Makefile.sub b/tools/jhls/Makefile.sub index e8c65ccb3..40afc6914 100644 --- a/tools/jhls/Makefile.sub +++ b/tools/jhls/Makefile.sub @@ -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))