150
|
1 function(mlir_tablegen ofn)
|
173
|
2 tablegen(MLIR ${ARGV})
|
150
|
3 set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
|
4 PARENT_SCOPE)
|
|
5 endfunction()
|
|
6
|
173
|
7 # Declare a dialect in the include directory
|
|
8 function(add_mlir_dialect dialect dialect_namespace)
|
|
9 set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
|
|
10 mlir_tablegen(${dialect}.h.inc -gen-op-decls)
|
|
11 mlir_tablegen(${dialect}.cpp.inc -gen-op-defs)
|
|
12 mlir_tablegen(${dialect}Dialect.h.inc -gen-dialect-decls -dialect=${dialect_namespace})
|
|
13 add_public_tablegen_target(MLIR${dialect}IncGen)
|
|
14 add_dependencies(mlir-headers MLIR${dialect}IncGen)
|
|
15 endfunction()
|
|
16
|
|
17 # Declare a dialect in the include directory
|
|
18 function(add_mlir_interface interface)
|
|
19 set(LLVM_TARGET_DEFINITIONS ${interface}.td)
|
|
20 mlir_tablegen(${interface}.h.inc -gen-op-interface-decls)
|
|
21 mlir_tablegen(${interface}.cpp.inc -gen-op-interface-defs)
|
|
22 add_public_tablegen_target(MLIR${interface}IncGen)
|
|
23 add_dependencies(mlir-generic-headers MLIR${interface}IncGen)
|
|
24 endfunction()
|
|
25
|
|
26
|
|
27 # Generate Documentation
|
|
28 function(add_mlir_doc doc_filename command output_file output_directory)
|
|
29 set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td)
|
|
30 tablegen(MLIR ${output_file}.md ${command} "-I${MLIR_MAIN_INCLUDE_DIR}" "-I${MLIR_INCLUDE_DIR}")
|
|
31 set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/${output_directory}${output_file}.md)
|
|
32 add_custom_command(
|
|
33 OUTPUT ${GEN_DOC_FILE}
|
|
34 COMMAND ${CMAKE_COMMAND} -E copy
|
|
35 ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md
|
|
36 ${GEN_DOC_FILE}
|
|
37 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md)
|
|
38 add_custom_target(${output_file}DocGen DEPENDS ${GEN_DOC_FILE})
|
|
39 add_dependencies(mlir-doc ${output_file}DocGen)
|
|
40 endfunction()
|
|
41
|
|
42 # Declare an mlir library which can be compiled in libMLIR.so
|
|
43 # In addition to everything that llvm_add_librar accepts, this
|
|
44 # also has the following option:
|
|
45 # EXCLUDE_FROM_LIBMLIR
|
|
46 # Don't include this library in libMLIR.so. This option should be used
|
|
47 # for test libraries, executable-specific libraries, or rarely used libraries
|
|
48 # with large dependencies.
|
|
49 function(add_mlir_library name)
|
|
50 cmake_parse_arguments(ARG
|
|
51 "SHARED;INSTALL_WITH_TOOLCHAIN;EXCLUDE_FROM_LIBMLIR"
|
|
52 ""
|
|
53 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
|
|
54 ${ARGN})
|
|
55 set(srcs)
|
|
56 if(MSVC_IDE OR XCODE)
|
|
57 # Add public headers
|
|
58 file(RELATIVE_PATH lib_path
|
|
59 ${MLIR_SOURCE_DIR}/lib/
|
|
60 ${CMAKE_CURRENT_SOURCE_DIR}
|
|
61 )
|
|
62 if(NOT lib_path MATCHES "^[.][.]")
|
|
63 file( GLOB_RECURSE headers
|
|
64 ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.h
|
|
65 ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.def
|
|
66 )
|
|
67 set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
|
|
68
|
|
69 file( GLOB_RECURSE tds
|
|
70 ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.td
|
|
71 )
|
|
72 source_group("TableGen descriptions" FILES ${tds})
|
|
73 set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON)
|
|
74
|
|
75 if(headers OR tds)
|
|
76 set(srcs ${headers} ${tds})
|
|
77 endif()
|
|
78 endif()
|
|
79 endif(MSVC_IDE OR XCODE)
|
|
80 if(srcs OR ARG_ADDITIONAL_HEADERS)
|
|
81 set(srcs
|
|
82 ADDITIONAL_HEADERS
|
|
83 ${srcs}
|
|
84 ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
|
|
85 )
|
|
86 endif()
|
|
87 if(ARG_SHARED)
|
|
88 set(LIBTYPE SHARED)
|
150
|
89 else()
|
173
|
90 # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
|
|
91 # so we need to handle it here.
|
|
92 if(BUILD_SHARED_LIBS)
|
|
93 set(LIBTYPE SHARED)
|
|
94 else()
|
|
95 set(LIBTYPE STATIC)
|
|
96 endif()
|
|
97 if(NOT XCODE)
|
|
98 # The Xcode generator doesn't handle object libraries correctly.
|
|
99 list(APPEND LIBTYPE OBJECT)
|
|
100 endif()
|
|
101 # Test libraries and such shouldn't be include in libMLIR.so
|
|
102 if(NOT ARG_EXCLUDE_FROM_LIBMLIR)
|
|
103 set_property(GLOBAL APPEND PROPERTY MLIR_STATIC_LIBS ${name})
|
|
104 set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
|
|
105 set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
|
|
106 endif()
|
150
|
107 endif()
|
173
|
108
|
|
109 # MLIR libraries uniformly depend on LLVMSupport. Just specify it once here.
|
|
110 list(APPEND ARG_LINK_COMPONENTS Support)
|
|
111
|
|
112 # LINK_COMPONENTS is necessary to allow libLLVM.so to be properly
|
|
113 # substituted for individual library dependencies if LLVM_LINK_LLVM_DYLIB
|
|
114 # Perhaps this should be in llvm_add_library instead? However, it fails
|
|
115 # on libclang-cpp.so
|
|
116 get_property(llvm_component_libs GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
|
|
117 foreach(lib ${ARG_LINK_LIBS})
|
|
118 if(${lib} IN_LIST llvm_component_libs)
|
|
119 message(SEND_ERROR "${name} specifies LINK_LIBS ${lib}, but LINK_LIBS cannot be used for LLVM libraries. Please use LINK_COMPONENTS instead.")
|
|
120 endif()
|
|
121 endforeach()
|
|
122
|
|
123 list(APPEND ARG_DEPENDS mlir-generic-headers)
|
|
124 llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS})
|
|
125
|
|
126 if(TARGET ${name})
|
|
127 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
|
|
128
|
|
129 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
130 set(export_to_mlirtargets)
|
|
131 if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
|
132 "mlir-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
|
133 NOT LLVM_DISTRIBUTION_COMPONENTS)
|
|
134 set(export_to_mlirtargets EXPORT MLIRTargets)
|
|
135 set_property(GLOBAL PROPERTY MLIR_HAS_EXPORTS True)
|
|
136 endif()
|
|
137
|
|
138 install(TARGETS ${name}
|
|
139 COMPONENT ${name}
|
|
140 ${export_to_mlirtargets}
|
|
141 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
142 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
143 RUNTIME DESTINATION bin)
|
|
144
|
|
145 if (NOT LLVM_ENABLE_IDE)
|
|
146 add_llvm_install_targets(install-${name}
|
|
147 DEPENDS ${name}
|
|
148 COMPONENT ${name})
|
|
149 endif()
|
|
150 set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
|
|
151 endif()
|
|
152 set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
|
|
153 else()
|
|
154 # Add empty "phony" target
|
|
155 add_custom_target(${name})
|
|
156 endif()
|
|
157 set_target_properties(${name} PROPERTIES FOLDER "MLIR libraries")
|
|
158 endfunction(add_mlir_library)
|
|
159
|
|
160 # Declare the library associated with a dialect.
|
|
161 function(add_mlir_dialect_library name)
|
|
162 set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
|
|
163 add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
|
164 endfunction(add_mlir_dialect_library)
|
|
165
|
|
166 # Declare the library associated with a conversion.
|
|
167 function(add_mlir_conversion_library name)
|
|
168 set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
|
|
169 add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
|
170 endfunction(add_mlir_conversion_library)
|
|
171
|
|
172 # Declare the library associated with a translation.
|
|
173 function(add_mlir_translation_library name)
|
|
174 set_property(GLOBAL APPEND PROPERTY MLIR_TRANSLATION_LIBS ${name})
|
|
175 add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
|
176 endfunction(add_mlir_translation_library)
|
|
177
|
|
178 # Verification tools to aid debugging.
|
|
179 function(mlir_check_link_libraries name)
|
|
180 if(TARGET ${name})
|
|
181 get_target_property(libs ${name} LINK_LIBRARIES)
|
|
182 # message("${name} libs are: ${libs}")
|
|
183 set(linking_llvm 0)
|
|
184 foreach(lib ${libs})
|
|
185 if(lib)
|
|
186 if(${lib} MATCHES "^LLVM$")
|
|
187 set(linking_llvm 1)
|
|
188 endif()
|
|
189 if((${lib} MATCHES "^LLVM.+") AND ${linking_llvm})
|
|
190 # This will almost always cause execution problems, since the
|
|
191 # same symbol might be loaded from 2 separate libraries. This
|
|
192 # often comes from referring to an LLVM library target
|
|
193 # explicitly in target_link_libraries()
|
|
194 message("WARNING: ${name} links LLVM and ${lib}!")
|
|
195 endif()
|
|
196 endif()
|
|
197 endforeach()
|
|
198 endif()
|
|
199 endfunction(mlir_check_link_libraries)
|
|
200
|
|
201 function(mlir_check_all_link_libraries name)
|
|
202 mlir_check_link_libraries(${name})
|
|
203 if(TARGET ${name})
|
|
204 get_target_property(libs ${name} LINK_LIBRARIES)
|
|
205 # message("${name} libs are: ${libs}")
|
|
206 foreach(lib ${libs})
|
|
207 mlir_check_link_libraries(${lib})
|
|
208 endforeach()
|
|
209 endif()
|
|
210 endfunction(mlir_check_all_link_libraries)
|