Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 24d9a67

Browse files
author
Sven Verdoolaege
committed
locally generate and store isl C++ interface
The process of building the C++ interface in TC's (cmake based) copy of isl was considered to be too fragile for mere users of TC. It was therefore decided to put this C++ interface inside TC's isl. Furthermore, in order not to disrupt development of TC's isl itself, the bindings are automatically generated and stored in a separate branch. This is only a temporary solution since the goal is to be able to use mainline isl whenever possible and mainline isl will not include this interface in its git repository. Put it in TC itself. While, in general, it's not a good idea to include generated files, this should be no worse than the current situation where the generated files are stored in TC's isl. The interface now needs to be generated by whoever updates the isl submodule, but it has to be generated in advance anyway to be able to test the isl submodule changes, so this shouldn't be too much of an extra burden. The header is generated by generate_isl_cpp_h instead of generate_isl because generate_isl is still defined by the isl submodule. This support can be removed from the isl submodule in a later step. Similarly, the local copy of the extract_interface executable is called extract_isl_interface. The configuration is based on the one in isl mainline, except that the defines are hard-coded to a specific version of LLVM/clang. This is the same as in TC's copy of isl, except that the latter missed one define causing it to miss out on the standard include paths.
1 parent 45ca22e commit 24d9a67

File tree

9 files changed

+22371
-2
lines changed

9 files changed

