[Mlir-commits] [mlir] 7add6b6 - [MLIR] add dependencies for all tablegen targets on 'mlir-headers'

Stephen Neuendorffer llvmlistbot at llvm.org
Fri May 1 21:38:35 PDT 2020


Author: Stephen Neuendorffer
Date: 2020-05-01T20:08:52-07:00
New Revision: 7add6b6b73fdb3e1303ee911f7e2acfb6bb467c8

URL: https://github.com/llvm/llvm-project/commit/7add6b6b73fdb3e1303ee911f7e2acfb6bb467c8
DIFF: https://github.com/llvm/llvm-project/commit/7add6b6b73fdb3e1303ee911f7e2acfb6bb467c8.diff

LOG: [MLIR] add dependencies for all tablegen targets on 'mlir-headers'

In cmake, dependencies on generated files require some sophistication in the build system.  At build time, files are parsed to determine which headers they depend on and these dependencies are injected into the build system.  This works well with ninja, but has some constraints with the makefile generator.  According to the cmake documentation, this only works reliably within the same directory.

This patch expands the usage of mlir-headers to include all generated headers and adds an mlir-generic-headers target which triggers generation of dialect-independent headers.  These targets are used to express dependencies on generated headers.  This is mostly handled in AddMLIR.cmake and only a few CMakeLists.txt files need to change.

Differential Revision: https://reviews.llvm.org/D79242

Added: 
    

Modified: 
    mlir/CMakeLists.txt
    mlir/cmake/modules/AddMLIR.cmake
    mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
    mlir/include/mlir/Dialect/LoopOps/CMakeLists.txt
    mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt
    mlir/include/mlir/IR/CMakeLists.txt
    mlir/include/mlir/Interfaces/CMakeLists.txt
    mlir/lib/Analysis/CMakeLists.txt
    mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
    mlir/lib/Parser/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 5c36eecd35b6..3671a97395d4 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -12,8 +12,13 @@ include(AddMLIR)
 
 # Installing the headers and docs needs to depend on generating any public
 # tablegen'd targets.
+# mlir-generic-headers are dialect-independent.
+add_custom_target(mlir-generic-headers)
+set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
+# mlir-headers may be dialect-dependent.
 add_custom_target(mlir-headers)
 set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
+add_dependencies(mlir-headers mlir-generic-headers)
 add_custom_target(mlir-doc)
 
 # Build the CUDA conversions and run according tests if the NVPTX backend

diff  --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index f1de17c682d2..6a2856b7f987 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -38,17 +38,17 @@ endmacro(add_mlir_library)
 # Declare the library associated with a dialect.
 function(add_mlir_dialect_library name)
   set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
-  add_mlir_library(${ARGV})
+  add_mlir_library(${ARGV} DEPENDS mlir-headers)
 endfunction(add_mlir_dialect_library)
 
 # Declare the library associated with a conversion.
 function(add_mlir_conversion_library name)
   set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
-  add_mlir_library(${ARGV})
+  add_mlir_library(${ARGV} DEPENDS mlir-headers)
 endfunction(add_mlir_conversion_library)
 
 # Declare the library associated with a translation.
 function(add_mlir_translation_library name)
   set_property(GLOBAL APPEND PROPERTY MLIR_TRANSLATION_LIBS ${name})
-  add_mlir_library(${ARGV})
+  add_mlir_library(${ARGV} DEPENDS mlir-headers)
 endfunction(add_mlir_translation_library)

diff  --git a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
index 6f25c2049272..fe67dcb7a660 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
@@ -29,6 +29,7 @@ add_linalg_ods_gen(LinalgNamedStructuredOpsSpec.tc LinalgNamedStructuredOps)
 # Provide a short name for all external dependency that needs to
 # include Linalg in ODS
 add_custom_target(LinalgOdsGen DEPENDS MLIRLinalgNamedStructuredOpsIncGen)
+add_dependencies(mlir-headers LinalgOdsGen)
 
 add_mlir_dialect(LinalgOps linalg)
 
@@ -40,8 +41,10 @@ mlir_tablegen(LinalgStructuredOps.h.inc -gen-op-decls)
 mlir_tablegen(LinalgStructuredOps.cpp.inc -gen-op-defs)
 add_public_tablegen_target(MLIRLinalgStructuredOpsIncGen)
 add_dependencies(MLIRLinalgStructuredOpsIncGen LinalgOdsGen)
