[SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (#90217)
[llvm-project.git] / mlir / lib / Target / LLVM / CMakeLists.txt
blobe0657c895e8a3894aa8194c63498b5a3006c2ab2
1 add_mlir_library(MLIRTargetLLVM
2   ModuleToObject.cpp
4   ADDITIONAL_HEADER_DIRS
5   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVM
7   DEPENDS
8   intrinsics_gen
10   LINK_COMPONENTS
11   Core
12   IPO
13   IRReader
14   Linker
15   MC
16   Passes
17   Support
18   Target
19   LINK_LIBS PUBLIC
20   MLIRExecutionEngineUtils
21   MLIRTargetLLVMIRExport
24 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
25   set(NVPTX_LIBS
26     NVPTXCodeGen
27     NVPTXDesc
28     NVPTXInfo
29   )
30 endif()
32 add_mlir_dialect_library(MLIRNVVMTarget
33   NVVM/Target.cpp
35   ADDITIONAL_HEADER_DIRS
36   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
38   LINK_COMPONENTS
39   ${NVPTX_LIBS}
41   LINK_LIBS PUBLIC
42   MLIRIR
43   MLIRExecutionEngineUtils
44   MLIRSupport
45   MLIRGPUDialect
46   MLIRTargetLLVM
47   MLIRNVVMToLLVMIRTranslation
48   )
50 if(MLIR_ENABLE_CUDA_CONVERSIONS)
51   # Find the CUDA toolkit.
52   find_package(CUDAToolkit)
54   if(CUDAToolkit_FOUND)
55     # Get the CUDA toolkit path. The path is needed for detecting `libdevice.bc`.
56     # These extra steps are needed because of a bug on CMake.
57     # See: https://gitlab.kitware.com/cmake/cmake/-/issues/24858
58     # TODO: Bump the MLIR CMake version to 3.26.4 and switch to
59     # ${CUDAToolkit_LIBRARY_ROOT}
60     if(NOT DEFINED ${CUDAToolkit_LIBRARY_ROOT})
61       get_filename_component(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_BIN_DIR}
62                              DIRECTORY ABSOLUTE)
63     else()
64       set(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_ROOT})
65     endif()
67     # Add the `nvptxcompiler` library.
68     if(MLIR_ENABLE_NVPTXCOMPILER)
69       # Find the `nvptxcompiler` library.
70       # TODO: Bump the MLIR CMake version to 3.25 and use `CUDA::nvptxcompiler_static`.
71       find_library(MLIR_NVPTXCOMPILER_LIB nvptxcompiler_static
72                   PATHS ${CUDAToolkit_LIBRARY_DIR} NO_DEFAULT_PATH)
74       # Fail if `nvptxcompiler_static` couldn't be found.
75       if(MLIR_NVPTXCOMPILER_LIB STREQUAL "MLIR_NVPTXCOMPILER_LIB-NOTFOUND")
76         message(FATAL_ERROR
77                 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
78       endif()
80       # Link against `nvptxcompiler_static`. TODO: use `CUDA::nvptxcompiler_static`.
81       target_link_libraries(MLIRNVVMTarget PRIVATE ${MLIR_NVPTXCOMPILER_LIB})
82       target_include_directories(obj.MLIRNVVMTarget PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
83     endif()
84   else()
85     # Fail if `MLIR_ENABLE_NVPTXCOMPILER` is enabled and the toolkit couldn't be found.
86     if(MLIR_ENABLE_NVPTXCOMPILER)
87       message(FATAL_ERROR
88               "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
89     endif()
90   endif()
91   message(VERBOSE "MLIR default CUDA toolkit path: ${MLIR_CUDAToolkit_ROOT}")
93   # Define the `CUDAToolkit` path.
94   target_compile_definitions(obj.MLIRNVVMTarget
95     PRIVATE
96     __DEFAULT_CUDATOOLKIT_PATH__="${MLIR_CUDAToolkit_ROOT}"
97   )
98 endif()
100 if (MLIR_ENABLE_ROCM_CONVERSIONS)
101   set(AMDGPU_LIBS
102     AMDGPUAsmParser
103     AMDGPUCodeGen
104     AMDGPUDesc
105     AMDGPUInfo
106   )
107 endif()
109 add_mlir_dialect_library(MLIRROCDLTarget
110   ROCDL/Target.cpp
112   LINK_COMPONENTS
113   MCParser
114   ${AMDGPU_LIBS}
116   LINK_LIBS PUBLIC
117   MLIRIR
118   MLIRExecutionEngineUtils
119   MLIRSupport
120   MLIRGPUDialect
121   MLIRTargetLLVM
122   MLIRROCDLToLLVMIRTranslation
123   )
125 if(MLIR_ENABLE_ROCM_CONVERSIONS)
126   if (NOT ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD))
127     message(SEND_ERROR
128       "Building mlir with ROCm support requires the AMDGPU backend")
129   endif()
131   if (DEFINED ROCM_PATH)
132     set(DEFAULT_ROCM_PATH "${ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
133   elseif(DEFINED ENV{ROCM_PATH})
134     set(DEFAULT_ROCM_PATH "$ENV{ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
135   else()
136     set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
137   endif()
138   message(VERBOSE "MLIR Default ROCM toolkit path: ${DEFAULT_ROCM_PATH}")
140   target_compile_definitions(obj.MLIRROCDLTarget
141     PRIVATE
142     __DEFAULT_ROCM_PATH__="${DEFAULT_ROCM_PATH}"
143   )
144 endif()