aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/FrontendTool
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-03-19 09:42:03 -0700
committerGitHub <noreply@github.com>2025-03-19 09:42:03 -0700
commit39ce99589b05ddd43e5c8b7f89ab5bbfda40d2ce (patch)
tree80a08af9b0ed4208d379867d8fe012a2d3ffc86f /clang/lib/FrontendTool
parentcd26dd55959c11c1cd0ea4fe1f07e0fa9cb7a72a (diff)
downloadllvm-39ce99589b05ddd43e5c8b7f89ab5bbfda40d2ce.zip
llvm-39ce99589b05ddd43e5c8b7f89ab5bbfda40d2ce.tar.gz
llvm-39ce99589b05ddd43e5c8b7f89ab5bbfda40d2ce.tar.bz2
[CIR] Upstream cir-canonicalize pass (#131891)
This change introduces the cir-canonicalize pass. This is a simple cir-to-cir transformation that eliminates empty scopes and redundant branches. It will be expanded in future changes to simplify other redundant instruction sequences. MLIR verification and mlir-specific command-line option handling is also introduced here.
Diffstat (limited to 'clang/lib/FrontendTool')
-rw-r--r--clang/lib/FrontendTool/CMakeLists.txt9
-rw-r--r--clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp20
2 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/FrontendTool/CMakeLists.txt b/clang/lib/FrontendTool/CMakeLists.txt
index 7c83086..061e54c 100644
--- a/clang/lib/FrontendTool/CMakeLists.txt
+++ b/clang/lib/FrontendTool/CMakeLists.txt
@@ -20,8 +20,17 @@ if(CLANG_ENABLE_CIR)
)
list(APPEND link_libs
clangCIRFrontendAction
+ MLIRCIRTransforms
MLIRIR
+ MLIRPass
)
+ list(APPEND deps
+ MLIRBuiltinLocationAttributesIncGen
+ MLIRBuiltinTypeInterfacesIncGen
+ )
+
+ include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
+ include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
endif()
if(CLANG_ENABLE_STATIC_ANALYZER)
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index bb3bb0a..6fc587f 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -32,6 +32,10 @@
#include "llvm/Support/ErrorHandling.h"
#if CLANG_ENABLE_CIR
+#include "mlir/IR/AsmState.h"
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
+#include "clang/CIR/Dialect/Passes.h"
#include "clang/CIR/FrontendAction/CIRGenAction.h"
#endif
@@ -270,6 +274,22 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
}
#endif
+#if CLANG_ENABLE_CIR
+ if (!Clang->getFrontendOpts().MLIRArgs.empty()) {
+ mlir::registerCIRPasses();
+ mlir::registerMLIRContextCLOptions();
+ mlir::registerPassManagerCLOptions();
+ mlir::registerAsmPrinterCLOptions();
+ unsigned NumArgs = Clang->getFrontendOpts().MLIRArgs.size();
+ auto Args = std::make_unique<const char *[]>(NumArgs + 2);
+ Args[0] = "clang (MLIR option parsing)";
+ for (unsigned i = 0; i != NumArgs; ++i)
+ Args[i + 1] = Clang->getFrontendOpts().MLIRArgs[i].c_str();
+ Args[NumArgs + 1] = nullptr;
+ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
+ }
+#endif
+
// If there were errors in processing arguments, don't do anything else.
if (Clang->getDiagnostics().hasErrorOccurred())
return false;