Skip to content

[CIR][cmake] Add support for cmake variable CLANG_ENABLE_CIR #86078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lanza
Copy link
Member

@lanza lanza commented Mar 21, 2024

Introduce a cmake variable that guards the inclusion of ClangIR into the
build of clang. Guard that we aren't trying to build without MLIR. Add
two subdirectories that, as of now, don't do anything.

lanza added 2 commits March 21, 2024 04:06
Created using spr 1.3.5
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 21, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 21, 2024

@llvm/pr-subscribers-clang

Author: Nathan Lanza (lanza)

Changes

Introduce a cmake variable that guards the inclusion of ClangIR into the
build of clang. Guard that we aren't trying to build without MLIR. Add
two subdirectories that, as of now, don't do anything.


Full diff: https://github.com/llvm/llvm-project/pull/86078.diff

7 Files Affected:

  • (modified) clang/CMakeLists.txt (+7)
  • (added) clang/include/clang/CIR/CMakeLists.txt ()
  • (modified) clang/include/clang/CMakeLists.txt (+3)
  • (modified) clang/include/clang/Config/config.h.cmake (+3)
  • (added) clang/lib/CIR/CMakeLists.txt ()
  • (modified) clang/lib/CMakeLists.txt (+4)
  • (modified) clang/test/CMakeLists.txt (+1)
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc2..0e2e9dbf7b2528 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -164,6 +164,13 @@ if(CLANG_ENABLE_LIBXML2)
   endif()
 endif()
 
+if(CLANG_ENABLE_CIR)
+  if (NOT "${LLVM_ENABLE_PROJECTS}" MATCHES "MLIR|mlir")
+    message(FATAL_ERROR
+      "Cannot build ClangIR without MLIR in LLVM_ENABLE_PROJECTS")
+  endif()
+endif()
+
 include(CheckIncludeFile)
 check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
 
diff --git a/clang/include/clang/CIR/CMakeLists.txt b/clang/include/clang/CIR/CMakeLists.txt
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/clang/include/clang/CMakeLists.txt b/clang/include/clang/CMakeLists.txt
index 0dc9ea5ed8ac8a..47ac70cd21690f 100644
--- a/clang/include/clang/CMakeLists.txt
+++ b/clang/include/clang/CMakeLists.txt
@@ -1,5 +1,8 @@
 add_subdirectory(AST)
 add_subdirectory(Basic)
+if(CLANG_ENABLE_CIR)
+  add_subdirectory(CIR)
+endif()
 add_subdirectory(Driver)
 add_subdirectory(Parse)
 add_subdirectory(Sema)
diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake
index 4015ac8040861c..27ed69e21562bf 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -83,4 +83,7 @@
 /* Spawn a new process clang.exe for the CC1 tool invocation, when necessary */
 #cmakedefine01 CLANG_SPAWN_CC1
 
+/* Whether CIR is built into Clang */
+#cmakedefine01 CLANG_ENABLE_CIR
+
 #endif
diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/clang/lib/CMakeLists.txt b/clang/lib/CMakeLists.txt
index 0cac86451f39e4..14ba55360fe050 100644
--- a/clang/lib/CMakeLists.txt
+++ b/clang/lib/CMakeLists.txt
@@ -31,3 +31,7 @@ if(CLANG_INCLUDE_TESTS)
 endif()
 add_subdirectory(Interpreter)
 add_subdirectory(Support)
+
+if(CLANG_ENABLE_CIR)
+  add_subdirectory(CIR)
+endif()
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index fcfca354f4a75f..df34a5707da33e 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -9,6 +9,7 @@ llvm_canonicalize_cmake_booleans(
   CLANG_ENABLE_STATIC_ANALYZER
   CLANG_PLUGIN_SUPPORT
   CLANG_SPAWN_CC1
+  CLANG_ENABLE_CIR
   ENABLE_BACKTRACES
   LLVM_ENABLE_ZLIB
   LLVM_ENABLE_ZSTD

@lanza lanza added the ClangIR Anything related to the ClangIR project label Mar 21, 2024
lanza added 3 commits March 21, 2024 04:09
Created using spr 1.3.5
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
lanza added 4 commits March 21, 2024 05:20
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes seem reasonable to me, but I've added the CMake code owners for final approval.

lanza and others added 4 commits March 21, 2024 22:25
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
@lanza lanza changed the base branch from users/lanza/sprmain.circmake-add-support-for-cmake-variable-clang_enable_cir to main April 11, 2024 20:56
@lanza lanza merged commit 44de2bb into main Apr 11, 2024
@lanza lanza deleted the users/lanza/sprcircmake-add-support-for-cmake-variable-clang_enable_cir branch April 11, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants