| 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" |
| 16 |
#include "clang/CIR/Dialect/Passes.h" |
| 17 |
#include "llvm/Support/TimeProfiler.h" |
| 18 |
|
| 19 |
namespace cir { |
| 20 |
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, |
| 21 |
mlir::MLIRContext &mlirContext, |
| 22 |
clang::ASTContext &astContext, |
| 23 |
bool enableVerifier, |
| 24 |
bool enableCIRSimplify) { |
| 25 |
|
| 26 |
llvm::TimeTraceScope scope("CIR To CIR Passes"); |
| 27 |
|
| 28 |
mlir::PassManager pm(&mlirContext); |
| 29 |
pm.addPass(mlir::createCIRCanonicalizePass()); |
| 30 |
|
| 31 |
if (enableCIRSimplify) |
| 32 |
pm.addPass(mlir::createCIRSimplifyPass()); |
| 33 |
|
| 34 |
pm.addPass(mlir::createCXXABILoweringPass()); |
| 35 |
pm.addPass(mlir::createLoweringPreparePass(&astContext)); |
| 36 |
|
| 37 |
pm.enableVerifier(enableVerifier); |
| 38 |
(void)mlir::applyPassManagerCLOptions(pm); |
| 39 |
return pm.run(theModule); |
| 40 |
} |
| 41 |
|
| 42 |
} // namespace cir |
| 43 |
|
| 44 |
namespace mlir { |
| 45 |
|
| 46 |
void populateCIRPreLoweringPasses(OpPassManager &pm) { |
| 47 |
pm.addPass(createHoistAllocasPass()); |
| 48 |
pm.addPass(createCIRFlattenCFGPass()); |
| 49 |
pm.addPass(createGotoSolverPass()); |
| 50 |
} |
| 51 |
|
| 52 |
} // namespace mlir |