Skip to content

Commit

Permalink
MLIR: #1 CMake Modifications to allow MLIR Support
Browse files Browse the repository at this point in the history
MLIR: #2 CMake - Adding FindMLIR.cmake
MLIR: #3 CMake - Updating FindMLIR
MLIR: #4 CMake - Updating Path 
MLIR: #5 CMake - Adding MLIRLibs
MLIR: #6 CMake - Supporting Dialect on FindMLIR
MLIR: #7 CMake - Adding Message of Ops.ts
MLIR: ldc-developers#8 CMake - Removing duplicated messages
MLIR: ldc-developers#9 CMake: Updating paths and setting libs
MLIR: ldc-developers#10 CMake - Removing duplicated MLIR Headers
Make MLIR optional, use MLIR_LIBRARIES
  • Loading branch information
Robertorosmaninho committed Feb 12, 2020
1 parent 3f5e526 commit ec02b7b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,27 @@ endif()
message(STATUS "LDC version identifier: ${LDC_VERSION}")
configure_file(driver/ldc-version.cpp.in driver/ldc-version.cpp)

#
# Setting MLIR headers
#

find_package(MLIR)
if(MLIR_FOUND)
message(STATUS "Buiding with MLIR support")
include_directories(${MLIR_ROOT_DIR})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${MLIR_BUILD_INCLUDE_DIRS})
include_directories(${MLIR_LIB_DIRS})
add_definitions("-DLDC_MLIR_ENABLED")

set(LLVM_LINK_COMPONENTS
Support
)

set(LLVM_LIBRARIES "${MLIR_LIBRARIES}" ${LLVM_LIBRARIES})

endif() #if MLIR_FOUND

# Also add the header files to the build so that they are available in IDE
# project files generated via CMake.
file(GLOB_RECURSE FE_SRC_D dmd/*.d)
Expand Down
68 changes: 68 additions & 0 deletions cmake/Modules/FindMLIR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# - Try to find MLIR project at LLVM
#
# The following are set after configuration is done:
# MLIR_FOUND
# MLIR_ROOT_DIRS
# MLIR_INCLUDE_DIRS
# MLIR_BUILD_INCLUDE_DIR
project(ldc)

find_path(MLIR_ROOT_DIR NAMES "LICENSE.TXT" HINTS ${LLVM_ROOT_DIR}/../mlir)

#Used to get the main header files
find_path(MLIR_INCLUDE_DIR NAMES "Parser.h" HINTS ${MLIR_ROOT_DIR}/include/mlir)

#Lib directories
find_path(MLIR_LIB_DIR NAMES "CMakeLists.txt" HINTS ${MLIR_ROOT_DIR}/lib/IR)

#Used to get StandardOps.h.inc
find_path(MLIR_BUILD_INCLUDE_DIR NAMES "cmake_install.cmake"
HINTS ${LLVM_ROOT_DIR}/tools/mlir/include/mlir)

message(STATUS "MLIR Dir: ${MLIR_ROOT_DIR}")
message(STATUS "MLIR Include Dir: ${MLIR_INCLUDE_DIR}/..")
message(STATUS "MLIR Lib Dir: ${MLIR_LIB_DIR}/..")
message(STATUS "MLIR Build Include Dir: ${MLIR_BUILD_INCLUDE_DIR}/..")

set(MLIR_ROOT_DIRS ${MLIR_ROOT_DIR})
set(MLIR_INCLUDE_DIRS ${MLIR_INCLUDE_DIR}/..)
set(MLIR_BUILD_INCLUDE_DIRS ${MLIR_BUILD_INCLUDE_DIR}/..)
set(MLIR_LIB_DIRS ${MLIR_LIB_DIR}/..)

if(EXISTS ${MLIR_ROOT_DIR})
#Resources to automatically generate Ops.h.inc and Ops.cpp.inc, assuming that
#mlir-tblgen is already built and is on the usual directory at llvm dir
set(MLIR_MAIN_SRC_DIR ${MLIR_INCLUDE_DIR}/.. )
set(MLIR_TABLEGEN_EXE ${LLVM_ROOT_DIR}/bin/mlir-tblgen)
set(MLIR_INCLUDE_DIR ${MLIR_BUILD_INCLUDE_DIR}/..)

function(mlir_tablegen)
cmake_parse_arguments(
ARG
"NAME"
"TARGET;OUTS;FLAG;SRCS"
${ARGN}
)

MESSAGE(STATUS "Setting target for Ops_" ${ARG_TARGET})

set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SRCS}
PARENT_SCOPE)
#mlir-tblgen ops.td --gen-op-* -I*-o=ops.*.inc
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_OUTS}
COMMAND ${MLIR_TABLEGEN_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SRCS} -I${MLIR_MAIN_SRC_DIR} -I${MLIR_INCLUDE_DIR} -o=${CMAKE_CURRENT_SOURCE_DIR}/${ARG_OUTS}
ARGS ${ARG_FLAG}
)
add_custom_target(Ops_${ARG_TARGET} ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_OUTS})
endfunction()

# Handle the QUIETLY and REQUIRED arguments and set the MLIR_FOUND to TRUE
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(MLIR DEFAULT_MSG MLIR_ROOT_DIRS MLIR_INCLUDE_DIRS
MLIR_BUILD_INCLUDE_DIRS MLIR_LIB_DIRS)

mark_as_advanced(MLIR_ROOT_DIRS MLIR_INCLUDE_DIRS MLIR_BUILD_INCLUDE_DIRS MLIR_LIB_DIRS)
endif()

0 comments on commit ec02b7b

Please sign in to comment.