From 074610cec65a47948f891fff92da4794bd91b1a0 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu Date: Tue, 26 Nov 2024 16:48:13 -0700 Subject: [PATCH] [kitsune] kit-config can query enabled frontends In principle, not all frontends may be enabled in any given build. For instance, even after support for lowering Fortran' DO CONCURRENT loops to Tapir instructions is added, flang may still not be enabled. In this case, we want to be able to use kit-config to query whether the frontend has been built. The primary use for this is in the kitsune-test-suite which can then automatically enable/disable certain tests. While implementing this, some code was also cleaned up. --- kitsune/CMakeLists.txt | 42 +++++---- kitsune/cmake/modules/KitsuneUtils.cmake | 26 ++++++ kitsune/include/kitsune/Config/config.h.cmake | 10 +++ kitsune/tools/kit-config/kit-config.cpp | 89 +++++++++++++------ 4 files changed, 123 insertions(+), 44 deletions(-) diff --git a/kitsune/CMakeLists.txt b/kitsune/CMakeLists.txt index e2ac6f7e0e4a4..7c99a75c3edad 100644 --- a/kitsune/CMakeLists.txt +++ b/kitsune/CMakeLists.txt @@ -8,9 +8,12 @@ cmake_minimum_required(VERSION 3.20) project(kitsune C CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + include(ExternalProject) include(FetchContent) include(GetClangResourceDir) +include(KitsuneUtils) if (WIN32) message(FATAL_ERROR "Kitsune is not supported on Windows") @@ -18,7 +21,7 @@ endif () set(KITSUNE_C_FRONTEND kitcc) set(KITSUNE_CXX_FRONTEND kit++) -set(KITSUNE_Fortran_FRONTEND kitfort) +set(KITSUNE_Fortran_FRONTEND kitfc) option(KITSUNE_INCLUDE_TESTS "Generate build targets for the Kitsune tests" @@ -502,24 +505,25 @@ endif() set(KITSUNE_DEFAULT_TAPIR_RUNTIME "opencilk" CACHE STRING "Default Tapir runtime used by -ftapir.") -# This is ugly because it creates a dangling symlink because this is executed -# before clang is built. However, we force clang to be built, so we are sure -# of it not dangling by the time everything is built. -add_custom_target(${KITSUNE_C_FRONTEND} ALL - ${CMAKE_COMMAND} -E create_symlink - clang - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KITSUNE_C_FRONTEND}) - -add_custom_target(${KITSUNE_CXX_FRONTEND} ALL - ${CMAKE_COMMAND} -E create_symlink - clang++ - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KITSUNE_CXX_FRONTEND}) - -foreach (link ${KITSUNE_C_FRONTEND} ${KITSUNE_CXX_FRONTEND}) - install(FILES - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${link} - DESTINATION ${CMAKE_INSTALL_BINDIR}) -endforeach() +# If any more languages are enabled, a corresponding variable should be added +# here. For instance, we may want to run Cuda code through Kitsune, in which +# case, a Cuda frontend will need to be created similar to the C and C++ ones. +set(KITSUNE_C_ENABLED OFF) +set(KITSUNE_CXX_ENABLED OFF) +set(KITSUNE_Fortran_ENABLED OFF) + +if ("clang" IN_LIST LLVM_ENABLE_PROJECTS) + set(KITSUNE_C_ENABLED ON) + setup_frontend_symlink(${KITSUNE_C_FRONTEND} clang) + + set(KITSUNE_CXX_ENABLED ON) + setup_frontend_symlink(${KITSUNE_CXX_FRONTEND} clang++) +endif () + +if ("flang" IN_LIST LLVM_ENABLE_PROJECTS) + set(KITSUNE_Fortran_ENABLED ON) + setup_frontend_symlink(${KITSUNE_Fortran_FRONTEND} flang) +endif () add_subdirectory(configs) add_subdirectory(include/kitsune) diff --git a/kitsune/cmake/modules/KitsuneUtils.cmake b/kitsune/cmake/modules/KitsuneUtils.cmake index 676042470ed9b..76eb0d9f3c944 100644 --- a/kitsune/cmake/modules/KitsuneUtils.cmake +++ b/kitsune/cmake/modules/KitsuneUtils.cmake @@ -1,3 +1,10 @@ +# ----------------------------- BEGIN MAYBE REMOVE ----------------------------- +# +# Everything in this block (until END MAYBE REMOVE) is probably obsolete and, if +# so, ought to be removed. These are only used in kitsune/examples, but those +# are also likely obsolete now. But we need to double-check that before doing +# so. + # # Get a list of all enabled tapir runtime targets so we can # walk through each and do "stuff" (e.g., build an executable @@ -63,3 +70,22 @@ function(add_tapir_dependency target abi) endif() endfunction() + +# ------------------------------ END MAYBE REMOVE ------------------------------ + +# Setup a Kitsune frontend symlink (kitcc, kit++ etc.). symlink is the name of +# the frontend. Target is the actual compiler that is the target of the symlink. +macro(setup_frontend_symlink symlink target) + # This is ugly! The create_symlink command creates a dangling symlink because + # it is executed before clang (and perhaps flang) is built. However, if + # everything builds correctly, it will not be dangling. Obviously, a build + # failure will result in a dangling symlink in the build directory. + add_custom_target(${symlink} ALL + ${CMAKE_COMMAND} -E create_symlink + ${target} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${symlink}) + + install(FILES + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${symlink} + DESTINATION ${CMAKE_INSTALL_BINDIR}) +endmacro() diff --git a/kitsune/include/kitsune/Config/config.h.cmake b/kitsune/include/kitsune/Config/config.h.cmake index c7a9b7a111538..734982732f301 100644 --- a/kitsune/include/kitsune/Config/config.h.cmake +++ b/kitsune/include/kitsune/Config/config.h.cmake @@ -16,6 +16,16 @@ // General configuration #define KITSUNE_LLD "${KITSUNE_LLD}" +// Kitsune language support that has been enabled +#cmakedefine01 KITSUNE_C_ENABLED +#cmakedefine01 KITSUNE_CXX_ENABLED +#cmakedefine01 KITSUNE_Fortran_ENABLED + +// The names of the Kitsune frontends +#define KITSUNE_C_FRONTEND "${KITSUNE_C_FRONTEND}" +#define KITSUNE_CXX_FRONTEND "${KITSUNE_CXX_FRONTEND}" +#define KITSUNE_Fortran_FRONTEND "${KITSUNE_Fortran_FRONTEND}" + // Kokkos configuration #cmakedefine01 KITSUNE_KOKKOS_ENABLED diff --git a/kitsune/tools/kit-config/kit-config.cpp b/kitsune/tools/kit-config/kit-config.cpp index e17b4b709296c..fb206d61da3c7 100644 --- a/kitsune/tools/kit-config/kit-config.cpp +++ b/kitsune/tools/kit-config/kit-config.cpp @@ -14,6 +14,8 @@ #include "kitsune/Config/config.h" #include "llvm/Config/config.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -25,56 +27,93 @@ usage: kit-config