Skip to content

Commit 62a204d

Browse files
bcardosolopeslanza
authored andcommitted
[CIR] Add 'cir' to LLVM_ENABLE_PROJECTS and make ClangIR build optional via CMAKE
- Also fix the way we do testing and disable when CIR not available.
1 parent d973152 commit 62a204d

File tree

10 files changed

+68
-13
lines changed

10 files changed

+68
-13
lines changed

clang/include/clang/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
add_subdirectory(AST)
22
add_subdirectory(Basic)
3-
add_subdirectory(CIR)
3+
if(CLANG_ENABLE_CIR)
4+
add_subdirectory(CIR)
5+
endif()
46
add_subdirectory(Driver)
57
add_subdirectory(Parse)
68
add_subdirectory(Sema)

clang/include/clang/Config/config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,7 @@
104104
/* Whether to enable opaque pointers by default */
105105
#cmakedefine01 CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL
106106

107+
/* Whether CIR is built into Clang */
108+
#cmakedefine01 CLANG_ENABLE_CIR
109+
107110
#endif

clang/lib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ if(CLANG_INCLUDE_TESTS)
3030
endif()
3131
add_subdirectory(Interpreter)
3232
add_subdirectory(Support)
33-
add_subdirectory(CIR)
33+
34+
if(CLANG_ENABLE_CIR)
35+
add_subdirectory(CIR)
36+
endif()

clang/lib/FrontendTool/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ set(link_libs
99
clangDriver
1010
clangExtractAPI
1111
clangFrontend
12-
clangCIRFrontendAction
1312
clangRewriteFrontend
1413
)
1514