-    
+add_dependencies(mlir-headers MLIRLinalgStructuredOpsIncGen)
+
 set(LLVM_TARGET_DEFINITIONS LinalgStructuredOpsInterface.td)
 mlir_tablegen(LinalgStructuredOpsInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(LinalgStructuredOpsInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRLinalgStructuredOpsInterfaceIncGen)
+add_dependencies(mlir-headers MLIRLinalgStructuredOpsInterfaceIncGen)

diff  --git a/mlir/include/mlir/Dialect/LoopOps/CMakeLists.txt b/mlir/include/mlir/Dialect/LoopOps/CMakeLists.txt
index 2627cbb542da..90de6b097a9d 100644
--- a/mlir/include/mlir/Dialect/LoopOps/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/LoopOps/CMakeLists.txt
@@ -4,5 +4,6 @@ add_mlir_doc(LoopOps -gen-dialect-doc LoopDialect Dialects/)
 set(LLVM_TARGET_DEFINITIONS Passes.td)
 mlir_tablegen(Passes.h.inc -gen-pass-decls)
 add_public_tablegen_target(MLIRLoopPassIncGen)
+add_dependencies(mlir-headers MLIRLoopPassIncGen)
 
 add_mlir_doc(Passes -gen-pass-doc LoopPasses ./)

diff  --git a/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt b/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt
index 15f4a4dfe847..1e0901f07e91 100644
--- a/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt
@@ -5,34 +5,41 @@ set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
 mlir_tablegen(SPIRVEnums.h.inc -gen-enum-decls)
 mlir_tablegen(SPIRVEnums.cpp.inc -gen-enum-defs)
 add_public_tablegen_target(MLIRSPIRVEnumsIncGen)
+add_dependencies(mlir-headers MLIRSPIRVEnumsIncGen)
 
 set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
 mlir_tablegen(SPIRVEnumAvailability.h.inc -gen-spirv-enum-avail-decls)
 mlir_tablegen(SPIRVEnumAvailability.cpp.inc -gen-spirv-enum-avail-defs)
 mlir_tablegen(SPIRVCapabilityImplication.inc -gen-spirv-capability-implication)
 add_public_tablegen_target(MLIRSPIRVEnumAvailabilityIncGen)
+add_dependencies(mlir-headers MLIRSPIRVEnumAvailabilityIncGen)
 
 set(LLVM_TARGET_DEFINITIONS SPIRVOps.td)
 mlir_tablegen(SPIRVAvailability.h.inc -gen-avail-interface-decls)
 mlir_tablegen(SPIRVAvailability.cpp.inc -gen-avail-interface-defs)
 mlir_tablegen(SPIRVOpAvailabilityImpl.inc -gen-spirv-avail-impls)
 add_public_tablegen_target(MLIRSPIRVAvailabilityIncGen)
+add_dependencies(mlir-headers MLIRSPIRVAvailabilityIncGen)
 
 set(LLVM_TARGET_DEFINITIONS SPIRVOps.td)
 mlir_tablegen(SPIRVSerialization.inc -gen-spirv-serialization)
 add_public_tablegen_target(MLIRSPIRVSerializationGen)
+add_dependencies(mlir-headers MLIRSPIRVSerializationGen)
 
 set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
 mlir_tablegen(SPIRVOpUtils.inc -gen-spirv-op-utils)
 add_public_tablegen_target(MLIRSPIRVOpUtilsGen)
+add_dependencies(mlir-headers MLIRSPIRVOpUtilsGen)
 
 set(LLVM_TARGET_DEFINITIONS TargetAndABI.td)
 mlir_tablegen(TargetAndABI.h.inc -gen-struct-attr-decls)
 mlir_tablegen(TargetAndABI.cpp.inc -gen-struct-attr-defs)
 add_public_tablegen_target(MLIRSPIRVTargetAndABIIncGen)
+add_dependencies(mlir-headers MLIRSPIRVTargetAndABIIncGen)
 
 set(LLVM_TARGET_DEFINITIONS Passes.td)
 mlir_tablegen(Passes.h.inc -gen-pass-decls)
 add_public_tablegen_target(MLIRSPIRVPassIncGen)
+add_dependencies(mlir-headers MLIRSPIRVPassIncGen)
 
 add_mlir_doc(Passes -gen-pass-doc SPIRVPasses ./)

diff  --git a/mlir/include/mlir/IR/CMakeLists.txt b/mlir/include/mlir/IR/CMakeLists.txt
index c4e6c99ba640..06c177aff3a8 100644
--- a/mlir/include/mlir/IR/CMakeLists.txt
+++ b/mlir/include/mlir/IR/CMakeLists.txt
@@ -2,8 +2,10 @@ set(LLVM_TARGET_DEFINITIONS OpAsmInterface.td)
 mlir_tablegen(OpAsmInterface.h.inc -gen-op-interface-decls)
 mlir_tablegen(OpAsmInterface.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIROpAsmInterfacesIncGen)
+add_dependencies(mlir-generic-headers MLIROpAsmInterfacesIncGen)
 
 set(LLVM_TARGET_DEFINITIONS SymbolInterfaces.td)
 mlir_tablegen(SymbolInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(SymbolInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRSymbolInterfacesIncGen)
+add_dependencies(mlir-generic-headers MLIRSymbolInterfacesIncGen)

diff  --git a/mlir/include/mlir/Interfaces/CMakeLists.txt b/mlir/include/mlir/Interfaces/CMakeLists.txt
index fea8ffb2fc0a..18efa97ab100 100644
--- a/mlir/include/mlir/Interfaces/CMakeLists.txt
+++ b/mlir/include/mlir/Interfaces/CMakeLists.txt
@@ -2,33 +2,40 @@ set(LLVM_TARGET_DEFINITIONS CallInterfaces.td)
 mlir_tablegen(CallInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(CallInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRCallInterfacesIncGen)
+add_dependencies(mlir-generic-headers MLIRCallInterfacesIncGen)
 
 set(LLVM_TARGET_DEFINITIONS ControlFlowInterfaces.td)
 mlir_tablegen(ControlFlowInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(ControlFlowInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRControlFlowInterfacesIncGen)
+add_dependencies(mlir-generic-headers MLIRControlFlowInterfacesIncGen)
 
 set(LLVM_TARGET_DEFINITIONS DerivedAttributeOpInterface.td)
 mlir_tablegen(DerivedAttributeOpInterface.h.inc -gen-op-interface-decls)
 mlir_tablegen(DerivedAttributeOpInterface.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRDerivedAttributeOpInterfaceIncGen)
+add_dependencies(mlir-generic-headers MLIRDerivedAttributeOpInterfaceIncGen)
 
 set(LLVM_TARGET_DEFINITIONS InferTypeOpInterface.td)
 mlir_tablegen(InferTypeOpInterface.h.inc -gen-op-interface-decls)
 mlir_tablegen(InferTypeOpInterface.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRInferTypeOpInterfaceIncGen)
+add_dependencies(mlir-generic-headers MLIRInferTypeOpInterfaceIncGen)
 
 set(LLVM_TARGET_DEFINITIONS LoopLikeInterface.td)
 mlir_tablegen(LoopLikeInterface.h.inc -gen-op-interface-decls)
 mlir_tablegen(LoopLikeInterface.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRLoopLikeInterfaceIncGen)
+add_dependencies(mlir-generic-headers MLIRLoopLikeInterfaceIncGen)
 
 set(LLVM_TARGET_DEFINITIONS SideEffects.td)
 mlir_tablegen(SideEffectInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(SideEffectInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRSideEffectOpInterfacesIncGen)
+add_dependencies(mlir-generic-headers MLIRSideEffectOpInterfacesIncGen)
 
 set(LLVM_TARGET_DEFINITIONS ViewLikeInterface.td)
 mlir_tablegen(ViewLikeInterface.h.inc -gen-op-interface-decls)
 mlir_tablegen(ViewLikeInterface.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRViewLikeInterfaceIncGen)
+add_dependencies(mlir-generic-headers MLIRViewLikeInterfaceIncGen)

diff  --git a/mlir/lib/Analysis/CMakeLists.txt b/mlir/lib/Analysis/CMakeLists.txt
index 5eeee048ba3b..2fa57c510fdf 100644
--- a/mlir/lib/Analysis/CMakeLists.txt
+++ b/mlir/lib/Analysis/CMakeLists.txt
@@ -16,6 +16,9 @@ add_mlir_library(MLIRAnalysis
 
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Analysis
+
+  DEPENDS
+  mlir-generic-headers
   )
 
 target_link_libraries(MLIRAnalysis
@@ -36,6 +39,9 @@ add_mlir_library(MLIRLoopAnalysis
 
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Analysis
+
+  DEPENDS
+  mlir-generic-headers
   )
 
 target_link_libraries(MLIRLoopAnalysis

diff  --git a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
index 5b4282a4977f..e8a47a3d1f16 100644
--- a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
+++ b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
@@ -7,8 +7,6 @@ add_mlir_dialect_library(MLIRLinalgOps
 
   DEPENDS
   intrinsics_gen
-  )
-add_dependencies(MLIRLinalgOps
   MLIRLinalgOpsIncGen
   MLIRLinalgStructuredOpsIncGen
   MLIRLinalgStructuredOpsInterfaceIncGen

diff  --git a/mlir/lib/Parser/CMakeLists.txt b/mlir/lib/Parser/CMakeLists.txt
index 79aca662d9d3..fe2e03030880 100644
--- a/mlir/lib/Parser/CMakeLists.txt
+++ b/mlir/lib/Parser/CMakeLists.txt
@@ -5,6 +5,9 @@ add_mlir_library(MLIRParser
 
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Parser
+
+  DEPENDS
+  mlir-generic-headers
   )
 target_link_libraries(MLIRParser
   PUBLIC


        


More information about the Mlir-commits mailing list