clang 24.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 "mlir/IR/BuiltinOps.h"
14#include "mlir/Pass/PassManager.h"
18#include "llvm/Support/TimeProfiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace cir {
22
23/// Map a target triple to the ABI target that drives CallConvLowering.
24/// Returns None for targets whose calling convention is not yet implemented.
25static CallConvTarget getCallConvTarget(const llvm::Triple &triple) {
26 if (triple.getArch() == llvm::Triple::x86_64)
29}
30
31mlir::LogicalResult
32runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirContext,
33 clang::ASTContext &astContext, bool enableVerifier,
34 bool enableIdiomRecognizer, bool enableCIRSimplify,
35 bool enableLibOpt, llvm::StringRef libOptOptions,
36 bool enableCallConvLowering) {
37
38 llvm::TimeTraceScope scope("CIR To CIR Passes");
39
40 mlir::PassManager pm(&mlirContext);
42
43 if (enableCIRSimplify)
44 pm.addPass(mlir::createCIRSimplifyPass());
45
46 if (enableIdiomRecognizer)
48
49 if (enableLibOpt) {
50 auto libOptPass = mlir::createLibOptPass();
51 auto errorHandler = [](const llvm::Twine &) -> mlir::LogicalResult {
52 return mlir::LogicalResult::failure();
53 };
54
55 if (libOptPass->initializeOptions(libOptOptions, errorHandler).failed())
56 return mlir::failure();
57
58 pm.addPass(std::move(libOptPass));
59 }
60
63
64 if (enableCallConvLowering) {
65 // CallConvLowering rewrites signatures and call sites using the classifier,
66 // so it must run after CXXABILowering has lowered C++ ABI types to plain
67 // records the classifier can handle. Only the x86_64 System V classifier
68 // is implemented; other targets are left unchanged.
69 CallConvTarget target =
71 if (target != CallConvTarget::None)
73 target, llvm::abi::X86AVXABILevel::None));
74 }
75
76 pm.addPass(mlir::createLoweringPreparePass(&astContext));
77
78 pm.enableVerifier(enableVerifier);
79 (void)mlir::applyPassManagerCLOptions(pm);
80 return pm.run(theModule);
81}
82
83} // namespace cir
84
85namespace mlir {
86
87void populateCIRPreLoweringPasses(OpPassManager &pm) {
88 pm.addPass(createHoistAllocasPass());
89 pm.addPass(createCIRFlattenCFGPass());
90 pm.addPass(createCIREHABILoweringPass());
91 pm.addPass(createGotoSolverPass());
92}
93
94} // namespace mlir
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:927
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Defines the clang::TargetInfo interface.
static CallConvTarget getCallConvTarget(const llvm::Triple &triple)
Map a target triple to the ABI target that drives CallConvLowering.
Definition CIRPasses.cpp:25
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, clang::ASTContext &astCtx, bool enableVerifier, bool enableIdiomRecognizer, bool enableCIRSimplify, bool enableLibOpt, llvm::StringRef libOptOptions, bool enableCallConvLowering)
Definition CIRPasses.cpp:32
CallConvTarget
The ABI target whose calling-convention rules drive CallConvLowering.
Definition Passes.h:23
std::unique_ptr< Pass > createCallConvLoweringPass()
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()