diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b1924f2b..5f114f4c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,10 @@ find_package(MLIR REQUIRED CONFIG) message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") +set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) +set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) +set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) + list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42b2d03f7..f6298c270 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,15 +1,6 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) -set(gc_opt_libs - ${dialect_libs} - ${conversion_libs} - MLIROptLib - GCPasses) -add_llvm_executable(gc-opt gc-opt.cpp) - -target_link_libraries(gc-opt PRIVATE ${gc_opt_libs}) -llvm_update_compile_flags(gc-opt) -mlir_check_all_link_libraries(gc-opt) - add_subdirectory(dnnl) +add_subdirectory(gc-cpu-runner) +add_subdirectory(gc-opt) diff --git a/src/gc-cpu-runner/CMakeLists.txt b/src/gc-cpu-runner/CMakeLists.txt new file mode 100644 index 000000000..eb45c93b0 --- /dev/null +++ b/src/gc-cpu-runner/CMakeLists.txt @@ -0,0 +1,33 @@ +# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream +set(LLVM_LINK_COMPONENTS + Core + Support + nativecodegen + native +) +set(MLIR_LINK_COMPONENTS + MLIRAnalysis + MLIRBuiltinToLLVMIRTranslation + MLIRExecutionEngine + MLIRIR + MLIRJitRunner + MLIRLLVMDialect + MLIRLLVMToLLVMIRTranslation + MLIRToLLVMIRTranslationRegistration + MLIRParser + MLIRTargetLLVMIRExport + MLIRSupport +) + +if(GC_MLIR_CXX_FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") +endif() + +#LLVM_LINK_COMPONENTS is processed by LLVM cmake in add_llvm_executable +set(gc_cpu_runner_libs + ${MLIR_LINK_COMPONENTS}) +add_llvm_executable(gc-cpu-runner gc-cpu-runner.cpp) + +target_link_libraries(gc-cpu-runner PRIVATE ${gc_cpu_runner_libs}) +llvm_update_compile_flags(gc-cpu-runner) +mlir_check_all_link_libraries(gc-cpu-runner) diff --git a/src/gc-cpu-runner/gc-cpu-runner.cpp b/src/gc-cpu-runner/gc-cpu-runner.cpp new file mode 100644 index 000000000..3ece8f2ff --- /dev/null +++ b/src/gc-cpu-runner/gc-cpu-runner.cpp @@ -0,0 +1,40 @@ + +/* + * Copyright (C) 2024 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/ExecutionEngine/JitRunner.h" +#include "mlir/ExecutionEngine/OptUtils.h" +#include "mlir/IR/Dialect.h" +#include "mlir/Target/LLVMIR/Dialect/All.h" + +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/TargetSelect.h" +#include + +int main(int argc, char **argv) { + llvm::InitLLVM y(argc, argv); + llvm::InitializeNativeTarget(); + llvm::InitializeNativeTargetAsmPrinter(); + llvm::InitializeNativeTargetAsmParser(); + + mlir::DialectRegistry registry; + mlir::registerAllToLLVMIRTranslations(registry); + + return mlir::JitRunnerMain(argc, argv, registry); +} \ No newline at end of file diff --git a/src/gc-opt/CMakeLists.txt b/src/gc-opt/CMakeLists.txt new file mode 100644 index 000000000..ff33375de --- /dev/null +++ b/src/gc-opt/CMakeLists.txt @@ -0,0 +1,15 @@ +set(gc_opt_libs + ${dialect_libs} + ${conversion_libs} + MLIROptLib + GCPasses) +if(GC_MLIR_CXX_FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") +endif() + +add_llvm_executable(gc-opt gc-opt.cpp) + +target_link_libraries(gc-opt PRIVATE ${gc_opt_libs}) +llvm_update_compile_flags(gc-opt) +mlir_check_all_link_libraries(gc-opt) + diff --git a/src/gc-opt.cpp b/src/gc-opt/gc-opt.cpp similarity index 100% rename from src/gc-opt.cpp rename to src/gc-opt/gc-opt.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 97bb57013..36d29abb2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,7 @@ set(GC_OPT_TEST_DEPENDS FileCheck count not # mlir-gen gc-opt + gc-cpu-runner GCUnitTests ) diff --git a/test/gc/cpu-runner/run.mlir b/test/gc/cpu-runner/run.mlir new file mode 100644 index 000000000..406bf68d9 --- /dev/null +++ b/test/gc/cpu-runner/run.mlir @@ -0,0 +1,5 @@ +// RUN: gc-opt %s --convert-func-to-llvm --convert-cf-to-llvm | gc-cpu-runner -e main -entry-point-result=void | FileCheck --allow-empty %s +func.func @main() { + return +} +// CHECK-NOT: any \ No newline at end of file diff --git a/test/lit.cfg.py b/test/lit.cfg.py index c6867ec2a..0f67b5115 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -41,12 +41,12 @@ # test_exec_root: The root path where tests should be run. config.test_exec_root = os.path.join(config.gc_obj_root, "test") -config.gc_tools_dir = os.path.join(config.gc_obj_root, "src") +config.gc_tools_dir = os.path.join(config.gc_obj_root, "bin") # Tweak the PATH to include the tools dir. llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) tool_dirs = [config.gc_tools_dir, config.llvm_tools_dir] -tools = ["gc-opt"] +tools = ["gc-opt", "gc-cpu-runner"] llvm_config.add_tool_substitutions(tools, tool_dirs)