Skip to content

Commit

Permalink
Use upstream add_mlir_library CMake functions (#297)
Browse files Browse the repository at this point in the history
* cmake regularization

* reformat
  • Loading branch information
makslevental authored Sep 5, 2023
1 parent 4a02e64 commit 80dd20d
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 113 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ foreach(target ${AIR_RUNTIME_TARGETS})
TEST_EXCLUDE_FROM_MAIN true)
endforeach()

if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime_lib/airhost/include
DESTINATION include/..
COMPONENT runtime_lib-headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp")

if(NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-runtime_lib-headers DEPENDS
runtime_lib-headers COMPONENT runtime_lib-headers)
endif()
endif()

add_subdirectory(python)
if(NOT AIR_RUNTIME_TEST_TARGET_VAL)
message(
Expand All @@ -181,5 +196,5 @@ else()
add_subdirectory(test)
endif()
add_subdirectory(tools)
add_subdirectory(cmake/modules)
add_subdirectory(mlir)
add_subdirectory(cmake/modules)
2 changes: 1 addition & 1 deletion cmake/modules/AIRConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ set(AIR_INCLUDE_DIRS "@AIR_CONFIG_INCLUDE_DIRS@")

# Provide all our library targets to users.
include("@AIR_CONFIG_EXPORTS_FILE@")

include("@MLIR_CONFIG_INCLUDE_EXPORTS_FILE@")
55 changes: 28 additions & 27 deletions cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

# Generate a list of CMake library targets so that other CMake projects can
# link against them. LLVM calls its version of this file LLVMExports.cmake, but
# the usual CMake convention seems to be ${Project}Targets.cmake.
# Generate a list of CMake library targets so that other CMake projects can link
# against them. LLVM calls its version of this file LLVMExports.cmake, but the
# usual CMake convention seems to be ${Project}Targets.cmake.
set(AIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/air)
set(air_cmake_builddir "${CMAKE_BINARY_DIR}/${AIR_INSTALL_PACKAGE_DIR}")

Expand All @@ -15,27 +15,25 @@ export(EXPORT AIRTargets FILE ${air_cmake_builddir}/AIRTargets.cmake)
set(AIR_CONFIG_CMAKE_DIR "${air_cmake_builddir}")
set(AIR_CONFIG_BINARY_DIR "${PROJECT_BINARY_DIR}")
set(AIR_CONFIG_TOOLS_BINARY_DIR "${PROJECT_BINARY_DIR}/bin")
set(AIR_CONFIG_INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include"
)
set(AIR_CONFIG_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include")
set(AIR_CONFIG_EXPORTS_FILE "\${AIR_CMAKE_DIR}/AIRTargets.cmake")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/AIRConfig.cmake.in
${air_cmake_builddir}/AIRConfig.cmake
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/AIRConfig.cmake.in
${air_cmake_builddir}/AIRConfig.cmake @ONLY)
set(AIR_CONFIG_CMAKE_DIR)
set(AIR_CONFIG_BINARY_DIR)
set(AIR_CONFIG_TOOLS_BINARY_DIR)
set(AIR_CONFIG_INCLUDE_DIRS)
set(AIR_CONFIG_EXPORTS_FILE)

# Generate AIRConfig.cmake for the install tree.
set(AIR_CONFIG_CODE "
set(AIR_CONFIG_CODE
"
# Compute the installation prefix from this file location.
get_filename_component(AIR_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
# Construct the proper number of get_filename_component(... PATH)
# calls to compute the installation prefix.
get_filename_component(AIR_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)"
)
# Construct the proper number of get_filename_component(... PATH) calls to
# compute the installation prefix.
string(REGEX REPLACE "/" ";" _count "${AIR_INSTALL_PACKAGE_DIR}")
foreach(p ${_count})
set(AIR_CONFIG_CODE "${AIR_CONFIG_CODE}
Expand All @@ -45,14 +43,11 @@ endforeach(p)
set(AIR_CONFIG_CMAKE_DIR "\${AIR_INSTALL_PREFIX}/${AIR_INSTALL_PACKAGE_DIR}")
set(AIR_CONFIG_BINARY_DIR "\${AIR_INSTALL_PREFIX}")
set(AIR_CONFIG_TOOLS_BINARY_DIR "\${AIR_INSTALL_PREFIX}/bin")
set(AIR_CONFIG_INCLUDE_DIRS
"\${AIR_INSTALL_PREFIX}/include"
)
set(AIR_CONFIG_INCLUDE_DIRS "\${AIR_INSTALL_PREFIX}/include")
set(AIR_CONFIG_EXPORTS_FILE "\${AIR_CMAKE_DIR}/AIRTargets.cmake")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/AIRConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/AIRConfig.cmake
@ONLY)
set(MLIR_CONFIG_INCLUDE_EXPORTS_FILE "\${AIR_CMAKE_DIR}/MLIRTargets.cmake")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/AIRConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/AIRConfig.cmake @ONLY)
set(AIR_CONFIG_CODE)
set(AIR_CONFIG_CMAKE_DIR)
set(AIR_CONFIG_BINARY_DIR)
Expand All @@ -61,9 +56,15 @@ set(AIR_CONFIG_INCLUDE_DIRS)
set(AIR_CONFIG_EXPORTS_FILE)

# export targets for the install directory
install(EXPORT AIRTargets DESTINATION ${AIR_INSTALL_PACKAGE_DIR}
COMPONENT air-cmake-exports)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/AIRConfig.cmake
install(
EXPORT AIRTargets
DESTINATION ${AIR_INSTALL_PACKAGE_DIR}
COMPONENT air-cmake-exports)
COMPONENT air-cmake-exports)
install(
EXPORT MLIRTargets
DESTINATION ${AIR_INSTALL_PACKAGE_DIR}
COMPONENT air-cmake-exports)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/AIRConfig.cmake
DESTINATION ${AIR_INSTALL_PACKAGE_DIR}
COMPONENT air-cmake-exports)
31 changes: 31 additions & 0 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,34 @@
add_subdirectory(lib)
add_subdirectory(include)
add_subdirectory(test)

