13#include "mlir/IR/BuiltinOps.h"
14#include "mlir/Pass/PassManager.h"
18#include "llvm/Support/TimeProfiler.h"
19#include "llvm/TargetParser/Triple.h"
27 if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindowsOrUEFI())
36 return llvm::abi::X86AVXABILevel::AVX512;
38 return llvm::abi::X86AVXABILevel::AVX;
39 return llvm::abi::X86AVXABILevel::None;
47 return !triple.isPS() && compat > clang::LangOptions::ClangABI::Ver23;
55static llvm::abi::X86ABICompatInfo
58 llvm::abi::X86ABICompatInfo abiCompat;
59 abiCompat.HonorsRevision98 = !triple.isOSDarwin();
60 abiCompat.ClassifyIntegerMMXAsSSE =
61 compat > clang::LangOptions::ClangABI::Ver3_8 && !triple.isOSDarwin() &&
62 !triple.isPS() && !triple.isOSFreeBSD();
63 abiCompat.PassInt128VectorsInMem =
64 compat > clang::LangOptions::ClangABI::Ver9 &&
65 (triple.isOSLinux() || triple.isOSNetBSD());
66 abiCompat.ReturnCXXRecordGreaterThan128InMem =
67 compat > clang::LangOptions::ClangABI::Ver20 && !triple.isPS();
68 abiCompat.Clang11Compat =
69 compat <= clang::LangOptions::ClangABI::Ver11 || triple.isPS();
75 bool enableVerifier,
bool enableIdiomRecognizer,
76 bool enableCIRSimplify,
bool enableLibOpt,
77 llvm::StringRef libOptOptions,
bool enableCallConvLowering) {
79 llvm::TimeTraceScope scope(
"CIR To CIR Passes");
81 auto tripleAttr = theModule->getAttrOfType<mlir::StringAttr>(
82 cir::CIRDialect::getTripleAttrName());
84 return theModule.emitError()
85 <<
"missing '" << cir::CIRDialect::getTripleAttrName()
87 llvm::Triple triple(tripleAttr.getValue());
89 auto abiAttr = theModule->getAttrOfType<mlir::StringAttr>(
90 cir::CIRDialect::getTargetABIAttrName());
92 return theModule.emitError()
93 <<
"missing '" << cir::CIRDialect::getTargetABIAttrName()
96 mlir::PassManager pm(&mlirContext);
99 if (enableCIRSimplify)
102 if (enableIdiomRecognizer)
107 auto errorHandler = [](
const llvm::Twine &) -> mlir::LogicalResult {
108 return mlir::LogicalResult::failure();
111 if (libOptPass->initializeOptions(libOptOptions, errorHandler).failed())
112 return mlir::failure();
114 pm.addPass(std::move(libOptPass));
126 if (enableCallConvLowering) {
138 auto compat = clang::LangOptions::ClangABI::Latest;
139 if (
auto loweringLangOpts =
140 theModule->getAttrOfType<cir::LoweringLangOptionsAttr>(
141 cir::CIRDialect::getLoweringLangOptionsAttrName()))
143 loweringLangOpts.getClangAbiCompat());
151 pm.enableVerifier(enableVerifier);
152 (void)mlir::applyPassManagerCLOptions(pm);
153 return pm.run(theModule);
Defines the clang::LangOptions interface.
ClangABI
Clang versions with different platform ABI conformance.
static bool allowsX86TargetAttrAvx(const llvm::Triple &triple, clang::LangOptions::ClangABI compat)
Whether __attribute__((target(...))) on a function may raise its AVX ABI level above the command line...
static CallConvTarget getCallConvTarget(const llvm::Triple &triple)
Map a target triple to the ABI target that drives CallConvLowering.
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, bool enableVerifier, bool enableIdiomRecognizer, bool enableCIRSimplify, bool enableLibOpt, llvm::StringRef libOptOptions, bool enableCallConvLowering)
static llvm::abi::X86AVXABILevel getX86AVXABILevel(llvm::StringRef abi)
The AVX level the classifier uses to size a native vector, read from the target ABI name.
static llvm::abi::X86ABICompatInfo getX86ABICompatInfo(const llvm::Triple &triple, clang::LangOptions::ClangABI compat)
The x86_64 ABI-compatibility flags, derived from the target and the requested compatibility version.
CallConvTarget
The ABI target whose calling-convention rules drive CallConvLowering.
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()
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()