[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote: Yeah, I can. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: Thanks! Done, I assume you can submit once it passes? Else, let me know. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote: Confirmed that #150769 fixes the issue. I'd appreciate if you could review it promptly, so I could do a fresh clean build and check for more issues today. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: Yeah I was wondering if linkage related as that's only way with the code not running that it could have impact. Definitely not intentionally skipping it ... Well and it also explains why I couldn't see anything different while trying different sanitizers, as I wasn't doing any shared lib builds. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote: (I'm trying a patch, will send a PR in a minute if it works) https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote: Oh, I think I know what's wrong here. ```diff diff --git a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt index 3232f6e2cafe..4f1da43d3f1b 100644 --- a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt @@ -11,11 +11,13 @@ add_clang_library(clangTidyLLVMModule STATIC PreferRegisterOverUnsignedCheck.cpp PreferStaticOverAnonymousNamespaceCheck.cpp TwineLocalCheck.cpp + UseNewMLIROpBuilderCheck.cpp LINK_LIBS clangTidy clangTidyReadabilityModule clangTidyUtils + clangTransformer DEPENDS omp_gen ``` My guess is that you're bypassing the dylib, and effectively the executables end up linking both dylib and all static libraries, which is a recipe for disaster. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote: Well, that's what bisect said for me. 889faabe78d2cb182414430601d6da2ed6619be3 passed, 3feb6f971577701713034d3404b6737fe6462d43 failed. llvm: [llvm-core:llvm-22.0.0.:20250726-132422.log.gz](https://github.com/user-attachments/files/21444961/llvm-core.llvm-22.0.0..20250726-132422.log.gz) (195k → 4.4M unpacked) clang: [llvm-core:clang-22.0.0.:20250726-132749.log.gz](https://github.com/user-attachments/files/21444936/llvm-core.clang-22.0.0..20250726-132749.log.gz) (1.1M → 19M unpacked) https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: Those failures don't seem related (no StringSet used here, not activated for abseil checks) https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
mgorny wrote:
Tons of failures on Gentoo as well:
```
Total Discovered Tests: 1352
Unsupported : 8 (0.59%)
Passed : 399 (29.51%)
Expectedly Failed: 1 (0.07%)
Failed : 944 (69.82%)
```
At a quick glance, they look like something's segfaulting on exit:
```
FAIL: Clang Tools :: clang-tidy/checkers/abseil/faster-strsplit-delimiter.cpp
(90 of 1270)
TEST 'Clang Tools ::
clang-tidy/checkers/abseil/faster-strsplit-delimiter.cpp' FAILED
Exit Code: 1
Command Output (stdout):
--
Running ['clang-tidy',
'/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/tools/extra/test/clang-tidy/checke
rs/abseil/Output/faster-strsplit-delimiter.cpp.tmp.cpp', '-fix',
'--checks=-*,abseil-faster-strsplit-delimiter', '--config={}', '--', '
-std=c++11', '-nostdinc++']...
clang-tidy
/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/tools/extra/test/clang-tidy/checkers/abseil/Out
put/faster-strsplit-delimiter.cpp.tmp.cpp -fix
--checks=-*,abseil-faster-strsplit-delimiter --config={} -- -std=c++11
-nostdinc++ faile
d:
14 warnings generated.
/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/tools/extra/test/clang-tidy/checkers/abseil/Output/faster-
strsplit-delimiter.cpp.tmp.cpp:42:25: warning: absl::StrSplit() called with a
string literal consisting of a single character; consider
using the character overload [abseil-faster-strsplit-delimiter]
42 | absl::StrSplit("ABC", "A");
| ^~~
| 'A'
[...]
/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/tools/extra/test/clang-tidy/checkers/abseil/Output/faster-
strsplit-delimiter.cpp.tmp.cpp:116:25: note: FIX-IT applied suggested code
changes
clang-tidy applied 14 of 14 suggested fixes.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and
include the crash backtrace.
#0 0x7f9426579133 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/usr/lib/llvm/22/lib64/libLLVM.so.22.0git3feb6f97+0xd79133)
#1 0x7f9426575ad4 llvm::sys::RunSignalHandlers()
(/usr/lib/llvm/22/lib64/libLLVM.so.22.0git3feb6f97+0xd75ad4)
#2 0x7f9426575c89
(/usr/lib/llvm/22/lib64/libLLVM.so.22.0git3feb6f97+0xd75c89)
#3 0x7f94252639d0 (/usr/lib64/libc.so.6+0x3d9d0)
#4 0x7f94252cadc7 cfree (/usr/lib64/libc.so.6+0xa4dc7)
#5 0x7f942c56db34 llvm::StringSet::~StringSet()
(/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/lib64/libclang-cpp.so.22.0git3feb6f97+0xb6db34)
#6 0x7f9425265aab __cxa_finalize (/usr/lib64/libc.so.6+0x3faab)
#7 0x7f942c48ebf7
(/var/tmp/portage/llvm-core/clang-22.0.0./work/x/y/clang-abi_x86_64.amd64/lib64/libclang-cpp.so.22.0git3feb6f97+0xa8ebf7)
```
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
ronlieb wrote: Suppressed 5449 warnings (5449 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. PLEASE submit a bug report to https://github.com/ROCm/aomp and include the crash backtrace. #0 0x7fc5930cfa30 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/rlieberm/rocm/aomp_22.0-8/lib/llvm/bin/../lib/libLLVM.so.22.0_AOMP_STANDALONE_22.0-8+0x8cfa30) #1 0x7fc5930cc6df llvm::sys::RunSignalHandlers() (/work/rlieberm/rocm/aomp_22.0-8/lib/llvm/bin/../lib/libLLVM.so.22.0_AOMP_STANDALONE_22.0-8+0x8cc6df) #2 0x7fc5930cc832 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #3 0x7fc592042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x7fc5920a28b8 _int_free ./malloc/malloc.c:4582:9 #5 0x7fc5920a54d3 __libc_free ./malloc/malloc.c:3394:3 #6 0x7fc59a96f328 llvm::StringSet::~StringSet() (/work/rlieberm/rocm/aomp_22.0-8/lib/llvm/bin/../lib/libclang-cpp.so.22.0_AOMP_STANDALONE_22.0-8+0x96f328) #7 0x7fc592045a56 __cxa_finalize ./stdlib/cxa_finalize.c:84:6 #8 0x7fc59a878057 __do_global_dtors_aux crtstuff.c:0:0 Segmentation fault https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
vbvictor wrote: > @EugeneZelenko i am also seeing downstream failures same as above noted by > buildbots, could you revert and fix ? Hi, could you share build logs/link if you can? First fail seems unrelated to the PR. On second I don't see exactly that this new check fails buildbot, seems more like a general failure of build-node. cc @jpienaar https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
ronlieb wrote: @EugeneZelenko i am also seeing downstream failures same as above noted by buildbots, could you revert and fix ? https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` running on `gribozavr4` while building `clang-tools-extra` at step 9 "test-build-unified-tree-check-clang-extra". Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/33735 Here is the relevant piece of the build log for the reference ``` Step 9 (test-build-unified-tree-check-clang-extra) failure: test (failure) TEST 'Clang Tools :: clang-tidy/CTTestTidyModule.cpp' FAILED Exit Code: 139 Command Output (stderr): -- clang-tidy -checks='-*,mytest*' --list-checks -load /b/1/llvm-x86_64-debian-dylib/build/./lib/CTTestTidyModule.so | FileCheck --check-prefix=CHECK-LIST /b/1/llvm-x86_64-debian-dylib/llvm-project/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp # RUN: at line 2 + clang-tidy '-checks=-*,mytest*' --list-checks -load /b/1/llvm-x86_64-debian-dylib/build/./lib/CTTestTidyModule.so + FileCheck --check-prefix=CHECK-LIST /b/1/llvm-x86_64-debian-dylib/llvm-project/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. #0 0x7f3b167a5fe7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/llvm-x86_64-debian-dylib/build/lib/libLLVM.so.22.0git+0xb15fe7) #1 0x7f3b167a3615 llvm::sys::RunSignalHandlers() (/b/1/llvm-x86_64-debian-dylib/build/lib/libLLVM.so.22.0git+0xb13615) #2 0x7f3b167a6d1a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #3 0x7f3b24925140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140) #4 0x7f3b1581546e free (/lib/x86_64-linux-gnu/libc.so.6+0x8646e) #5 0x7f3b2097b78c llvm::StringMap::~StringMap() crtstuff.c:0:0 #6 0x7f3b157cab86 __cxa_finalize (/lib/x86_64-linux-gnu/libc.so.6+0x3bb86) #7 0x7f3b208b7933 __do_global_dtors_aux crtstuff.c:0:0 /b/1/llvm-x86_64-debian-dylib/build/tools/clang/tools/extra/test/clang-tidy/Output/CTTestTidyModule.cpp.script: line 2: 4132567 Segmentation fault clang-tidy -checks='-*,mytest*' --list-checks -load /b/1/llvm-x86_64-debian-dylib/build/./lib/CTTestTidyModule.so 4132569 Done| FileCheck --check-prefix=CHECK-LIST /b/1/llvm-x86_64-debian-dylib/llvm-project/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp -- ``` https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` running on `premerge-linux-1` while building `clang-tools-extra` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/39212 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) ... PASS: lld :: COFF/export-exe.test (98894 of 101873) PASS: lld :: COFF/export-armnt.yaml (98895 of 101873) PASS: lit :: discovery.py (98896 of 101873) PASS: lld :: COFF/entry-inference-mingw.s (98897 of 101873) PASS: lld :: COFF/deploadflag-cfg-x64.s (98898 of 101873) PASS: lld :: COFF/filename-casing.s (98899 of 101873) PASS: cfi-devirt-lld-thinlto-x86_64 :: cross-dso/icall/dlopen.cpp (98900 of 101873) PASS: lld :: COFF/exportas.test (98901 of 101873) PASS: lld :: COFF/driver-opt.s (98902 of 101873) TIMEOUT: MLIR :: Examples/standalone/test.toy (98903 of 101873) TEST 'MLIR :: Examples/standalone/test.toy' FAILED Exit Code: 1 Timeout: Reached timeout of 60 seconds Command Output (stdout): -- # RUN: at line 1 "/etc/cmake/bin/cmake" "/build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone" -G "Ninja" -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE="/usr/bin/python3.10" # executed command: /etc/cmake/bin/cmake /build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE=/usr/bin/python3.10 # .---command stdout # | -- The CXX compiler identification is Clang 16.0.6 # | -- The C compiler identification is Clang 16.0.6 # | -- Detecting CXX compiler ABI info # | -- Detecting CXX compiler ABI info - done # | -- Check for working CXX compiler: /usr/bin/clang++ - skipped # | -- Detecting CXX compile features # | -- Detecting CXX compile features - done # | -- Detecting C compiler ABI info # | -- Detecting C compiler ABI info - done # | -- Check for working C compiler: /usr/bin/clang - skipped # | -- Detecting C compile features # | -- Detecting C compile features - done # | -- Looking for histedit.h # | -- Looking for histedit.h - found # | -- Found LibEdit: /usr/include (found version "2.11") # | -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") # | -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") # | -- Using MLIRConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir # | -- Using LLVMConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/llvm # | -- Linker detection: unknown # | -- Performing Test LLVM_LIBSTDCXX_MIN # | -- Performing Test LLVM_LIBSTDCXX_MIN - Success # | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR # | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success # | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER # | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Success # | -- Performing Test C_SUPPORTS_FPIC # | -- Performing Test C_SUPPORTS_FPIC - Success # | -- Performing Test CXX_SUPPORTS_FPIC ``` https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar closed https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/14] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/13] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -29,6 +30,8 @@ class LLVMModule : public ClangTidyModule {
"llvm-else-after-return");
CheckFactories.registerCheck("llvm-header-guard");
CheckFactories.registerCheck("llvm-include-order");
+CheckFactories.registerCheck(
+"llvm-use-new-mlir-op-builder");
vbvictor wrote:
Make in alphabetical order by check name.
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,132 @@ +//===--- MLIROpBuilderCheck.cpp - clang-tidy --===// vbvictor wrote: ```suggestion //===--- UseNewMLIROpBuilderCheck.cpp - clang-tidy ===// ``` https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -14,6 +14,7 @@ #include "../readability/QualifiedAutoCheck.h" #include "HeaderGuardCheck.h" #include "IncludeOrderCheck.h" +#include "MLIROpBuilderCheck.h" vbvictor wrote: Please rename `MLIROpBuilderCheck.h` -> `UseNewMLIROpBuilderCheck.h` And make in alphabetical order by check name. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -7,6 +7,7 @@ add_clang_library(clangTidyLLVMModule STATIC HeaderGuardCheck.cpp IncludeOrderCheck.cpp LLVMTidyModule.cpp + MLIROpBuilderCheck.cpp vbvictor wrote: Please rename `MLIROpBuilderCheck.cpp` -> `UseNewMLIROpBuilderCheck.cpp` And make in alphabetical order by check name. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor commented: Please rename all files/classes to use `UseNewMLIROpBuilder` as the new check name, otherwise LGTM https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/12] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/12] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy --match-partial-fixes %s
llvm-use-new-mlir-op-builder %t
+
+namespace mlir {
+class Location {};
+class OpBuilder {
+public:
+ template
+ OpTy create(Location location, Args &&...args) {
+return OpTy(args...);
+ }
+ Location getUnknownLoc() { return Location(); }
+};
+class ImplicitLocOpBuilder : public OpBuilder {
+public:
+ template
+ OpTy create(Args &&...args) {
+return OpTy(args...);
+ }
+};
+struct ModuleOp {
+ ModuleOp() {}
+ static ModuleOp create(OpBuilder &builder, Location location) {
+return ModuleOp();
+ }
+};
+struct NamedOp {
+ NamedOp(const char* name) {}
+ static NamedOp create(OpBuilder &builder, Location location, const char*
name) {
+return NamedOp(name);
+ }
+};
+} // namespace mlir
+
+#define ASSIGN(A, B, C, D) A = B.create(B.getUnknownLoc(), D)
+
+template
+void g(mlir::OpBuilder &b) {
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use OpType::create(builder, ...)
instead of builder.create(...) [llvm-use-new-mlir-op-builder]
jpienaar wrote:
Fixed, thanks
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy --match-partial-fixes %s llvm-mlir-op-builder %t
+
+namespace mlir {
+class Location {};
+class OpBuilder {
+public:
+ template
+ OpTy create(Location location, Args &&...args) {
+return OpTy(args...);
+ }
+ Location getUnknownLoc() { return Location(); }
+};
+class ImplicitLocOpBuilder : public OpBuilder {
+public:
+ template
+ OpTy create(Args &&...args) {
+return OpTy(args...);
+ }
+};
+struct ModuleOp {
+ ModuleOp() {}
+ static ModuleOp create(OpBuilder &builder, Location location) {
+return ModuleOp();
+ }
+};
+struct NamedOp {
+ NamedOp(const char* name) {}
+ static NamedOp create(OpBuilder &builder, Location location, const char*
name) {
+return NamedOp(name);
+ }
+};
+} // namespace mlir
+
+void f() {
jpienaar wrote:
SGTM, yes it turned out if I redo it as an EditGenerator rather than ASTEdit, I
can at least warn about macros, so that's all I do when encountering.
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/11] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 01/10] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/PiotrZSL approved this pull request. +- LGTM https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy --match-partial-fixes %s
llvm-use-new-mlir-op-builder %t
+
+namespace mlir {
+class Location {};
+class OpBuilder {
+public:
+ template
+ OpTy create(Location location, Args &&...args) {
+return OpTy(args...);
+ }
+ Location getUnknownLoc() { return Location(); }
+};
+class ImplicitLocOpBuilder : public OpBuilder {
+public:
+ template
+ OpTy create(Args &&...args) {
+return OpTy(args...);
+ }
+};
+struct ModuleOp {
+ ModuleOp() {}
+ static ModuleOp create(OpBuilder &builder, Location location) {
+return ModuleOp();
+ }
+};
+struct NamedOp {
+ NamedOp(const char* name) {}
+ static NamedOp create(OpBuilder &builder, Location location, const char*
name) {
+return NamedOp(name);
+ }
+};
+} // namespace mlir
+
+#define ASSIGN(A, B, C, D) A = B.create(B.getUnknownLoc(), D)
+
+template
+void g(mlir::OpBuilder &b) {
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use OpType::create(builder, ...)
instead of builder.create(...) [llvm-use-new-mlir-op-builder]
PiotrZSL wrote:
shoudn't be: 'OpType::create(builder, ...)' ?
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/PiotrZSL edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,21 @@ +.. title:: clang-tidy - llvm-mlir-op-builder + +llvm-mlir-op-builder + + +Checks for uses of MLIR's old/to be deprecated `OpBuilder::create` form +and suggests using `T::create` instead. EugeneZelenko wrote: ```suggestion Checks for uses of MLIR's old/to be deprecated ``OpBuilder::create`` form and suggests using ``T::create`` instead. ``` https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy --match-partial-fixes %s llvm-mlir-op-builder %t
+
+namespace mlir {
+class Location {};
+class OpBuilder {
+public:
+ template
+ OpTy create(Location location, Args &&...args) {
+return OpTy(args...);
+ }
+ Location getUnknownLoc() { return Location(); }
+};
+class ImplicitLocOpBuilder : public OpBuilder {
+public:
+ template
+ OpTy create(Args &&...args) {
+return OpTy(args...);
+ }
+};
+struct ModuleOp {
+ ModuleOp() {}
+ static ModuleOp create(OpBuilder &builder, Location location) {
+return ModuleOp();
+ }
+};
+struct NamedOp {
+ NamedOp(const char* name) {}
+ static NamedOp create(OpBuilder &builder, Location location, const char*
name) {
+return NamedOp(name);
+ }
+};
+} // namespace mlir
+
+void f() {
jpienaar wrote:
For the macro case, the matcher matches, but the rewrite is never attempted.
Its been a few years since I last wrote a clang-tidy check, so not sure why. If
I change to a noopEdit then it is flagged not sure if due to returning an
ASTEdit rather than EditGenerator. Using the latter may be possible, is rather
low level but perhaps possible. Is there a pattern I'm missing here?
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 1/9] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 1/8] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy --match-partial-fixes %s llvm-mlir-op-builder %t
+
+namespace mlir {
+class Location {};
+class OpBuilder {
+public:
+ template
+ OpTy create(Location location, Args &&...args) {
+return OpTy(args...);
+ }
+ Location getUnknownLoc() { return Location(); }
+};
+class ImplicitLocOpBuilder : public OpBuilder {
+public:
+ template
+ OpTy create(Args &&...args) {
+return OpTy(args...);
+ }
+};
+struct ModuleOp {
+ ModuleOp() {}
+ static ModuleOp create(OpBuilder &builder, Location location) {
+return ModuleOp();
+ }
+};
+struct NamedOp {
+ NamedOp(const char* name) {}
+ static NamedOp create(OpBuilder &builder, Location location, const char*
name) {
+return NamedOp(name);
+ }
+};
+} // namespace mlir
+
+void f() {
vbvictor wrote:
Could you add tests with `builder.create`
- inside macros
- inside template functions when template parameter of `create` is dependent.
- when `builder.create` is in multiple lines like:
```cpp
builder.
create(
builder.getUnknownLoc(),
"baz");
```
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,103 @@
+//===--- MLIROpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "MLIROpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/SourceCode.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/Support/Error.h"
+
+namespace clang::tidy::llvm_check {
+namespace {
+
+using namespace ::clang::ast_matchers; // NOLINT: Too many names.
+using namespace ::clang::transformer; // NOLINT: Too many names.
+
+class TypeAsWrittenStencil : public StencilInterface {
+public:
+ explicit TypeAsWrittenStencil(std::string S) : Id(std::move(S)) {}
+ std::string toString() const override {
+return (llvm::Twine("TypeAsWritten(\"") + Id + "\")").str();
+ }
+
+ llvm::Error eval(const MatchFinder::MatchResult &match,
+ std::string *result) const override {
+llvm::Expected n = node(Id)(match);
+if (!n)
+ return n.takeError();
+const SourceRange SrcRange = n->getAsRange();
+if (SrcRange.isInvalid()) {
+ return llvm::make_error(llvm::errc::invalid_argument,
+ "SrcRange is invalid");
+}
+const CharSourceRange Range = n->getTokenRange(SrcRange);
+auto NextToken = [&](std::optional Token) {
+ if (!Token)
+return Token;
+ return clang::Lexer::findNextToken(Token->getLocation(),
+ *match.SourceManager,
+ match.Context->getLangOpts());
+};
+std::optional LessToken = clang::Lexer::findNextToken(
+Range.getBegin(), *match.SourceManager, match.Context->getLangOpts());
+while (LessToken && LessToken->getKind() != clang::tok::less) {
+ LessToken = NextToken(LessToken);
+}
+if (!LessToken) {
+ return llvm::make_error(llvm::errc::invalid_argument,
+ "missing '<' token");
+}
+std::optional EndToken = NextToken(LessToken);
+for (std::optional GreaterToken = NextToken(EndToken);
+ GreaterToken && GreaterToken->getKind() != clang::tok::greater;
+ GreaterToken = NextToken(GreaterToken)) {
+ EndToken = GreaterToken;
+}
+if (!EndToken) {
+ return llvm::make_error(llvm::errc::invalid_argument,
+ "missing '>' token");
+}
+*result += clang::tooling::getText(
+CharSourceRange::getTokenRange(LessToken->getEndLoc(),
+ EndToken->getLastLoc()),
+*match.Context);
+return llvm::Error::success();
+ }
+ std::string Id;
+};
+
+Stencil typeAsWritten(StringRef Id) {
+ // Using this instead of `describe` so that we get the exact same spelling.
+ return std::make_shared(std::string(Id));
+}
+
+RewriteRuleWith mlirOpBuilderCheckRule() {
+ return makeRule(
+ cxxMemberCallExpr(
+ on(expr(hasType(
+ cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"
+ .bind("builder")),
+ callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument(,
+ callee(cxxMethodDecl(hasName("create"
+ .bind("call"),
+ changeTo(cat(typeAsWritten("call"), "::create(", node("builder"), ", ",
+ callArgs("call"), ")")),
+ cat("Use OpType::create(builder, ...) instead of "
+ "builder.create(...)"));
vbvictor wrote:
```suggestion
cat("use 'OpType::create(builder, ...)' instead of "
"'builder.create(...)'"));
```
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,21 @@ +.. title:: clang-tidy - llvm-mlir-op-builder + +llvm-mlir-op-builder + + +Flags usage of old form of invoking create on MLIR's ``OpBuilder`` and suggests +new form. vbvictor wrote: I think we should write why the user should prefer new for, maybe the old one is deprecated? https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,103 @@
+//===--- MLIROpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "MLIROpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/SourceCode.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/Support/Error.h"
+
+namespace clang::tidy::llvm_check {
+namespace {
+
+using namespace ::clang::ast_matchers; // NOLINT: Too many names.
+using namespace ::clang::transformer; // NOLINT: Too many names.
vbvictor wrote:
are NOLINT necessary? AFAIK there should be no `clang-tidy` warnings
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -40,6 +41,7 @@ class LLVMModule : public ClangTidyModule {
CheckFactories.registerCheck(
"llvm-qualified-auto");
CheckFactories.registerCheck("llvm-twine-local");
+CheckFactories.registerCheck("llvm-mlir-op-builder");
vbvictor wrote:
Please place in alphabetic order by check name
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,29 @@
+//===--- MLIROpBuilderCheck.h - clang-tidy --*- C++
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_MLIROPBUILDERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_MLIROPBUILDERCHECK_H
+
+#include "../utils/TransformerClangTidyCheck.h"
+
+namespace clang::tidy::llvm_check {
+
+/// Checks for uses of MLIR's `OpBuilder::create` and suggests using
+/// `T::create` instead.
vbvictor wrote:
Should be in sync with ReleaseNotes and docs
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/vbvictor commented: I think we need a more verbose check name for users to understand what is the check about, e.g. `llvm-prefer-new-mlir-op-builder` `llvm-use-new-mlir-op-builder` `llvm-use-static-function-mlir-op-builder` https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 1/7] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,103 @@
+//===--- MLIROpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "MLIROpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/SourceCode.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/Support/Error.h"
+
+namespace clang::tidy::llvm_check {
+namespace {
+
+using namespace ::clang::ast_matchers; // NOLINT: Too many names.
+using namespace ::clang::transformer; // NOLINT: Too many names.
+
+class TypeAsWrittenStencil : public StencilInterface {
+public:
+ explicit TypeAsWrittenStencil(std::string S) : id(std::move(S)) {}
+ std::string toString() const override {
+return (llvm::Twine("TypeAsWritten(\"") + id + "\")").str();
+ }
+
+ llvm::Error eval(const MatchFinder::MatchResult &match,
+ std::string *result) const override {
+llvm::Expected n = node(id)(match);
+if (!n)
+ return n.takeError();
+SourceRange srcRange = n->getAsRange();
EugeneZelenko wrote:
```suggestion
const SourceRange srcRange = n->getAsRange();
```
Please also run Clang-Tidy on your files: looks like variables naming is not
confirmed to LLVM coding style.
https://github.com/llvm/llvm-project/pull/149148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH 1/6] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
vbvictor wrote: > Something like > https://github.com/llvm/llvm-project/compare/main...jpienaar:llvm-project:cleanout?expand=1 Looks good, that must be the patch needed. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar edited https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: Something like https://github.com/llvm/llvm-project/compare/main...jpienaar:llvm-project:cleanout?expand=1 https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: It seems it has been only https://github.com/llvm/llvm-project/pull/148018 submitted to it and that's not on the 21.x branch, and then its returning it to https://github.com/llvm/llvm-project/blob/3bd3e06f3fe418e24af65457877f40cee0544f9d/clang-tools-extra/docs/ReleaseNotes.rst ? (That is, would clearing it entail returning to this version and moving over the changes for that last commit?) https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
vbvictor wrote: Yes, Tobias didn't have time to make a PR with cleaning release notes. https://discord.com/channels/636084430946959380/654052269301694465/1394963436538040421. At this time of the week, I can't either:( We shouldn't merge anything before release notes update https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: Good question. I think there are a few style things we could flag, but nothing planned. And this current one I'd assume lives for like 6-9 months and then we remove it. Having this flagged on commits to both MLIR & Flang to reduce migration need later. Well I know a couple of downstream projects that would want this too and I'd mass apply this across multiple projects while guarding against new additions before deprecation. I can move to LLVM module and then delete it in like 9 months. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
carlosgalvezp wrote: I agree that a new module seems unnecessary, do we know that it will contain more checks in the future? If not moving to llvm or plugins would perhaps be more suitable. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
jpienaar wrote: I considered placing it in LLVM module instead given part of LLVM project. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
vbvictor wrote: I think we should go through an RFC before creating a new module. TBH, I don't think we need a new module for MLIR in upstream since it is not a widely known thing in C++ community. Would it be viable for MLIR folks to use [plugins](https://clang.llvm.org/extra/clang-tidy/Contributing.html#out-of-tree-check-plugins) or have a dedicated directory with custom checks in MLIR project like libcxx [do](https://github.com/llvm/llvm-project/tree/main/libcxx/test/tools/clang_tidy_checks). https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
llvmbot wrote:
@llvm/pr-subscribers-clang-tools-extra
Author: Jacques Pienaar (jpienaar)
Changes
Moving towards new create method invocation, add check to flag old usage.
---
Full diff: https://github.com/llvm/llvm-project/pull/149148.diff
10 Files Affected:
- (modified) clang-tools-extra/clang-tidy/CMakeLists.txt (+2)
- (modified) clang-tools-extra/clang-tidy/ClangTidyForceLinker.h (+5)
- (added) clang-tools-extra/clang-tidy/mlir/CMakeLists.txt (+28)
- (added) clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp (+39)
- (added) clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp (+102)
- (added) clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h (+21)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5)
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+2)
- (added) clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst (+22)
- (added) clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp (+51)
``diff
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
new file mode 100644
index 0..7521096d5b91d
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar ready_for_review https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From f5d80596c0dc56086b585e9d59afa7472ff16321 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../docs/clang-tidy/checks/list.rst | 2 +
.../clang-tidy/checks/mlir/op-builder.rst | 22
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
10 files changed, 277 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From b24a881d3391e095fbf37f75ef8f0bd8bce12f74 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 28 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
8 files changed, 253 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..7d0b2de1df24c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+ clangTransformer
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int M
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From 11335cdf95fbfe9679f7831d7a726767ed45dac2 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 27 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
8 files changed, 252 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..4c47246cd887d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSourc
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From c9b0b62c612aef1ff9deec748ac89f30749bb445 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 27 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
8 files changed, 252 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..4c47246cd887d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..f542020a0afdd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the ModuleModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSourc
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From 291ca559c2ff55405c00c0db791c9b9fb312cd6c Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/ClangTidyForceLinker.h | 5 +
.../clang-tidy/mlir/CMakeLists.txt| 27 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
7 files changed, 247 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index adde9136ff1dd..3cde93124c6e4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
+// This anchor is used to force the linker to link the MLIRModule.
+extern volatile int MLIRModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination =
+MLIRModuleAnchorSource;
+
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..4c47246cd887d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..75e403f1fab09
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the LLVMTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // n
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From 5c4ab5ae7cb18a3cc81ce0647da62a0d061957d9 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/mlir/CMakeLists.txt| 27 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
6 files changed, 242 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..4c47246cd887d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ MLIRTidyModule.cpp
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..75e403f1fab09
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the LLVMTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
new file mode 100644
index 0..7521096d5b91d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
@@ -0,0 +1,102 @@
+//===--- OpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "OpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transfor
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From 05e7a590273c5e7a34038ded2cf4b6dd5fd6920d Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/mlir/CMakeLists.txt| 26 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
6 files changed, 241 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..380a28a5908c4
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,26 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..75e403f1fab09
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the LLVMTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
new file mode 100644
index 0..7521096d5b91d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
@@ -0,0 +1,102 @@
+//===--- OpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "OpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#i
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated
https://github.com/llvm/llvm-project/pull/149148
>From 99ce9442348dbc2b49f39306c4b16de8fab1203b Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag old usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/mlir/CMakeLists.txt| 26 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
6 files changed, 241 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..380a28a5908c4
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,26 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ OpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..75e403f1fab09
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the LLVMTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
new file mode 100644
index 0..7521096d5b91d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
@@ -0,0 +1,102 @@
+//===--- OpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "OpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#i
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar created
https://github.com/llvm/llvm-project/pull/149148
Moving towards new create method invocation, add check to flag old usage.
>From 311e30ac75c7fcc0a13ad7908cc1eaa1f7cb1e07 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar
Date: Wed, 16 Jul 2025 17:37:53 +
Subject: [PATCH] [clang-tidy] Add MLIR check for old op builder usage.
Moving towards new create method invocation, add check to flag off usage.
---
clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +
.../clang-tidy/mlir/CMakeLists.txt| 26 +
.../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++
.../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++
.../clang-tidy/mlir/OpBuilderCheck.h | 21
.../clang-tidy/checkers/mlir/op_builder.cpp | 51 +
6 files changed, 241 insertions(+)
create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h
create mode 100644
clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 93117cf1d6373..b89003bf6c926 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -66,6 +66,7 @@ add_subdirectory(linuxkernel)
add_subdirectory(llvm)
add_subdirectory(llvmlibc)
add_subdirectory(misc)
+add_subdirectory(mlir)
add_subdirectory(modernize)
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
@@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS
clangTidyLLVMModule
clangTidyLLVMLibcModule
clangTidyMiscModule
+ clangTidyMLIRModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
new file mode 100644
index 0..2d0c969082218
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt
@@ -0,0 +1,26 @@
+set(LLVM_LINK_COMPONENTS
+ FrontendOpenMP
+ Support
+ )
+
+add_clang_library(clangTidyMLIRModule STATIC
+ NewOpBuilderCheck.cpp
+
+ LINK_LIBS
+ clangTidy
+ clangTidyReadabilityModule
+ clangTidyUtils
+
+ DEPENDS
+ omp_gen
+ ClangDriverOptions
+ )
+
+clang_target_link_libraries(clangTidyMLIRModule
+ PRIVATE
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
new file mode 100644
index 0..75e403f1fab09
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp
@@ -0,0 +1,39 @@
+//===--- MLIRTidyModule.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "OpBuilderCheck.h"
+
+namespace clang::tidy {
+namespace mlir_check {
+
+class MLIRModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("mlir-op-builder");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+return Options;
+ }
+};
+
+// Register the LLVMTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("mlir-module",
+ "Adds MLIR lint checks.");
+
+} // namespace mlir_check
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MLIRModule.
+volatile int MLIRModuleAnchorSource = 0; // NOLINT(misc-use-internal-linkage)
+
+} // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
new file mode 100644
index 0..7521096d5b91d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp
@@ -0,0 +1,102 @@
+//===--- OpBuilderCheck.cpp - clang-tidy
--===//
+//
+// 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
+//
+//===--===//
+
+#include "OpBuilderCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/Transf