15+
if(CLANG_ENABLE_CIR)
16+
list(APPEND link_libs
17+
clangCIRFrontendAction
18+
)
19+
endif()
20+
1621
if(CLANG_ENABLE_ARCMT)
1722
list(APPEND link_libs
1823
clangARCMigrate

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/ARCMigrate/ARCMTActions.h"
15-
#include "clang/CIRFrontendAction/CIRGenAction.h"
1615
#include "clang/CodeGen/CodeGenAction.h"
1716
#include "clang/Config/config.h"
1817
#include "clang/Driver/Options.h"
@@ -32,8 +31,12 @@
3231
#include "llvm/Support/BuryPointer.h"
3332
#include "llvm/Support/DynamicLibrary.h"
3433
#include "llvm/Support/ErrorHandling.h"
34+
35+
#if CLANG_ENABLE_CIR
36+
#include "clang/CIRFrontendAction/CIRGenAction.h"
37+
#endif
38+
3539
using namespace clang;
36-
using namespace cir;
3740
using namespace llvm::opt;
3841

3942
namespace clang {
@@ -68,19 +71,29 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
6871
case DumpTokens: return std::make_unique<DumpTokensAction>();
6972
case EmitAssembly: return std::make_unique<EmitAssemblyAction>();
7073
case EmitBC: return std::make_unique<EmitBCAction>();
71-
case EmitCIR: return std::make_unique<EmitCIRAction>();
72-
case EmitCIROnly: return std::make_unique<EmitCIROnlyAction>();
74+
#if CLANG_ENABLE_CIR
75+
case EmitCIR: return std::make_unique<::cir::EmitCIRAction>();
76+
case EmitCIROnly: return std::make_unique<::cir::EmitCIROnlyAction>();
77+
#else
78+
case EmitCIR:
79+
case EmitCIROnly:
80+
llvm_unreachable("CIR suppport not built into clang");
81+
#endif
7382
case EmitHTML: return std::make_unique<HTMLPrintAction>();
7483
case EmitLLVM: {
84+
#if CLANG_ENABLE_CIR
7585
if (UseCIR)
76-
return std::make_unique<cir::EmitLLVMAction>();
86+
return std::make_unique<::cir::EmitLLVMAction>();
87+
#endif
7788
return std::make_unique<EmitLLVMAction>();
7889
}
7990
case EmitLLVMOnly: return std::make_unique<EmitLLVMOnlyAction>();
8091
case EmitCodeGenOnly: return std::make_unique<EmitCodeGenOnlyAction>();
8192
case EmitObj: {
93+
#if CLANG_ENABLE_CIR
8294
if (UseCIR)
83-
return std::make_unique<cir::EmitObjAction>();
95+
return std::make_unique<::cir::EmitObjAction>();
96+
#endif
8497
return std::make_unique<EmitObjAction>();
8598
}
8699
case ExtractAPI:

clang/test/CIR/lit.local.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not config.root.clang_enable_cir:
2+
config.unsupported = True

clang/test/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ llvm_canonicalize_cmake_booleans(
1010
CLANG_ENABLE_STATIC_ANALYZER
1111
CLANG_PLUGIN_SUPPORT
1212
CLANG_SPAWN_CC1
13+
CLANG_ENABLE_CIR
1314
ENABLE_BACKTRACES
1415
LLVM_ENABLE_ZLIB
1516
LLVM_ENABLE_ZSTD
@@ -59,7 +60,6 @@ endif ()
5960
list(APPEND CLANG_TEST_DEPS
6061
apinotes-test
6162
c-index-test
62-
cir-tool
6363
clang
6464
clang-fuzzer-dictionary
6565
clang-resource-headers
@@ -75,7 +75,13 @@ list(APPEND CLANG_TEST_DEPS
7575
hmaptool
7676
mlir-translate
7777
)
78-
78+
79+
if(CLANG_ENABLE_CIR)
80+
list(APPEND CLANG_TEST_DEPS
81+
cir-tool
82+
)
83+
endif()
84+
7985
if(CLANG_ENABLE_STATIC_ANALYZER)
8086
list(APPEND CLANG_TEST_DEPS
8187
clang-check

clang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ config.clang_default_std_cxx = "@CLANG_DEFAULT_STD_CXX@"
2929
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
3030
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
3131
config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@
32+
config.clang_enable_cir = @CLANG_ENABLE_CIR@
3233
config.clang_examples = @CLANG_BUILD_EXAMPLES@
3334
config.enable_shared = @ENABLE_SHARED@
3435
config.enable_backtrace = @ENABLE_BACKTRACES@

clang/tools/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ create_subdirectory_options(CLANG TOOL)
33
add_clang_subdirectory(diagtool)
44
add_clang_subdirectory(driver)
55
add_clang_subdirectory(apinotes-test)
6-
add_clang_subdirectory(cir-tool)
6+
if(CLANG_ENABLE_CIR)
7+
add_clang_subdirectory(cir-tool)
8+
endif()
79
add_clang_subdirectory(clang-diff)
810
add_clang_subdirectory(clang-format)
911
add_clang_subdirectory(clang-format-vs)

llvm/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ endif()
109109
# LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS
110110
# This allows an easy way of setting up a build directory for llvm and another
111111
# one for llvm+clang+... using the same sources.
112-
set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;mlir;openmp;polly;pstl")
112+
set(LLVM_ALL_PROJECTS "bolt;cir;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;mlir;openmp;polly;pstl")
113113
# The flang project is not yet part of "all" projects (see C++ requirements)
114114
set(LLVM_EXTRA_PROJECTS "flang")
115115
# List of all known projects in the mono repo
@@ -143,6 +143,17 @@ if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
143143
endif()
144144
endif()
145145

146+
if ("cir" IN_LIST LLVM_ENABLE_PROJECTS)
147+
if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
148+
message(STATUS "Enabling MLIR as a dependency to CIR")
149+
list(APPEND LLVM_ENABLE_PROJECTS "mlir")
150+
endif()
151+
152+
if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
153+
message(FATAL_ERROR "Clang is not enabled, but is required to use CIR")
154+
endif()
155+
endif()
156+
146157
# Select the runtimes to build
147158
#
148159
# As we migrate runtimes to using the bootstrapping build, the set of default runtimes
@@ -184,6 +195,13 @@ if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
184195
string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
185196
if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS)
186197
message(STATUS "${proj} project is enabled")
198+
# ClangIR is integrated inside clang and also provides the cir-tool,
199+
# it needs some special handling.
200+
if ("${proj}" STREQUAL "cir")
201+
set(CLANG_ENABLE_CIR ON)
202+
continue()
203+
endif()
204+
187205
set(SHOULD_ENABLE_PROJECT TRUE)
188206
set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
189207
if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")

0 commit comments

Comments
 (0)