+22371
-2
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ message(STATUS "Found ATen.so file: ${ATEN_LIBRARIES}")
227227
# isl
228228
################################################################################
229229
set(ISL_INT "gmp" CACHE STRING "Which package to use to represent multi-precision integers (gmp|imath)")
230+
# use locally generated C++ bindings
231+
include_directories(AFTER ${PROJECT_SOURCE_DIR}/isl_interface/include)
230232
include_directories(AFTER ${PROJECT_SOURCE_DIR}/third-party/islpp/include)
231233
include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR}/third-party/islpp/include)
232234
add_subdirectory(third-party/islpp)
@@ -323,3 +325,7 @@ if (WITH_CAFFE2 AND WITH_CUDA)
323325
else()
324326
message(STATUS "Not building benchmarks, caffe2 or CUDA not available")
325327
endif()
328+
329+
if (WITH_BINDINGS)
330+
add_subdirectory(isl_interface)
331+
endif()

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ Another alternative is to use the provided script:
6161
CLANG=${PATH_TO_CLANG_INSTALL_BINARY}/clang-format ./check_and_fix_format.sh
6262
```
6363

64+
## Changes to isl submodule
65+
66+
If you update the isl submodule, then you will typically also need
67+
to update the C++ bindings in isl_interface.
68+
To generate these bindings, you need to build with `WITH_BINDINGS=ON`.

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CXX=${CXX:="`which g++`"}
2020
WITH_CUDA=${WITH_CUDA:=ON}
2121
WITH_CAFFE2=${WITH_CAFFE2:=OFF}
2222
WITH_TAPIR=${WITH_TAPIR:=ON}
23+
WITH_BINDINGS=${WITH_BINDINGS:=OFF}
2324

2425
CUDNN_ROOT_DIR=${CUDNN_ROOT_DIR:=${CONDA_PREFIX}}
2526
CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH:=${CONDA_PREFIX}/lib/cmake}

isl_interface/CMakeLists.txt

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Location of the isl submodule.
2+
SET(ISL_DIR "${PROJECT_SOURCE_DIR}/third-party/islpp")
3+
# Location of extract_interface source files.
4+
SET(ISL_INTERFACE_DIR "${ISL_DIR}/interface")
5+
6+
add_definitions(-DCLANG_PREFIX="${CLANG_PREFIX}")
7+
8+
# Hard-coded defines for LLVM/clang 5.0.0
9+
add_definitions(-DADDPATH_TAKES_4_ARGUMENTS)
10+
add_definitions(-DCREATETARGETINFO_TAKES_SHARED_PTR)
11+
add_definitions(-DCREATEPREPROCESSOR_TAKES_TUKIND)
12+
add_definitions(-DHAVE_BASIC_DIAGNOSTICOPTIONS_H)
13+
add_definitions(-DHAVE_LEX_PREPROCESSOROPTIONS_H)
14+
add_definitions(-DHAVE_SETMAINFILEID)
15+
add_definitions(-DSETINVOCATION_TAKES_SHARED_PTR)
16+
add_definitions(-DSETLANGDEFAULTS_TAKES_5_ARGUMENTS)
17+
add_definitions(-DUSE_ARRAYREF)
18+
add_definitions(-DgetNumArgs=getNumParams)
19+
add_definitions(-DgetArgType=getParamType)
20+
add_definitions(-DHandleTopLevelDeclReturn=bool)
21+
add_definitions(-DHandleTopLevelDeclContinue=true)
22+
add_definitions(-DIK_C=InputKind::C)
23+
24+
find_library(CLANG_FRONTEND_LIB REQUIRED clangFrontend
25+
${CLANG_PREFIX} PATH_SUFFIXES lib)
26+
find_library(CLANG_SERIALIZATION_LIB REQUIRED clangSerialization
27+
${CLANG_PREFIX} PATH_SUFFIXES lib)
28+
find_library(CLANG_PARSE_LIB REQUIRED clangParse
29+
${CLANG_PREFIX} PATH_SUFFIXES lib)
30+
find_library(CLANG_SEMA_LIB REQUIRED clangSema
31+
${CLANG_PREFIX} PATH_SUFFIXES lib)
32+
find_library(CLANG_EDIT_LIB REQUIRED clangEdit
33+
${CLANG_PREFIX} PATH_SUFFIXES lib)
34+
find_library(CLANG_ANALYSIS_LIB REQUIRED clangAnalysis
35+
${CLANG_PREFIX} PATH_SUFFIXES lib)
36+
find_library(CLANG_AST_LIB REQUIRED clangAST
37+
${CLANG_PREFIX} PATH_SUFFIXES lib)
38+
find_library(CLANG_LEX_LIB REQUIRED clangLex
39+
${CLANG_PREFIX} PATH_SUFFIXES lib)
40+
find_library(CLANG_BASIC_LIB REQUIRED clangBasic
41+
${CLANG_PREFIX} PATH_SUFFIXES lib)
42+
find_library(CLANG_DRIVER_LIB REQUIRED clangDriver
43+
${CLANG_PREFIX} PATH_SUFFIXES lib)
44+
45+
SET(CLANG_LIBRARIES
46+
"${CLANG_FRONTEND_LIB}"
47+
"${CLANG_SERIALIZATION_LIB}"
48+
"${CLANG_PARSE_LIB}"
49+
"${CLANG_SEMA_LIB}"
50+
"${CLANG_EDIT_LIB}"
51+
"${CLANG_ANALYSIS_LIB}"
52+
"${CLANG_AST_LIB}"
53+
"${CLANG_LEX_LIB}"
54+
"${CLANG_BASIC_LIB}"
55+
"${CLANG_DRIVER_LIB}"
56+
)
57+
58+
find_program(LLVM_CONFIG_BIN llvm-config PATHS ${CLANG_PREFIX}
59+
PATH_SUFFIXES bin
60+
NO_DEFAULT_PATH)
61+
62+
# The process of finding the right libraries to link against
63+
# is based on isl's m4/ax_detect_clang.m4.
64+
execute_process(COMMAND
65+
"${LLVM_CONFIG_BIN}" --targets-built
66+
OUTPUT_VARIABLE LLVM_TARGETS OUTPUT_STRIP_TRAILING_WHITESPACE)
67+
SET(LLVM_COMPONENTS ${LLVM_TARGETS} asmparser bitreader support mc option)
68+
execute_process(COMMAND
69+
"${LLVM_CONFIG_BIN}" --libs ${LLVM_COMPONENTS}
70+
OUTPUT_VARIABLE LLVM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
71+
execute_process(COMMAND
72+
"${LLVM_CONFIG_BIN}" --system-libs
73+
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
74+
75+
# Add current directory for mock isl_config.h
76+
include_directories(.)
77+
add_executable(extract_isl_interface
78+
${ISL_INTERFACE_DIR}/cpp.cc
79+
${ISL_INTERFACE_DIR}/extract_interface.cc
80+
${ISL_INTERFACE_DIR}/generator.cc
81+
${ISL_INTERFACE_DIR}/python.cc
82+
)
83+
target_link_libraries(extract_isl_interface
84+
"${CLANG_LIBRARIES}" ${LLVM_LIBS} ${LLVM_SYSTEM_LIBS})
85+
86+
# Dummy library to ensure that C++ bindings depend on contents of header files.
87+
add_library(isl_all_h_dep STATIC ${ISL_DIR}/all.c)
88+
89+
SET(ISL_CPP_H "${CMAKE_CURRENT_LIST_DIR}/include/isl/cpp.h")
90+
add_custom_command(
91+
OUTPUT ${ISL_CPP_H}
92+
DEPENDS isl_all_h_dep
93+
DEPENDS ${ISL_DIR}/cpp/cpp.h.top
94+
DEPENDS ${ISL_DIR}/cpp/cpp.h.pre
95+
DEPENDS ${ISL_DIR}/all.h
96+
DEPENDS ${ISL_DIR}/cpp/cpp.h.bot
97+
COMMAND mkdir -p ${CMAKE_CURRENT_LIST_DIR}/include/isl
98+
COMMAND cat ${ISL_DIR}/cpp/cpp.h.top > ${ISL_CPP_H} || exit 1
99+
# Turn off reformatting on this generated file.
100+
COMMAND echo "// clang-format off" >> ${ISL_CPP_H} || exit 1
101+
COMMAND cat ${ISL_DIR}/all.h >> ${ISL_CPP_H} || exit 1
102+
COMMAND cat ${ISL_DIR}/cpp/cpp.h.pre >> ${ISL_CPP_H} || exit 1
103+
COMMAND extract_isl_interface --language=cpp
104+
-I${ISL_DIR}/include ${ISL_DIR}/all.h
105+
-I${CMAKE_CURRENT_LIST_DIR} >> ${ISL_CPP_H} || exit 1
106+
COMMAND cat ${ISL_DIR}/cpp/cpp.h.bot >> ${ISL_CPP_H} || exit 1
107+
DEPENDS extract_isl_interface
108+
)
109+
# generate_isl_cpp_h is the dependency that should be used
110+
# by code that depends on the isl C++ bindings.
111+
add_custom_target(generate_isl_cpp_h DEPENDS ${ISL_CPP_H})

0 commit comments

Comments
 (0)