Skip to content

Commit

Permalink
[eudsl-tblgen] bind MLIRTableGen
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Jan 4, 2025
1 parent a6c3fc9 commit ffefb69
Show file tree
Hide file tree
Showing 4 changed files with 1,686 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_test_release_eudsl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ jobs:
# just to/make sure total build continues to work
- name: "Build all of eudsl"
if: ${{ github.event_name == 'pull_request' }}
run: |
pip install -r requirements.txt
Expand All @@ -173,7 +174,7 @@ jobs:
- name: "Save cache"
uses: actions/cache/save@v3
if: ${{ !cancelled() && github.event_name == 'push' && github.ref_name == 'main' }}
if: ${{ !cancelled() && (github.event_name == 'push' || github.event_name == 'pull_request') && github.ref_name == 'main' }}
with:
path: ${{ steps.setup_base.outputs.cache-dir }}
key: ${{ env.cache-key }}
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if(EUDSL_STANDALONE_BUILD)
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})
set(MLIR_INCLUDE_DIR ${MLIR_INCLUDE_DIRS})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
Expand All @@ -40,8 +41,6 @@ if(EUDSL_STANDALONE_BUILD)
include(AddLLVM)
include(AddMLIR)
include(AddClang)

set(MLIR_INCLUDE_DIR ${MLIR_INCLUDE_DIRS})
else()
# turning LLVM -DLLVM_OPTIMIZED_TABLEGEN=ON builds some stuff in the NATIVE dir
# but not everything so LLVM_BINARY_DIR isn't correct
Expand Down
43 changes: 22 additions & 21 deletions projects/eudsl-tblgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
message("Building ${LLVM_SUBPROJECT_TITLE} as a standalone project.")
project(${LLVM_SUBPROJECT_TITLE} CXX C)
find_package(LLVM REQUIRED CONFIG)
find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")

include(TableGen)
include(AddLLVM)
# TODO(max): probably don't need this anymore after landing the nanobind fix?
# technically we need this on windows too but our LLVM is compiled without exception handling
# and that breaks windows
if(NOT WIN32)
include(HandleLLVMOptions)
endif()
include(AddMLIR)
include(HandleLLVMOptions)
endif()

include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})
Expand All @@ -49,42 +49,43 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR)
find_package(nanobind CONFIG REQUIRED)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/eudsl_tblgen)
set(EUDSL_TBLGEN_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EUDSL_TBLGEN_SRC_DIR}/eudsl_tblgen)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

nanobind_add_module(eudsl_tblgen_ext NB_STATIC STABLE_ABI
src/eudsl_tblgen_ext.cpp
src/TGParser.cpp
src/TGLexer.cpp
)
target_link_libraries(eudsl_tblgen_ext PRIVATE LLVMTableGenCommon LLVMTableGen)
target_link_libraries(eudsl_tblgen_ext PRIVATE
LLVMTableGenCommon LLVMTableGen MLIRTableGen)
target_compile_options(eudsl_tblgen_ext
PUBLIC
-Wno-cast-qual
$<$<PLATFORM_ID:Linux>:-fexceptions -frtti>
$<$<PLATFORM_ID:Darwin>:-fexceptions -frtti>
$<$<PLATFORM_ID:Windows>:/EHsc /GR>)

nanobind_add_stub(
eudsl_tblgen_ext_stub
MODULE eudsl_tblgen_ext
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/eudsl_tblgen/eudsl_tblgen_ext.pyi
PYTHON_PATH $<TARGET_FILE_DIR:eudsl_tblgen_ext>
DEPENDS eudsl_tblgen_ext
)
nanobind_add_stub(
eudsl_tblgen_stub
MODULE eudsl_tblgen
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/eudsl_tblgen/__init__.pyi
PYTHON_PATH ${CMAKE_CURRENT_LIST_DIR}
# note WORKING_DIRECTORY
set(NB_STUBGEN_CMD "${Python_EXECUTABLE}" "-m" "nanobind.stubgen"
--module eudsl_tblgen_ext --recursive --include-private --output-dir .)
set(NB_STUBGEN_OUTPUTS "__init__.pyi")
add_custom_command(
OUTPUT ${NB_STUBGEN_OUTPUTS}
COMMAND ${NB_STUBGEN_CMD}
WORKING_DIRECTORY "${EUDSL_TBLGEN_SRC_DIR}/eudsl_tblgen"
DEPENDS eudsl_tblgen_ext
)
add_custom_target(eudsl_tblgen_ext_stub ALL DEPENDS ${NB_STUBGEN_OUTPUTS})

install(TARGETS eudsl_tblgen_ext LIBRARY DESTINATION eudsl_tblgen)
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/eudsl_tblgen
DIRECTORY ${EUDSL_TBLGEN_SRC_DIR}/eudsl_tblgen
DESTINATION ${CMAKE_INSTALL_PREFIX}
PATTERN "*.pyc" EXCLUDE
PATTERN "*.so" EXCLUDE
PATTERN "*.a" EXCLUDE
PATTERN "__pycache__" EXCLUDE
PATTERN ".gitignore" EXCLUDE
)
Loading

0 comments on commit ffefb69

Please sign in to comment.