xref: /freebsd/contrib/llvm-project/clang/lib/CIR/Lowering/CIRPasses.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric //
9*700637cbSDimitry Andric // This file implements machinery for any CIR <-> CIR passes used by clang.
10*700637cbSDimitry Andric //
11*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
12*700637cbSDimitry Andric 
13*700637cbSDimitry Andric // #include "clang/AST/ASTContext.h"
14*700637cbSDimitry Andric #include "mlir/IR/BuiltinOps.h"
15*700637cbSDimitry Andric #include "mlir/Pass/PassManager.h"
16*700637cbSDimitry Andric #include "clang/CIR/Dialect/Passes.h"
17*700637cbSDimitry Andric #include "llvm/Support/TimeProfiler.h"
18*700637cbSDimitry Andric 
19*700637cbSDimitry Andric namespace cir {
runCIRToCIRPasses(mlir::ModuleOp theModule,mlir::MLIRContext & mlirContext,clang::ASTContext & astContext,bool enableVerifier,bool enableCIRSimplify)20*700637cbSDimitry Andric mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
21*700637cbSDimitry Andric                                       mlir::MLIRContext &mlirContext,
22*700637cbSDimitry Andric                                       clang::ASTContext &astContext,
23*700637cbSDimitry Andric                                       bool enableVerifier,
24*700637cbSDimitry Andric                                       bool enableCIRSimplify) {
25*700637cbSDimitry Andric 
26*700637cbSDimitry Andric   llvm::TimeTraceScope scope("CIR To CIR Passes");
27*700637cbSDimitry Andric 
28*700637cbSDimitry Andric   mlir::PassManager pm(&mlirContext);
29*700637cbSDimitry Andric   pm.addPass(mlir::createCIRCanonicalizePass());
30*700637cbSDimitry Andric 
31*700637cbSDimitry Andric   if (enableCIRSimplify)
32*700637cbSDimitry Andric     pm.addPass(mlir::createCIRSimplifyPass());
33*700637cbSDimitry Andric 
34*700637cbSDimitry Andric   pm.addPass(mlir::createLoweringPreparePass());
35*700637cbSDimitry Andric 
36*700637cbSDimitry Andric   pm.enableVerifier(enableVerifier);
37*700637cbSDimitry Andric   (void)mlir::applyPassManagerCLOptions(pm);
38*700637cbSDimitry Andric   return pm.run(theModule);
39*700637cbSDimitry Andric }
40*700637cbSDimitry Andric 
41*700637cbSDimitry Andric } // namespace cir
42*700637cbSDimitry Andric 
43*700637cbSDimitry Andric namespace mlir {
44*700637cbSDimitry Andric 
populateCIRPreLoweringPasses(OpPassManager & pm)45*700637cbSDimitry Andric void populateCIRPreLoweringPasses(OpPassManager &pm) {
46*700637cbSDimitry Andric   pm.addPass(createHoistAllocasPass());
47*700637cbSDimitry Andric   pm.addPass(createCIRFlattenCFGPass());
48*700637cbSDimitry Andric }
49*700637cbSDimitry Andric 
50*700637cbSDimitry Andric } // namespace mlir
51