Skip to content

[CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td #86080

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

This adds no real content, it just incrementally adds some scaffolding
necessary to enable a future patch to just add our first few ops.

Test Plan:

$ cmake -Sllvm -Bbuild -DCLANG_ENABLE_CIR=1 \
  -DLLVM_ENABLE_PROJECTS='clang;mlir' \
  -DCMAKE_BUILD_TYPE=Release -GNinja
$ ninja -C build check-clang
$ ninja -C build MLIRCIROpsIncGen
$ ninja -C build MLIRCIR

lanza added 2 commits March 21, 2024 04:36
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

This adds no real content, it just incrementally adds some scaffolding
necessary to enable a future patch to just add our first few ops.


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

9 Files Affected:

  • (modified) clang/include/clang/CIR/CMakeLists.txt (+7)
  • (added) clang/include/clang/CIR/Dialect/CMakeLists.txt (+1)
  • (added) clang/include/clang/CIR/Dialect/IR/CIRDialect.h ()
  • (added) clang/include/clang/CIR/Dialect/IR/CIROps.td ()
  • (added) clang/include/clang/CIR/Dialect/IR/CMakeLists.txt (+16)
  • (modified) clang/lib/CIR/CMakeLists.txt (+4)
  • (added) clang/lib/CIR/Dialect/CMakeLists.txt (+1)
  • (added) clang/lib/CIR/Dialect/IR/CIRDialect.cpp ()
  • (added) clang/lib/CIR/Dialect/IR/CMakeLists.txt ()
diff --git a/clang/include/clang/CIR/CMakeLists.txt b/clang/include/clang/CIR/CMakeLists.txt
index e69de29bb2d1d6..928dc6bf8a6fa4 100644
--- a/clang/include/clang/CIR/CMakeLists.txt
+++ b/clang/include/clang/CIR/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --src-root
+set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --includedir
+set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
+include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
+include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
+
+add_subdirectory(Dialect)
diff --git a/clang/include/clang/CIR/Dialect/CMakeLists.txt b/clang/include/clang/CIR/Dialect/CMakeLists.txt
new file mode 100644
index 00000000000000..f33061b2d87cff
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(IR)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt b/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
new file mode 100644
index 00000000000000..28ae30dab8dfb2
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
@@ -0,0 +1,16 @@
+# This replicates part of the add_mlir_dialect cmake function from MLIR that
+# cannot be used here. This happens because it expects to be run inside MLIR
+# directory which is not the case for CIR (and also FIR, both have similar
+# workarounds).
+
+# Equivalent to add_mlir_dialect(CIROps cir)
+set(LLVM_TARGET_DEFINITIONS CIROps.td)
+mlir_tablegen(CIROps.h.inc -gen-op-decls)
+mlir_tablegen(CIROps.cpp.inc -gen-op-defs)
+mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls)
+mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs)
+mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls)
+mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
+add_public_tablegen_target(MLIRCIROpsIncGen)
+add_dependencies(mlir-headers MLIRCIROpsIncGen)
+
diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt
index e69de29bb2d1d6..d2ff200e0da5f5 100644
--- a/clang/lib/CIR/CMakeLists.txt
+++ b/clang/lib/CIR/CMakeLists.txt
@@ -0,0 +1,4 @@
+include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
+include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
+
+add_subdirectory(Dialect)
diff --git a/clang/lib/CIR/Dialect/CMakeLists.txt b/clang/lib/CIR/Dialect/CMakeLists.txt
new file mode 100644
index 00000000000000..f33061b2d87cff
--- /dev/null
+++ b/clang/lib/CIR/Dialect/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(IR)
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
new file mode 100644
index 00000000000000..e69de29bb2d1d6

@lanza lanza added the ClangIR Anything related to the ClangIR project label Mar 21, 2024
Created using spr 1.3.5
bcardosolopes

This comment was marked as resolved.

lanza added 5 commits March 21, 2024 05:12
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
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

CIR/Dialect/IR/CIRDialect.h should get a comment header too, and could likely be already included by CIRDialect.cpp.

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.

Generally LGTM as well, but added the CMake code owners for their opinions on those bits.

@tschuett tschuett requested a review from joker-eph March 21, 2024 19:18
lanza added 2 commits March 21, 2024 22:25
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
marbre and others added 2 commits April 11, 2024 21:52
Created using spr 1.3.5

[skip ci]
Created using spr 1.3.5
kazutakahirata and others added 2 commits April 17, 2024 05:27
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.

LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate the cmake changes (they look sensible to me, but I never know if there's a better way to do things in CMake).

@lanza
Copy link
Member Author

lanza commented Apr 17, 2024

LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate the cmake changes (they look sensible to me, but I never know if there's a better way to do things in CMake).

We already did that above. Petr left a comment and it was fixed :p

@AaronBallman
Copy link
Collaborator

LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate the cmake changes (they look sensible to me, but I never know if there's a better way to do things in CMake).

We already did that above. Petr left a comment and it was fixed :p

Ah, I missed that entirely because the conversations were resolved. Phew, then yeah, LGTM!

Comment on lines +1 to +2
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
Copy link
Member

Choose a reason for hiding this comment

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

I think something like target_include_directories is generally preferred, because it is less of a sledgehammer effecting many targets at once.

lanza and others added 3 commits April 24, 2024 17:42
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.cirnfc-add-scaffolding-for-the-cir-dialect-and-ciropstd to main April 25, 2024 02:26
@lanza lanza merged commit 10661ba into main Apr 25, 2024
@lanza lanza deleted the users/lanza/sprcirnfc-add-scaffolding-for-the-cir-dialect-and-ciropstd branch April 25, 2024 02:26
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.