clang 23.0.0git
CIRPasses.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements machinery for any CIR <-> CIR passes used by clang.
10//
11//===----------------------------------------------------------------------===//
12
13// #include "clang/AST/ASTContext.h"
14#include "mlir/IR/BuiltinOps.h"
15#include "mlir/Pass/PassManager.h"
17#include "llvm/Support/TimeProfiler.h"
18
19namespace cir {
20
21mlir::LogicalResult
22runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirContext,
23 clang::ASTContext &astContext, bool enableVerifier,
24 bool enableIdiomRecognizer, bool enableCIRSimplify,
25 bool enableLibOpt, llvm::StringRef libOptOptions) {
26
27 llvm::TimeTraceScope scope("CIR To CIR Passes");
28
29 mlir::PassManager pm(&mlirContext);
31
32 if (enableCIRSimplify)
33 pm.addPass(mlir::createCIRSimplifyPass());
34
35 if (enableIdiomRecognizer)
36 pm.addPass(mlir::createIdiomRecognizerPass(&astContext));
37
38 if (enableLibOpt) {
39 auto libOptPass = mlir::createLibOptPass();
40 auto errorHandler = [](const llvm::Twine &) -> mlir::LogicalResult {
41 return mlir::LogicalResult::failure();
42 };
43
44 if (libOptPass->initializeOptions(libOptOptions, errorHandler).failed())
45 return mlir::failure();
46
47 pm.addPass(std::move(libOptPass));
48 }
49
52 pm.addPass(mlir::createLoweringPreparePass(&astContext));
53
54 pm.enableVerifier(enableVerifier);
55 (void)mlir::applyPassManagerCLOptions(pm);
56 return pm.run(theModule);
57}
58
59} // namespace cir
60
61namespace mlir {
62
63void populateCIRPreLoweringPasses(OpPassManager &pm) {
64 pm.addPass(createHoistAllocasPass());
65 pm.addPass(createCIRFlattenCFGPass());
66 pm.addPass(createCIREHABILoweringPass());
67 pm.addPass(createGotoSolverPass());
68}
69
70} // namespace mlir
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, clang::ASTContext &astCtx, bool enableVerifier, bool enableIdiomRecognizer, bool enableCIRSimplify, bool enableLibOpt, llvm::StringRef libOptOptions)
Definition CIRPasses.cpp:22
std::unique_ptr< Pass > createCIREHABILoweringPass()
std::unique_ptr< Pass > createCIRCanonicalizePass()
std::unique_ptr< Pass > createCIRFlattenCFGPass()
std::unique_ptr< Pass > createLibOptPass()
Definition LibOpt.cpp:75
std::unique_ptr< Pass > createIdiomRecognizerPass()
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm)
std::unique_ptr< Pass > createTargetLoweringPass()
std::unique_ptr< Pass > createGotoSolverPass()
std::unique_ptr< Pass > createLoweringPreparePass()
std::unique_ptr< Pass > createCIRSimplifyPass()
std::unique_ptr< Pass > createCXXABILoweringPass()
std::unique_ptr< Pass > createHoistAllocasPass()