if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(
DIRECTORY include/air include/air-c
DESTINATION include
COMPONENT air-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.inc"
PATTERN "*.td"
PATTERN "LICENSE.TXT")

install(
DIRECTORY ${PROJECT_BINARY_DIR}/include/air
DESTINATION include
COMPONENT air-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.gen"
PATTERN "*.inc"
PATTERN "*.td"
PATTERN "CMakeFiles" EXCLUDE
PATTERN "config.h" EXCLUDE)

if(NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-air-headers DEPENDS air-headers COMPONENT
air-headers)
endif()
endif()
6 changes: 3 additions & 3 deletions mlir/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ add_subdirectory(Util)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

add_air_library(AIRInitAll
add_mlir_library(
AIRInitAll
InitAll.cpp

DEPENDS
Expand All @@ -29,5 +30,4 @@ add_air_library(AIRInitAll
AIRUtil
MLIRSupport
${conversion_libs}
${dialect_libs}
)
${dialect_libs})
50 changes: 25 additions & 25 deletions mlir/lib/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

add_air_library(AIRConversionPasses
ConvertToAIRPass.cpp
AIRLoweringPass.cpp
AIRRtToLLVMPass.cpp
AIRToAIEPass.cpp
AIRToAsyncPass.cpp
AIRPipeline.cpp
Passes.cpp
add_mlir_library(
AIRConversionPasses
ConvertToAIRPass.cpp
AIRLoweringPass.cpp
AIRRtToLLVMPass.cpp
AIRToAIEPass.cpp
AIRToAsyncPass.cpp
AIRPipeline.cpp
Passes.cpp

DEPENDS
AIRConversionPassIncGen
AIRDialect
AIRRtDialect
DEPENDS
AIRConversionPassIncGen
AIRDialect
AIRRtDialect

LINK_COMPONENTS
Core
LINK_COMPONENTS
Core

LINK_LIBS
AIRDialect
AIRRtDialect
AIRUtil
AIE
MLIRIR
MLIRLinalgUtils
MLIRLinalgTransforms
MLIRSupport
MLIRTransforms
)
LINK_LIBS
AIRDialect
AIRRtDialect
AIRUtil
AIE
MLIRIR
MLIRLinalgUtils
MLIRLinalgTransforms
MLIRSupport
MLIRTransforms)
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/AIR/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

add_air_dialect_library(AIRDialect
add_mlir_dialect_library(
AIRDialect
AIRDialect.cpp

ADDITIONAL_HEADER_DIRS
Expand All @@ -13,5 +14,4 @@ add_air_dialect_library(AIRDialect
MLIRAIROpInterfacesIncGen

LINK_LIBS PUBLIC
MLIRIR
)
MLIRIR)
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/AIRRt/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

add_air_dialect_library(AIRRtDialect
add_mlir_dialect_library(
AIRRtDialect
AIRRtDialect.cpp
AIRRtOps.cpp

Expand All @@ -13,5 +14,4 @@ add_air_dialect_library(AIRRtDialect
MLIRAIRRtOpsIncGen

LINK_LIBS PUBLIC
MLIRIR
)
MLIRIR)
10 changes: 4 additions & 6 deletions mlir/lib/Targets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

add_air_library(AIRTargets
add_mlir_library(
AIRTargets
AIRTargets.cpp
AIRHerdToJSON.cpp

LINK_LIBS

PUBLIC
LINK_LIBS PUBLIC
AIRRtDialect
AIRDialect
MLIRIR
MLIRSupport
MLIRTransforms
)
MLIRTransforms)
72 changes: 36 additions & 36 deletions mlir/lib/Transform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@
# Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

add_air_library(AIRTransformPasses
AffineLoopOptPass.cpp
AIRAutomaticTilingPass.cpp
AIRHerdAssignPass.cpp
AIRHerdPlacementPass.cpp
AIRLinalgCodegen.cpp
AIRLinalgOpStats.cpp
AIRLoopMergingPass.cpp
AIRLoopPermutationPass.cpp
AIRLowerLinalgTensors.cpp
AIRMiscPasses.cpp
AIRRegularizeLoopPass.cpp
AIRTilingUtils.cpp
AIRTransformInterpreter.cpp
AIRDependency.cpp
AIRDependencyScheduleOpt.cpp
AIRDependencyCanonicalize.cpp
AIRDependencyParseGraph.cpp
Passes.cpp
ReturnEliminationPass.cpp
add_mlir_library(
AIRTransformPasses
AffineLoopOptPass.cpp
AIRAutomaticTilingPass.cpp
AIRHerdAssignPass.cpp
AIRHerdPlacementPass.cpp
AIRLinalgCodegen.cpp
AIRLinalgOpStats.cpp
AIRLoopMergingPass.cpp
AIRLoopPermutationPass.cpp
AIRLowerLinalgTensors.cpp
AIRMiscPasses.cpp
AIRRegularizeLoopPass.cpp
AIRTilingUtils.cpp
AIRTransformInterpreter.cpp
AIRDependency.cpp
AIRDependencyScheduleOpt.cpp
AIRDependencyCanonicalize.cpp
AIRDependencyParseGraph.cpp
Passes.cpp
ReturnEliminationPass.cpp

DEPENDS
AIRTransformOpsIncGen
AIRTransformPassIncGen
AIRDialect
AIRRtDialect
DEPENDS
AIRTransformOpsIncGen
AIRTransformPassIncGen
AIRDialect
AIRRtDialect

LINK_COMPONENTS
Core
LINK_COMPONENTS
Core

LINK_LIBS PUBLIC
AIRDialect
AIRRtDialect
AIRUtil
MLIRIR
MLIRLinalgTransforms
MLIRLinalgUtils
MLIRSupport
)
LINK_LIBS PUBLIC
AIRDialect
AIRRtDialect
AIRUtil
MLIRIR
MLIRLinalgTransforms
MLIRLinalgUtils
MLIRSupport)
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare_mlir_python_extension(AirPythonExtensions.MLIR
SOURCES
AIRMLIRModule.cpp
AIRRunnerModule.cpp
AIRRunnerModule.h
EMBED_CAPI_LINK_LIBS
AIRCAPI
PRIVATE_LINK_LIBS
Expand All @@ -73,6 +74,7 @@ declare_mlir_python_extension(AirPythonExtensions.AIRRt
SOURCES
Module.cpp
LibAirHostModule.cpp
LibAirHostModule.h
EMBED_CAPI_LINK_LIBS
AIRCAPI
PRIVATE_LINK_LIBS
Expand Down
Loading

0 comments on commit 80dd20d

Please sign in to comment.