[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,222 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include Hardcode84 wrote: Most of those includes are not being used and can be removed (map, mutex, vector, atomic) https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,222 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + static sycl::device syclDevice; + static bool isDeviceInitialised = false; + if(!isDeviceInitialised) { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +syclDevice = platform.get_devices()[0]; +isDeviceInitialised = true; +return syclDevice; + } +throw std::runtime_error("getDefaultDevice failed"); Hardcode84 wrote: Just side comment, SYCL itself uses exceptions to report errors, so it's not possible to disable them completely and that's `catchAll` wrapper is for. https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,222 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + static sycl::device syclDevice; + static bool isDeviceInitialised = false; + if(!isDeviceInitialised) { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +syclDevice = platform.get_devices()[0]; +isDeviceInitialised = true; +return syclDevice; + } +throw std::runtime_error("getDefaultDevice failed"); Hardcode84 wrote: Just side comment, SYCL itself uses exceptions to report errors, so it's not possible to disable them completely and that's `catchAll` wrapper is for. https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,222 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 Hardcode84 wrote: There is a cmake module https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html to generate those macro automatically, what the llvm/mlir position on using it? https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,222 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 Hardcode84 wrote: There is a cmake module https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html to generate those macro automatically, what the llvm/mlir position on using it? https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
https://github.com/Hardcode84 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,209 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements wrappers around the sycl runtime library with C linkage +// +//===--===// + +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + static sycl::device syclDevice; + static bool isDeviceInitialised = false; + if (!isDeviceInitialised) { +auto platformList = sycl::platform::get_platforms(); +for (const auto &platform : platformList) { + auto platformName = platform.get_info(); + bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; + if (!isLevelZero) +continue; + + syclDevice = platform.get_devices()[0]; + isDeviceInitialised = true; + return syclDevice; +} +throw std::runtime_error("getDefaultDevice failed"); + } else +return syclDevice; +} + +static sycl::context getDefaultContext() { + static sycl::context syclContext{getDefaultDevice()}; + return syclContext; +} + +static void *allocDeviceMemory(sycl::queue *queue, size_t size, bool isShared) { + void *memPtr = nullptr; + if (isShared) { +memPtr = sycl::aligned_alloc_shared(64, size, getDefaultDevice(), +getDefaultContext()); + } else { +memPtr = sycl::aligned_alloc_device(64, size, getDefaultDevice(), +getDefaultContext()); + } + if (memPtr == nullptr) { +throw std::runtime_error("mem allocation failed!"); + } + return memPtr; +} + +static void deallocDeviceMemory(sycl::queue *queue, void *ptr) { + sycl::free(ptr, *queue); +} + +static ze_module_handle_t loadModule(const void *data, size_t dataSize) { + assert(data); + ze_module_handle_t zeModule; + ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC, + nullptr, + ZE_MODULE_FORMAT_IL_SPIRV, + dataSize, + (const uint8_t *)data, + nullptr, + nullptr}; + auto zeDevice = sycl::get_native( + getDefaultDevice()); + auto zeContext = sycl::get_native( + getDefaultContext()); + L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr)); + return zeModule; +} + +static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) { + assert(zeModule); + assert(name); + ze_kernel_handle_t zeKernel; + ze_kernel_desc_t desc = {}; + desc.pKernelName = name; + + L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel)); + sycl::kernel_bundle kernelBundle = + sycl::make_kernel_bundle( + {zeModule}, getDefaultContext()); + + auto kernel = sycl::make_kernel( + {kernelBundle, zeKernel}, getDefaultContext()); + return new sycl::kernel(kernel); +} + +static void launchKernel(sycl::queue *queue, sycl::kernel *kernel, size_t gridX, + size_t gridY, size_t gridZ, size_t blockX, + size_t blockY, size_t blockZ, size_t sharedMemBytes, + void **params, size_t paramsCount) { + auto syclGlobalRange = + sycl::range<3>(blockZ * gridZ, blockY * gridY, blockX * gridX); + auto syclLocalRange = sycl::range<3>(blockZ, blockY, blockX); + sycl::nd_range<3> syclNdRange(syclGlobalRange, syclLocalRange); + + queue->submit([&](sycl::handler &cgh) { +for (size_t i = 0; i < paramsCount; i++) { + cgh.set_arg(st
[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)
@@ -0,0 +1,209 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implements wrappers around the sycl runtime library with C linkage +// +//===--===// + +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + static sycl::device syclDevice; + static bool isDeviceInitialised = false; + if (!isDeviceInitialised) { +auto platformList = sycl::platform::get_platforms(); +for (const auto &platform : platformList) { + auto platformName = platform.get_info(); + bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; + if (!isLevelZero) +continue; + + syclDevice = platform.get_devices()[0]; + isDeviceInitialised = true; + return syclDevice; +} +throw std::runtime_error("getDefaultDevice failed"); + } else +return syclDevice; +} + +static sycl::context getDefaultContext() { + static sycl::context syclContext{getDefaultDevice()}; + return syclContext; +} + +static void *allocDeviceMemory(sycl::queue *queue, size_t size, bool isShared) { + void *memPtr = nullptr; + if (isShared) { +memPtr = sycl::aligned_alloc_shared(64, size, getDefaultDevice(), +getDefaultContext()); + } else { +memPtr = sycl::aligned_alloc_device(64, size, getDefaultDevice(), +getDefaultContext()); + } + if (memPtr == nullptr) { +throw std::runtime_error("mem allocation failed!"); + } + return memPtr; +} + +static void deallocDeviceMemory(sycl::queue *queue, void *ptr) { + sycl::free(ptr, *queue); +} + +static ze_module_handle_t loadModule(const void *data, size_t dataSize) { + assert(data); + ze_module_handle_t zeModule; + ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC, + nullptr, + ZE_MODULE_FORMAT_IL_SPIRV, + dataSize, + (const uint8_t *)data, + nullptr, + nullptr}; + auto zeDevice = sycl::get_native( + getDefaultDevice()); + auto zeContext = sycl::get_native( + getDefaultContext()); + L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr)); + return zeModule; +} + +static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) { + assert(zeModule); + assert(name); + ze_kernel_handle_t zeKernel; + ze_kernel_desc_t desc = {}; + desc.pKernelName = name; + + L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel)); + sycl::kernel_bundle kernelBundle = + sycl::make_kernel_bundle( + {zeModule}, getDefaultContext()); + + auto kernel = sycl::make_kernel( + {kernelBundle, zeKernel}, getDefaultContext()); + return new sycl::kernel(kernel); +} + +static void launchKernel(sycl::queue *queue, sycl::kernel *kernel, size_t gridX, + size_t gridY, size_t gridZ, size_t blockX, + size_t blockY, size_t blockZ, size_t sharedMemBytes, + void **params, size_t paramsCount) { + auto syclGlobalRange = + sycl::range<3>(blockZ * gridZ, blockY * gridY, blockX * gridX); + auto syclLocalRange = sycl::range<3>(blockZ, blockY, blockX); + sycl::nd_range<3> syclNdRange(syclGlobalRange, syclLocalRange); + + queue->submit([&](sycl::handler &cgh) { +for (size_t i = 0; i < paramsCount; i++) { + cgh.set_arg(st
[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)
https://github.com/Hardcode84 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/69648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Enabling Intel GPU Integration. (PR #65539)
Hardcode84 wrote: I suggest to extract `mgpu` interface changes and `serializetoSpirv` pass to 2 separate PRs. https://github.com/llvm/llvm-project/pull/65539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)
Hardcode84 wrote: I suggest to extract `mgpu` interface changes and `serializetoSpirv` pass to 2 separate PRs. https://github.com/llvm/llvm-project/pull/65539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 created https://github.com/llvm/llvm-project/pull/150805 `InitAll***` functions are used by `opt`-style tools to init all MLIR dialects/passes/extensions. Currently they are implemeted as inline functions and include essentially the entire MLIR header tree. Each file which includes this header (~10 currently) takes 10+ sec and multiple GB of ram to compile (tested with clang-19), which limits amount of parallel compiler jobs which can be run. Also, flang just casually includes this file into one of its headers. Move the actual registration code to the static libarary, so it's compiled only once. >From 746c0d5891721b7be7f28cd9c9d35a89a941d741 Mon Sep 17 00:00:00 2001 From: Ivan Butygin Date: Sun, 27 Jul 2025 00:39:56 +0200 Subject: [PATCH] [mlir][core] Move `InitAll***` implementation into static library. `InitAll***` functions are used by `opt`-style tools to init all MLIR dialects/passes/extensions. Currently they are implemeted as inline functions and include essentially the entire MLIR header tree. Each file which includes this header (~10 currently) takes 10+ sec and multiple GB of ram to compile (tested with clang-19), which limits amount of parallel compiler jobs which can be run. Also, flang just casually includes this file into one of its headers. Move the actual registration code to the static libarary, so it's compiled only once. --- clang/tools/cir-lsp-server/CMakeLists.txt | 6 +- .../include/flang/Optimizer/Support/InitFIR.h | 8 + flang/lib/Optimizer/Support/CMakeLists.txt| 6 +- .../standalone/standalone-opt/CMakeLists.txt | 5 +- .../standalone-opt/standalone-opt.cpp | 2 + mlir/examples/toy/Ch5/CMakeLists.txt | 5 +- mlir/examples/toy/Ch5/toyc.cpp| 1 + mlir/examples/toy/Ch6/CMakeLists.txt | 7 +- mlir/examples/toy/Ch6/toyc.cpp| 1 + mlir/examples/toy/Ch7/CMakeLists.txt | 7 +- mlir/examples/toy/Ch7/toyc.cpp| 1 + mlir/examples/transform-opt/CMakeLists.txt| 8 +- .../transform-opt/mlir-transform-opt.cpp | 1 + mlir/include/mlir/InitAllDialects.h | 193 +--- mlir/include/mlir/InitAllExtensions.h | 99 + mlir/include/mlir/InitAllPasses.h | 86 +--- .../CAPI/RegisterEverything/CMakeLists.txt| 7 +- mlir/lib/CMakeLists.txt | 15 ++ mlir/lib/InitAllDialects.cpp | 207 ++ mlir/lib/InitAllExtensions.cpp| 115 ++ mlir/lib/InitAllPasses.cpp| 99 + mlir/tools/mlir-lsp-server/CMakeLists.txt | 19 +- .../tools/mlir-lsp-server/mlir-lsp-server.cpp | 1 + mlir/tools/mlir-opt/CMakeLists.txt| 17 +- mlir/tools/mlir-query/CMakeLists.txt | 4 +- mlir/tools/mlir-reduce/CMakeLists.txt | 9 +- mlir/tools/mlir-rewrite/CMakeLists.txt| 4 +- mlir/tools/mlir-rewrite/mlir-rewrite.cpp | 1 + mlir/unittests/ExecutionEngine/CMakeLists.txt | 3 +- mlir/unittests/Target/LLVM/CMakeLists.txt | 4 +- 30 files changed, 478 insertions(+), 463 deletions(-) create mode 100644 mlir/lib/InitAllDialects.cpp create mode 100644 mlir/lib/InitAllExtensions.cpp create mode 100644 mlir/lib/InitAllPasses.cpp diff --git a/clang/tools/cir-lsp-server/CMakeLists.txt b/clang/tools/cir-lsp-server/CMakeLists.txt index aad2646ce0187..2591bbf697265 100644 --- a/clang/tools/cir-lsp-server/CMakeLists.txt +++ b/clang/tools/cir-lsp-server/CMakeLists.txt @@ -1,12 +1,7 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) -get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) - include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) set(LIBS - ${dialect_libs} - ${conversion_libs} ${test_libs} clangCIR clangCIRLoweringDirectToLLVM @@ -21,6 +16,7 @@ set(LIBS MLIRTransformUtils MLIRSupport MLIRIR + MLIRRegisterEverything ) add_mlir_tool(cir-lsp-server diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h index aacba233a2b32..3e42ffd41591e 100644 --- a/flang/include/flang/Optimizer/Support/InitFIR.h +++ b/flang/include/flang/Optimizer/Support/InitFIR.h @@ -20,12 +20,20 @@ #include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h" #include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h" #include "mlir/Conversion/Passes.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Complex/IR/Complex.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" +#include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/Func/Extensions/InlinerExtension.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Index/IR/IndexDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" +#include
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 updated https://github.com/llvm/llvm-project/pull/150805 >From 746c0d5891721b7be7f28cd9c9d35a89a941d741 Mon Sep 17 00:00:00 2001 From: Ivan Butygin Date: Sun, 27 Jul 2025 00:39:56 +0200 Subject: [PATCH 1/2] [mlir][core] Move `InitAll***` implementation into static library. `InitAll***` functions are used by `opt`-style tools to init all MLIR dialects/passes/extensions. Currently they are implemeted as inline functions and include essentially the entire MLIR header tree. Each file which includes this header (~10 currently) takes 10+ sec and multiple GB of ram to compile (tested with clang-19), which limits amount of parallel compiler jobs which can be run. Also, flang just casually includes this file into one of its headers. Move the actual registration code to the static libarary, so it's compiled only once. --- clang/tools/cir-lsp-server/CMakeLists.txt | 6 +- .../include/flang/Optimizer/Support/InitFIR.h | 8 + flang/lib/Optimizer/Support/CMakeLists.txt| 6 +- .../standalone/standalone-opt/CMakeLists.txt | 5 +- .../standalone-opt/standalone-opt.cpp | 2 + mlir/examples/toy/Ch5/CMakeLists.txt | 5 +- mlir/examples/toy/Ch5/toyc.cpp| 1 + mlir/examples/toy/Ch6/CMakeLists.txt | 7 +- mlir/examples/toy/Ch6/toyc.cpp| 1 + mlir/examples/toy/Ch7/CMakeLists.txt | 7 +- mlir/examples/toy/Ch7/toyc.cpp| 1 + mlir/examples/transform-opt/CMakeLists.txt| 8 +- .../transform-opt/mlir-transform-opt.cpp | 1 + mlir/include/mlir/InitAllDialects.h | 193 +--- mlir/include/mlir/InitAllExtensions.h | 99 + mlir/include/mlir/InitAllPasses.h | 86 +--- .../CAPI/RegisterEverything/CMakeLists.txt| 7 +- mlir/lib/CMakeLists.txt | 15 ++ mlir/lib/InitAllDialects.cpp | 207 ++ mlir/lib/InitAllExtensions.cpp| 115 ++ mlir/lib/InitAllPasses.cpp| 99 + mlir/tools/mlir-lsp-server/CMakeLists.txt | 19 +- .../tools/mlir-lsp-server/mlir-lsp-server.cpp | 1 + mlir/tools/mlir-opt/CMakeLists.txt| 17 +- mlir/tools/mlir-query/CMakeLists.txt | 4 +- mlir/tools/mlir-reduce/CMakeLists.txt | 9 +- mlir/tools/mlir-rewrite/CMakeLists.txt| 4 +- mlir/tools/mlir-rewrite/mlir-rewrite.cpp | 1 + mlir/unittests/ExecutionEngine/CMakeLists.txt | 3 +- mlir/unittests/Target/LLVM/CMakeLists.txt | 4 +- 30 files changed, 478 insertions(+), 463 deletions(-) create mode 100644 mlir/lib/InitAllDialects.cpp create mode 100644 mlir/lib/InitAllExtensions.cpp create mode 100644 mlir/lib/InitAllPasses.cpp diff --git a/clang/tools/cir-lsp-server/CMakeLists.txt b/clang/tools/cir-lsp-server/CMakeLists.txt index aad2646ce0187..2591bbf697265 100644 --- a/clang/tools/cir-lsp-server/CMakeLists.txt +++ b/clang/tools/cir-lsp-server/CMakeLists.txt @@ -1,12 +1,7 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) -get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) - include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) set(LIBS - ${dialect_libs} - ${conversion_libs} ${test_libs} clangCIR clangCIRLoweringDirectToLLVM @@ -21,6 +16,7 @@ set(LIBS MLIRTransformUtils MLIRSupport MLIRIR + MLIRRegisterEverything ) add_mlir_tool(cir-lsp-server diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h index aacba233a2b32..3e42ffd41591e 100644 --- a/flang/include/flang/Optimizer/Support/InitFIR.h +++ b/flang/include/flang/Optimizer/Support/InitFIR.h @@ -20,12 +20,20 @@ #include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h" #include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h" #include "mlir/Conversion/Passes.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Complex/IR/Complex.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" +#include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/Func/Extensions/InlinerExtension.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Index/IR/IndexDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" +#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h" +#include "mlir/Dialect/Math/IR/Math.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" #include "mlir/Dialect/OpenACC/Transforms/Passes.h" +#include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/SCF/Transforms/Passes.h" #include "mlir/InitAllDialects.h" #include "mlir/Pass/Pass.h" diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt index 7ccdd4fd9c25c..324a01527c470 100644 --- a/flang/lib/Optimizer/Support/CMakeLists.txt +++ b/flang/l
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
@@ -20,3 +20,18 @@ add_subdirectory(Target) add_subdirectory(Tools) add_subdirectory(Transforms) add_subdirectory(ExecutionEngine) + +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS) + +add_mlir_library(MLIRRegisterEverything + InitAllDialects.cpp + InitAllExtensions.cpp + InitAllPasses.cpp Hardcode84 wrote: Done, although, it's not so fine grained in practice, as `MLIRRegisterAllPasses` has to include `${dialect_libs}` too. https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 ready_for_review https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 updated https://github.com/llvm/llvm-project/pull/150805 >From 6959f31208a886251e5ee92f5701232d7c595de1 Mon Sep 17 00:00:00 2001 From: Ivan Butygin Date: Sun, 27 Jul 2025 00:39:56 +0200 Subject: [PATCH 1/3] [mlir][core] Move `InitAll***` implementation into static library. `InitAll***` functions are used by `opt`-style tools to init all MLIR dialects/passes/extensions. Currently they are implemeted as inline functions and include essentially the entire MLIR header tree. Each file which includes this header (~10 currently) takes 10+ sec and multiple GB of ram to compile (tested with clang-19), which limits amount of parallel compiler jobs which can be run. Also, flang just casually includes this file into one of its headers. Move the actual registration code to the static libarary, so it's compiled only once. --- clang/tools/cir-lsp-server/CMakeLists.txt | 6 +- .../include/flang/Optimizer/Support/InitFIR.h | 8 + flang/lib/Optimizer/Support/CMakeLists.txt| 6 +- .../standalone/standalone-opt/CMakeLists.txt | 5 +- .../standalone-opt/standalone-opt.cpp | 2 + mlir/examples/toy/Ch5/CMakeLists.txt | 5 +- mlir/examples/toy/Ch5/toyc.cpp| 1 + mlir/examples/toy/Ch6/CMakeLists.txt | 7 +- mlir/examples/toy/Ch6/toyc.cpp| 1 + mlir/examples/toy/Ch7/CMakeLists.txt | 7 +- mlir/examples/toy/Ch7/toyc.cpp| 1 + mlir/examples/transform-opt/CMakeLists.txt| 8 +- .../transform-opt/mlir-transform-opt.cpp | 1 + mlir/include/mlir/InitAllDialects.h | 193 +--- mlir/include/mlir/InitAllExtensions.h | 99 + mlir/include/mlir/InitAllPasses.h | 86 +--- .../CAPI/RegisterEverything/CMakeLists.txt| 7 +- mlir/lib/CMakeLists.txt | 15 ++ mlir/lib/InitAllDialects.cpp | 207 ++ mlir/lib/InitAllExtensions.cpp| 115 ++ mlir/lib/InitAllPasses.cpp| 99 + mlir/tools/mlir-lsp-server/CMakeLists.txt | 19 +- .../tools/mlir-lsp-server/mlir-lsp-server.cpp | 1 + mlir/tools/mlir-opt/CMakeLists.txt| 17 +- mlir/tools/mlir-query/CMakeLists.txt | 4 +- mlir/tools/mlir-reduce/CMakeLists.txt | 9 +- mlir/tools/mlir-rewrite/CMakeLists.txt| 4 +- mlir/tools/mlir-rewrite/mlir-rewrite.cpp | 1 + mlir/unittests/ExecutionEngine/CMakeLists.txt | 3 +- mlir/unittests/Target/LLVM/CMakeLists.txt | 4 +- 30 files changed, 478 insertions(+), 463 deletions(-) create mode 100644 mlir/lib/InitAllDialects.cpp create mode 100644 mlir/lib/InitAllExtensions.cpp create mode 100644 mlir/lib/InitAllPasses.cpp diff --git a/clang/tools/cir-lsp-server/CMakeLists.txt b/clang/tools/cir-lsp-server/CMakeLists.txt index aad2646ce0187..2591bbf697265 100644 --- a/clang/tools/cir-lsp-server/CMakeLists.txt +++ b/clang/tools/cir-lsp-server/CMakeLists.txt @@ -1,12 +1,7 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) -get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) - include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) set(LIBS - ${dialect_libs} - ${conversion_libs} ${test_libs} clangCIR clangCIRLoweringDirectToLLVM @@ -21,6 +16,7 @@ set(LIBS MLIRTransformUtils MLIRSupport MLIRIR + MLIRRegisterEverything ) add_mlir_tool(cir-lsp-server diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h index aacba233a2b32..3e42ffd41591e 100644 --- a/flang/include/flang/Optimizer/Support/InitFIR.h +++ b/flang/include/flang/Optimizer/Support/InitFIR.h @@ -20,12 +20,20 @@ #include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h" #include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h" #include "mlir/Conversion/Passes.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Complex/IR/Complex.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" +#include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/Func/Extensions/InlinerExtension.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Index/IR/IndexDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" +#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h" +#include "mlir/Dialect/Math/IR/Math.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" #include "mlir/Dialect/OpenACC/Transforms/Passes.h" +#include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/SCF/Transforms/Passes.h" #include "mlir/InitAllDialects.h" #include "mlir/Pass/Pass.h" diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt index 7ccdd4fd9c25c..324a01527c470 100644 --- a/flang/lib/Optimizer/Support/CMakeLists.txt +++ b/flang/l
[clang] [flang] [mlir] [mlir] Reland `Move InitAll*** implementation into static library` (PR #151150)
https://github.com/Hardcode84 created https://github.com/llvm/llvm-project/pull/151150 Reland https://github.com/llvm/llvm-project/pull/150805 Shared libs build was broken. Add `${dialect_libs}` and `${conversion_libs}` to `MLIRRegisterAllExtensions` because it depends on `registerConvert***ToLLVMInterface`. >From b719c92400a6b22c138f186925659e73598d31b4 Mon Sep 17 00:00:00 2001 From: Ivan Butygin Date: Tue, 29 Jul 2025 12:57:07 +0200 Subject: [PATCH 1/2] Revert "Revert "[mlir][core] Move `InitAll***` implementation into static library." (#151118)" This reverts commit 7057eee4819a31aef06fc05bfef43919861ef2e9. --- clang/tools/cir-lsp-server/CMakeLists.txt | 15 +- clang/tools/cir-opt/cir-opt.cpp | 3 +- .../include/flang/Optimizer/Support/InitFIR.h | 8 + flang/lib/Optimizer/Support/CMakeLists.txt| 9 +- .../standalone/standalone-opt/CMakeLists.txt | 14 +- .../standalone-opt/standalone-opt.cpp | 2 + mlir/examples/toy/Ch5/CMakeLists.txt | 9 +- mlir/examples/toy/Ch5/toyc.cpp| 1 + mlir/examples/toy/Ch6/CMakeLists.txt | 11 +- mlir/examples/toy/Ch6/toyc.cpp| 1 + mlir/examples/toy/Ch7/CMakeLists.txt | 11 +- mlir/examples/toy/Ch7/toyc.cpp| 1 + mlir/examples/transform-opt/CMakeLists.txt| 10 +- .../transform-opt/mlir-transform-opt.cpp | 1 + mlir/include/mlir/InitAllDialects.h | 193 +--- mlir/include/mlir/InitAllExtensions.h | 99 + mlir/include/mlir/InitAllPasses.h | 86 +--- .../CAPI/RegisterEverything/CMakeLists.txt| 11 +- mlir/lib/CMakeLists.txt | 32 +++ mlir/lib/RegisterAllDialects.cpp | 207 ++ mlir/lib/RegisterAllExtensions.cpp| 115 ++ mlir/lib/RegisterAllPasses.cpp| 99 + mlir/tools/mlir-lsp-server/CMakeLists.txt | 21 +- .../tools/mlir-lsp-server/mlir-lsp-server.cpp | 1 + mlir/tools/mlir-opt/CMakeLists.txt| 19 +- mlir/tools/mlir-query/CMakeLists.txt | 4 +- mlir/tools/mlir-reduce/CMakeLists.txt | 10 +- mlir/tools/mlir-rewrite/CMakeLists.txt| 10 +- mlir/tools/mlir-rewrite/mlir-rewrite.cpp | 1 + mlir/unittests/ExecutionEngine/CMakeLists.txt | 3 +- mlir/unittests/Target/LLVM/CMakeLists.txt | 4 +- 31 files changed, 531 insertions(+), 480 deletions(-) create mode 100644 mlir/lib/RegisterAllDialects.cpp create mode 100644 mlir/lib/RegisterAllExtensions.cpp create mode 100644 mlir/lib/RegisterAllPasses.cpp diff --git a/clang/tools/cir-lsp-server/CMakeLists.txt b/clang/tools/cir-lsp-server/CMakeLists.txt index aad2646ce0187..f421215173e62 100644 --- a/clang/tools/cir-lsp-server/CMakeLists.txt +++ b/clang/tools/cir-lsp-server/CMakeLists.txt @@ -1,26 +1,23 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) -get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) - include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) set(LIBS - ${dialect_libs} - ${conversion_libs} ${test_libs} clangCIR clangCIRLoweringDirectToLLVM - MLIRCIR MLIRAffineAnalysis MLIRAnalysis + MLIRCIR MLIRDialect + MLIRIR MLIRLspServerLib MLIRParser MLIRPass - MLIRTransforms - MLIRTransformUtils + MLIRRegisterAllDialects + MLIRRegisterAllPasses MLIRSupport - MLIRIR + MLIRTransformUtils + MLIRTransforms ) add_mlir_tool(cir-lsp-server diff --git a/clang/tools/cir-opt/cir-opt.cpp b/clang/tools/cir-opt/cir-opt.cpp index 3dad3b18f7082..c4d29a2117c75 100644 --- a/clang/tools/cir-opt/cir-opt.cpp +++ b/clang/tools/cir-opt/cir-opt.cpp @@ -17,11 +17,12 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/InitAllPasses.h" +#include "mlir/IR/BuiltinDialect.h" #include "mlir/Pass/PassManager.h" #include "mlir/Pass/PassOptions.h" #include "mlir/Pass/PassRegistry.h" #include "mlir/Tools/mlir-opt/MlirOptMain.h" +#include "mlir/Transforms/Passes.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" #include "clang/CIR/Passes.h" diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h index aacba233a2b32..3e42ffd41591e 100644 --- a/flang/include/flang/Optimizer/Support/InitFIR.h +++ b/flang/include/flang/Optimizer/Support/InitFIR.h @@ -20,12 +20,20 @@ #include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h" #include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h" #include "mlir/Conversion/Passes.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Complex/IR/Complex.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" +#include "mlir/Dialect/DLTI/DLTI.h" #inc
[clang] [flang] [mlir] [mlir] Reland `Move InitAll*** implementation into static library` (PR #151150)
https://github.com/Hardcode84 edited https://github.com/llvm/llvm-project/pull/151150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir][core] Move `InitAll***` implementation into static library. (PR #150805)
https://github.com/Hardcode84 closed https://github.com/llvm/llvm-project/pull/150805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [mlir] Reland `Move InitAll*** implementation into static library` (PR #151150)
https://github.com/Hardcode84 closed https://github.com/llvm/llvm-project/pull/151150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits